Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Definition reverse_spec :=
DECLARE _reverse
WITH a0: val, sh : share, contents : list int, size: Z
PRE [ _a OF (tptr tint), _n OF tint ]
PROP (0 <= size <= Int.max_signed; writable_share sh)
LOCAL (temp _a a0; temp _n (Vint (Int.repr size)))
SEP (data_at sh (tarray tint size) (map Vint contents) a0)
POST [ tvoid ]
PROP() LOCAL()
SEP(data_at sh (tarray tint size) (map Vint (rev contents)) a0).
Definition main_spec :=
DECLARE _main
WITH gv : globals
PRE  [] main_pre prog tt nil gv
POST [ tint ] main_post prog nil gv.
Definition Gprog : funspecs :=   ltac:(with_library prog [reverse_spec; main_spec]).
Definition flip_ends {A} lo hi (contents: list A) :=
sublist 0 lo (rev contents)
++ sublist lo hi contents
++ sublist hi (Zlength contents) (rev contents).
Definition reverse_Inv a0 sh contents size :=
(EX j:Z,
(PROP  (0 <= j; j <= size-j)
LOCAL  (temp _a a0; temp _lo (Vint (Int.repr j)); temp _hi (Vint (Int.repr (size-j))))
SEP (data_at sh (tarray tint size) (flip_ends j (size-j) contents) a0)))%assert.
Hint Rewrite @Zlength_flip_ends using (autorewrite with sublist; omega) : sublist.

Lemma flip_fact_3:
forall A (al: list A) j size,
size = Zlength al ->
0 <= j < size - j - 1 ->
sublist 0 j (flip_ends j (size - j) al) ++
sublist (size - j - 1) (size - j) al ++
sublist (j + 1) size
(sublist 0 (size - j - 1) (flip_ends j (size - j) al) ++
sublist j (j + 1) (flip_ends j (size - j) al) ++
sublist (size - j) size (flip_ends j (size - j) al)) =
flip_ends (j + 1) (size - (j + 1)) al.