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.
Definition AccessMap_II_Property  (j12 j23 j12' :meminj) (m1 m1' m2 : mem)
(AM:ZMap.t (Z -> perm_kind -> option permission)):Prop :=
forall b2,
(Mem.valid_block m2 b2 -> forall k ofs2,
match j23 b2 with
None => PMap.get b2 AM ofs2 k  = PMap.get b2 m2.(Mem.mem_access) ofs2 k
| Some (b3,d3) =>
match source j12 m1 b2 ofs2 with
Some(b1,ofs1) =>  PMap.get b2 AM ofs2 k =
PMap.get b1 m1'.(Mem.mem_access) ofs1 k
| None =>  PMap.get b2 AM ofs2 k =
PMap.get b2 m2.(Mem.mem_access) ofs2 k
end
end)
/\ (~ Mem.valid_block m2 b2 -> forall k ofs2,
match source j12' m1' b2 ofs2 with
Some(b1,ofs1) => PMap.get b2 AM ofs2 k =
PMap.get b1 m1'.(Mem.mem_access) ofs1 k
| None =>  PMap.get b2 AM ofs2 k = None
end).
Definition Content_II_Property (j12 j12' j23':meminj) (m1 m1' m2:Mem.mem)
(CM:ZMap.t (ZMap.t memval)):=
forall b2,
(Mem.valid_block m2 b2 -> forall ofs2,
match source j12 m1 b2 ofs2 with
Some(b1,ofs1) =>
match j23' b2 with
None => ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
| Some(b3,ofs3) =>
ZMap.get ofs2 (PMap.get b2 CM) =
inject_memval j12'
(ZMap.get ofs1 (PMap.get b1 m1'.(Mem.mem_contents)))
end
| None => ZMap.get ofs2 (PMap.get b2 CM) =
ZMap.get ofs2 (PMap.get b2 m2.(Mem.mem_contents))
end)
/\ (~ Mem.valid_block m2 b2 -> forall ofs2,
match source j12' m1' b2 ofs2 with
None => ZMap.get ofs2 (PMap.get b2 CM) =Undef
| Some(b1,ofs1) =>
ZMap.get ofs2 (PMap.get b2 CM) =
inject_memval j12'
(ZMap.get ofs1 (PMap.get b1 m1'.(Mem.mem_contents)))
end)
/\ fst CM !! b2 = Undef.

Lemma cont_split: forall m b (A B Q: Prop)
(SPLIT: (Mem.valid_block m b  -> A) /\ (~Mem.valid_block m b -> B) /\ Q)
(P:Prop)
(HA: Mem.valid_block m b -> A -> Q -> P)
(HB: ~Mem.valid_block m b -> B -> Q -> P), P.