@Override
	public boolean applyTo(Program program, TaskMonitor monitor) {

		FunctionManager functionMgr = program.getFunctionManager();

		if (referencedFunctionAddr == Address.NO_ADDRESS) {
			referencedFunctionAddr = null;
		}

		// TODO: If thunk already exists as a function with a non-default signature (i.e., imported)
		// should we migrate that signature to the thunked function (referencedFunction) if it has
		// a default signature

		thunkFunction = functionMgr.getFunctionAt(entry);
		if (body != null) {
			for (Function f : functionMgr.getFunctions(body, true)) {
				if (f != thunkFunction) {
					setStatusMsg("Specified body overlaps existing function '" + f.getName() +
						"' at " + f.getEntryPoint());
					return false;
				}
			}
		}

		referencedFunction = getReferencedFunction(
			referencedFunctionAddr == null && referencedSymbol == null, program, monitor);
		if (referencedFunction == null) {
			thunkFunction = null;
			return false;
		}
		referencedFunctionAddr = referencedFunction.getEntryPoint();

		if (thunkFunction != null) {
			try {
				thunkFunction.setThunkedFunction(referencedFunction);
			}
			catch (IllegalArgumentException e) {
				setStatusMsg("Invalid thunked function specified: " + e.getMessage());
				return false;
			}
			if (body != null) {
				try {
					thunkFunction.setBody(body);
				}
				catch (OverlappingFunctionException e) {
					setStatusMsg("Specified body overlaps existing function(s): " + e.getMessage());
					return false;
				}
			}
			return true;
		}

		if (program.getListing().getFunctionContaining(entry) != null) {
			setStatusMsg("Thunk function entry contained within another function");
			return false;
		}

		if (body == null) {
			body = computeThunkBody(program);
			if (body == null) {
				return false;
			}
		}
		else if (body.contains(referencedFunctionAddr)) {
			// TODO: This only handles the simple cases of fixing body
			body = body.subtract(referencedFunction.getBody());
			if (body.getNumAddressRanges() != 1 || !body.contains(entry)) {
				return false;
			}
		}

		Namespace namespace = program.getGlobalNamespace();
		String name = null;
		SourceType source = SourceType.DEFAULT;
		Symbol s = program.getSymbolTable().getPrimarySymbol(entry);
		if (s != null) {
			name = s.getName();
			namespace = s.getParentNamespace();
			source = s.getSource();
		}

		try {
			thunkFunction = functionMgr.createThunkFunction(name, namespace, entry, body,
				referencedFunction, source);
		}
		catch (OverlappingFunctionException e) {
			setStatusMsg("Specified body overlaps existing function(s): " + e.getMessage());
			return false;
		}

		return true;
	}
Constructs a new command for creating a thunk function that can compute the function this function is thunking to.

@param entry entry point address for the function to be created.
@param checkForSideEffects true to check for side-effects that indicate it is not a pure thunk.

The body may be computed.  References to the thunked to function may be created.

If no function exists at the location being thunked, it will be created based on the above rules.
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/function/CreateThunkFunctionCmd.java