Section RENUMBER.
Variable f: PTree.t positive.
Hypothesis f_inj: forall x1 x2 y, f!x1 = Some y -> f!x2 = Some y -> x1 = x2.
End RENUMBER.
Definition pnum (f: function) := postorder (successors_map f) f.(fn_entrypoint).
Definition reach (f: function) (pc: node) := reachable (successors_map f) f.(fn_entrypoint) pc.
Ltac TR_AT :=
match goal with
| [ A: (fn_code _)!_ = Some _ , B: reach _ _ |- _ ] =>
generalize (transf_function_at _ _ _ A B); simpl renum_instr; intros
end.
Inductive match_frames: RTL.stackframe -> RTL.stackframe -> Prop :=
| match_frames_intro: forall res f sp pc rs
(REACH: reach f pc),
match_frames (Stackframe res f sp pc rs)
(Stackframe res (transf_function f) sp (renum_pc (pnum f) pc) rs).
Inductive match_states: RTL.state -> RTL.state -> Prop :=
| match_regular_states: forall stk f sp pc rs m stk'
(STACKS: list_forall2 match_frames stk stk')
(REACH: reach f pc),
match_states (State stk f sp pc rs m)
(State stk' (transf_function f) sp (renum_pc (pnum f) pc) rs m)
| match_callstates: forall stk f args m stk'
(STACKS: list_forall2 match_frames stk stk'),
match_states (Callstate stk f args m)
(Callstate stk' (transf_fundef f) args m)
| match_returnstates: forall stk v m stk'
(STACKS: list_forall2 match_frames stk stk'),
match_states (Returnstate stk v m)
(Returnstate stk' v m).

Theorem transf_program_correct:
forward_simulation (RTL.semantics prog) (RTL.semantics tprog).