Ltac set_up_net_handlers :=
    intros;
    match goal with
      | [ H : context [ NetHandler (pDst ?p) _ _ _ ] |- _ ] =>
        destruct (pDst p) eqn:?
    end; simpl in *;
    [find_apply_lem_hyp ClientNetHandler_cases |
     find_apply_lem_hyp ServerNetHandler_cases; intuition; try break_exists ];
    intuition; subst;
    simpl in *; intuition;
    repeat find_rewrite;
    repeat find_inversion;
    simpl in *;
    try now rewrite update_nop_ext.

(* Specifications: *)
Lemma locks_correct_net_handlers : forall p sigma u st' out ms, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> locks_correct_locked sigma p -> locks_correct (update name_eq_dec sigma (pDst p) st').
Lemma locks_correct_unlock_sent_lock : forall sigma p, pBody p = Lock -> locks_correct_unlock sigma p.
Lemma locks_correct_unlock_sent_locked : forall sigma p, pBody p = Locked -> locks_correct_unlock sigma p.
Lemma locks_correct_unlock_input_handlers_old : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> locks_correct_unlock (update name_eq_dec sigma h st') p.
Lemma locked_in_flight_all_clients_false : forall sigma p, pBody p = Locked -> locks_correct_locked sigma p -> locks_correct sigma -> (forall c, held (sigma (Client c)) = false).
Lemma locks_correct_locked_sent_lock : forall sigma p, pBody p = Lock -> locks_correct_locked sigma p.
Lemma locks_correct_locked_sent_unlock : forall sigma p, pBody p = Unlock -> locks_correct_locked sigma p.
Lemma locks_correct_locked_input_handlers_old : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_locked sigma p -> locks_correct_locked (update name_eq_dec sigma h st') p.
Lemma locks_correct_unlock_true_to_false : forall sigma p x st', at_head_of_queue sigma x -> held st' = false -> pSrc p = Client x -> locks_correct_unlock (update name_eq_dec sigma (Client x) st') p.
Lemma locks_correct_unlock_input_handlers_new : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> In (pDst p, pBody p) ms -> pSrc p = h -> locks_correct_unlock (update name_eq_dec sigma h st') p.
Lemma locks_correct_locked_input_handlers_new : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> In (pDst p, pBody p) ms -> locks_correct_locked (update name_eq_dec sigma h st') p.
Lemma nwnw_locked_lock : forall p q, LockServ_network_network_invariant p q -> pBody p = Locked -> pBody q = Lock.
Lemma nwnw_unlock_lock : forall p q, LockServ_network_network_invariant p q -> pBody p = Unlock -> pBody q = Lock.
Lemma locks_correct_unlock_at_head : forall sigma p c, pSrc p = Client c -> pBody p = Unlock -> locks_correct_unlock sigma p -> at_head_of_queue sigma c.
Lemma locks_correct_unlock_at_head_preserved : forall sigma st' p, locks_correct_unlock sigma p -> (forall c, at_head_of_queue sigma c -> at_head_of_queue (update name_eq_dec sigma Server st') c) -> locks_correct_unlock (update name_eq_dec sigma Server st') p.
Lemma locks_correct_unlock_net_handlers_old : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma q -> LockServ_network_network_invariant p q -> locks_correct_unlock (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_locked_at_head_preserved : forall sigma st' p, locks_correct_locked sigma p -> (forall c, at_head_of_queue sigma c -> at_head_of_queue (update name_eq_dec sigma Server st') c) -> locks_correct_locked (update name_eq_dec sigma Server st') p.
Lemma locks_correct_locked_net_handlers_old : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_locked sigma q -> LockServ_network_network_invariant p q -> locks_correct_locked (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_unlock_net_handlers_new : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> In (pDst q, pBody q) ms -> locks_correct_unlock (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_locked_intro : forall sigma p c t st', pDst p = Client c -> held (sigma (Client c)) = false -> queue st' = c :: t -> locks_correct_locked (update name_eq_dec sigma Server st') p.
Lemma locks_correct_locked_net_handlers_new : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> In (pDst q, pBody q) ms -> locks_correct_locked (update name_eq_dec sigma (pDst p) st') q.
Lemma nwnw_lock : forall p p', pBody p = Lock -> LockServ_network_network_invariant p p'.
Lemma LockServ_nwnw_input_handlers_old_new : forall h i sigma u st' out ms p p', InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> In (pDst p', pBody p') ms -> pSrc p' = h -> LockServ_network_network_invariant p p'.
Lemma LockServ_nwnw_input_handlers_new_new : forall h i sigma u st' out ms, InputHandler h i (sigma h) = (u, out, st', ms) -> distinct_pairs_and LockServ_network_network_invariant (map (fun m => mkPacket h (fst m) (snd m)) ms).
Lemma LockServ_nwnw_net_handlers_old_new : forall p sigma u st' out ms q p', NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> LockServ_network_invariant sigma q -> LockServ_network_network_invariant p q -> In (pDst p', pBody p') ms -> LockServ_network_network_invariant p' q.
Lemma LockServ_nwnw_net_handlers_new_new : forall p sigma u st' out ms, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> distinct_pairs_and LockServ_network_network_invariant (map (fun m => mkPacket (pDst p) (fst m) (snd m)) ms).
Lemma locks_correct_net_handlers : forall p sigma u st' out ms, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> locks_correct_locked sigma p -> locks_correct (update name_eq_dec sigma (pDst p) st').
Lemma locks_correct_unlock_sent_lock : forall sigma p, pBody p = Lock -> locks_correct_unlock sigma p.
Lemma locks_correct_unlock_sent_locked : forall sigma p, pBody p = Locked -> locks_correct_unlock sigma p.
Lemma locks_correct_unlock_input_handlers_old : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> locks_correct_unlock (update name_eq_dec sigma h st') p.
Lemma locked_in_flight_all_clients_false : forall sigma p, pBody p = Locked -> locks_correct_locked sigma p -> locks_correct sigma -> (forall c, held (sigma (Client c)) = false).
Lemma locks_correct_locked_sent_lock : forall sigma p, pBody p = Lock -> locks_correct_locked sigma p.
Lemma locks_correct_locked_sent_unlock : forall sigma p, pBody p = Unlock -> locks_correct_locked sigma p.
Lemma locks_correct_locked_input_handlers_old : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_locked sigma p -> locks_correct_locked (update name_eq_dec sigma h st') p.
Lemma locks_correct_unlock_true_to_false : forall sigma p x st', at_head_of_queue sigma x -> held st' = false -> pSrc p = Client x -> locks_correct_unlock (update name_eq_dec sigma (Client x) st') p.
Lemma locks_correct_unlock_input_handlers_new : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> In (pDst p, pBody p) ms -> pSrc p = h -> locks_correct_unlock (update name_eq_dec sigma h st') p.
Lemma locks_correct_locked_input_handlers_new : forall h i sigma u st' out ms p, InputHandler h i (sigma h) = (u, out, st', ms) -> In (pDst p, pBody p) ms -> locks_correct_locked (update name_eq_dec sigma h st') p.
Lemma nwnw_locked_lock : forall p q, LockServ_network_network_invariant p q -> pBody p = Locked -> pBody q = Lock.
Lemma nwnw_unlock_lock : forall p q, LockServ_network_network_invariant p q -> pBody p = Unlock -> pBody q = Lock.
Lemma locks_correct_unlock_at_head : forall sigma p c, pSrc p = Client c -> pBody p = Unlock -> locks_correct_unlock sigma p -> at_head_of_queue sigma c.
Lemma locks_correct_unlock_at_head_preserved : forall sigma st' p, locks_correct_unlock sigma p -> (forall c, at_head_of_queue sigma c -> at_head_of_queue (update name_eq_dec sigma Server st') c) -> locks_correct_unlock (update name_eq_dec sigma Server st') p.
Lemma locks_correct_unlock_net_handlers_old : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma q -> LockServ_network_network_invariant p q -> locks_correct_unlock (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_locked_at_head_preserved : forall sigma st' p, locks_correct_locked sigma p -> (forall c, at_head_of_queue sigma c -> at_head_of_queue (update name_eq_dec sigma Server st') c) -> locks_correct_locked (update name_eq_dec sigma Server st') p.
Lemma locks_correct_locked_net_handlers_old : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_locked sigma q -> LockServ_network_network_invariant p q -> locks_correct_locked (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_unlock_net_handlers_new : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> In (pDst q, pBody q) ms -> locks_correct_unlock (update name_eq_dec sigma (pDst p) st') q.
Lemma locks_correct_locked_intro : forall sigma p c t st', pDst p = Client c -> held (sigma (Client c)) = false -> queue st' = c :: t -> locks_correct_locked (update name_eq_dec sigma Server st') p.
Lemma locks_correct_locked_net_handlers_new : forall p sigma u st' out ms q, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> locks_correct_unlock sigma p -> In (pDst q, pBody q) ms -> locks_correct_locked (update name_eq_dec sigma (pDst p) st') q.
Lemma nwnw_lock : forall p p', pBody p = Lock -> LockServ_network_network_invariant p p'.
Lemma LockServ_nwnw_input_handlers_old_new : forall h i sigma u st' out ms p p', InputHandler h i (sigma h) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> In (pDst p', pBody p') ms -> pSrc p' = h -> LockServ_network_network_invariant p p'.
Lemma LockServ_nwnw_input_handlers_new_new : forall h i sigma u st' out ms, InputHandler h i (sigma h) = (u, out, st', ms) -> distinct_pairs_and LockServ_network_network_invariant (map (fun m => mkPacket h (fst m) (snd m)) ms).
Lemma LockServ_nwnw_net_handlers_old_new : forall p sigma u st' out ms q p', NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> LockServ_network_invariant sigma q -> LockServ_network_network_invariant p q -> In (pDst p', pBody p') ms -> LockServ_network_network_invariant p' q.
Lemma LockServ_nwnw_net_handlers_new_new : forall p sigma u st' out ms, NetHandler (pDst p) (pSrc p) (pBody p) (sigma (pDst p)) = (u, out, st', ms) -> locks_correct sigma -> LockServ_network_invariant sigma p -> distinct_pairs_and LockServ_network_network_invariant (map (fun m => mkPacket (pDst p) (fst m) (snd m)) ms).