Proof using.
induction tr; intros; simpl in *; intuition.
repeat break_match; subst; simpl in *; intuition eauto; try congruence;
unfold output_before_input; simpl in *; intuition.
- right. intuition.
+ do_bool.
destruct k'.  simpl in *.
match goal with
| _ : I (?x, ?y) = I (?x', ?y') -> False |- _ =>
destruct (clientId_eq_dec x x'); destruct (eq_nat_dec y y')
end; subst; intuition.
* right. do_bool. intuition.
* left. break_if; congruence.
* left. break_if; congruence.
+ apply IHtr. eauto using before_remove.
- break_if; intuition. right.
intuition. find_apply_lem_hyp before_app; [find_apply_lem_hyp before_remove_all|]; intuition eauto.
+ find_apply_lem_hyp in_dedup_was_in.
find_apply_lem_hyp In_filterMap.
break_exists. intuition. break_match; congruence.
+ find_apply_lem_hyp in_dedup_was_in.
find_apply_lem_hyp In_filterMap.
break_exists.
intuition. break_match; try congruence.
subst. find_inversion. simpl in *.
match goal with
| H : _ -> False |- False => apply H
end. eexists; eauto.
Qed.

Lemma has_key_true_key_of :
forall c i e,
has_key c i e = true ->
key_of e = (c, i).