Out of interest is there a reason for having a single branch-controlling flag for 1/2/3 then doing all this copying and dropping of the flag? Visually it feels simpler if you do something like:
OP_IF
standard thing 1
OP_ELSE
standard thing 2
OP_ENDIF
...and feed it a 1 or 0 as a flag, or for three-branch case:
OP_IF
standard thing 1
OP_ELSE
OP_IF
standard thing 2
OP_ELSE
standard thing 3
OP_ENDIF
OP_ENDIF
...which you would feed either 1 (for the outer first branch) or 0 (for the outer second branch) preceded by 1 or 0 (to pick the inner branch)
PS. Apologies to the OP for hijacking their thread...