public int calculateCyclomaticComplexity(Function function, TaskMonitor monitor)
			throws CancelledException {
		BasicBlockModel basicBlockModel = new BasicBlockModel(function.getProgram());
		CodeBlockIterator codeBlockIterator =
			basicBlockModel.getCodeBlocksContaining(function.getBody(), monitor);
		Address entryPoint = function.getEntryPoint();
		int nodes = 0;
		int edges = 0;
		int exits = 0;
		while (codeBlockIterator.hasNext()) {
			if (monitor.isCancelled()) {
				break;
			}
			CodeBlock codeBlock = codeBlockIterator.next();
			++nodes;
			if (codeBlock.getFlowType().isTerminal()) {
				++exits;
				// strongly connect the exit to the entry point (*)
				++edges;
			}
			CodeBlockReferenceIterator destinations = codeBlock.getDestinations(monitor);
			while (destinations.hasNext()) {
				if (monitor.isCancelled()) {
					break;
				}
				CodeBlockReference reference = destinations.next();
				FlowType flowType = reference.getFlowType();
				if (flowType.isIndirect() || flowType.isCall()) {
					continue;
				}
				++edges;
				if (codeBlock.getFlowType().isTerminal() &&
					reference.getDestinationAddress().equals(entryPoint)) {
					// remove the edge I created since it already exists and was counted above at (*)
					--edges;
				}
			}
		}
		int complexity = edges - nodes + exits;
		return complexity < 0 ? 0 : complexity;
	}
Calculates the cyclomatic complexity of a function by decomposing it into a flow
graph using a BasicBlockModel.
@param function the function
@param monitor a monitor
@return the cyclomatic complexity
@throws CancelledException
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/util/CyclomaticComplexity.java