Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Definition t_struct_tree := Tstruct _tree noattr.
Fixpoint tree_rep (t: tree val) (p: val) : mpred :=
match t with
| E => !!(p=nullval) && emp
| T a x v b => !! (Int.min_signed <= Z.of_nat x <= Int.max_signed /\ tc_val (tptr Tvoid) v) &&
EX pa:val, EX pb:val,
data_at Tsh t_struct_tree (Vint (Int.repr (Z.of_nat x)),(v,(pa,pb))) p *
tree_rep a pa * tree_rep b pb
end.
Definition treebox_rep (t: tree val) (b: val) :=
EX p: val, data_at Tsh (tptr t_struct_tree) p b * tree_rep t p.

(* Specifications: *)
Lemma tree_rep_spec: forall (t: tree val) (p: val),
tree_rep t p =
match t with
| E => !!(p=nullval) && emp
| T a x v b => !! (Int.min_signed <= Z.of_nat x <= Int.max_signed /\ tc_val (tptr Tvoid) v) &&
EX pa:val, EX pb:val,
data_at Tsh t_struct_tree (Vint (Int.repr (Z.of_nat x)),(v,(pa,pb))) p *
tree_rep a pa * tree_rep b pb
end.
Lemma treebox_rep_spec: forall (t: tree val) (b: val),
treebox_rep t b =
EX p: val,
data_at Tsh (tptr t_struct_tree) p b *
match t with
| E => !!(p=nullval) && emp
| T l x v r => !! (Int.min_signed <= Z.of_nat x <= Int.max_signed /\ tc_val (tptr Tvoid) v) &&
field_at Tsh t_struct_tree [StructField _key] (Vint (Int.repr (Z.of_nat x))) p *
field_at Tsh t_struct_tree [StructField _value] v p *
treebox_rep l (field_address t_struct_tree [StructField _left] p) *
treebox_rep r (field_address t_struct_tree [StructField _right] p)
end.
Lemma treebox_rep_tree_rep: forall (t: tree val) (b: val),
treebox_rep t b = EX p: val, data_at Tsh (tptr t_struct_tree) p b * tree_rep t p.
Lemma tree_rep_treebox_rep: forall (t: tree val) (p: val),
tree_rep t p =
match t with
| E => !!(p=nullval) && emp
| T l x v r => !! (Int.min_signed <= Z.of_nat x <= Int.max_signed /\ tc_val (tptr Tvoid) v) &&
field_at Tsh t_struct_tree [StructField _key] (Vint (Int.repr (Z.of_nat x))) p *
field_at Tsh t_struct_tree [StructField _value] v p *
treebox_rep l (field_address t_struct_tree [StructField _left] p) *
treebox_rep r (field_address t_struct_tree [StructField _right] p)
end.