Require Import VST.floyd.proofauto.
Require Import VST.progs.tree.
Require Import VST.msl.iter_sepcon.
Require Import VST.msl.wand_frame.
Require Import VST.msl.wandQ_frame.

Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.

Definition t_struct_Xnode := Tstruct _Xnode noattr.
Definition t_struct_Xlist := Tstruct _XList noattr.
Definition t_struct_Ynode := Tstruct _Ynode noattr.
Definition t_struct_Ylist := Tstruct _YList noattr.
Definition t_struct_Ytree := Tstruct _BinaryTree noattr.

Section LISTS.
Variable V: Type.

Variable list_cell: V -> val -> val -> mpred.

Fixpoint list_rep (l: list V) (x: val) : mpred :=
 match l with
 | h::hs => 
    EX y:val, list_cell h y x * list_rep hs y
 | nil => 
    !! (x = nullval) && emp
 end.

Lemma list_rep_valid_pointer:
  (forall v q p, list_cell v q p |-- valid_pointer p) ->
  forall l p, list_rep l p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (list_rep l p) (valid_pointer p) *)
  destruct l; simpl; normalize; auto with valid_pointer.
Qed.

Lemma list_rep_local_facts:
  (forall v q p, list_cell v q p |-- !! (isptr p)) ->
  forall l p, list_rep l p |-- !! (is_pointer_or_null p  /\ (p=nullval <-> l=nil)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (list_rep l p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list V) l (@nil V))))) *)
  destruct l; simpl; normalize; entailer!.
  + split; auto.
  + split; intros; try congruence.
(* Goal: @eq tree (T t1 v t2) E *)
    subst; inv Pp.
Qed.

End LISTS.
Arguments list_rep {V} _ _ _.
Arguments list_rep_valid_pointer {V} _ _ _ _ _ _.
Arguments list_rep_local_facts {V} _ _ _ _ _ _.

Section TREES.
Variable V : Type.

Inductive tree : Type :=
 | E : tree
 | T: tree -> V -> tree -> tree.

Variable tree_cell: V -> val -> val -> val -> mpred.

Fixpoint tree_rep (t: tree) (p: val) : mpred :=
 match t with
 | E => !!(p=nullval) && emp
 | T a v b =>
    EX pa:val, EX pb:val,
    tree_cell v pa pb p *
    tree_rep a pa * tree_rep b pb
 end.

Lemma tree_rep_valid_pointer:
  (forall v L R p, tree_cell v L R p |-- valid_pointer p) ->
  forall t p, tree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (valid_pointer p) *)
  destruct t; simpl; normalize; auto with valid_pointer.
Qed.

Lemma tree_rep_local_facts:
  (forall v L R p, tree_cell v L R p |-- !! (isptr p)) ->
  forall t p, tree_rep t p |-- !! (is_pointer_or_null p  /\ (p=nullval <-> t=E)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq YTree t YLeaf)))) *)
  destruct t; simpl; normalize; entailer!.
  + split; auto.
  + split; intros; try congruence.
(* Goal: @eq tree (T t1 v t2) E *)
    subst; inv Pp.
Qed.

End TREES.
Arguments E {V}.
Arguments T {V} _ _ _.
Arguments tree_rep {V} _ _ _.
Arguments tree_rep_valid_pointer {V} _ _ _ _ _ _.
Arguments tree_rep_local_facts {V} _ _ _ _ _ _.

Definition map_tree {V1 V2: Type} (f: V1 -> V2): tree V1 -> tree V2 :=
  fix map_tree (t: tree V1) :=
    match t with
    | E => E
    | T t1 x t2 => T (map_tree t1) (f x) (map_tree t2)
    end.

Section IterTreeSepCon.

  Context {A : Type}.
  Context {B : Type}.
  Context {ND : NatDed A}.
  Context {SL : SepLog A}.
  Context {ClS: ClassicalSep A}.
  Context {CoSL: CorableSepLog A}.
  Context (p : B -> A).

Fixpoint iter_tree_sepcon (t1 : tree B) : A :=
    match t1 with
    | E => emp
    | T a x b => p x * iter_tree_sepcon a * iter_tree_sepcon b
    end.

End IterTreeSepCon.

Section IterTreeSepCon2.

  Context {A : Type}.
  Context {B1 B2 : Type}.
  Context {ND : NatDed A}.
  Context {SL : SepLog A}.
  Context {ClS: ClassicalSep A}.
  Context {CoSL: CorableSepLog A}.
  Context (p : B1 -> B2 -> A).

Fixpoint iter_tree_sepcon2 (t1 : tree B1) : tree B2 -> A :=
    match t1 with
    | E => fun t2 =>
       match t2 with
       | E => emp
       | _ => FF
       end
    | T xa x xb => fun t2 =>
       match t2 with
       | E => FF
       | T ya y yb => p x y * iter_tree_sepcon2 xa ya * iter_tree_sepcon2 xb yb
       end
  end.

Lemma iter_tree_sepcon2_spec: forall tl1 tl2,
  iter_tree_sepcon2 tl1 tl2 =
  EX tl: tree (B1 * B2),
  !! (tl1 = map_tree fst tl /\ tl2 = map_tree snd tl) &&
  iter_tree_sepcon (uncurry p) tl.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @eq A (iter_tree_sepcon2 tl1 tl2) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) tl1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) tl2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
  apply pred_ext.
  + revert tl2; induction tl1; intros; destruct tl2.
    - apply (exp_right E); simpl.
(* Goal: @derives A ND (@emp A ND SL) (@andp A ND (@prop A ND (and (@eq (tree B1) (@E B1) (@E B1)) (@eq (tree B2) (@E B2) (@E B2)))) (@emp A ND SL)) *)
      apply andp_right; auto.
(* Goal: @derives A ND (@emp A ND SL) (@prop A ND (and (@eq (tree B1) (@E B1) (@E B1)) (@eq (tree B2) (@E B2) (@E B2)))) *)
      apply prop_right; auto.
    - simpl.
(* Goal: @derives A ND (@FF A ND) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@E B2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      apply FF_left.
    - simpl.
(* Goal: @derives A ND (@FF A ND) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@E B2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      apply FF_left.
    - simpl.
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (iter_tree_sepcon2 tl1_1 tl2_1)) (iter_tree_sepcon2 tl1_2 tl2_2)) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@T B2 tl2_1 b tl2_2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      specialize (IHtl1_1 tl2_1).
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (iter_tree_sepcon2 tl1_1 tl2_1)) (iter_tree_sepcon2 tl1_2 tl2_2)) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@T B2 tl2_1 b tl2_2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      specialize (IHtl1_2 tl2_2).
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (iter_tree_sepcon2 tl1_1 tl2_1)) (iter_tree_sepcon2 tl1_2 tl2_2)) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@T B2 tl2_1 b tl2_2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      eapply derives_trans; [apply sepcon_derives; [apply sepcon_derives |]; [apply derives_refl | apply IHtl1_1 | apply IHtl1_2] | clear IHtl1_1 IHtl1_2].
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) tl1_1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) tl2_1 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl)))) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) tl1_2 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) tl2_2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl)))) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 tl1_1 v tl1_2) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@T B2 tl2_1 b tl2_2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      Intros tl_2 tl_1; subst.
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_1)) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_2)) (@exp A ND (tree (prod B1 B2)) (fun tl : tree (prod B1 B2) => @andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_1) v (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_2)) (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) (@T B2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_1) b (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_2)) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl))) *)
      Exists (T tl_1 (v, b) tl_2).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
      simpl.
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (p v b) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_1)) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_2)) (@andp A ND (@prop A ND (and (@eq (tree B1) (@T B1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_1) v (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_2)) (@T B1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_1) v (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl_2))) (@eq (tree B2) (@T B2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_1) b (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_2)) (@T B2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_1) b (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl_2))))) (@sepcon A ND SL (@sepcon A ND SL (@uncurry B1 B2 A p (@pair B1 B2 v b)) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_1)) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl_2))) *)
      apply andp_right; [apply prop_right; subst; auto |].
(* Goal: @derives mpred Nveric (lt_ytree_rep (lty_add1 tl) q) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => @exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t0 : prod unit YTree) (p0 : val) => (fix ytree_rep (t1 : YTree) (p1 : val) {struct t1} : mpred := match t1 with | YLeaf => @andp mpred Nveric (@prop mpred Nveric (@eq val p1 nullval)) (@emp mpred Nveric Sveric) | YNode ttl v => @exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr v))) p1) (@exp mpred Nveric (list val) (fun r0 : list val => @sepcon mpred Nveric Sveric (y_list_rep r0 q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t2 : prod (tree (prod unit YTree)) unit) (p2 : val) => @exp mpred Nveric (tree val) (fun s0 : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s0 p2) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t3 : prod unit YTree) (p3 : val) => ytree_rep (@snd unit YTree t3) p3) (@fst (tree (prod unit YTree)) unit t2) s0))) ttl r0)))) end) (@snd unit YTree t0) p0) (@fst (tree (prod unit YTree)) unit t) s))) (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair : prod unit YTree => @pair unit YTree tt ((fix y_add1 (t : YTree) : YTree := match t with | YLeaf => YLeaf | YNode tl v => YNode (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair0 : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair0 : prod unit YTree => @pair unit YTree tt (y_add1 (@snd unit YTree u_t_pair0))) (@fst (tree (prod unit YTree)) unit tt_u_pair0)) tt) tl) (Z.add v (Zpos xH)) end) (@snd unit YTree u_t_pair))) (@fst (tree (prod unit YTree)) unit tt_u_pair)) tt) tl) r))) *)
      apply derives_refl.
  + apply exp_left; intros tl.
(* Goal: @derives A ND (@andp A ND (@prop A ND (and (@eq (tree B1) tl1 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl)) (@eq (tree B2) tl2 (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl)))) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl)) (iter_tree_sepcon2 tl1 tl2) *)
    normalize.
(* Goal: forall _ : @fold_right Prop Prop and (Z.ge v Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.ge x Z0)) tl), @fold_right Prop Prop and (Z.gt (Z.add v (Zpos xH)) Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.gt x Z0)) (@map XTree XTree x_add1 tl)) *)
    induction tl.
    - simpl. auto.
    - simpl.
(* Goal: @derives A ND (@sepcon A ND SL (@sepcon A ND SL (@uncurry B1 B2 A p v) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl1)) (@iter_tree_sepcon A (prod B1 B2) ND SL (@uncurry B1 B2 A p) tl2)) (@sepcon A ND SL (@sepcon A ND SL (p (@fst B1 B2 v) (@snd B1 B2 v)) (iter_tree_sepcon2 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl1) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl1))) (iter_tree_sepcon2 (@map_tree (prod B1 B2) B1 (@fst B1 B2) tl2) (@map_tree (prod B1 B2) B2 (@snd B1 B2) tl2))) *)
      eapply derives_trans; [apply sepcon_derives; [apply sepcon_derives |]; [apply derives_refl | apply IHtl1 | apply IHtl2] | clear IHtl1 IHtl2].
(* Goal: @derives mpred Nveric (lt_ytree_rep (lty_add1 tl) q) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => @exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t0 : prod unit YTree) (p0 : val) => (fix ytree_rep (t1 : YTree) (p1 : val) {struct t1} : mpred := match t1 with | YLeaf => @andp mpred Nveric (@prop mpred Nveric (@eq val p1 nullval)) (@emp mpred Nveric Sveric) | YNode ttl v => @exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr v))) p1) (@exp mpred Nveric (list val) (fun r0 : list val => @sepcon mpred Nveric Sveric (y_list_rep r0 q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t2 : prod (tree (prod unit YTree)) unit) (p2 : val) => @exp mpred Nveric (tree val) (fun s0 : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s0 p2) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t3 : prod unit YTree) (p3 : val) => ytree_rep (@snd unit YTree t3) p3) (@fst (tree (prod unit YTree)) unit t2) s0))) ttl r0)))) end) (@snd unit YTree t0) p0) (@fst (tree (prod unit YTree)) unit t) s))) (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair : prod unit YTree => @pair unit YTree tt ((fix y_add1 (t : YTree) : YTree := match t with | YLeaf => YLeaf | YNode tl v => YNode (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair0 : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair0 : prod unit YTree => @pair unit YTree tt (y_add1 (@snd unit YTree u_t_pair0))) (@fst (tree (prod unit YTree)) unit tt_u_pair0)) tt) tl) (Z.add v (Zpos xH)) end) (@snd unit YTree u_t_pair))) (@fst (tree (prod unit YTree)) unit tt_u_pair)) tt) tl) r))) *)
      apply derives_refl.
Qed.

End IterTreeSepCon2.

(* X_DEFS *)

Inductive XTree: Type :=
| XLeaf: XTree
| XNode: list XTree -> Z -> XTree.

Fixpoint xtree_rep (t: XTree) (p: val): mpred :=
  match t with
  | XLeaf =>
      !!(p = nullval) && emp
  | XNode tl v =>
      EX q: val,
        data_at Tsh t_struct_Xnode (q, Vint (Int.repr v)) p *
        EX r: list val,
          list_rep (fun (p: val) (n: val) (q: val) => data_at Tsh t_struct_Xlist (p, n) q) r q *
          iter_sepcon2 xtree_rep tl r
  end.

Lemma xtree_rep_valid_pointer:
  forall t p, xtree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (valid_pointer p) *)
destruct t; simpl; normalize; auto with valid_pointer.
Qed.
Hint Resolve xtree_rep_valid_pointer: valid_pointer.

Lemma xtree_rep_local_facts:
  forall t p, xtree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = XLeaf)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq YTree t YLeaf)))) *)
destruct t; simpl; normalize; entailer!.
+ split; auto.
+ split; intros; try congruence.
(* Goal: @eq YTree (YNode l z) YLeaf *)
  subst; destruct H as [? _]; inv H.
Qed.
Hint Resolve xtree_rep_local_facts: saturate_local.

Lemma list_rep_Xlist_valid_pointer:
  forall (r: list val) (q: val),
    list_rep (fun (p: val) (n: val) (q: val) => data_at Tsh t_struct_Xlist (p, n) q) r q |-- valid_pointer q.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (y_list_rep t p) (valid_pointer p) *)
  apply list_rep_valid_pointer.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (valid_pointer p) *)
  auto with valid_pointer.
Qed.
Hint Resolve list_rep_Xlist_valid_pointer: valid_pointer.

Lemma list_rep_Xlist_local_facts:
  forall (r: list val) (q: val),
    list_rep (fun (p: val) (n: val) (q: val) => data_at Tsh t_struct_Xlist (p, n) q) r q |-- !! (is_pointer_or_null q  /\ (q=nullval <-> r=nil)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: forall (t : list val) (p : val), @derives mpred Nveric (y_list_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list val) t (@nil val))))) *)
  apply list_rep_local_facts.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
Qed.
Hint Resolve list_rep_Xlist_local_facts: saturate_local.

Lemma xtree_rep_nullval: forall t,
  xtree_rep t nullval |-- !! (t = XLeaf).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (xtree_rep t nullval) (@prop mpred Nveric (@eq XTree t XLeaf)) *)
  destruct t; [entailer! |].
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
  simpl xtree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  Intros q r. entailer!.
Qed.
Hint Resolve xtree_rep_nullval: saturate_local.

(* X_DEFS ends. *)

(* Y_DEFS *)

Inductive YTree: Type :=
| YLeaf: YTree
| YNode: list (tree (unit * YTree) * unit) -> Z -> YTree.

Definition y_tree_rep (t: tree val) (p: val): mpred :=
  tree_rep (fun q L R p: val => data_at Tsh t_struct_Ytree (q, (L, R)) p) t p.

Definition y_list_rep (l: list val) (p: val): mpred :=
  list_rep (fun q n p: val => data_at Tsh t_struct_Ylist (q, n) p) l p.

Fixpoint ytree_rep (t: YTree) (p: val): mpred :=
  match t with
  | YLeaf =>
      !!(p = nullval) && emp
  | YNode ttl v =>
      let rep1 (t: unit * YTree) p := ytree_rep (snd t) p in
      let rep2 (t: tree (unit * YTree) * unit) p :=
            EX s: tree val, y_tree_rep s p * iter_tree_sepcon2 rep1 (fst t) s in
      let rep3 (t: list (tree (unit * YTree) * unit)) p :=
            EX r: list val, y_list_rep r p * iter_sepcon2 rep2 t r in
      EX q: val, 
        data_at Tsh t_struct_Ynode (q, Vint (Int.repr v)) p * rep3 ttl q
  end.

Definition t_ytree_rep (t: tree (unit * YTree)) (p: val): mpred :=
  EX s: tree val, y_tree_rep s p * iter_tree_sepcon2 (fun t p => ytree_rep (snd t) p) t s.

Definition lt_ytree_rep (t: list (tree (unit * YTree) * unit)) (p: val): mpred :=
  EX r: list val, y_list_rep r p * iter_sepcon2 (fun t p => t_ytree_rep (fst t) p) t r.

Theorem ytree_rep_spec: forall t p,
  ytree_rep t p =
  match t with
  | YLeaf =>
      !!(p = nullval) && emp
  | YNode ttl v =>
      EX q: val, 
        data_at Tsh t_struct_Ynode (q, Vint (Int.repr v)) p * lt_ytree_rep ttl q
  end.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
  induction t; auto.
Qed.

Lemma y_list_rep_valid_pointer: forall t p, y_list_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (y_list_rep t p) (valid_pointer p) *)
  apply list_rep_valid_pointer.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (valid_pointer p) *)
  intros; auto with valid_pointer.
Qed.
Hint Resolve y_list_rep_valid_pointer: valid_pointer.

Lemma y_list_rep_local_facts: forall t p, y_list_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = nil)).
Proof.
(* Goal: forall (t : list val) (p : val), @derives mpred Nveric (y_list_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list val) t (@nil val))))) *)
  apply list_rep_local_facts.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  intros; entailer!.
Qed.
Hint Resolve y_list_rep_local_facts: saturate_local.

Lemma y_tree_rep_valid_pointer: forall t p, y_tree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (y_tree_rep t p) (valid_pointer p) *)
  apply tree_rep_valid_pointer.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (valid_pointer p) *)
  intros; auto with valid_pointer.
Qed.
Hint Resolve y_tree_rep_valid_pointer: valid_pointer.

Lemma y_tree_rep_local_facts: forall t p, y_tree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = E)).
Proof.
(* Goal: forall (t : tree val) (p : val), @derives mpred Nveric (y_tree_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (tree val) t (@E val))))) *)
  apply tree_rep_local_facts.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  intros; entailer!.
Qed.
Hint Resolve y_tree_rep_local_facts: saturate_local.

Lemma ytree_rep_valid_pointer:
  forall t p, ytree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (valid_pointer p) *)
destruct t; simpl; normalize; auto with valid_pointer.
Qed.
Hint Resolve ytree_rep_valid_pointer: valid_pointer.

Lemma ytree_rep_local_facts:
  forall t p, ytree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = YLeaf)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
intros.
(* Goal: @derives mpred Nveric (ytree_rep t p) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq YTree t YLeaf)))) *)
destruct t; simpl; normalize; entailer!.
+ split; auto.
+ split; intros; try congruence.
(* Goal: @eq YTree (YNode l z) YLeaf *)
  subst; destruct H as [? _]; inv H.
Qed.
Hint Resolve ytree_rep_local_facts: saturate_local.

Lemma lt_ytree_rep_valid_pointer: forall t p, lt_ytree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 t') y) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (lt_ytree_rep (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) p) *)
  unfold lt_ytree_rep.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r))) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) r))) *)
  Intros r.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (valid_pointer p) *)
  auto with valid_pointer.
Qed.
Hint Resolve lt_ytree_rep_valid_pointer: valid_pointer.

Lemma lt_ytree_rep_local_facts: forall t p, lt_ytree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = nil)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 t') y) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (lt_ytree_rep (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) p) *)
  unfold lt_ytree_rep.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r))) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) r))) *)
  Intros r.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t r)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list (prod (tree (prod unit YTree)) unit)) t (@nil (prod (tree (prod unit YTree)) unit)))))) *)
  rewrite iter_sepcon2_spec.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_list_rep r p) (@exp mpred Nveric (list (prod (prod (tree (prod unit YTree)) unit) val)) (fun l : list (prod (prod (tree (prod unit YTree)) unit) val) => @andp mpred Nveric (@prop mpred Nveric (and (@eq (list (prod (tree (prod unit YTree)) unit)) t (@map (prod (prod (tree (prod unit YTree)) unit) val) (prod (tree (prod unit YTree)) unit) (@fst (prod (tree (prod unit YTree)) unit) val) l)) (@eq (list val) r (@map (prod (prod (tree (prod unit YTree)) unit) val) val (@snd (prod (tree (prod unit YTree)) unit) val) l)))) (@iter_sepcon mpred (prod (prod (tree (prod unit YTree)) unit) val) Nveric Sveric (@uncurry (prod (tree (prod unit YTree)) unit) val mpred (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p)) l)))) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list (prod (tree (prod unit YTree)) unit)) t (@nil (prod (tree (prod unit YTree)) unit)))))) *)
  Intros l.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon mpred (prod (prod unit YTree) val) Nveric Sveric (@uncurry (prod unit YTree) val mpred (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p)) tl)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (tree (prod unit YTree)) t (@E (prod unit YTree)))))) *)
  subst.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
(* Goal: iff (@eq val p nullval) (@eq (tree (prod unit YTree)) (@map_tree (prod (prod unit YTree) val) (prod unit YTree) (@fst (prod unit YTree) val) tl) (@E (prod unit YTree))) *)
  rewrite H.
(* Goal: iff (@eq (list val) (@map (prod (prod (tree (prod unit YTree)) unit) val) val (@snd (prod (tree (prod unit YTree)) unit) val) l) (@nil val)) (@eq (list (prod (tree (prod unit YTree)) unit)) (@map (prod (prod (tree (prod unit YTree)) unit) val) (prod (tree (prod unit YTree)) unit) (@fst (prod (tree (prod unit YTree)) unit) val) l) (@nil (prod (tree (prod unit YTree)) unit))) *)
  destruct l; simpl; split; intros; congruence.
Qed.
Hint Resolve lt_ytree_rep_local_facts: saturate_local.

Lemma t_ytree_rep_valid_pointer: forall t p, t_ytree_rep t p |-- valid_pointer p.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  unfold t_ytree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) s))) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  Intros s.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (valid_pointer p) *)
  auto with valid_pointer.
Qed.
Hint Resolve t_ytree_rep_valid_pointer: valid_pointer.

Lemma t_ytree_rep_local_facts: forall t p, t_ytree_rep t p |-- !! (is_pointer_or_null p /\ (p = nullval <-> t = E)).
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  unfold t_ytree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) s))) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  Intros s.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) t s)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (tree (prod unit YTree)) t (@E (prod unit YTree)))))) *)
  rewrite iter_tree_sepcon2_spec.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@exp mpred Nveric (tree (prod (prod unit YTree) val)) (fun tl : tree (prod (prod unit YTree) val) => @andp mpred Nveric (@prop mpred Nveric (and (@eq (tree (prod unit YTree)) t (@map_tree (prod (prod unit YTree) val) (prod unit YTree) (@fst (prod unit YTree) val) tl)) (@eq (tree val) s (@map_tree (prod (prod unit YTree) val) val (@snd (prod unit YTree) val) tl)))) (@iter_tree_sepcon mpred (prod (prod unit YTree) val) Nveric Sveric (@uncurry (prod unit YTree) val mpred (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p)) tl)))) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (tree (prod unit YTree)) t (@E (prod unit YTree)))))) *)
  Intros tl.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon mpred (prod (prod unit YTree) val) Nveric Sveric (@uncurry (prod unit YTree) val mpred (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p)) tl)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (tree (prod unit YTree)) t (@E (prod unit YTree)))))) *)
  subst.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
(* Goal: iff (@eq val p nullval) (@eq (tree (prod unit YTree)) (@map_tree (prod (prod unit YTree) val) (prod unit YTree) (@fst (prod unit YTree) val) tl) (@E (prod unit YTree))) *)
  rewrite H.
(* Goal: iff (@eq (tree val) (@map_tree (prod (prod unit YTree) val) val (@snd (prod unit YTree) val) tl) (@E val)) (@eq (tree (prod unit YTree)) (@map_tree (prod (prod unit YTree) val) (prod unit YTree) (@fst (prod unit YTree) val) tl) (@E (prod unit YTree))) *)
  destruct tl; simpl; split; intros; congruence.
Qed.
Hint Resolve t_ytree_rep_local_facts: saturate_local.

(* Y_DEFS ends. *)

Module Alternative.

Fixpoint ytree_rep (t: YTree) (p: val): mpred :=
  match t with
  | YLeaf =>
      !!(p = nullval) && emp
  | YNode ttl v =>
      EX q: val, EX r: list val,
        data_at Tsh t_struct_Ynode (q, Vint (Int.repr v)) p *
        list_rep (fun r n q => data_at Tsh t_struct_Ylist (r, n) q) r q *
        iter_sepcon2 (fun tt_u_pair r =>
          EX s: tree val,
          tree_rep (fun p L R r => data_at Tsh t_struct_Ytree (p, (L, R)) r) s r *
          iter_tree_sepcon2 (fun u_t_pair s => ytree_rep (snd u_t_pair) s) (fst tt_u_pair) s) ttl r
  end.

End Alternative.

Fixpoint x_add1 (t: XTree): XTree :=
  match t with
  | XLeaf =>
      XLeaf
  | XNode tl v =>
      XNode (map x_add1 tl) (v + 1)
  end.

Section Forall_XTree.

Variable (P: Z -> Prop).

Fixpoint Forall_XTree (t: XTree): Prop :=
  match t with
  | XLeaf =>
      True
  | XNode tl v =>
      fold_right and (P v) (map Forall_XTree tl)
  end.

End Forall_XTree.

Lemma add1_pos: forall t, Forall_XTree (fun x => x >= 0) t -> Forall_XTree (fun x => x > 0) (x_add1 t).
Proof.
  refine (fix H t :=
            match t as t_pat
              return Forall_XTree (fun x : Z => x >= 0) t_pat ->
                     Forall_XTree (fun x : Z => x > 0) (x_add1 t_pat)
            with
            | XLeaf => fun _ => I
            | XNode tl v => _
            end).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  simpl.
(* Goal: forall _ : @fold_right Prop Prop and (Z.ge v Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.ge x Z0)) tl), @fold_right Prop Prop and (Z.gt (Z.add v (Zpos xH)) Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.gt x Z0)) (@map XTree XTree x_add1 tl)) *)
  induction tl.
  + simpl.
(* Goal: forall _ : Z.ge v Z0, Z.gt (Z.add v (Zpos xH)) Z0 *)
    intros; clear H; omega.
  + simpl.
(* Goal: forall _ : and (Forall_XTree (fun x : Z => Z.ge x Z0) a) (@fold_right Prop Prop and (Z.ge v Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.ge x Z0)) tl)), and (Forall_XTree (fun x : Z => Z.gt x Z0) (x_add1 a)) (@fold_right Prop Prop and (Z.gt (Z.add v (Zpos xH)) Z0) (@map XTree Prop (Forall_XTree (fun x : Z => Z.gt x Z0)) (@map XTree XTree x_add1 tl))) *)
    exact (fun HH => conj (H _ (proj1 HH)) (IHtl (proj2 HH))).
Qed.

Definition Xnode_add_spec :=
 DECLARE _Xnode_add
  WITH p: val, t: XTree
  PRE  [ _p OF (tptr t_struct_Xnode) ]
    PROP  ()
    LOCAL (temp _p p)
    SEP (xtree_rep t p)
  POST [ Tvoid ] 
    PROP()
    LOCAL()
    SEP (xtree_rep (x_add1 t) p).

Definition Xfoo_spec :=
 DECLARE _Xfoo
  WITH p: val, t: XTree
  PRE  [ _p OF (tptr t_struct_Xnode) ]
    PROP  (Forall_XTree (fun x => x >= 0) t)
    LOCAL (temp _p p)
    SEP (xtree_rep t p)
  POST [ Tvoid ]
    EX t': XTree,
      PROP(Forall_XTree (fun x => x > 0) t')
      LOCAL()
      SEP (xtree_rep t' p).

Fixpoint y_add1 (t: YTree): YTree :=
  match t with
  | YLeaf =>
      YLeaf
  | YNode tl v =>
      let map1 := fun u_t_pair => (tt, y_add1 (snd u_t_pair)) in
      let map2 := fun tt_u_pair => (map_tree map1 (fst tt_u_pair), tt) in
      let map3 := fun tl => map map2 tl in
      YNode (map3 tl) (v + 1)
  end.

Definition ty_add1 (t: tree (unit * YTree)) :=
  map_tree (fun t => (tt, y_add1 (snd t))) t.

Definition lty_add1 (t: list (tree (unit * YTree) * unit)) :=
  map (fun t => (ty_add1 (fst t), tt)) t.

Theorem y_add1_spec: forall t,
  y_add1 t = 
  match t with
  | YLeaf =>
      YLeaf
  | YNode tl v =>
      YNode (lty_add1 tl) (v + 1)
  end.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
  induction t; auto.
Qed.

Definition Ynode_add_spec :=
 DECLARE _Ynode_add
  WITH p: val, t: YTree
  PRE  [ _p OF (tptr t_struct_Ynode) ]
    PROP  ()
    LOCAL (temp _p p)
    SEP (ytree_rep t p)
  POST [ Tvoid ] 
    PROP()
    LOCAL()
    SEP (ytree_rep (y_add1 t) p).

Definition YTree_add_spec :=
 DECLARE _YTree_add
  WITH p: val, t: tree (unit * YTree)
  PRE  [ _p OF (tptr t_struct_Ytree) ]
    PROP  ()
    LOCAL (temp _p p)
    SEP (t_ytree_rep t p)
  POST [ Tvoid ] 
    PROP()
    LOCAL()
    SEP (t_ytree_rep (ty_add1 t) p).

Definition YList_add_spec :=
 DECLARE _YList_add
  WITH p: val, t: list (tree (unit * YTree) * unit)
  PRE  [ _p OF (tptr t_struct_Ylist) ]
    PROP  ()
    LOCAL (temp _p p)
    SEP (lt_ytree_rep t p)
  POST [ Tvoid ] 
    PROP()
    LOCAL()
    SEP (lt_ytree_rep (lty_add1 t) p).

Definition main_spec :=
 DECLARE _main
  WITH gv : globals
  PRE  [] main_pre prog nil gv
  POST [ tint ]
     PROP() LOCAL () SEP(TT).

Definition Gprog : funspecs :=
  ltac:(with_library prog
    [Xnode_add_spec; Xfoo_spec; Ynode_add_spec; YList_add_spec; YTree_add_spec; main_spec]).

Module GeneralLseg.

Section GeneralLseg.

Context {V: Type}.

Variable listrep: list V -> val -> mpred.

Definition lseg (contents: list V) (x z: val) : mpred :=
  ALL tcontents: list V, listrep tcontents z -* listrep (contents ++ tcontents) x.

Lemma emp_lseg_nil: forall (x: val),
  emp |-- lseg nil x x.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  apply allp_right; intros.
(* Goal: @derives mpred Nveric (@emp mpred Nveric Sveric) (@wand mpred Nveric Sveric (listrep v x) (listrep (@app V (@nil V) v) x)) *)
  apply wand_sepcon_adjoint.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  simpl.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
Qed.

Lemma lseg_lseg: forall (s1 s2: list V) (x y z: val),
  lseg s2 y z * lseg s1 x y |-- lseg (s1 ++ s2) x z.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  unfold lseg.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@allp mpred Nveric (list V) (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents z) (listrep (@app V s2 tcontents) y))) (@allp mpred Nveric (list V) (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents y) (listrep (@app V s1 tcontents) x)))) (@allp mpred Nveric (list V) (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents z) (listrep (@app V (@app V s1 s2) tcontents) x))) *)
  eapply derives_trans; [apply sepcon_derives; [apply derives_refl |] | apply wandQ_frame_ver].
(* Goal: @derives mpred Nveric (@allp mpred Nveric (list V) (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents y) (listrep (@app V s1 tcontents) x))) (@allp mpred Nveric (list V) (@wand (forall _ : list V, mpred) (@LiftNatDed (list V) mpred Nveric) (@LiftSepLog (list V) mpred Nveric Sveric) (fun tcontents : list V => listrep (@app V s2 tcontents) y) (fun tcontents : list V => listrep (@app V (@app V s1 s2) tcontents) x))) *)
  eapply derives_trans; [apply (wandQ_frame_refine _ _ _ (app s2)) |].
(* Goal: @derives mpred Nveric (@allp mpred Nveric (list V) (fun c : list V => (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents y) (listrep (@app V s1 tcontents) x)) (@app V s2 c))) (@allp mpred Nveric (list V) (@wand (forall _ : list V, mpred) (@LiftNatDed (list V) mpred Nveric) (@LiftSepLog (list V) mpred Nveric Sveric) (fun tcontents : list V => listrep (@app V s2 tcontents) y) (fun tcontents : list V => listrep (@app V (@app V s1 s2) tcontents) x))) *)
  apply derives_refl'.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  f_equal; extensionality tcontents; simpl.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V s1 (@app V s2 tcontents)) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
  rewrite app_assoc.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
  auto.
Qed.

Lemma list_lseg: forall (s1 s2: list V) (x y: val),
  listrep s2 y * lseg s1 x y |-- listrep (s1 ++ s2) x.
Proof.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  intros.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
  unfold lseg.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (@allp mpred Nveric (list V) (fun tcontents : list V => @wand mpred Nveric Sveric (listrep tcontents y) (listrep (@app V s1 tcontents) x)))) (listrep (@app V s1 s2) x) *)
  change (listrep s2 y) with ((fun s2 => listrep s2 y) s2).
   change
     (ALL tcontents : list V, listrep tcontents y -* listrep (s1 ++ tcontents) x)
   with
     (allp ((fun tcontents => listrep tcontents y) -* (fun tcontents => listrep (s1 ++ tcontents) x))).
   change (listrep (s1 ++ s2) x) with ((fun s2 => listrep (s1 ++ s2) x) s2).
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric ((fun s2 : list V => listrep s2 y) s2) (@allp mpred Nveric (list V) (@wand (forall _ : list V, mpred) (@LiftNatDed (list V) mpred Nveric) (@LiftSepLog (list V) mpred Nveric Sveric) (fun tcontents : list V => listrep tcontents y) (fun tcontents : list V => listrep (@app V s1 tcontents) x)))) ((fun s2 : list V => listrep (@app V s1 s2) x) s2) *)
   apply wandQ_frame_elim.
Qed.

End GeneralLseg.
End GeneralLseg.

Lemma body_Xnode_add: semax_body Vprog Gprog f_Xnode_add Xnode_add_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
  forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
    simpl.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
    auto.
  }
  unfold Sfor.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  destruct t as [| tl v].
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
    simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@andp mpred Nveric (@prop mpred Nveric (@eq val p nullval)) (@emp mpred Nveric Sveric)) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    Intros.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@emp mpred Nveric Sveric) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    contradiction.
  }
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
  simpl xtree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at_ CompSpecs Tsh (Tstruct _Xnode noattr) v_q) (@cons mpred (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (@list_rep val (fun p n q0 : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q0) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r))))) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'4 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'4 (tptr (Tstruct _XList noattr))))) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'3 tuint))) (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))))) MORE_COMMANDS) POSTCONDITION *)
  Intros q r.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t r)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list (prod (tree (prod unit YTree)) unit)) t (@nil (prod (tree (prod unit YTree)) unit)))))) *)
  rewrite iter_sepcon2_spec.
  Intros tl'.
  subst tl r; rename tl' into tl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 (Vint (Int.repr v))) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.add (Int.repr v) (Int.repr (Zpos xH))))) p) (@cons mpred (lt_ytree_rep tl q) (@nil mpred)))))) (Ssequence (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr)))) MORE_COMMANDS) POSTCONDITION *)
  rewrite add_repr.
  unfold Sfor.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
  rename q into q_root.
  forward_loop
    (EX tl1: list (XTree * val), EX tl2: list (XTree * val), EX q: val,
      PROP (map (fun tp => (x_add1 (fst tp), snd tp)) tl = tl1 ++ map (fun tp => (x_add1 (fst tp), snd tp)) tl2)
      LOCAL (temp _q q)
      SEP (data_at Tsh t_struct_Xnode (q_root, Vint (Int.repr (v + 1))) p;
           GeneralLseg.lseg (list_rep (fun p n q : val => data_at Tsh t_struct_Xlist (p, n) q)) (map snd tl1) q_root q;
           iter_sepcon (uncurry xtree_rep) tl1;
           list_rep (fun p n q : val => data_at Tsh t_struct_Xlist (p, n) q) (map snd tl2) q;
           iter_sepcon (uncurry xtree_rep) tl2))%assert
  break:
    ( PROP ()
      LOCAL ()
      SEP (data_at Tsh t_struct_Xnode (q_root, Vint (Int.repr (v + 1))) p;
           list_rep (fun p n q : val => data_at Tsh t_struct_Xlist (p, n) q) (map snd tl) q_root;
           iter_sepcon (uncurry xtree_rep) (map (fun tp => (x_add1 (fst tp), snd tp)) tl)))%assert.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
    Exists (@nil (XTree * val)) tl q_root.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
    apply GeneralLseg.emp_lseg_nil.
  }
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
    Intros tl1 tl2 q.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
    forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
    2:{
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
      forward.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
      entailer!.
      assert (tl2 = nil) by (pose proof proj1 H4 eq_refl as HH; destruct tl2; auto; inv HH).
      subst tl2; clear H4.
      simpl in H0; rewrite app_nil_r in H0.
      simpl map.
      sep_apply (GeneralLseg.list_lseg (list_rep (fun p0 n q : val => data_at Tsh t_struct_Xlist (p0, n) q)) (map snd tl1) nil q_root nullval).
      sep_apply (eq_sym (iter_sepcon_app (uncurry xtree_rep) tl1 [])).
      rewrite !app_nil_r.
      rewrite <- H0, map_map.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
      simpl. change (fun x : XTree * val => snd x) with (@snd XTree val).
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
      cancel.
    }
    destruct tl2 as [| [t p'] tl2].
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
    {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
      simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@andp mpred Nveric (@prop mpred Nveric (@eq val p nullval)) (@emp mpred Nveric Sveric)) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
      Intros.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@emp mpred Nveric Sveric) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
      contradiction.
    }
    simpl list_rep; simpl iter_sepcon.
    Intros q'.
    change (uncurry xtree_rep (t, p')) with (xtree_rep t p').
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
    forward_call (p', t).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
    Exists (tl1 ++ (x_add1 t, p') :: nil) tl2 q'.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
    + rewrite <- app_assoc; auto.
    + change (xtree_rep (x_add1 t) p') with (uncurry xtree_rep (x_add1 t, p')).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
      rewrite iter_sepcon_app; simpl.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
      cancel.
      eapply derives_trans; [| rewrite map_app; apply (GeneralLseg.lseg_lseg _ _ _ _ q)].
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
      cancel.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
      clear.
(* Goal: forall (s1 s2 : list V) (x y : val), @derives mpred Nveric (@sepcon mpred Nveric Sveric (listrep s2 y) (lseg s1 x y)) (listrep (@app V s1 s2) x) *)
      apply allp_right; intros.
(* Goal: @derives mpred Nveric (@emp mpred Nveric Sveric) (@wand mpred Nveric Sveric (listrep v x) (listrep (@app V (@nil V) v) x)) *)
      apply wand_sepcon_adjoint.
      simpl list_rep.
      Exists q'.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
      cancel.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  simpl.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  Exists q_root; cancel.
  Exists (map snd tl).
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  cancel.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t r)) (@prop mpred Nveric (and (is_pointer_or_null p) (iff (@eq val p nullval) (@eq (list (prod (tree (prod unit YTree)) unit)) t (@nil (prod (tree (prod unit YTree)) unit)))))) *)
  rewrite iter_sepcon2_spec.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  Exists (map (fun tp : XTree * val => (x_add1 (fst tp), snd tp)) tl); cancel.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
  rewrite !map_map.
  split; f_equal.
Qed.

Lemma body_Xfoo: semax_body Vprog Gprog f_Xfoo Xfoo_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
  forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@data_at_ CompSpecs Tsh (Tstruct _Xnode noattr) v_q) (xtree_rep t nullval)) (@exp mpred Nveric XTree (fun a : XTree => @andp mpred Nveric (@prop mpred Nveric (Forall_XTree (fun x : Z => Z.gt x Z0) a)) (@sepcon mpred Nveric Sveric (xtree_rep a nullval) (@data_at_ CompSpecs Tsh (Tstruct _Xnode noattr) v_q)))) *)
    Exists XLeaf.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  destruct t as [| tl v].
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
    simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@andp mpred Nveric (@prop mpred Nveric (@eq val p nullval)) (@emp mpred Nveric Sveric)) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    Intros.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@emp mpred Nveric Sveric) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    contradiction.
  }
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
  simpl xtree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at_ CompSpecs Tsh (Tstruct _Xnode noattr) v_q) (@cons mpred (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (@list_rep val (fun p n q0 : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q0) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r))))) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'4 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'4 (tptr (Tstruct _XList noattr))))) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'3 tuint))) (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))))) MORE_COMMANDS) POSTCONDITION *)
  Intros q r.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'3 (Vint (Int.repr v))) (@cons localdef (temp _t'4 q) (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@data_at CompSpecs Tsh (Tstruct _Xnode noattr) (@pair val val q (Vint (Int.repr v))) v_q) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@cons mpred (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r q) (@cons mpred (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r) (@nil mpred)))))))) (Ssequence (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))) MORE_COMMANDS) POSTCONDITION *)
  gather_SEP 0 2 3.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'3 (Vint (Int.repr v))) (@cons localdef (temp _t'4 q) (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh (Tstruct _Xnode noattr) (@pair val val q (Vint (Int.repr v))) v_q) (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r))) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@nil mpred)))))) (Ssequence (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))) MORE_COMMANDS) POSTCONDITION *)
  replace_SEP 0 (xtree_rep (XNode tl v) v_q).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
    simpl xtree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh (Tstruct _Xnode noattr) (@pair val val q (Vint (Int.repr v))) v_q) (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r q)) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r)) (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) v_q) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (@list_rep val (fun p n q0 : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q0) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep tl r))))) *)
    Exists q r.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'3 (Vint (Int.repr v))) (@cons localdef (temp _t'4 q) (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (xtree_rep (XNode tl v) v_q) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@nil mpred)))))) (Ssequence (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))) MORE_COMMANDS) POSTCONDITION *)
  deadvars!.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (xtree_rep (XNode tl v) v_q) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@nil mpred)))))) (Ssequence (Ssequence (Scall (@None ident) (Evar _Xnode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Xnode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Eaddrof (Evar _q (Tstruct _Xnode noattr)) (tptr (Tstruct _Xnode noattr))) (@nil expr))) (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint))))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (v_q, XNode tl v).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
  simpl xtree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr (Z.add v (Zpos xH))))) v_q) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (@list_rep val (fun p n q0 : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q0) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r))))) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr v))) p) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Evar _q (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr)))) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _list (tptr (Tstruct _XList noattr))) (Etempvar _t'2 (tptr (Tstruct _XList noattr))))) (Ssequence (Sset _t'1 (Efield (Evar _q (Tstruct _Xnode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Xnode noattr))) (Tstruct _Xnode noattr)) _v tuint) (Etempvar _t'1 tuint)))) MORE_COMMANDS) POSTCONDITION *)
  Intros q' r'.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) v_q) (@cons mpred (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@cons mpred (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p) (@nil mpred)))))))) (Sreturn (@None expr)) POSTCONDITION *)
  gather_SEP 1 2 3.
  replace_SEP 0 (xtree_rep (XNode (map x_add1 tl) (v + 1)) p).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@sepcon mpred Nveric Sveric (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r') (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p))) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (xtree_rep (XNode (@map XTree XTree x_add1 tl) (Z.add v (Zpos xH))) p)) *)
    simpl xtree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@list_rep val (fun p n q : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q) r' q') (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r')) (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) p)) (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q (Vint (Int.repr (Z.add v (Zpos xH))))) p) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (@list_rep val (fun p n q0 : val => @data_at CompSpecs Tsh t_struct_Xlist (@pair val val p n) q0) r q) (@iter_sepcon2 mpred XTree val Nveric Sveric xtree_rep (@map XTree XTree x_add1 tl) r))))) *)
    Exists q' r'.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
  }
  change ((XNode (map x_add1 tl) (v + 1))) with (x_add1 (XNode tl v)).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 (Vint (Int.repr (Z.add v (Zpos xH))))) (@cons localdef (temp _t'2 q') (@cons localdef (lvar _q (Tstruct _Xnode noattr) v_q) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (xtree_rep (x_add1 (XNode tl v)) p) (@cons mpred (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) v_q) (@nil mpred)))))) (Sreturn (@None expr)) POSTCONDITION *)
  forget (XNode tl v) as t.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (xtree_rep (x_add1 t) p) (@data_at CompSpecs Tsh t_struct_Xnode (@pair val val q' (Vint (Int.repr (Z.add v (Zpos xH))))) v_q)) (@exp mpred Nveric XTree (fun a : XTree => @andp mpred Nveric (@prop mpred Nveric (Forall_XTree (fun x : Z => Z.gt x Z0) a)) (@sepcon mpred Nveric Sveric (xtree_rep a p) (@data_at_ CompSpecs Tsh (Tstruct _Xnode noattr) v_q)))) *)
  Exists (x_add1 t).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
  entailer!.
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
  apply add1_pos; auto.
Qed.

Lemma body_Ynode_add: semax_body Vprog Gprog f_Ynode_add Ynode_add_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
  forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
(* Goal: @derives mpred Nveric (t_ytree_rep t nullval) (t_ytree_rep (ty_add1 t) nullval) *)
    destruct H0 as [? _]; specialize (H eq_refl).
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
    subst; simpl; auto.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  destruct t as [| tl v].
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
    simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@andp mpred Nveric (@prop mpred Nveric (@eq val p nullval)) (@emp mpred Nveric Sveric)) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    Intros.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@emp mpred Nveric Sveric) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
    contradiction.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep (YNode tl v) p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  rewrite ytree_rep_spec.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr v))) p) (lt_ytree_rep tl q))) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint)) (Sassign (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _v tuint) (Ebinop Oadd (Etempvar _t'2 tuint) (Econst_int (Int.repr (Zpos xH)) tint) tuint))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  Intros q.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 (Vint (Int.repr v))) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.add (Int.repr v) (Int.repr (Zpos xH))))) p) (@cons mpred (lt_ytree_rep tl q) (@nil mpred)))))) (Ssequence (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _Ynode noattr))) (Tstruct _Ynode noattr)) _list (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr)))) MORE_COMMANDS) POSTCONDITION *)
  rewrite add_repr.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 q) (@cons localdef (temp _t'2 (Vint (Int.repr v))) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr (Z.add v (Zpos xH))))) p) (@cons mpred (lt_ytree_rep tl q) (@nil mpred)))))) (Ssequence (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (q, tl).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 tl) q) (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr (Z.add v (Zpos xH))))) p)) (ytree_rep (y_add1 (YNode tl v)) p) *)
  Exists q.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  cancel.
(* Goal: @derives mpred Nveric (lt_ytree_rep (lty_add1 tl) q) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => @exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t0 : prod unit YTree) (p0 : val) => (fix ytree_rep (t1 : YTree) (p1 : val) {struct t1} : mpred := match t1 with | YLeaf => @andp mpred Nveric (@prop mpred Nveric (@eq val p1 nullval)) (@emp mpred Nveric Sveric) | YNode ttl v => @exp mpred Nveric val (fun q : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ynode (@pair val val q (Vint (Int.repr v))) p1) (@exp mpred Nveric (list val) (fun r0 : list val => @sepcon mpred Nveric Sveric (y_list_rep r0 q) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t2 : prod (tree (prod unit YTree)) unit) (p2 : val) => @exp mpred Nveric (tree val) (fun s0 : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s0 p2) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t3 : prod unit YTree) (p3 : val) => ytree_rep (@snd unit YTree t3) p3) (@fst (tree (prod unit YTree)) unit t2) s0))) ttl r0)))) end) (@snd unit YTree t0) p0) (@fst (tree (prod unit YTree)) unit t) s))) (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair : prod unit YTree => @pair unit YTree tt ((fix y_add1 (t : YTree) : YTree := match t with | YLeaf => YLeaf | YNode tl v => YNode (@map (prod (tree (prod unit YTree)) unit) (prod (tree (prod unit YTree)) unit) (fun tt_u_pair0 : prod (tree (prod unit YTree)) unit => @pair (tree (prod unit YTree)) unit (@map_tree (prod unit YTree) (prod unit YTree) (fun u_t_pair0 : prod unit YTree => @pair unit YTree tt (y_add1 (@snd unit YTree u_t_pair0))) (@fst (tree (prod unit YTree)) unit tt_u_pair0)) tt) tl) (Z.add v (Zpos xH)) end) (@snd unit YTree u_t_pair))) (@fst (tree (prod unit YTree)) unit tt_u_pair)) tt) tl) r))) *)
  apply derives_refl.
Qed.

Lemma body_YList_add: semax_body Vprog Gprog f_YList_add YList_add_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
  forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
(* Goal: @derives mpred Nveric (t_ytree_rep t nullval) (t_ytree_rep (ty_add1 t) nullval) *)
    destruct H0 as [? _]; specialize (H eq_refl).
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
    subst; simpl; auto.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (lt_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _tree (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _next (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  assert_PROP (t <> nil).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: False *)
    destruct H0 as [_ ?]; specialize (H0 eq_refl).
(* Goal: False *)
    congruence.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (lt_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _tree (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _next (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  destruct t as [| [? ?] t']; [congruence | clear H0].
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 t') y) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (lt_ytree_rep (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) p) *)
  unfold lt_ytree_rep.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r))) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) r))) *)
  Intros r.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_list_rep r p) (@cons mpred (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t') r) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _tree (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _next (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  destruct r; [simpl; normalize |].
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric val (fun y : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (y_list_rep r y))) (@cons mpred (@sepcon mpred Nveric Sveric (t_ytree_rep t v) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t' r)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _tree (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _YList noattr))) (Tstruct _YList noattr)) _next (tptr (Tstruct _YList noattr)))) (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))))) MORE_COMMANDS) POSTCONDITION *)
  Intros y.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 v) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (@cons mpred (y_list_rep r y) (@cons mpred (t_ytree_rep t v) (@cons mpred (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t' r) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (v, t).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 y) (@cons localdef (temp _t'2 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (t_ytree_rep (ty_add1 t) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (@cons mpred (y_list_rep r y) (@cons mpred (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t' r) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  gather_SEP 2 3.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 y) (@cons localdef (temp _t'2 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) t' r)) (@cons mpred (t_ytree_rep (ty_add1 t) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (@nil mpred))))))) (Ssequence (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  replace_SEP 0 (lt_ytree_rep t' y).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 t') y) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (lt_ytree_rep (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) p) *)
    unfold lt_ytree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
    Exists r; cancel.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 y) (@cons localdef (temp _t'2 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (lt_ytree_rep t' y) (@cons mpred (t_ytree_rep (ty_add1 t) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (@nil mpred))))))) (Ssequence (Scall (@None ident) (Evar _YList_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _YList noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _YList noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (y, t').
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  clear.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (lt_ytree_rep (lty_add1 t') y) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (lt_ytree_rep (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) p) *)
  unfold lt_ytree_rep.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r))) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) r))) *)
  Intros r.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (y_list_rep r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r)) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@exp mpred Nveric (list val) (fun r : list val => @sepcon mpred Nveric Sveric (y_list_rep r p) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 (@cons (prod (tree (prod unit YTree)) unit) (@pair (tree (prod unit YTree)) unit t u) t')) r))) *)
  Exists (v :: r).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  unfold y_list_rep; simpl.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@list_rep val (fun q n p : val => @data_at CompSpecs Tsh t_struct_Ylist (@pair val val q n) p) r y) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r)) (t_ytree_rep (ty_add1 t) v)) (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p)) (@sepcon mpred Nveric Sveric (@exp mpred Nveric val (fun y : val => @sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ylist (@pair val val v y) p) (@list_rep val (fun q n p : val => @data_at CompSpecs Tsh t_struct_Ylist (@pair val val q n) p) r y))) (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 t) v) (@iter_sepcon2 mpred (prod (tree (prod unit YTree)) unit) val Nveric Sveric (fun (t : prod (tree (prod unit YTree)) unit) (p : val) => t_ytree_rep (@fst (tree (prod unit YTree)) unit t) p) (lty_add1 t') r))) *)
  Exists y.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  cancel.
Qed.

Lemma body_YTree_add: semax_body Vprog Gprog f_YTree_add YTree_add_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Sifthenelse (Ebinop Oeq (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Ecast (Econst_int (Int.repr Z0) tint) (tptr tvoid)) tint) (Sreturn (@None expr)) Sskip) (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))))))) MORE_COMMANDS) POSTCONDITION *)
  forward_if.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
    forward.
(* Goal: @derives mpred Nveric (t_ytree_rep t nullval) (t_ytree_rep (ty_add1 t) nullval) *)
    destruct H0 as [? _]; specialize (H eq_refl).
(* Goal: @eq mpred (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) (@wand mpred Nveric Sveric (listrep (@app V s2 tcontents) y) (listrep (@app V (@app V s1 s2) tcontents) x)) *)
    subst; simpl; auto.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  assert_PROP (t <> E).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: False *)
    destruct H0 as [_ ?]; specialize (H0 eq_refl).
(* Goal: False *)
    congruence.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  destruct t as [| a [? ?] b]; [congruence |].
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  unfold t_ytree_rep.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) s))) (@nil mpred))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  Intros s.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep s p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) s) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  destruct s; [simpl; normalize |].
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  simpl.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (@exp mpred Nveric val (fun pa : val => @exp mpred Nveric val (fun pb : val => @sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (y_tree_rep s1 pa)) (y_tree_rep s2 pb)))) (@cons mpred (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep y v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) a s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  Intros pa pb.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))) (SEPx (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@cons mpred (y_tree_rep s1 pa) (@cons mpred (y_tree_rep s2 pb) (@cons mpred (ytree_rep y v) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) a s1) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2) (@nil mpred)))))))))) (Ssequence (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (v, y).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@cons mpred (y_tree_rep s1 pa) (@cons mpred (y_tree_rep s2 pb) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) a s1) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2) (@nil mpred)))))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  gather_SEP 2 4.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) a s1)) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@cons mpred (y_tree_rep s2 pb) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2) (@nil mpred))))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  replace_SEP 0 (t_ytree_rep a pa).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
    unfold t_ytree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
    Exists s1; cancel.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef)))) (SEPx (@cons mpred (t_ytree_rep a pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@cons mpred (y_tree_rep s2 pb) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2) (@nil mpred))))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (pa, a).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@cons mpred (y_tree_rep s2 pb) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2) (@nil mpred))))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  gather_SEP 3 4.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  replace_SEP 0 (t_ytree_rep b pb).
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (t_ytree_rep b pb)) *)
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  {
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
    unfold t_ytree_rep.
(* Goal: @derives (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (@andp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) (local (tc_environ Delta)) (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s2)) (@nil mpred)))))) (@liftx (LiftEnviron mpred) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) b s)))) *)
    entailer!.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
    Exists s2; cancel.
  }
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _t'1 pb) (@cons localdef (temp _t'2 pa) (@cons localdef (temp _t'3 v) (@cons localdef (temp _p p) (@nil localdef))))) (SEPx (@cons mpred (t_ytree_rep b pb) (@cons mpred (t_ytree_rep (ty_add1 a) pa) (@cons mpred (ytree_rep (y_add1 y) v) (@cons mpred (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@nil mpred)))))))) (Ssequence (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr))) MORE_COMMANDS) POSTCONDITION *)
  forward_call (pb, b).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  clear.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (t_ytree_rep (ty_add1 b) pb) (t_ytree_rep (ty_add1 a) pa)) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (t_ytree_rep (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) p) *)
  unfold t_ytree_rep.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s))) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s)))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) s))) *)
  Intros s2 s1.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (y_tree_rep s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (y_tree_rep s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@exp mpred Nveric (tree val) (fun s : tree val => @sepcon mpred Nveric Sveric (y_tree_rep s p) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 (@T (prod unit YTree) a (@pair unit YTree u y) b)) s))) *)
  Exists (T s1 v s2).
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (y_tree_rep (@T val s1 v s2) p) (@cons mpred (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (@T (prod unit YTree) a (@pair unit YTree u y) b) (@T val s1 v s2)) (@nil mpred)))))) (Ssequence (Ssequence (Ssequence (Sset _t'3 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _node (tptr (Tstruct _Ynode noattr)))) (Scall (@None ident) (Evar _Ynode_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _Ynode noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'3 (tptr (Tstruct _Ynode noattr))) (@nil expr)))) (Ssequence (Ssequence (Sset _t'2 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _left (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'2 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))) (Ssequence (Sset _t'1 (Efield (Ederef (Etempvar _p (tptr (Tstruct _BinaryTree noattr))) (Tstruct _BinaryTree noattr)) _right (tptr (Tstruct _BinaryTree noattr)))) (Scall (@None ident) (Evar _YTree_add (Tfunction (Ctypes.Tcons (tptr (Tstruct _BinaryTree noattr)) Ctypes.Tnil) tvoid cc_default)) (@cons expr (Etempvar _t'1 (tptr (Tstruct _BinaryTree noattr))) (@nil expr)))))) MORE_COMMANDS) POSTCONDITION *)
  unfold y_tree_rep; simpl.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@exp mpred Nveric val (fun pa : val => @exp mpred Nveric val (fun pb : val => @sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)))) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  Exists pa pb.
(* Goal: @derives mpred Nveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2)) (@sepcon mpred Nveric Sveric (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1))) (ytree_rep (y_add1 y) v)) (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (@data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) v (@pair val val pa pb)) p) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s1 pa)) (@tree_rep val (fun q L R p : val => @data_at CompSpecs Tsh t_struct_Ytree (@pair val (prod val val) q (@pair val val L R)) p) s2 pb)) (@sepcon mpred Nveric Sveric (@sepcon mpred Nveric Sveric (ytree_rep (y_add1 y) v) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 a) s1)) (@iter_tree_sepcon2 mpred (prod unit YTree) val Nveric Sveric (fun (t : prod unit YTree) (p : val) => ytree_rep (@snd unit YTree t) p) (ty_add1 b) s2))) *)
  cancel.
Qed.

Lemma body_main:  semax_body Vprog Gprog f_main main_spec.
Proof.
(* Goal: semax_body Vprog Gprog CompSpecs f_main main_spec *)
  start_function.
(* Goal: semax CompSpecs Espec Delta (PROPx (@nil Prop) (LOCALx (@cons localdef (gvars gv) (@nil localdef)) (SEPx (@nil mpred)))) (Sreturn (@Some expr (Econst_int (Int.repr Z0) tint))) POSTCONDITION *)
  forward.
Qed.

Existing Instance NullExtension.Espec.

Lemma prog_correct:
  semax_prog prog Vprog Gprog.
Proof.
(* Goal: semax_prog NullExtension.Espec CompSpecs prog Vprog Gprog *)
prove_semax_prog.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xnode_add (@Internal function f_Xnode_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Ynode_add (@Internal function f_Ynode_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YList_add (@Internal function f_YList_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YTree_add (@Internal function f_YTree_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xfoo (@Internal function f_Xfoo)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function))))))))) (@cons (prod ident funspec) (@pair ident funspec _Xnode_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep (x_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _Ynode_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ynode)) (@nil (prod ident type))) Tvoid) cc_default (prod val YTree) (fun x : prod val YTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep t p) (@nil mpred))))) (fun x : prod val YTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (ytree_rep (y_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _YList_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ylist)) (@nil (prod ident type))) Tvoid) cc_default (prod val (list (prod (tree (prod unit YTree)) unit))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (lt_ytree_rep t p) (@nil mpred))))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (lt_ytree_rep (lty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _YTree_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ytree)) (@nil (prod ident type))) Tvoid) cc_default (prod val (tree (prod unit YTree))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (t_ytree_rep (ty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _Xfoo (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.ge x0 Z0) t) (@nil Prop)) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, _) := x in @exp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) XTree (fun t' : XTree => PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.gt x0 Z0) t') (@nil Prop)) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep t' p) (@nil mpred)))))))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec)))))))) *)
semax_func_cons body_Xnode_add.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Ynode_add (@Internal function f_Ynode_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YList_add (@Internal function f_YList_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YTree_add (@Internal function f_YTree_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xfoo (@Internal function f_Xfoo)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function)))))))) (@cons (prod ident funspec) (@pair ident funspec _Ynode_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ynode)) (@nil (prod ident type))) Tvoid) cc_default (prod val YTree) (fun x : prod val YTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (ytree_rep t p) (@nil mpred))))) (fun x : prod val YTree => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (ytree_rep (y_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _YList_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ylist)) (@nil (prod ident type))) Tvoid) cc_default (prod val (list (prod (tree (prod unit YTree)) unit))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (lt_ytree_rep t p) (@nil mpred))))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (lt_ytree_rep (lty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _YTree_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ytree)) (@nil (prod ident type))) Tvoid) cc_default (prod val (tree (prod unit YTree))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (t_ytree_rep (ty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _Xfoo (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.ge x0 Z0) t) (@nil Prop)) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, _) := x in @exp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) XTree (fun t' : XTree => PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.gt x0 Z0) t') (@nil Prop)) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep t' p) (@nil mpred)))))))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec))))))) *)
semax_func_cons body_Ynode_add.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YList_add (@Internal function f_YList_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YTree_add (@Internal function f_YTree_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xfoo (@Internal function f_Xfoo)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function))))))) (@cons (prod ident funspec) (@pair ident funspec _YList_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ylist)) (@nil (prod ident type))) Tvoid) cc_default (prod val (list (prod (tree (prod unit YTree)) unit))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (lt_ytree_rep t p) (@nil mpred))))) (fun x : prod val (list (prod (tree (prod unit YTree)) unit)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (lt_ytree_rep (lty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _YTree_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ytree)) (@nil (prod ident type))) Tvoid) cc_default (prod val (tree (prod unit YTree))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (t_ytree_rep (ty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _Xfoo (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.ge x0 Z0) t) (@nil Prop)) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, _) := x in @exp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) XTree (fun t' : XTree => PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.gt x0 Z0) t') (@nil Prop)) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep t' p) (@nil mpred)))))))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec)))))) *)
semax_func_cons body_YList_add.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _YTree_add (@Internal function f_YTree_add)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xfoo (@Internal function f_Xfoo)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function)))))) (@cons (prod ident funspec) (@pair ident funspec _YTree_add (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Ytree)) (@nil (prod ident type))) Tvoid) cc_default (prod val (tree (prod unit YTree))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (t_ytree_rep t p) (@nil mpred))))) (fun x : prod val (tree (prod unit YTree)) => let (p, t) := x in PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (t_ytree_rep (ty_add1 t) p) (@nil mpred))))))) (@cons (prod ident funspec) (@pair ident funspec _Xfoo (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.ge x0 Z0) t) (@nil Prop)) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, _) := x in @exp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) XTree (fun t' : XTree => PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.gt x0 Z0) t') (@nil Prop)) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep t' p) (@nil mpred)))))))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec))))) *)
semax_func_cons body_YTree_add.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _Xfoo (@Internal function f_Xfoo)) (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function))))) (@cons (prod ident funspec) (@pair ident funspec _Xfoo (NDmk_funspec (@pair (list (prod ident type)) type (@cons (prod ident type) (@pair ident type _p (tptr t_struct_Xnode)) (@nil (prod ident type))) Tvoid) cc_default (prod val XTree) (fun x : prod val XTree => let (p, t) := x in PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.ge x0 Z0) t) (@nil Prop)) (LOCALx (@cons localdef (temp _p p) (@nil localdef)) (SEPx (@cons mpred (xtree_rep t p) (@nil mpred))))) (fun x : prod val XTree => let (p, _) := x in @exp (forall _ : environ, mpred) (@LiftNatDed' mpred Nveric) XTree (fun t' : XTree => PROPx (@cons Prop (Forall_XTree (fun x0 : Z => Z.gt x0 Z0) t') (@nil Prop)) (LOCALx (@nil localdef) (SEPx (@cons mpred (xtree_rep t' p) (@nil mpred)))))))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec)))) *)
semax_func_cons body_Xfoo.
(* Goal: semax_func NullExtension.Espec Vprog Gprog CompSpecs (@cons (prod ident (fundef function)) (@pair ident (fundef function) _main (@Internal function f_main)) (@nil (prod ident (fundef function)))) (@cons (prod ident funspec) (@pair ident funspec _main (NDmk_funspec (@pair (list (prod ident type)) type (@nil (prod ident type)) tint) cc_default globals (fun gv : globals => main_pre prog (@nil Type) gv) (fun _ : globals => PROPx (@nil Prop) (LOCALx (@nil localdef) (SEPx (@cons mpred (@TT mpred Nveric) (@nil mpred))))))) (@nil (prod ident funspec))) *)
semax_func_cons body_main.
Qed.


