Proof using.
unfold cacheApplyEntry.
intros.
repeat break_match; repeat find_inversion; simpl in *; intuition.
- do_bool. subst. eauto using output_correct_monotonic, getLastId_Some_In.
- eapply applyEntry_output_correct; eauto.
do_bool. assert (n < eId e) by auto with *.
intros. assert (eId e' <= n) by eauto. omega.
- eapply applyEntry_output_correct; eauto.
intros.
find_apply_hyp_hyp.
break_exists. break_and.
repeat find_rewrite. discriminate.
Qed.

Lemma cacheApplyEntry_stateMachine_correct :
forall st e l st' es,
cacheApplyEntry st e = (l, st') ->
stateMachine st = snd (execute_log (deduplicate_log es)) ->
(forall c i o,
getLastId st c = Some (i, o) ->
exists e,
In e es /\
eClient e = c /\
eId e = i) ->
(forall c i o e',
getLastId st c = Some (i, o) ->
In e' es ->
eClient e' = c ->
eId e' <= i) ->
(forall e',
In e' es ->
exists i o,
getLastId st (eClient e') = Some (i, o) /\
eId e' <= i) ->
stateMachine st' = snd (execute_log (deduplicate_log (es ++ [e]))).