private void addReferencesForInstruction(InstructionDB inst) {

		List<Reference> oldRefList = null;
		if (redisassemblyMode) {
			for (Reference ref : refManager.getReferencesFrom(inst.getMinAddress())) {
				if (ref.getSource() != SourceType.DEFAULT || !ref.isMemoryReference()) {
					continue;
				}
				if (oldRefList == null) {
					oldRefList = new ArrayList<>();
				}
				oldRefList.add(ref);
			}
		}

		InstructionPrototype prototype = inst.getPrototype();

		Address[] flowAddrs = prototype.getFlows(inst);
		int remainingAddrs = flowAddrs.length;

		int opCount = prototype.getNumOperands();
		for (int opIndex = 0; opIndex < opCount; opIndex++) {
			// don't go through the instruction, go to the prototype,
			//  we only want the addresses reported by the prototype,
			//  not any addresses that are added by the user.
			int refCnt = 0;

			Reference operandPrimaryRef = null;

			// First look through the pieces of the operand to find the addresses
			ArrayList<Object> opList = prototype.getOpRepresentationList(opIndex, inst);
			for (Object obj : opList) {
				if (obj instanceof Address) {
					Address refAddr = (Address) obj;
					++refCnt;
					RefType refType =
						getOperandMemoryReferenceType(inst, opIndex, flowAddrs, refAddr);
					if (refType != null) {
						operandPrimaryRef = addDefaultMemoryReferenceIfMissing(inst, opIndex,
							refAddr, refType, oldRefList, operandPrimaryRef);
						--remainingAddrs;
					}
				}
			}
			// If there are still more addresses on this operand, see if the whole operand has any
			if (refCnt == 0 && remainingAddrs > 0) {
				Address refAddr = prototype.getAddress(opIndex, inst);
				if (refAddr != null) {
					RefType refType =
						getOperandMemoryReferenceType(inst, opIndex, flowAddrs, refAddr);
					if (refType != null) {
						operandPrimaryRef = addDefaultMemoryReferenceIfMissing(inst, opIndex,
							refAddr, refType, oldRefList, operandPrimaryRef);
						--remainingAddrs;
					}
				}
			}

			if (operandPrimaryRef != null && !operandPrimaryRef.isPrimary()) {
				// ensure that we have a primary ref on the operand if one exists
				refManager.setPrimary(operandPrimaryRef, true);
			}
		}

		Reference mnemonicPrimaryRef = null;

		for (Address flowAddr : flowAddrs) {
			if (flowAddr != null && flowAddr.isMemoryAddress()) {
				FlowType flowType = RefTypeFactory.getDefaultFlowType(inst, flowAddr, false);
				if (flowType == null) {
					flowType = RefType.INVALID;
				}
				// Only remove jump reference if the function flowtype says it has a fallthrough
				//   Removing the branch to next address if instruction has no fallthrough causes
				//   flow following issues, for example creating a function body.
				boolean isFallthrough =
					(flowType.isJump() && flowAddr.equals(inst.getMaxAddress().next())) &&
						inst.hasFallthrough();

				if (!isFallthrough) {
					mnemonicPrimaryRef = addDefaultMemoryReferenceIfMissing(inst,
						Reference.MNEMONIC, flowAddr, flowType, oldRefList, mnemonicPrimaryRef);
				}
			}
		}

		if (mnemonicPrimaryRef != null && !mnemonicPrimaryRef.isPrimary()) {
			// ensure that we have a primary ref on the mnemonic if one exists
			refManager.setPrimary(mnemonicPrimaryRef, true);
		}

		if (oldRefList != null && !oldRefList.isEmpty()) {
			for (Reference ref : oldRefList) {
				refManager.delete(ref);
			}
		}
	}
Updates the default references for a new or updated instruction.
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/database/code/CodeManager.java