public static Address getThunkedAddr(Program program, Address entry,
			boolean checkForSideEffects) {
		// General algorithm:
		//
		// get function, if has no other calls, and no other flow
		// if does no other computation than computing the jump???
		// simple number of instructions?  Specialized for a given processor?
		// Danger that side-effects are not found.
		// All other instruction refs are just reads, and have good addresses?
		// All instructions go into the computation of the jump, simplified away?
		// Put it in the patterns file?
		// small number of instructions, look at pcode, all loads, arith
		// no branching other than final computed jump

		// check if the first instruction is an indirect jump
		Listing listing = program.getListing();

		Instruction instr = listing.getInstructionAt(entry);
		if (instr == null) {
			return null;
		}

		FlowType flowType;

		// Treat single jump or call-return as thunk
		Address simpleFlowAddr = getSimpleFlow(instr);
		if (simpleFlowAddr != null) {
			return simpleFlowAddr;
		}

		// 8-bit registers are normally flag registers
		//   for 16-bit address spaces, the registers may be too small, so don't allow
		//   non-use of an 8-bit register
		boolean allow8bitNonUse = true;
		if (program.getAddressFactory().getDefaultAddressSpace().getSize() <= 16) {
			allow8bitNonUse = false;
		}

		// only go three instructions deep
		// keep a list of outputs and inputs
		// if inputs are used, get rid of them
		// if only output is the PC, and small registers, assume OK
		// any write to memory is bad
		int numInstr = 1;
		HashSet<Varnode> setAtStartRegisters = new HashSet<>();
		HashSet<Varnode> setRegisters = new HashSet<>();
		HashSet<Varnode> usedRegisters = new HashSet<>();

		// add in the registers that are set at the beginning of the function
		addSetRegisters(program, entry, setAtStartRegisters);

		while (instr != null && numInstr++ <= MAX_NUMBER_OF_THUNKING_INSTRUCTIONS) {
			flowType = instr.getFlowType();

			// Keep track of any read/writes to registers, need to see if there are any side-effects
			// check Pcode, any writes to memory are bad
			PcodeOp[] pcode = instr.getPcode(false);
			for (PcodeOp element : pcode) {
				PcodeOp pcodeOp = element;

				// Storing to a location is not allowed for a thunk
				//   as a side-effect of the thunk.
				if (checkForSideEffects && pcodeOp.getOpcode() == PcodeOp.STORE) {
					return null;
				}

				// record any used registers, checking for use of an unexpected unset register
				if (checkForSideEffects && !addRegisterUsage(program, setAtStartRegisters,
					setRegisters, usedRegisters, pcodeOp, allow8bitNonUse)) {
					return null;
				}
			}

			// any instruction with a delay slot is actually a branching instruction.
			//  only do this for instructions that aren't delay slot instructions
			if (instr.isFallthrough() && instr.getDelaySlotDepth() == 0) {
				Address fallAddr = instr.getFallThrough();
				instr = listing.getInstructionAt(fallAddr);
				continue;
			}

			// keep going if flow target is right below, allow only a simple branch.
			if (isLocalBranch(listing, instr, flowType)) {
				continue;
			}

			// reached a flow, end of the line, gotta see what we have
			return getFlowingAddrFromFinalState(program, instr, flowType, checkForSideEffects,
				setRegisters, usedRegisters);
		}

		return null;
	}
Get the address that this function would thunk if it is a valid thunk

@param program the program
@param entry location to check for a thunk
@param checkForSideEffects true if there should be no extra registers affected

@return address that the thunk thunks,Address.NO_ADDRESS if thunk but unknown addr, null otherwise
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java