private void replaceReferences(CodeUnit originCu, int opIndex) {
		Address resultAddress = originToResultTranslator.getAddress(originCu.getMinAddress());
		CodeUnit resultCu = resultListing.getCodeUnitAt(resultAddress);
		if (opIndex > resultCu.getNumOperands()) {
			return;
		}
		ReferenceManager resultRM = resultProgram.getReferenceManager();
		Reference[] resultRefs = resultRM.getReferencesFrom(resultCu.getMinAddress(), opIndex);
		Reference[] originRefs = originProgram.getReferenceManager()
				.getReferencesFrom(originCu.getMinAddress(), opIndex);
		HashMap<Reference, Reference> resultsToKeep = new HashMap<>(); // key=OriginRef, value=ResultRef
		// Determine the result references to keep that match the origin references.
		for (Reference originRef : originRefs) {
			Reference resultRef = DiffUtility.getReference(originToResultTranslator, originRef);
			resultsToKeep.put(originRef, resultRef); // resultRef may be null
		}
		// Remove references we don't need any more or those that are there but not the same.
		for (Reference resultRef : resultRefs) {
			if (!resultsToKeep.containsValue(resultRef)) {
				resultRM.delete(resultRef);
			}
		}
		// Add the references that aren't there yet and those that weren't the same.
		for (Reference originRef : resultsToKeep.keySet()) {
			Reference resultRef = resultsToKeep.get(originRef);
			replaceReference(resultRef, originRef);
		}
	}
<CODE>mergeReferences</CODE> merges the references in
program1 for the specified address set with the references from program2.
If an equivalent reference already exists then it is updated to match the
new reference if possible. A merge of references prevents the loss of any
non-default references already in the result program.
<br> Important: Fallthrough references will not be merged by this method.
Fallthroughs are handled by merging code units.
<br> Note: All reference types (memory, stack, external) get replaced
where possible. i.e. If a function or variable doesn't exist for a
variable reference then it will not be able to replace the reference.

@param originAddressSet the addresses to be merged.
The addresses in this set should be derived from the origin program.
@param onlyKeepDefaults true indicates to merge only the default references
from the origin program into the result program. Non-default references will not be merged.
false indicates merge all references except fallthroughs.
@param monitor the task monitor for notifying the user of this merge's
progress.
@throws CancelledException if the user cancels the replace via the monitor.
@throws UnsupportedOperationException if the ProgramMerge translators are not
"one for one translators".
Ghidra/Features/Base/src/main/java/ghidra/program/util/ProgramMerge.java