protected void clearAndRepairFlows(Program program, AddressSet repairedCallLocations,
			AddressSet protectedLocs, TaskMonitor monitor) throws CancelledException {
		//ReferenceIterator refIter = program.getReferenceManager().getReferencesTo(entry);
		long numRefs = repairedCallLocations.getNumAddresses();
		int refCnt = 0;

		lastPrimaryStatusMessage = "Repair";
		SubMonitor subMonitor = new SubMonitor(monitor);

		AddressSet clearInstSet = new AddressSet();
		AddressSet clearDataSet = new AddressSet();

		AddressIterator addrIter = repairedCallLocations.getAddresses(true);

		while (addrIter.hasNext()) {
			monitor.checkCancelled();
			monitor.setMaximum(numRefs);
			monitor.setProgress(refCnt++);
			Address fromAddr = addrIter.next();

			Instruction instr = program.getListing().getInstructionAt(fromAddr);
			if (instr == null) {
				continue;
			}
			Address fallthruAddr = instr.getFallThrough();
			if (fallthruAddr == null) {
				try {
					fallthruAddr =
						instr.getMinAddress().addNoWrap(instr.getDefaultFallThroughOffset());
				}
				catch (AddressOverflowException e) {
					// handled below
				}
			}
			if (fallthruAddr == null) {
				continue;
			}
			// if location right below is an entry point, don't clear it
			if (program.getSymbolTable().isExternalEntryPoint(fallthruAddr)) {
				continue;
			}

			// If there is a non-default function below, don't clear
			Function functionBelow = program.getFunctionManager().getFunctionAt(fallthruAddr);
			if (functionBelow != null &&
				functionBelow.getSymbol().getSource() != SourceType.DEFAULT) {
				continue;
			}

			if (!hasFlowRefInto(program, fallthruAddr)) {
				Instruction inst = program.getListing().getInstructionAt(fallthruAddr);
				if (inst != null) {
					clearInstSet.add(fallthruAddr);
				}
				else {
					clearDataSet.add(fallthruAddr);
				}
			}
		}

		program.getBookmarkManager()
				.removeBookmarks(repairedCallLocations, BookmarkType.ERROR, monitor);

		if (!clearInstSet.isEmpty()) {
			// entries including data flow referenced from instructions will be repaired
			AddressSet protect = new AddressSet(repairedCallLocations).union(protectedLocs);
			ClearFlowAndRepairCmd cmd =
				new ClearFlowAndRepairCmd(clearInstSet, protect, true, false, true);
			cmd.applyTo(program, subMonitor);
		}
		if (!clearDataSet.isEmpty()) {
			// entries that are data should not be cleared, only possible bookmarks
			ClearFlowAndRepairCmd.clearBadBookmarks(program, clearDataSet, subMonitor);
		}
	}
Fix the bodies of all functions that called the non-returning function.

@param program containing the functions
@param callLocations that need the bodies of the functions containing them fixed
@param monitor to allow canceling

@return the set of all repaired function entry points

@throws CancelledException
Ghidra/Features/Base/src/main/java/ghidra/app/plugin/core/disassembler/CallFixupAnalyzer.java