@Test
	public void testFlowOverridePrimacy() throws AddressFormatException {
		//verify the instructions needed for the test
		Address callAddr = defaultSpace.getAddress(CALL_PLUS_TWO_100010);
		Instruction call = program.getListing().getInstructionAt(callAddr);
		assertNotNull(call);
		assertEquals("call 0x00100012", call.toString());
		Address addAddr = defaultSpace.getAddress(ADD_R0_R0_100012);
		Instruction add = program.getListing().getInstructionAt(addAddr);
		assertNotNull(add);
		assertEquals("add r0,r0", add.toString());
		Address subAddr = defaultSpace.getAddress(SUB_R0_R0_100014);
		Instruction sub = program.getListing().getInstructionAt(subAddr);
		assertNotNull(sub);
		assertEquals("sub r0,r0", sub.toString());

		//get unmodified Pcode
		PcodeOp[] unmodified = call.getPcode(false);
		assertTrue(unmodified.length == 2);
		assertTrue(unmodified[0].getOpcode() == PcodeOp.COPY); //save return address to lr
		assertTrue(unmodified[1].getOpcode() == PcodeOp.CALL); //perform call

		//verify that requesting overrides has no effect on the pcode before any overrides
		//are applied
		assertTrue(equalPcodeOpArrays(call.getPcode(true), call.getPcode(false)));

		//apply a CALL_OVERRIDE_UNCONDITIONAL reference and verify that it changes the 
		//call target
		//place it on operand 0 so that the default reference to the call target
		//is made not primary
		int id = program.startTransaction("test");
		Reference callOverrideRef = refManager.addMemoryReference(callAddr, func2Addr,
			RefType.CALL_OVERRIDE_UNCONDITIONAL, SourceType.USER_DEFINED, 0);
		refManager.setPrimary(callOverrideRef, true);
		program.endTransaction(id, true);

		PcodeOp[] callOverride = call.getPcode(true);
		assertTrue(callOverride[1].getOpcode() == PcodeOp.CALL);
		assertTrue(callOverride[1].getInput(0).getOffset() == func2Addr.getOffset());

		//deactivate the call override by setting the reference to non-primary
		id = program.startTransaction("test");
		refManager.setPrimary(callOverrideRef, false);
		program.endTransaction(id, true);

		//verify that the pcode is not changed
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(false)));
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(true)));

		//apply flow override
		int tid = program.startTransaction("test");
		call.setFlowOverride(FlowOverride.BRANCH);
		program.endTransaction(tid, true);

		//verify that nothing changes if no overrides are requested
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(false)));
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode()));

		//verify the flow override occurred
		PcodeOp[] flow = call.getPcode(true);
		assertTrue(flow.length == unmodified.length);
		//first op saves the return address to lr; shouldn't change
		assertTrue(equalPcodeOps(unmodified[0], flow[0]));

		//verify that the flow override changed the CALL to a BRANCH
		//and made no other changes
		PcodeOp callOp = unmodified[1];
		PcodeOp branchOp = flow[1];
		assertTrue(branchOp.getOpcode() == PcodeOp.BRANCH);
		assertTrue(equalInputsAndOutput(branchOp, callOp));

		//set the CALL_OVERRIDE_CALL reference to primary
		id = program.startTransaction("test");
		refManager.setPrimary(callOverrideRef, true);
		program.endTransaction(id, true);

		//verify that a primary CALL_OVERRIDE_CALL reference has no effect since
		//the flow override has precedence
		assertTrue(equalPcodeOpArrays(flow, call.getPcode(true)));

		//delete callOverrideRef - no longer needed
		//note: simply setting it to non-primary can cause complications later in
		//this test since removing a flow override updates existing references
		id = program.startTransaction("test");
		refManager.delete(callOverrideRef);
		program.endTransaction(id, true);

		//apply fallthrough override
		tid = program.startTransaction("test");
		call.setFallThrough(subAddr);
		program.endTransaction(tid, true);

		//verify that nothing changes if no overrides are requested
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(false)));
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode()));

		PcodeOp[] flowFallthrough = call.getPcode(true);

		//verify that the first op hasn't changed
		assertTrue(equalPcodeOps(unmodified[0], flowFallthrough[0]));

		//verify that the target of the branch that was a call has changed
		PcodeOp adjustedBranch = flowFallthrough[1];
		assertTrue(Objects.equals(branchOp.getOutput(), adjustedBranch.getOutput()));
		assertTrue(adjustedBranch.getOpcode() == PcodeOp.BRANCH);
		assertTrue(adjustedBranch.getNumInputs() == 1);
		assertTrue(adjustedBranch.getInput(0).isAddress());
		assertTrue(adjustedBranch.getInput(0).getOffset() == subAddr.getOffset());
		assertTrue(branchOp.getInput(0).isAddress());
		assertTrue(branchOp.getInput(0).getOffset() == addAddr.getOffset());

		//verify that exactly one op has been appended
		assertTrue(flowFallthrough.length == unmodified.length + 1);

		//verify the appended branch
		PcodeOp appendedBranch = flowFallthrough[2];
		assertNull(appendedBranch.getOutput());
		assertTrue(appendedBranch.getOpcode() == PcodeOp.BRANCH);
		assertTrue(appendedBranch.getNumInputs() == 1);
		assertTrue(appendedBranch.getInput(0).isAddress());
		assertTrue(appendedBranch.getInput(0).getOffset() == subAddr.getOffset());

		//apply an overriding jump reference
		tid = program.startTransaction("test");
		Reference jumpOverrideRef = refManager.addMemoryReference(callAddr, func1Addr,
			RefType.JUMP_OVERRIDE_UNCONDITIONAL, SourceType.USER_DEFINED, -1);
		refManager.setPrimary(jumpOverrideRef, true);
		program.endTransaction(tid, true);

		//verify that nothing changes if no overrides are requested
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(false)));
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode()));

		//ref should change the appended BRANCH since the fallthrough override has precedence
		//on the adjusted branch
		PcodeOp[] flowFallthroughRef = call.getPcode(true);
		assertEquals(flowFallthroughRef.length, unmodified.length + 1);
		assertTrue(equalPcodeOps(flowFallthrough[0], flowFallthroughRef[0])); //save return address
		assertTrue(equalPcodeOps(flowFallthrough[1], flowFallthroughRef[1])); //adjusted branch
		PcodeOp appended = flowFallthroughRef[2]; //appended branch
		assertNull(appended.getOutput());
		assertTrue(appended.getOpcode() == PcodeOp.BRANCH);
		assertTrue(appended.getNumInputs() == 1);
		assertTrue(appended.getInput(0).isAddress());
		assertTrue(appended.getInput(0).getOffset() == func1Addr.getOffset());

		//remove fallthrough override
		tid = program.startTransaction("test");
		call.clearFallThroughOverride();
		program.endTransaction(tid, true);

		//verify that nothing changes if no overrides are requested
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode(false)));
		assertTrue(equalPcodeOpArrays(unmodified, call.getPcode()));

		PcodeOp[] flowRef = call.getPcode(true);
		assertTrue(flowRef.length == unmodified.length);
		//first op shouldn't change
		assertTrue(equalPcodeOps(flowRef[0], unmodified[0]));

		//overriding jump reference should now change BRANCH from flow override
		PcodeOp refBranch = flowRef[1];
		assertNull(refBranch.getOutput());
		assertTrue(refBranch.getOpcode() == PcodeOp.BRANCH);
		assertTrue(refBranch.getNumInputs() == 1);
		assertTrue(refBranch.getInput(0).isAddress());
		assertTrue(refBranch.getInput(0).getOffset() == func1Addr.getOffset());

		//remove flow override
		tid = program.startTransaction("test");
		call.setFlowOverride(FlowOverride.NONE);
		program.endTransaction(tid, true);

		//overriding jump ref should do nothing since it doesn't apply to CALL ops
		PcodeOp[] ref = call.getPcode(true);
		assertTrue(equalPcodeOpArrays(ref, unmodified));
	}
Tests that pcode ops introduced by a flow override can be affected by fallthrough overrides 
and overriding references.
@throws AddressFormatException if {@code AddressSpace.getAddress} throws it
Ghidra/Test/IntegrationTest/src/test.slow/java/ghidra/program/model/pcode/PcodeEmitContextTest.java