Instance CompSpecs : compspecs. make_compspecs prog. Defined.
Definition Vprog : varspecs. mk_varspecs prog. Defined.
Definition putchars_spec := DECLARE _putchars putchars_spec.
Definition getchars_spec := DECLARE _getchars getchars_spec.
Program Fixpoint chars_of_Z (n : Z) { measure (Z.to_nat n) } : list byte :=
let n' := n / 10 in
match n' <=? 0 with true => [Byte.repr (n + char0)] | false => chars_of_Z n' ++ [Byte.repr (n mod 10 + char0)] end.
Next Obligation.
(*Opaque bind.  Opaque Nat.div Nat.modulo.*)

Lemma read_sum_eq : forall n lc, read_sum n lc ≈
if zlt n 1000 then
let nums := map (fun c => Byte.unsigned c - char0) lc in
b <- for_loop 0 4 (read_sum_inner n nums) ;; if (b : bool) then Ret tt else
lc' <- read_list stdin 4;; read_sum (n + sum_Z nums) lc'
else Ret tt.