Definition latest_read (h : hist) v :=
  (* initial condition *)
  ((forall t r w, h t = Some (AE r w) -> w = Empty -> r = Empty) /\ v = vint 1) \/
  v <> Empty /\ exists n, h n = Some (AE v Empty) /\
  forall t r w, h t = Some (AE r w) -> w = Empty -> r <> Empty -> (t <= n)%nat.

(* Specifications: *)
Lemma lock_struct_array : forall sh z (v : list val) p, data_at sh (tarray (tptr (Tstruct _lock_t noattr)) z) v p = data_at sh (tarray (tptr tlock) z) v p.
Lemma Empty_inj : forall i, vint i = Empty -> repable_signed i -> i = -1.
Lemma repable_buf : forall a, -1 <= a < B -> repable_signed a.
Lemma last_two_reads_cons : forall r w h, last_two_reads (AE r w :: h) = if eq_dec w Empty then if eq_dec r Empty then last_two_reads h else (r, fst (last_two_reads h)) else last_two_reads h.
Lemma prev_taken_cons : forall r w h, prev_taken (AE r w :: h) = if eq_dec w Empty then prev_taken h else fst (find_read h (vint 1)).
Lemma find_read_pos : forall d h, d <> Empty -> fst (find_read h d) <> Empty.