private Function getExternalFunction(Program program) {

		ExternalManager externalMgr = program.getExternalManager();
		ExternalLocationIterator externalLocations =
			externalMgr.getExternalLocations(referencedFunctionAddr);
		if (!externalLocations.hasNext()) {
			// create new external location
			ExternalLocation extLoc;
			try {
				extLoc = externalMgr.addExtFunction(Library.UNKNOWN, null, referencedFunctionAddr,
					SourceType.DEFAULT);
				Msg.debug(this, "Created new external location for address " +
					referencedFunctionAddr + ": " + extLoc.toString());
			}
			catch (DuplicateNameException | InvalidInputException e) {
				throw new RuntimeException("Unexpected exception", e);
			}
			return extLoc.getFunction();
		}

		ExternalLocation extLoc = externalLocations.next();
		if (extLoc.isFunction()) {
			// found existing external function with same address
			return extLoc.getFunction();
		}

		Msg.debug(this, "Converting external location to a function: " + extLoc.toString());
		return extLoc.createFunction();
	}
Get the first blocks unconditional jump or call destination

@param program program
@param monitor monitor for potentially long operation
@return first blocks unconditional call/jump, null if none in first block
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java