Fixpoint mkInjectionsN (N:nat)(n1 n2:block)(j k l: meminj)
:  meminj * meminj * block * block :=
match N with O => (j,k,n1,n2)
| S M => mkInjectionsN M (Pos.succ n1) (Pos.succ n2)
(fun b => if eq_block b n1
then Some (n2,0)
else j b)
(fun b => if eq_block b n2 then l n1 else k b)
l
end.
Definition mkInjections (m1 m1' m2:mem) (j k l: meminj)
:  meminj * meminj * block * block :=
if plt (Mem.nextblock m1) (Mem.nextblock m1')
then mkInjectionsN (Pos.to_nat (Mem.nextblock m1') - Pos.to_nat(Mem.nextblock m1))
(Mem.nextblock m1)
(Mem.nextblock m2) j k l
else (j,k,Mem.nextblock m1,Mem.nextblock m2).
Definition removeUndefs (j l j':meminj):meminj :=
fun b => match j b with
None => match l b with
None => None | Some (b1,delta1) => j' b
end
| Some(b2,delta2) => Some(b2, delta2)
end.
Definition inject_memval (j:meminj) (v:memval): memval :=
match v with
Pointer b ofs n =>
match j b with
None => Undef
| Some(b',delta) => Pointer b' (Int.add ofs (Int.repr delta)) n
end
| _ => v
end.

Lemma inject_memval_memval_inject: forall j v v'
(IM: inject_memval j v = v') (U: v' <> Undef), memval_inject j v v'.