private static int getDestinations(CodeBlock block, LinkedList<CodeBlockReferenceImpl> blockRefQueue, 
    	boolean followIndirectFlows, TaskMonitor monitor) throws CancelledException {
    
    	if (block == null)
            return 0;

		CodeBlockModel m = block.getModel().getBasicBlockModel();
		if (!(m instanceof SimpleBlockModel))
			throw new IllegalArgumentException();	
		SimpleBlockModel model = (SimpleBlockModel)m;
		boolean includeExternals = model.externalsIncluded();
		
		Address start = block.getMinAddress();
		Address end = block.getMaxAddress();
		if (start == null || start.isExternalAddress())
			return 0;
			
		int count = 0;
		Listing listing = model.getListing();
		ReferenceIterator refIter = model.getProgram().getReferenceManager().getReferenceIterator(start);
		Instruction instr = null;
		while (refIter.hasNext()) {

        	if (monitor != null && monitor.isCancelled())
				throw new CancelledException();
				
        	Reference ref = refIter.next();
			Address fromAddr = ref.getFromAddress();
			if (fromAddr.compareTo(end) > 0)
				break;

    		// Examine all flow-type references
    		RefType refType = ref.getReferenceType();
    		if (!(refType.isFlow()))
    			continue;
    		
    		// Handle possible indirection
    		// Indirect flow should be to a data pointer which references code.
    		if (refType == RefType.INDIRECTION) {
				Instruction destInstr = listing.getInstructionContaining(ref.getToAddress());
				int cnt = 0;
    			if (destInstr == null && followIndirectFlows) {
    				if (instr == null || !instr.getMinAddress().equals(fromAddr)) {
						instr = listing.getInstructionAt(fromAddr);
					}
        			cnt = followIndirection(blockRefQueue, includeExternals, block, ref, 
						instr.getFlowType().isCall() ? RefType.COMPUTED_CALL : RefType.COMPUTED_JUMP,
						monitor);
    			}
    			if (cnt == 0) {
    				// Improper indirection - add original reference
    				queueDestReference(
    					blockRefQueue,
    					block, 
            			fromAddr,
            			ref.getToAddress(),
						RefType.INDIRECTION);
            		cnt = 1;
    			}
    			count += cnt;        			
    		}
    		
    		// Handle other FlowType reference
    		else {
    			// Add FlowType references
    			queueDestReference(
    				blockRefQueue, 
    				block,
        			fromAddr,
        			ref.getToAddress(),
        			(FlowType)refType);
        		++count;
    		}
        }
		
		// Check for implied indirection if no destinations were found
		if (followIndirectFlows && count == 0 && block.getFlowType().isComputed()) {
			
			instr = listing.getInstructionContaining(block.getMaxAddress());
	        if (instr != null) {
	        	
	        	// search backwards until a non-delay slot instruction is found
	        	while (instr.isInDelaySlot()) {
		        	Address fallFrom = instr.getFallFrom();
		        	if (fallFrom == null) {
		        	    Msg.warn(SimpleDestReferenceIterator.class, "WARNING: Invalid delay slot instruction found at " + instr.getMinAddress());
		        		break;
		        	}
		        	instr = listing.getInstructionContaining(fallFrom);
		        }
	        	for (Reference ref : instr.getReferencesFrom()) {
	        		count += followIndirection(blockRefQueue, includeExternals, block, ref, 
							instr.getFlowType().isCall() ? RefType.COMPUTED_CALL : RefType.COMPUTED_JUMP,
							monitor);
	        	}
	        }
			
		}
        
        // Check for single fall-through destination
        instr = listing.getInstructionContaining(end);
        if (instr != null) {
        	instr = instr.getNext();
        	if (instr != null) {
        		Address addr = instr.getFallFrom();
        		if (addr != null && addr.compareTo(end) <= 0) {
					queueDestReference(
						blockRefQueue,
						block,
						addr,
						instr.getMinAddress(),
						RefType.FALL_THROUGH);
					++count;
        		}
	        }
        }

		return count;
    }
Count and queue all destination references flowing out of this block.
All Calls from this block, and all external FlowType block references
from this block are counted.

@param block code block to get the number of destination references from.
@param blockRefQueue the CodeBlockReference queue, may be null
@param followIndirectFlows indirect references will only be included if true
@param includeExternals externals will be included if true
@param monitor task monitor which allows user to cancel operation.
@throws CancelledException if the monitor cancels the operation.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/block/SimpleDestReferenceIterator.java