(* Generated by coq-of-rust *)
Require Import CoqOfRust.CoqOfRust.

Module collections.
  Module btree.
    Module navigate.
      (* StructRecord
        {
          name := "LeafRange";
          const_params := [];
          ty_params := [ "BorrowType"; "K"; "V" ];
          fields :=
            [
              ("front",
                Ty.apply
                  (Ty.path "core::option::Option")
                  []
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            BorrowType;
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ]
                  ]);
              ("back",
                Ty.apply
                  (Ty.path "core::option::Option")
                  []
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            BorrowType;
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ]
                  ])
            ];
        } *)
      
      Module Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_Immut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ].
        
        (*
            fn clone(&self) -> Self {
                LeafRange { front: self.front.clone(), back: self.back.clone() }
            }
        *)
        Definition clone (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              Value.StructRecord
                "alloc::collections::btree::navigate::LeafRange"
                [
                  ("front",
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::clone::Clone",
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ],
                        [],
                        "clone",
                        []
                      |),
                      [
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::collections::btree::navigate::LeafRange",
                          "front"
                        |)
                      ]
                    |));
                  ("back",
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::clone::Clone",
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ],
                        [],
                        "clone",
                        []
                      |),
                      [
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::collections::btree::navigate::LeafRange",
                          "back"
                        |)
                      ]
                    |))
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (K V : Ty.t),
          M.IsTraitInstance
            "core::clone::Clone"
            (Self K V)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("clone", InstanceField.Method (clone K V)) ].
      End Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_Immut_K_V.
      
      Module Impl_core_default_Default_for_alloc_collections_btree_navigate_LeafRange_B_K_V.
        Definition Self (B K V : Ty.t) : Ty.t :=
          Ty.apply (Ty.path "alloc::collections::btree::navigate::LeafRange") [] [ B; K; V ].
        
        (*
            fn default() -> Self {
                LeafRange { front: None, back: None }
            }
        *)
        Definition default
            (B K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self B K V in
          match ε, τ, α with
          | [], [], [] =>
            ltac:(M.monadic
              (Value.StructRecord
                "alloc::collections::btree::navigate::LeafRange"
                [
                  ("front", Value.StructTuple "core::option::Option::None" []);
                  ("back", Value.StructTuple "core::option::Option::None" [])
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (B K V : Ty.t),
          M.IsTraitInstance
            "core::default::Default"
            (Self B K V)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("default", InstanceField.Method (default B K V)) ].
      End Impl_core_default_Default_for_alloc_collections_btree_navigate_LeafRange_B_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LeafRange_BorrowType_K_V.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LeafRange")
            []
            [ BorrowType; K; V ].
        
        (*
            pub fn none() -> Self {
                LeafRange { front: None, back: None }
            }
        *)
        Definition none
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [] =>
            ltac:(M.monadic
              (Value.StructRecord
                "alloc::collections::btree::navigate::LeafRange"
                [
                  ("front", Value.StructTuple "core::option::Option::None" []);
                  ("back", Value.StructTuple "core::option::Option::None" [])
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_none :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "none" (none BorrowType K V).
        
        (*
            fn is_empty(&self) -> bool {
                self.front == self.back
            }
        *)
        Definition is_empty
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_trait_method (|
                  "core::cmp::PartialEq",
                  Ty.apply
                    (Ty.path "core::option::Option")
                    []
                    [
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::Handle")
                        []
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              BorrowType;
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::Leaf"
                            ];
                          Ty.path "alloc::collections::btree::node::marker::Edge"
                        ]
                    ],
                  [
                    Ty.apply
                      (Ty.path "core::option::Option")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::Handle")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                BorrowType;
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::Leaf"
                              ];
                            Ty.path "alloc::collections::btree::node::marker::Edge"
                          ]
                      ]
                  ],
                  "eq",
                  []
                |),
                [
                  M.SubPointer.get_struct_record_field (|
                    M.read (| self |),
                    "alloc::collections::btree::navigate::LeafRange",
                    "front"
                  |);
                  M.SubPointer.get_struct_record_field (|
                    M.read (| self |),
                    "alloc::collections::btree::navigate::LeafRange",
                    "back"
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_is_empty :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "is_empty" (is_empty BorrowType K V).
        
        (*
            pub fn reborrow(&self) -> LeafRange<marker::Immut<'_>, K, V> {
                LeafRange {
                    front: self.front.as_ref().map(|f| f.reborrow()),
                    back: self.back.as_ref().map(|b| b.reborrow()),
                }
            }
        *)
        Definition reborrow
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              Value.StructRecord
                "alloc::collections::btree::navigate::LeafRange"
                [
                  ("front",
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ]
                          ],
                        "map",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Immut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "&")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::Handle")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Leaf"
                                            ];
                                          Ty.path "alloc::collections::btree::node::marker::Edge"
                                        ]
                                    ]
                                ]
                            ]
                            (Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ])
                        ]
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "core::option::Option")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ],
                            "as_ref",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::collections::btree::navigate::LeafRange",
                              "front"
                            |)
                          ]
                        |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let f := M.copy (| γ |) in
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Leaf"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Edge"
                                                ],
                                              "reborrow",
                                              []
                                            |),
                                            [ M.read (| f |) ]
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |));
                  ("back",
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ]
                          ],
                        "map",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Immut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "&")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::Handle")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Leaf"
                                            ];
                                          Ty.path "alloc::collections::btree::node::marker::Edge"
                                        ]
                                    ]
                                ]
                            ]
                            (Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ])
                        ]
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "core::option::Option")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ],
                            "as_ref",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::collections::btree::navigate::LeafRange",
                              "back"
                            |)
                          ]
                        |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let b := M.copy (| γ |) in
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Leaf"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Edge"
                                                ],
                                              "reborrow",
                                              []
                                            |),
                                            [ M.read (| b |) ]
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |))
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_reborrow :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "reborrow" (reborrow BorrowType K V).
        (*
            fn perform_next_checked<F, R>(&mut self, f: F) -> Option<R>
            where
                F: Fn(&Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, marker::KV>) -> R,
            {
                if self.is_empty() {
                    None
                } else {
                    super::mem::replace(self.front.as_mut().unwrap(), |front| {
                        let kv = front.next_kv().ok().unwrap();
                        let result = f(&kv);
                        (kv.next_leaf_edge(), Some(result))
                    })
                }
            }
        *)
        Definition perform_next_checked
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [ F; R ], [ self; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let f := M.alloc (| f |) in
              M.read (|
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use
                            (M.alloc (|
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                                    []
                                    [ BorrowType; K; V ],
                                  "is_empty",
                                  []
                                |),
                                [ M.read (| self |) ]
                              |)
                            |)) in
                        let _ :=
                          M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                        M.alloc (| Value.StructTuple "core::option::Option::None" [] |)));
                    fun γ =>
                      ltac:(M.monadic
                        (M.alloc (|
                          M.call_closure (|
                            M.get_function (|
                              "alloc::collections::btree::mem::replace",
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ];
                                Ty.apply (Ty.path "core::option::Option") [] [ R ];
                                Ty.function
                                  [
                                    Ty.tuple
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                BorrowType;
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Leaf"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::Edge"
                                          ]
                                      ]
                                  ]
                                  (Ty.tuple
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::Handle")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Leaf"
                                            ];
                                          Ty.path "alloc::collections::btree::node::marker::Edge"
                                        ];
                                      Ty.apply (Ty.path "core::option::Option") [] [ R ]
                                    ])
                              ]
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "core::option::Option")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "&mut")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Leaf"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ]
                                        ]
                                    ],
                                  "unwrap",
                                  []
                                |),
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "core::option::Option")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Leaf"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ]
                                        ],
                                      "as_mut",
                                      []
                                    |),
                                    [
                                      M.SubPointer.get_struct_record_field (|
                                        M.read (| self |),
                                        "alloc::collections::btree::navigate::LeafRange",
                                        "front"
                                      |)
                                    ]
                                  |)
                                ]
                              |);
                              M.closure
                                (fun γ =>
                                  ltac:(M.monadic
                                    match γ with
                                    | [ α0 ] =>
                                      ltac:(M.monadic
                                        (M.match_operator (|
                                          M.alloc (| α0 |),
                                          [
                                            fun γ =>
                                              ltac:(M.monadic
                                                (let front := M.copy (| γ |) in
                                                M.read (|
                                                  let~ kv :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_associated_function (|
                                                          Ty.apply
                                                            (Ty.path "core::option::Option")
                                                            []
                                                            [
                                                              Ty.apply
                                                                (Ty.path
                                                                  "alloc::collections::btree::node::Handle")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      BorrowType;
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ];
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::KV"
                                                                ]
                                                            ],
                                                          "unwrap",
                                                          []
                                                        |),
                                                        [
                                                          M.call_closure (|
                                                            M.get_associated_function (|
                                                              Ty.apply
                                                                (Ty.path "core::result::Result")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::Handle")
                                                                    []
                                                                    [
                                                                      Ty.apply
                                                                        (Ty.path
                                                                          "alloc::collections::btree::node::NodeRef")
                                                                        []
                                                                        [
                                                                          BorrowType;
                                                                          K;
                                                                          V;
                                                                          Ty.path
                                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                        ];
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::KV"
                                                                    ];
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      BorrowType;
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ]
                                                                ],
                                                              "ok",
                                                              []
                                                            |),
                                                            [
                                                              M.call_closure (|
                                                                M.get_associated_function (|
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::Handle")
                                                                    []
                                                                    [
                                                                      Ty.apply
                                                                        (Ty.path
                                                                          "alloc::collections::btree::node::NodeRef")
                                                                        []
                                                                        [
                                                                          BorrowType;
                                                                          K;
                                                                          V;
                                                                          Ty.path
                                                                            "alloc::collections::btree::node::marker::Leaf"
                                                                        ];
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::Edge"
                                                                    ],
                                                                  "next_kv",
                                                                  []
                                                                |),
                                                                [ M.read (| front |) ]
                                                              |)
                                                            ]
                                                          |)
                                                        ]
                                                      |)
                                                    |) in
                                                  let~ result :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_trait_method (|
                                                          "core::ops::function::Fn",
                                                          F,
                                                          [
                                                            Ty.tuple
                                                              [
                                                                Ty.apply
                                                                  (Ty.path "&")
                                                                  []
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path
                                                                        "alloc::collections::btree::node::Handle")
                                                                      []
                                                                      [
                                                                        Ty.apply
                                                                          (Ty.path
                                                                            "alloc::collections::btree::node::NodeRef")
                                                                          []
                                                                          [
                                                                            BorrowType;
                                                                            K;
                                                                            V;
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                          ];
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::KV"
                                                                      ]
                                                                  ]
                                                              ]
                                                          ],
                                                          "call",
                                                          []
                                                        |),
                                                        [ f; Value.Tuple [ kv ] ]
                                                      |)
                                                    |) in
                                                  M.alloc (|
                                                    Value.Tuple
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    BorrowType;
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ],
                                                            "next_leaf_edge",
                                                            []
                                                          |),
                                                          [ M.read (| kv |) ]
                                                        |);
                                                        Value.StructTuple
                                                          "core::option::Option::Some"
                                                          [ M.read (| result |) ]
                                                      ]
                                                  |)
                                                |)))
                                          ]
                                        |)))
                                    | _ => M.impossible "wrong number of arguments"
                                    end))
                            ]
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_perform_next_checked :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "perform_next_checked"
            (perform_next_checked BorrowType K V).
        
        (*
            fn perform_next_back_checked<F, R>(&mut self, f: F) -> Option<R>
            where
                F: Fn(&Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, marker::KV>) -> R,
            {
                if self.is_empty() {
                    None
                } else {
                    super::mem::replace(self.back.as_mut().unwrap(), |back| {
                        let kv = back.next_back_kv().ok().unwrap();
                        let result = f(&kv);
                        (kv.next_back_leaf_edge(), Some(result))
                    })
                }
            }
        *)
        Definition perform_next_back_checked
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [ F; R ], [ self; f ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let f := M.alloc (| f |) in
              M.read (|
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use
                            (M.alloc (|
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                                    []
                                    [ BorrowType; K; V ],
                                  "is_empty",
                                  []
                                |),
                                [ M.read (| self |) ]
                              |)
                            |)) in
                        let _ :=
                          M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                        M.alloc (| Value.StructTuple "core::option::Option::None" [] |)));
                    fun γ =>
                      ltac:(M.monadic
                        (M.alloc (|
                          M.call_closure (|
                            M.get_function (|
                              "alloc::collections::btree::mem::replace",
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ];
                                Ty.apply (Ty.path "core::option::Option") [] [ R ];
                                Ty.function
                                  [
                                    Ty.tuple
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                BorrowType;
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Leaf"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::Edge"
                                          ]
                                      ]
                                  ]
                                  (Ty.tuple
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::Handle")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Leaf"
                                            ];
                                          Ty.path "alloc::collections::btree::node::marker::Edge"
                                        ];
                                      Ty.apply (Ty.path "core::option::Option") [] [ R ]
                                    ])
                              ]
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "core::option::Option")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "&mut")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Leaf"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ]
                                        ]
                                    ],
                                  "unwrap",
                                  []
                                |),
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "core::option::Option")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Leaf"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ]
                                        ],
                                      "as_mut",
                                      []
                                    |),
                                    [
                                      M.SubPointer.get_struct_record_field (|
                                        M.read (| self |),
                                        "alloc::collections::btree::navigate::LeafRange",
                                        "back"
                                      |)
                                    ]
                                  |)
                                ]
                              |);
                              M.closure
                                (fun γ =>
                                  ltac:(M.monadic
                                    match γ with
                                    | [ α0 ] =>
                                      ltac:(M.monadic
                                        (M.match_operator (|
                                          M.alloc (| α0 |),
                                          [
                                            fun γ =>
                                              ltac:(M.monadic
                                                (let back := M.copy (| γ |) in
                                                M.read (|
                                                  let~ kv :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_associated_function (|
                                                          Ty.apply
                                                            (Ty.path "core::option::Option")
                                                            []
                                                            [
                                                              Ty.apply
                                                                (Ty.path
                                                                  "alloc::collections::btree::node::Handle")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      BorrowType;
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ];
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::KV"
                                                                ]
                                                            ],
                                                          "unwrap",
                                                          []
                                                        |),
                                                        [
                                                          M.call_closure (|
                                                            M.get_associated_function (|
                                                              Ty.apply
                                                                (Ty.path "core::result::Result")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::Handle")
                                                                    []
                                                                    [
                                                                      Ty.apply
                                                                        (Ty.path
                                                                          "alloc::collections::btree::node::NodeRef")
                                                                        []
                                                                        [
                                                                          BorrowType;
                                                                          K;
                                                                          V;
                                                                          Ty.path
                                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                        ];
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::KV"
                                                                    ];
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      BorrowType;
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ]
                                                                ],
                                                              "ok",
                                                              []
                                                            |),
                                                            [
                                                              M.call_closure (|
                                                                M.get_associated_function (|
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::Handle")
                                                                    []
                                                                    [
                                                                      Ty.apply
                                                                        (Ty.path
                                                                          "alloc::collections::btree::node::NodeRef")
                                                                        []
                                                                        [
                                                                          BorrowType;
                                                                          K;
                                                                          V;
                                                                          Ty.path
                                                                            "alloc::collections::btree::node::marker::Leaf"
                                                                        ];
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::Edge"
                                                                    ],
                                                                  "next_back_kv",
                                                                  []
                                                                |),
                                                                [ M.read (| back |) ]
                                                              |)
                                                            ]
                                                          |)
                                                        ]
                                                      |)
                                                    |) in
                                                  let~ result :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_trait_method (|
                                                          "core::ops::function::Fn",
                                                          F,
                                                          [
                                                            Ty.tuple
                                                              [
                                                                Ty.apply
                                                                  (Ty.path "&")
                                                                  []
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path
                                                                        "alloc::collections::btree::node::Handle")
                                                                      []
                                                                      [
                                                                        Ty.apply
                                                                          (Ty.path
                                                                            "alloc::collections::btree::node::NodeRef")
                                                                          []
                                                                          [
                                                                            BorrowType;
                                                                            K;
                                                                            V;
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                          ];
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::KV"
                                                                      ]
                                                                  ]
                                                              ]
                                                          ],
                                                          "call",
                                                          []
                                                        |),
                                                        [ f; Value.Tuple [ kv ] ]
                                                      |)
                                                    |) in
                                                  M.alloc (|
                                                    Value.Tuple
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    BorrowType;
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ],
                                                            "next_back_leaf_edge",
                                                            []
                                                          |),
                                                          [ M.read (| kv |) ]
                                                        |);
                                                        Value.StructTuple
                                                          "core::option::Option::Some"
                                                          [ M.read (| result |) ]
                                                      ]
                                                  |)
                                                |)))
                                          ]
                                        |)))
                                    | _ => M.impossible "wrong number of arguments"
                                    end))
                            ]
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_perform_next_back_checked :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "perform_next_back_checked"
            (perform_next_back_checked BorrowType K V).
      End Impl_alloc_collections_btree_navigate_LeafRange_BorrowType_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_Immut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ].
        
        (*
            pub fn next_checked(&mut self) -> Option<(&'a K, &'a V)> {
                self.perform_next_checked(|kv| kv.into_kv())
            }
        *)
        Definition next_checked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                    []
                    [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ],
                  "perform_next_checked",
                  [
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Immut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]);
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let kv := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Immut";
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::KV"
                                          ],
                                        "into_kv",
                                        []
                                      |),
                                      [ M.read (| M.read (| kv |) |) ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_checked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_checked" (next_checked K V).
        
        (*
            pub fn next_back_checked(&mut self) -> Option<(&'a K, &'a V)> {
                self.perform_next_back_checked(|kv| kv.into_kv())
            }
        *)
        Definition next_back_checked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                    []
                    [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ],
                  "perform_next_back_checked",
                  [
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Immut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]);
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let kv := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Immut";
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::KV"
                                          ],
                                        "into_kv",
                                        []
                                      |),
                                      [ M.read (| M.read (| kv |) |) ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_checked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_checked" (next_back_checked K V).
      End Impl_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_Immut_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_ValMut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ].
        
        (*
            pub fn next_checked(&mut self) -> Option<(&'a K, &'a mut V)> {
                self.perform_next_checked(|kv| unsafe { ptr::read(kv) }.into_kv_valmut())
            }
        *)
        Definition next_checked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                    []
                    [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ],
                  "perform_next_checked",
                  [
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&mut") [] [ V ] ]);
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&mut") [] [ V ] ]
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let kv := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::ValMut";
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::KV"
                                          ],
                                        "into_kv_valmut",
                                        []
                                      |),
                                      [
                                        M.call_closure (|
                                          M.get_function (|
                                            "core::ptr::read",
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::ValMut";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::KV"
                                                ]
                                            ]
                                          |),
                                          [ M.read (| kv |) ]
                                        |)
                                      ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_checked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_checked" (next_checked K V).
        
        (*
            pub fn next_back_checked(&mut self) -> Option<(&'a K, &'a mut V)> {
                self.perform_next_back_checked(|kv| unsafe { ptr::read(kv) }.into_kv_valmut())
            }
        *)
        Definition next_back_checked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                    []
                    [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ],
                  "perform_next_back_checked",
                  [
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&mut") [] [ V ] ]);
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&mut") [] [ V ] ]
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let kv := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::ValMut";
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::KV"
                                          ],
                                        "into_kv_valmut",
                                        []
                                      |),
                                      [
                                        M.call_closure (|
                                          M.get_function (|
                                            "core::ptr::read",
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::ValMut";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::KV"
                                                ]
                                            ]
                                          |),
                                          [ M.read (| kv |) ]
                                        |)
                                      ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_checked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_checked" (next_back_checked K V).
      End Impl_alloc_collections_btree_navigate_LeafRange_alloc_collections_btree_node_marker_ValMut_K_V.
      
      
      (*
      Enum LazyLeafHandle
      {
        const_params := [];
        ty_params := [ "BorrowType"; "K"; "V" ];
        variants :=
          [
            {
              name := "Root";
              item :=
                StructTuple
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::NodeRef")
                      []
                      [
                        BorrowType;
                        K;
                        V;
                        Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                      ]
                  ];
              discriminant := None;
            };
            {
              name := "Edge";
              item :=
                StructTuple
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            BorrowType;
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ]
                  ];
              discriminant := None;
            }
          ];
      }
      *)
      
      Module Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LazyLeafHandle_alloc_collections_btree_node_marker_Immut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ].
        
        (*
            fn clone(&self) -> Self {
                match self {
                    LazyLeafHandle::Root(root) => LazyLeafHandle::Root( *root),
                    LazyLeafHandle::Edge(edge) => LazyLeafHandle::Edge( *edge),
                }
            }
        *)
        Definition clone (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                M.match_operator (|
                  self,
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                            0
                          |) in
                        let root := M.alloc (| γ1_0 |) in
                        M.alloc (|
                          Value.StructTuple
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root"
                            [ M.read (| M.read (| root |) |) ]
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge",
                            0
                          |) in
                        let edge := M.alloc (| γ1_0 |) in
                        M.alloc (|
                          Value.StructTuple
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge"
                            [ M.read (| M.read (| edge |) |) ]
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (K V : Ty.t),
          M.IsTraitInstance
            "core::clone::Clone"
            (Self K V)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("clone", InstanceField.Method (clone K V)) ].
      End Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LazyLeafHandle_alloc_collections_btree_node_marker_Immut_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LazyLeafHandle_BorrowType_K_V.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
            []
            [ BorrowType; K; V ].
        
        (*
            fn reborrow(&self) -> LazyLeafHandle<marker::Immut<'_>, K, V> {
                match self {
                    LazyLeafHandle::Root(root) => LazyLeafHandle::Root(root.reborrow()),
                    LazyLeafHandle::Edge(edge) => LazyLeafHandle::Edge(edge.reborrow()),
                }
            }
        *)
        Definition reborrow
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                M.match_operator (|
                  self,
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                            0
                          |) in
                        let root := M.alloc (| γ1_0 |) in
                        M.alloc (|
                          Value.StructTuple
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root"
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      BorrowType;
                                      K;
                                      V;
                                      Ty.path
                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                    ],
                                  "reborrow",
                                  []
                                |),
                                [ M.read (| root |) ]
                              |)
                            ]
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge",
                            0
                          |) in
                        let edge := M.alloc (| γ1_0 |) in
                        M.alloc (|
                          Value.StructTuple
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge"
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::Handle")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                                        ];
                                      Ty.path "alloc::collections::btree::node::marker::Edge"
                                    ],
                                  "reborrow",
                                  []
                                |),
                                [ M.read (| edge |) ]
                              |)
                            ]
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_reborrow :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "reborrow" (reborrow BorrowType K V).
      End Impl_alloc_collections_btree_navigate_LazyLeafHandle_BorrowType_K_V.
      
      (* StructRecord
        {
          name := "LazyLeafRange";
          const_params := [];
          ty_params := [ "BorrowType"; "K"; "V" ];
          fields :=
            [
              ("front",
                Ty.apply
                  (Ty.path "core::option::Option")
                  []
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                      []
                      [ BorrowType; K; V ]
                  ]);
              ("back",
                Ty.apply
                  (Ty.path "core::option::Option")
                  []
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                      []
                      [ BorrowType; K; V ]
                  ])
            ];
        } *)
      
      Module Impl_core_default_Default_for_alloc_collections_btree_navigate_LazyLeafRange_B_K_V.
        Definition Self (B K V : Ty.t) : Ty.t :=
          Ty.apply (Ty.path "alloc::collections::btree::navigate::LazyLeafRange") [] [ B; K; V ].
        
        (*
            fn default() -> Self {
                LazyLeafRange { front: None, back: None }
            }
        *)
        Definition default
            (B K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self B K V in
          match ε, τ, α with
          | [], [], [] =>
            ltac:(M.monadic
              (Value.StructRecord
                "alloc::collections::btree::navigate::LazyLeafRange"
                [
                  ("front", Value.StructTuple "core::option::Option::None" []);
                  ("back", Value.StructTuple "core::option::Option::None" [])
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (B K V : Ty.t),
          M.IsTraitInstance
            "core::default::Default"
            (Self B K V)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("default", InstanceField.Method (default B K V)) ].
      End Impl_core_default_Default_for_alloc_collections_btree_navigate_LazyLeafRange_B_K_V.
      
      Module Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Immut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ].
        
        (*
            fn clone(&self) -> Self {
                LazyLeafRange { front: self.front.clone(), back: self.back.clone() }
            }
        *)
        Definition clone (K V : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              Value.StructRecord
                "alloc::collections::btree::navigate::LazyLeafRange"
                [
                  ("front",
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::clone::Clone",
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ]
                          ],
                        [],
                        "clone",
                        []
                      |),
                      [
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::collections::btree::navigate::LazyLeafRange",
                          "front"
                        |)
                      ]
                    |));
                  ("back",
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::clone::Clone",
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ]
                          ],
                        [],
                        "clone",
                        []
                      |),
                      [
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::collections::btree::navigate::LazyLeafRange",
                          "back"
                        |)
                      ]
                    |))
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom Implements :
          forall (K V : Ty.t),
          M.IsTraitInstance
            "core::clone::Clone"
            (Self K V)
            (* Trait polymorphic types *) []
            (* Instance *) [ ("clone", InstanceField.Method (clone K V)) ].
      End Impl_core_clone_Clone_for_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Immut_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LazyLeafRange_BorrowType_K_V.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
            []
            [ BorrowType; K; V ].
        
        (*
            pub fn none() -> Self {
                LazyLeafRange { front: None, back: None }
            }
        *)
        Definition none
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [] =>
            ltac:(M.monadic
              (Value.StructRecord
                "alloc::collections::btree::navigate::LazyLeafRange"
                [
                  ("front", Value.StructTuple "core::option::Option::None" []);
                  ("back", Value.StructTuple "core::option::Option::None" [])
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_none :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "none" (none BorrowType K V).
        
        (*
            pub fn reborrow(&self) -> LazyLeafRange<marker::Immut<'_>, K, V> {
                LazyLeafRange {
                    front: self.front.as_ref().map(|f| f.reborrow()),
                    back: self.back.as_ref().map(|b| b.reborrow()),
                }
            }
        *)
        Definition reborrow
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              Value.StructRecord
                "alloc::collections::btree::navigate::LazyLeafRange"
                [
                  ("front",
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                                  []
                                  [ BorrowType; K; V ]
                              ]
                          ],
                        "map",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "&")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path
                                          "alloc::collections::btree::navigate::LazyLeafHandle")
                                        []
                                        [ BorrowType; K; V ]
                                    ]
                                ]
                            ]
                            (Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ])
                        ]
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "core::option::Option")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                                  []
                                  [ BorrowType; K; V ]
                              ],
                            "as_ref",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::collections::btree::navigate::LazyLeafRange",
                              "front"
                            |)
                          ]
                        |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let f := M.copy (| γ |) in
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path
                                                  "alloc::collections::btree::navigate::LazyLeafHandle")
                                                []
                                                [ BorrowType; K; V ],
                                              "reborrow",
                                              []
                                            |),
                                            [ M.read (| f |) ]
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |));
                  ("back",
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                                  []
                                  [ BorrowType; K; V ]
                              ]
                          ],
                        "map",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "&")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path
                                          "alloc::collections::btree::navigate::LazyLeafHandle")
                                        []
                                        [ BorrowType; K; V ]
                                    ]
                                ]
                            ]
                            (Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ])
                        ]
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "core::option::Option")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                                  []
                                  [ BorrowType; K; V ]
                              ],
                            "as_ref",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::collections::btree::navigate::LazyLeafRange",
                              "back"
                            |)
                          ]
                        |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let b := M.copy (| γ |) in
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path
                                                  "alloc::collections::btree::navigate::LazyLeafHandle")
                                                []
                                                [ BorrowType; K; V ],
                                              "reborrow",
                                              []
                                            |),
                                            [ M.read (| b |) ]
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |))
                ]))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_reborrow :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "reborrow" (reborrow BorrowType K V).
        (*
            fn init_front(
                &mut self,
            ) -> Option<&mut Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>> {
                if let Some(LazyLeafHandle::Root(root)) = &self.front {
                    self.front = Some(LazyLeafHandle::Edge(unsafe { ptr::read(root) }.first_leaf_edge()));
                }
                match &mut self.front {
                    None => None,
                    Some(LazyLeafHandle::Edge(edge)) => Some(edge),
                    // SAFETY: the code above would have replaced it.
                    Some(LazyLeafHandle::Root(_)) => unsafe { hint::unreachable_unchecked() },
                }
            }
        *)
        Definition init_front
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.alloc (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::collections::btree::navigate::LazyLeafRange",
                                "front"
                              |)
                            |) in
                          let γ := M.read (| γ |) in
                          let γ1_0 :=
                            M.SubPointer.get_struct_tuple_field (|
                              γ,
                              "core::option::Option::Some",
                              0
                            |) in
                          let γ2_0 :=
                            M.SubPointer.get_struct_tuple_field (|
                              γ1_0,
                              "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                              0
                            |) in
                          let root := M.alloc (| γ2_0 |) in
                          let~ _ :=
                            M.write (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::collections::btree::navigate::LazyLeafRange",
                                "front"
                              |),
                              Value.StructTuple
                                "core::option::Option::Some"
                                [
                                  Value.StructTuple
                                    "alloc::collections::btree::navigate::LazyLeafHandle::Edge"
                                    [
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                            ],
                                          "first_leaf_edge",
                                          []
                                        |),
                                        [
                                          M.call_closure (|
                                            M.get_function (|
                                              "core::ptr::read",
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                  ]
                                              ]
                                            |),
                                            [ M.read (| root |) ]
                                          |)
                                        ]
                                      |)
                                    ]
                                ]
                            |) in
                          M.alloc (| Value.Tuple [] |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                M.match_operator (|
                  M.alloc (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::collections::btree::navigate::LazyLeafRange",
                      "front"
                    |)
                  |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in
                        M.alloc (| Value.StructTuple "core::option::Option::None" [] |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let γ2_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ1_0,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge",
                            0
                          |) in
                        let edge := M.alloc (| γ2_0 |) in
                        M.alloc (|
                          Value.StructTuple "core::option::Option::Some" [ M.read (| edge |) ]
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let γ2_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ1_0,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                            0
                          |) in
                        M.alloc (|
                          M.never_to_any (|
                            M.call_closure (|
                              M.get_function (| "core::hint::unreachable_unchecked", [] |),
                              []
                            |)
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_init_front :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "init_front" (init_front BorrowType K V).
        
        (*
            fn init_back(
                &mut self,
            ) -> Option<&mut Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>> {
                if let Some(LazyLeafHandle::Root(root)) = &self.back {
                    self.back = Some(LazyLeafHandle::Edge(unsafe { ptr::read(root) }.last_leaf_edge()));
                }
                match &mut self.back {
                    None => None,
                    Some(LazyLeafHandle::Edge(edge)) => Some(edge),
                    // SAFETY: the code above would have replaced it.
                    Some(LazyLeafHandle::Root(_)) => unsafe { hint::unreachable_unchecked() },
                }
            }
        *)
        Definition init_back
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.alloc (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::collections::btree::navigate::LazyLeafRange",
                                "back"
                              |)
                            |) in
                          let γ := M.read (| γ |) in
                          let γ1_0 :=
                            M.SubPointer.get_struct_tuple_field (|
                              γ,
                              "core::option::Option::Some",
                              0
                            |) in
                          let γ2_0 :=
                            M.SubPointer.get_struct_tuple_field (|
                              γ1_0,
                              "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                              0
                            |) in
                          let root := M.alloc (| γ2_0 |) in
                          let~ _ :=
                            M.write (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::collections::btree::navigate::LazyLeafRange",
                                "back"
                              |),
                              Value.StructTuple
                                "core::option::Option::Some"
                                [
                                  Value.StructTuple
                                    "alloc::collections::btree::navigate::LazyLeafHandle::Edge"
                                    [
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                            ],
                                          "last_leaf_edge",
                                          []
                                        |),
                                        [
                                          M.call_closure (|
                                            M.get_function (|
                                              "core::ptr::read",
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                  ]
                                              ]
                                            |),
                                            [ M.read (| root |) ]
                                          |)
                                        ]
                                      |)
                                    ]
                                ]
                            |) in
                          M.alloc (| Value.Tuple [] |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                M.match_operator (|
                  M.alloc (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::collections::btree::navigate::LazyLeafRange",
                      "back"
                    |)
                  |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let _ := M.is_struct_tuple (| γ, "core::option::Option::None" |) in
                        M.alloc (| Value.StructTuple "core::option::Option::None" [] |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let γ2_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ1_0,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Edge",
                            0
                          |) in
                        let edge := M.alloc (| γ2_0 |) in
                        M.alloc (|
                          Value.StructTuple "core::option::Option::Some" [ M.read (| edge |) ]
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ := M.read (| γ |) in
                        let γ1_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let γ2_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ1_0,
                            "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                            0
                          |) in
                        M.alloc (|
                          M.never_to_any (|
                            M.call_closure (|
                              M.get_function (| "core::hint::unreachable_unchecked", [] |),
                              []
                            |)
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_init_back :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "init_back" (init_back BorrowType K V).
      End Impl_alloc_collections_btree_navigate_LazyLeafRange_BorrowType_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Immut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ].
        
        (*
            pub unsafe fn next_unchecked(&mut self) -> (&'a K, &'a V) {
                unsafe { self.init_front().unwrap().next_unchecked() }
            }
        *)
        Definition next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::Handle")
                    []
                    [
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::NodeRef")
                        []
                        [
                          Ty.path "alloc::collections::btree::node::marker::Immut";
                          K;
                          V;
                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                        ];
                      Ty.path "alloc::collections::btree::node::marker::Edge"
                    ],
                  "next_unchecked",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "core::option::Option")
                        []
                        [
                          Ty.apply
                            (Ty.path "&mut")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      Ty.path "alloc::collections::btree::node::marker::Immut";
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::Edge"
                                ]
                            ]
                        ],
                      "unwrap",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ],
                          "init_front",
                          []
                        |),
                        [ M.read (| self |) ]
                      |)
                    ]
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_unchecked" (next_unchecked K V).
        
        (*
            pub unsafe fn next_back_unchecked(&mut self) -> (&'a K, &'a V) {
                unsafe { self.init_back().unwrap().next_back_unchecked() }
            }
        *)
        Definition next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::Handle")
                    []
                    [
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::NodeRef")
                        []
                        [
                          Ty.path "alloc::collections::btree::node::marker::Immut";
                          K;
                          V;
                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                        ];
                      Ty.path "alloc::collections::btree::node::marker::Edge"
                    ],
                  "next_back_unchecked",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "core::option::Option")
                        []
                        [
                          Ty.apply
                            (Ty.path "&mut")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      Ty.path "alloc::collections::btree::node::marker::Immut";
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::Edge"
                                ]
                            ]
                        ],
                      "unwrap",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ],
                          "init_back",
                          []
                        |),
                        [ M.read (| self |) ]
                      |)
                    ]
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_unchecked" (next_back_unchecked K V).
      End Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Immut_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_ValMut_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ].
        
        (*
            pub unsafe fn next_unchecked(&mut self) -> (&'a K, &'a mut V) {
                unsafe { self.init_front().unwrap().next_unchecked() }
            }
        *)
        Definition next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::Handle")
                    []
                    [
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::NodeRef")
                        []
                        [
                          Ty.path "alloc::collections::btree::node::marker::ValMut";
                          K;
                          V;
                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                        ];
                      Ty.path "alloc::collections::btree::node::marker::Edge"
                    ],
                  "next_unchecked",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "core::option::Option")
                        []
                        [
                          Ty.apply
                            (Ty.path "&mut")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      Ty.path "alloc::collections::btree::node::marker::ValMut";
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::Edge"
                                ]
                            ]
                        ],
                      "unwrap",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ],
                          "init_front",
                          []
                        |),
                        [ M.read (| self |) ]
                      |)
                    ]
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_unchecked" (next_unchecked K V).
        
        (*
            pub unsafe fn next_back_unchecked(&mut self) -> (&'a K, &'a mut V) {
                unsafe { self.init_back().unwrap().next_back_unchecked() }
            }
        *)
        Definition next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::Handle")
                    []
                    [
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::NodeRef")
                        []
                        [
                          Ty.path "alloc::collections::btree::node::marker::ValMut";
                          K;
                          V;
                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                        ];
                      Ty.path "alloc::collections::btree::node::marker::Edge"
                    ],
                  "next_back_unchecked",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "core::option::Option")
                        []
                        [
                          Ty.apply
                            (Ty.path "&mut")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      Ty.path "alloc::collections::btree::node::marker::ValMut";
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::Edge"
                                ]
                            ]
                        ],
                      "unwrap",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply
                            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                            []
                            [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ],
                          "init_back",
                          []
                        |),
                        [ M.read (| self |) ]
                      |)
                    ]
                  |)
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_unchecked" (next_back_unchecked K V).
      End Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_ValMut_K_V.
      
      Module Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Dying_K_V.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
            []
            [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V ].
        
        (*
            fn take_front(
                &mut self,
            ) -> Option<Handle<NodeRef<marker::Dying, K, V, marker::Leaf>, marker::Edge>> {
                match self.front.take()? {
                    LazyLeafHandle::Root(root) => Some(root.first_leaf_edge()),
                    LazyLeafHandle::Edge(edge) => Some(edge),
                }
            }
        *)
        Definition take_front
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    M.match_operator (|
                      M.match_operator (|
                        M.alloc (|
                          M.call_closure (|
                            M.get_trait_method (|
                              "core::ops::try_trait::Try",
                              Ty.apply
                                (Ty.path "core::option::Option")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::navigate::LazyLeafHandle")
                                    []
                                    [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V
                                    ]
                                ],
                              [],
                              "branch",
                              []
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "core::option::Option")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path
                                          "alloc::collections::btree::navigate::LazyLeafHandle")
                                        []
                                        [
                                          Ty.path "alloc::collections::btree::node::marker::Dying";
                                          K;
                                          V
                                        ]
                                    ],
                                  "take",
                                  []
                                |),
                                [
                                  M.SubPointer.get_struct_record_field (|
                                    M.read (| self |),
                                    "alloc::collections::btree::navigate::LazyLeafRange",
                                    "front"
                                  |)
                                ]
                              |)
                            ]
                          |)
                        |),
                        [
                          fun γ =>
                            ltac:(M.monadic
                              (let γ0_0 :=
                                M.SubPointer.get_struct_tuple_field (|
                                  γ,
                                  "core::ops::control_flow::ControlFlow::Break",
                                  0
                                |) in
                              let residual := M.copy (| γ0_0 |) in
                              M.alloc (|
                                M.never_to_any (|
                                  M.read (|
                                    M.return_ (|
                                      M.call_closure (|
                                        M.get_trait_method (|
                                          "core::ops::try_trait::FromResidual",
                                          Ty.apply
                                            (Ty.path "core::option::Option")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Dying";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Leaf"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Edge"
                                                ]
                                            ],
                                          [
                                            Ty.apply
                                              (Ty.path "core::option::Option")
                                              []
                                              [ Ty.path "core::convert::Infallible" ]
                                          ],
                                          "from_residual",
                                          []
                                        |),
                                        [ M.read (| residual |) ]
                                      |)
                                    |)
                                  |)
                                |)
                              |)));
                          fun γ =>
                            ltac:(M.monadic
                              (let γ0_0 :=
                                M.SubPointer.get_struct_tuple_field (|
                                  γ,
                                  "core::ops::control_flow::ControlFlow::Continue",
                                  0
                                |) in
                              let val := M.copy (| γ0_0 |) in
                              val))
                        ]
                      |),
                      [
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "alloc::collections::btree::navigate::LazyLeafHandle::Root",
                                0
                              |) in
                            let root := M.copy (| γ0_0 |) in
                            M.alloc (|
                              Value.StructTuple
                                "core::option::Option::Some"
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          Ty.path "alloc::collections::btree::node::marker::Dying";
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                        ],
                                      "first_leaf_edge",
                                      []
                                    |),
                                    [ M.read (| root |) ]
                                  |)
                                ]
                            |)));
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "alloc::collections::btree::navigate::LazyLeafHandle::Edge",
                                0
                              |) in
                            let edge := M.copy (| γ0_0 |) in
                            M.alloc (|
                              Value.StructTuple "core::option::Option::Some" [ M.read (| edge |) ]
                            |)))
                      ]
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_take_front :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "take_front" (take_front K V).
        
        (*
            pub unsafe fn deallocating_next_unchecked<A: Allocator + Clone>(
                &mut self,
                alloc: A,
            ) -> Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV> {
                debug_assert!(self.front.is_some());
                let front = self.init_front().unwrap();
                unsafe { front.deallocating_next_unchecked(alloc) }
            }
        *)
        Definition deallocating_next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ := M.use (M.alloc (| Value.Bool true |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          let~ _ :=
                            M.match_operator (|
                              M.alloc (| Value.Tuple [] |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let γ :=
                                      M.use
                                        (M.alloc (|
                                          UnOp.not (|
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path "core::option::Option")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::navigate::LazyLeafHandle")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V
                                                      ]
                                                  ],
                                                "is_some",
                                                []
                                              |),
                                              [
                                                M.SubPointer.get_struct_record_field (|
                                                  M.read (| self |),
                                                  "alloc::collections::btree::navigate::LazyLeafRange",
                                                  "front"
                                                |)
                                              ]
                                            |)
                                          |)
                                        |)) in
                                    let _ :=
                                      M.is_constant_or_break_match (|
                                        M.read (| γ |),
                                        Value.Bool true
                                      |) in
                                    M.alloc (|
                                      M.never_to_any (|
                                        M.call_closure (|
                                          M.get_function (| "core::panicking::panic", [] |),
                                          [
                                            M.read (|
                                              Value.String "assertion failed: self.front.is_some()"
                                            |)
                                          ]
                                        |)
                                      |)
                                    |)));
                                fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                              ]
                            |) in
                          M.alloc (| Value.Tuple [] |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ front :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&mut")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Dying";
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ]
                          ],
                        "unwrap",
                        []
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V ],
                            "init_front",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::Handle")
                        []
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::Dying";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::Leaf"
                            ];
                          Ty.path "alloc::collections::btree::node::marker::Edge"
                        ],
                      "deallocating_next_unchecked",
                      [ A ]
                    |),
                    [ M.read (| front |); M.read (| alloc |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction
            (Self K V)
            "deallocating_next_unchecked"
            (deallocating_next_unchecked K V).
        
        (*
            pub unsafe fn deallocating_next_back_unchecked<A: Allocator + Clone>(
                &mut self,
                alloc: A,
            ) -> Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV> {
                debug_assert!(self.back.is_some());
                let back = self.init_back().unwrap();
                unsafe { back.deallocating_next_back_unchecked(alloc) }
            }
        *)
        Definition deallocating_next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ := M.use (M.alloc (| Value.Bool true |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          let~ _ :=
                            M.match_operator (|
                              M.alloc (| Value.Tuple [] |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let γ :=
                                      M.use
                                        (M.alloc (|
                                          UnOp.not (|
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path "core::option::Option")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::navigate::LazyLeafHandle")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V
                                                      ]
                                                  ],
                                                "is_some",
                                                []
                                              |),
                                              [
                                                M.SubPointer.get_struct_record_field (|
                                                  M.read (| self |),
                                                  "alloc::collections::btree::navigate::LazyLeafRange",
                                                  "back"
                                                |)
                                              ]
                                            |)
                                          |)
                                        |)) in
                                    let _ :=
                                      M.is_constant_or_break_match (|
                                        M.read (| γ |),
                                        Value.Bool true
                                      |) in
                                    M.alloc (|
                                      M.never_to_any (|
                                        M.call_closure (|
                                          M.get_function (| "core::panicking::panic", [] |),
                                          [
                                            M.read (|
                                              Value.String "assertion failed: self.back.is_some()"
                                            |)
                                          ]
                                        |)
                                      |)
                                    |)));
                                fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                              ]
                            |) in
                          M.alloc (| Value.Tuple [] |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ back :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "core::option::Option")
                          []
                          [
                            Ty.apply
                              (Ty.path "&mut")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Dying";
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ]
                              ]
                          ],
                        "unwrap",
                        []
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                              []
                              [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V ],
                            "init_back",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::Handle")
                        []
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::Dying";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::Leaf"
                            ];
                          Ty.path "alloc::collections::btree::node::marker::Edge"
                        ],
                      "deallocating_next_back_unchecked",
                      [ A ]
                    |),
                    [ M.read (| back |); M.read (| alloc |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction
            (Self K V)
            "deallocating_next_back_unchecked"
            (deallocating_next_back_unchecked K V).
        
        (*
            pub fn deallocating_end<A: Allocator + Clone>(&mut self, alloc: A) {
                if let Some(front) = self.take_front() {
                    front.deallocating_end(alloc)
                }
            }
        *)
        Definition deallocating_end
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.read (|
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::navigate::LazyLeafRange")
                                  []
                                  [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V
                                  ],
                                "take_front",
                                []
                              |),
                              [ M.read (| self |) ]
                            |)
                          |) in
                        let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let front := M.copy (| γ0_0 |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      Ty.path "alloc::collections::btree::node::marker::Dying";
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::Edge"
                                ],
                              "deallocating_end",
                              [ A ]
                            |),
                            [ M.read (| front |); M.read (| alloc |) ]
                          |)
                        |)));
                    fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_end :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "deallocating_end" (deallocating_end K V).
      End Impl_alloc_collections_btree_navigate_LazyLeafRange_alloc_collections_btree_node_marker_Dying_K_V.
      
      
      Module Impl_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::NodeRef")
            []
            [ BorrowType; K; V; Ty.path "alloc::collections::btree::node::marker::LeafOrInternal" ].
        
        (*
            unsafe fn find_leaf_edges_spanning_range<Q: ?Sized, R>(
                self,
                range: R,
            ) -> LeafRange<BorrowType, K, V>
            where
                Q: Ord,
                K: Borrow<Q>,
                R: RangeBounds<Q>,
            {
                match self.search_tree_for_bifurcation(&range) {
                    Err(_) => LeafRange::none(),
                    Ok((
                        node,
                        lower_edge_idx,
                        upper_edge_idx,
                        mut lower_child_bound,
                        mut upper_child_bound,
                    )) => {
                        let mut lower_edge = unsafe { Handle::new_edge(ptr::read(&node), lower_edge_idx) };
                        let mut upper_edge = unsafe { Handle::new_edge(node, upper_edge_idx) };
                        loop {
                            match (lower_edge.force(), upper_edge.force()) {
                                (Leaf(f), Leaf(b)) => return LeafRange { front: Some(f), back: Some(b) },
                                (Internal(f), Internal(b)) => {
                                    (lower_edge, lower_child_bound) =
                                        f.descend().find_lower_bound_edge(lower_child_bound);
                                    (upper_edge, upper_child_bound) =
                                        b.descend().find_upper_bound_edge(upper_child_bound);
                                }
                                _ => unreachable!("BTreeMap has different depths"),
                            }
                        }
                    }
                }
            }
        *)
        Definition find_leaf_edges_spanning_range
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [ Q; R ], [ self; range ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let range := M.alloc (| range |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    M.match_operator (|
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                BorrowType;
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                              ],
                            "search_tree_for_bifurcation",
                            [ Q; R ]
                          |),
                          [ M.read (| self |); range ]
                        |)
                      |),
                      [
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "core::result::Result::Err",
                                0
                              |) in
                            M.alloc (|
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::navigate::LeafRange")
                                    []
                                    [ BorrowType; K; V ],
                                  "none",
                                  []
                                |),
                                []
                              |)
                            |)));
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "core::result::Result::Ok",
                                0
                              |) in
                            let γ1_0 := M.SubPointer.get_tuple_field (| γ0_0, 0 |) in
                            let γ1_1 := M.SubPointer.get_tuple_field (| γ0_0, 1 |) in
                            let γ1_2 := M.SubPointer.get_tuple_field (| γ0_0, 2 |) in
                            let γ1_3 := M.SubPointer.get_tuple_field (| γ0_0, 3 |) in
                            let γ1_4 := M.SubPointer.get_tuple_field (| γ0_0, 4 |) in
                            let node := M.copy (| γ1_0 |) in
                            let lower_edge_idx := M.copy (| γ1_1 |) in
                            let upper_edge_idx := M.copy (| γ1_2 |) in
                            let lower_child_bound := M.copy (| γ1_3 |) in
                            let upper_child_bound := M.copy (| γ1_4 |) in
                            let~ lower_edge :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::Handle")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::NodeRef")
                                          []
                                          [
                                            BorrowType;
                                            K;
                                            V;
                                            Ty.path
                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                          ];
                                        Ty.path "alloc::collections::btree::node::marker::Edge"
                                      ],
                                    "new_edge",
                                    []
                                  |),
                                  [
                                    M.call_closure (|
                                      M.get_function (|
                                        "core::ptr::read",
                                        [
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::NodeRef")
                                            []
                                            [
                                              BorrowType;
                                              K;
                                              V;
                                              Ty.path
                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                            ]
                                        ]
                                      |),
                                      [ node ]
                                    |);
                                    M.read (| lower_edge_idx |)
                                  ]
                                |)
                              |) in
                            let~ upper_edge :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::Handle")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::NodeRef")
                                          []
                                          [
                                            BorrowType;
                                            K;
                                            V;
                                            Ty.path
                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                          ];
                                        Ty.path "alloc::collections::btree::node::marker::Edge"
                                      ],
                                    "new_edge",
                                    []
                                  |),
                                  [ M.read (| node |); M.read (| upper_edge_idx |) ]
                                |)
                              |) in
                            M.alloc (|
                              M.never_to_any (|
                                M.read (|
                                  M.loop (|
                                    ltac:(M.monadic
                                      (M.match_operator (|
                                        M.alloc (|
                                          Value.Tuple
                                            [
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::Handle")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          BorrowType;
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ];
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Edge"
                                                    ],
                                                  "force",
                                                  []
                                                |),
                                                [ M.read (| lower_edge |) ]
                                              |);
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::Handle")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          BorrowType;
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ];
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Edge"
                                                    ],
                                                  "force",
                                                  []
                                                |),
                                                [ M.read (| upper_edge |) ]
                                              |)
                                            ]
                                        |),
                                        [
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_tuple_field (| γ, 0 |) in
                                              let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in
                                              let γ1_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ0_0,
                                                  "alloc::collections::btree::node::ForceResult::Leaf",
                                                  0
                                                |) in
                                              let f := M.copy (| γ1_0 |) in
                                              let γ1_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ0_1,
                                                  "alloc::collections::btree::node::ForceResult::Leaf",
                                                  0
                                                |) in
                                              let b := M.copy (| γ1_0 |) in
                                              M.alloc (|
                                                M.never_to_any (|
                                                  M.read (|
                                                    M.return_ (|
                                                      Value.StructRecord
                                                        "alloc::collections::btree::navigate::LeafRange"
                                                        [
                                                          ("front",
                                                            Value.StructTuple
                                                              "core::option::Option::Some"
                                                              [ M.read (| f |) ]);
                                                          ("back",
                                                            Value.StructTuple
                                                              "core::option::Option::Some"
                                                              [ M.read (| b |) ])
                                                        ]
                                                    |)
                                                  |)
                                                |)
                                              |)));
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_tuple_field (| γ, 0 |) in
                                              let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in
                                              let γ1_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ0_0,
                                                  "alloc::collections::btree::node::ForceResult::Internal",
                                                  0
                                                |) in
                                              let f := M.copy (| γ1_0 |) in
                                              let γ1_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ0_1,
                                                  "alloc::collections::btree::node::ForceResult::Internal",
                                                  0
                                                |) in
                                              let b := M.copy (| γ1_0 |) in
                                              let~ _ :=
                                                M.match_operator (|
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::NodeRef")
                                                          []
                                                          [
                                                            BorrowType;
                                                            K;
                                                            V;
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                          ],
                                                        "find_lower_bound_edge",
                                                        [ Q ]
                                                      |),
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    BorrowType;
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Internal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Edge"
                                                              ],
                                                            "descend",
                                                            []
                                                          |),
                                                          [ M.read (| f |) ]
                                                        |);
                                                        M.read (| lower_child_bound |)
                                                      ]
                                                    |)
                                                  |),
                                                  [
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (let γ0_0 :=
                                                          M.SubPointer.get_tuple_field (| γ, 0 |) in
                                                        let γ0_1 :=
                                                          M.SubPointer.get_tuple_field (| γ, 1 |) in
                                                        let lhs := M.copy (| γ0_0 |) in
                                                        let lhs := M.copy (| γ0_1 |) in
                                                        let~ _ :=
                                                          M.write (|
                                                            lower_edge,
                                                            M.read (| lhs |)
                                                          |) in
                                                        let~ _ :=
                                                          M.write (|
                                                            lower_child_bound,
                                                            M.read (| lhs |)
                                                          |) in
                                                        M.alloc (| Value.Tuple [] |)))
                                                  ]
                                                |) in
                                              let~ _ :=
                                                M.match_operator (|
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::NodeRef")
                                                          []
                                                          [
                                                            BorrowType;
                                                            K;
                                                            V;
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                          ],
                                                        "find_upper_bound_edge",
                                                        [ Q ]
                                                      |),
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    BorrowType;
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Internal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Edge"
                                                              ],
                                                            "descend",
                                                            []
                                                          |),
                                                          [ M.read (| b |) ]
                                                        |);
                                                        M.read (| upper_child_bound |)
                                                      ]
                                                    |)
                                                  |),
                                                  [
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (let γ0_0 :=
                                                          M.SubPointer.get_tuple_field (| γ, 0 |) in
                                                        let γ0_1 :=
                                                          M.SubPointer.get_tuple_field (| γ, 1 |) in
                                                        let lhs := M.copy (| γ0_0 |) in
                                                        let lhs := M.copy (| γ0_1 |) in
                                                        let~ _ :=
                                                          M.write (|
                                                            upper_edge,
                                                            M.read (| lhs |)
                                                          |) in
                                                        let~ _ :=
                                                          M.write (|
                                                            upper_child_bound,
                                                            M.read (| lhs |)
                                                          |) in
                                                        M.alloc (| Value.Tuple [] |)))
                                                  ]
                                                |) in
                                              M.alloc (| Value.Tuple [] |)));
                                          fun γ =>
                                            ltac:(M.monadic
                                              (M.alloc (|
                                                M.never_to_any (|
                                                  M.call_closure (|
                                                    M.get_function (|
                                                      "core::panicking::panic_fmt",
                                                      []
                                                    |),
                                                    [
                                                      M.call_closure (|
                                                        M.get_associated_function (|
                                                          Ty.path "core::fmt::Arguments",
                                                          "new_v1",
                                                          []
                                                        |),
                                                        [
                                                          M.alloc (|
                                                            Value.Array
                                                              [
                                                                M.read (|
                                                                  Value.String
                                                                    "internal error: entered unreachable code: BTreeMap has different depths"
                                                                |)
                                                              ]
                                                          |);
                                                          M.alloc (|
                                                            M.call_closure (|
                                                              M.get_associated_function (|
                                                                Ty.path "core::fmt::rt::Argument",
                                                                "none",
                                                                []
                                                              |),
                                                              []
                                                            |)
                                                          |)
                                                        ]
                                                      |)
                                                    ]
                                                  |)
                                                |)
                                              |)))
                                        ]
                                      |)))
                                  |)
                                |)
                              |)
                            |)))
                      ]
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_find_leaf_edges_spanning_range :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "find_leaf_edges_spanning_range"
            (find_leaf_edges_spanning_range BorrowType K V).
        (*
            pub fn first_leaf_edge(self) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge> {
                let mut node = self;
                loop {
                    match node.force() {
                        Leaf(leaf) => return leaf.first_edge(),
                        Internal(internal) => node = internal.first_edge().descend(),
                    }
                }
            }
        *)
        Definition first_leaf_edge
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ node := M.copy (| self |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.match_operator (|
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                        ],
                                      "force",
                                      []
                                    |),
                                    [ M.read (| node |) ]
                                  |)
                                |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 :=
                                        M.SubPointer.get_struct_tuple_field (|
                                          γ,
                                          "alloc::collections::btree::node::ForceResult::Leaf",
                                          0
                                        |) in
                                      let leaf := M.copy (| γ0_0 |) in
                                      M.alloc (|
                                        M.never_to_any (|
                                          M.read (|
                                            M.return_ (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Leaf"
                                                    ],
                                                  "first_edge",
                                                  []
                                                |),
                                                [ M.read (| leaf |) ]
                                              |)
                                            |)
                                          |)
                                        |)
                                      |)));
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 :=
                                        M.SubPointer.get_struct_tuple_field (|
                                          γ,
                                          "alloc::collections::btree::node::ForceResult::Internal",
                                          0
                                        |) in
                                      let internal := M.copy (| γ0_0 |) in
                                      M.write (|
                                        node,
                                        M.call_closure (|
                                          M.get_associated_function (|
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::Handle")
                                              []
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Internal"
                                                  ];
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Edge"
                                              ],
                                            "descend",
                                            []
                                          |),
                                          [
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Internal"
                                                  ],
                                                "first_edge",
                                                []
                                              |),
                                              [ M.read (| internal |) ]
                                            |)
                                          ]
                                        |)
                                      |)))
                                ]
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_first_leaf_edge :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "first_leaf_edge"
            (first_leaf_edge BorrowType K V).
        
        (*
            pub fn last_leaf_edge(self) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge> {
                let mut node = self;
                loop {
                    match node.force() {
                        Leaf(leaf) => return leaf.last_edge(),
                        Internal(internal) => node = internal.last_edge().descend(),
                    }
                }
            }
        *)
        Definition last_leaf_edge
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ node := M.copy (| self |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.match_operator (|
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                        ],
                                      "force",
                                      []
                                    |),
                                    [ M.read (| node |) ]
                                  |)
                                |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 :=
                                        M.SubPointer.get_struct_tuple_field (|
                                          γ,
                                          "alloc::collections::btree::node::ForceResult::Leaf",
                                          0
                                        |) in
                                      let leaf := M.copy (| γ0_0 |) in
                                      M.alloc (|
                                        M.never_to_any (|
                                          M.read (|
                                            M.return_ (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Leaf"
                                                    ],
                                                  "last_edge",
                                                  []
                                                |),
                                                [ M.read (| leaf |) ]
                                              |)
                                            |)
                                          |)
                                        |)
                                      |)));
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 :=
                                        M.SubPointer.get_struct_tuple_field (|
                                          γ,
                                          "alloc::collections::btree::node::ForceResult::Internal",
                                          0
                                        |) in
                                      let internal := M.copy (| γ0_0 |) in
                                      M.write (|
                                        node,
                                        M.call_closure (|
                                          M.get_associated_function (|
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::Handle")
                                              []
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Internal"
                                                  ];
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Edge"
                                              ],
                                            "descend",
                                            []
                                          |),
                                          [
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    BorrowType;
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Internal"
                                                  ],
                                                "last_edge",
                                                []
                                              |),
                                              [ M.read (| internal |) ]
                                            |)
                                          ]
                                        |)
                                      |)))
                                ]
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_last_leaf_edge :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "last_leaf_edge"
            (last_leaf_edge BorrowType K V).
        (*
            pub fn lower_bound<Q: ?Sized>(
                self,
                mut bound: SearchBound<&Q>,
            ) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>
            where
                Q: Ord,
                K: Borrow<Q>,
            {
                let mut node = self;
                loop {
                    let (edge, new_bound) = node.find_lower_bound_edge(bound);
                    match edge.force() {
                        Leaf(edge) => return edge,
                        Internal(edge) => {
                            node = edge.descend();
                            bound = new_bound;
                        }
                    }
                }
            }
        *)
        Definition lower_bound
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [ Q ], [ self; bound ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let bound := M.alloc (| bound |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ node := M.copy (| self |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.match_operator (|
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                        ],
                                      "find_lower_bound_edge",
                                      [ Q ]
                                    |),
                                    [ M.read (| node |); M.read (| bound |) ]
                                  |)
                                |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in
                                      let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in
                                      let edge := M.copy (| γ0_0 |) in
                                      let new_bound := M.copy (| γ0_1 |) in
                                      M.match_operator (|
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Edge"
                                                ],
                                              "force",
                                              []
                                            |),
                                            [ M.read (| edge |) ]
                                          |)
                                        |),
                                        [
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ,
                                                  "alloc::collections::btree::node::ForceResult::Leaf",
                                                  0
                                                |) in
                                              let edge := M.copy (| γ0_0 |) in
                                              M.alloc (|
                                                M.never_to_any (|
                                                  M.read (| M.return_ (| M.read (| edge |) |) |)
                                                |)
                                              |)));
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ,
                                                  "alloc::collections::btree::node::ForceResult::Internal",
                                                  0
                                                |) in
                                              let edge := M.copy (| γ0_0 |) in
                                              let~ _ :=
                                                M.write (|
                                                  node,
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              BorrowType;
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Internal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "descend",
                                                      []
                                                    |),
                                                    [ M.read (| edge |) ]
                                                  |)
                                                |) in
                                              let~ _ :=
                                                M.write (| bound, M.read (| new_bound |) |) in
                                              M.alloc (| Value.Tuple [] |)))
                                        ]
                                      |)))
                                ]
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_lower_bound :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "lower_bound" (lower_bound BorrowType K V).
        
        (*
            pub fn upper_bound<Q: ?Sized>(
                self,
                mut bound: SearchBound<&Q>,
            ) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge>
            where
                Q: Ord,
                K: Borrow<Q>,
            {
                let mut node = self;
                loop {
                    let (edge, new_bound) = node.find_upper_bound_edge(bound);
                    match edge.force() {
                        Leaf(edge) => return edge,
                        Internal(edge) => {
                            node = edge.descend();
                            bound = new_bound;
                        }
                    }
                }
            }
        *)
        Definition upper_bound
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [ Q ], [ self; bound ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let bound := M.alloc (| bound |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ node := M.copy (| self |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.match_operator (|
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                        ],
                                      "find_upper_bound_edge",
                                      [ Q ]
                                    |),
                                    [ M.read (| node |); M.read (| bound |) ]
                                  |)
                                |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 := M.SubPointer.get_tuple_field (| γ, 0 |) in
                                      let γ0_1 := M.SubPointer.get_tuple_field (| γ, 1 |) in
                                      let edge := M.copy (| γ0_0 |) in
                                      let new_bound := M.copy (| γ0_1 |) in
                                      M.match_operator (|
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::Handle")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ];
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Edge"
                                                ],
                                              "force",
                                              []
                                            |),
                                            [ M.read (| edge |) ]
                                          |)
                                        |),
                                        [
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ,
                                                  "alloc::collections::btree::node::ForceResult::Leaf",
                                                  0
                                                |) in
                                              let edge := M.copy (| γ0_0 |) in
                                              M.alloc (|
                                                M.never_to_any (|
                                                  M.read (| M.return_ (| M.read (| edge |) |) |)
                                                |)
                                              |)));
                                          fun γ =>
                                            ltac:(M.monadic
                                              (let γ0_0 :=
                                                M.SubPointer.get_struct_tuple_field (|
                                                  γ,
                                                  "alloc::collections::btree::node::ForceResult::Internal",
                                                  0
                                                |) in
                                              let edge := M.copy (| γ0_0 |) in
                                              let~ _ :=
                                                M.write (|
                                                  node,
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              BorrowType;
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Internal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "descend",
                                                      []
                                                    |),
                                                    [ M.read (| edge |) ]
                                                  |)
                                                |) in
                                              let~ _ :=
                                                M.write (| bound, M.read (| new_bound |) |) in
                                              M.alloc (| Value.Tuple [] |)))
                                        ]
                                      |)))
                                ]
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_upper_bound :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "upper_bound" (upper_bound BorrowType K V).
      End Impl_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
      
      (*
      fn full_range<BorrowType: marker::BorrowType, K, V>(
          root1: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
          root2: NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
      ) -> LazyLeafRange<BorrowType, K, V> {
          LazyLeafRange {
              front: Some(LazyLeafHandle::Root(root1)),
              back: Some(LazyLeafHandle::Root(root2)),
          }
      }
      *)
      Definition full_range (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
        match ε, τ, α with
        | [], [ BorrowType; K; V ], [ root1; root2 ] =>
          ltac:(M.monadic
            (let root1 := M.alloc (| root1 |) in
            let root2 := M.alloc (| root2 |) in
            Value.StructRecord
              "alloc::collections::btree::navigate::LazyLeafRange"
              [
                ("front",
                  Value.StructTuple
                    "core::option::Option::Some"
                    [
                      Value.StructTuple
                        "alloc::collections::btree::navigate::LazyLeafHandle::Root"
                        [ M.read (| root1 |) ]
                    ]);
                ("back",
                  Value.StructTuple
                    "core::option::Option::Some"
                    [
                      Value.StructTuple
                        "alloc::collections::btree::navigate::LazyLeafHandle::Root"
                        [ M.read (| root2 |) ]
                    ])
              ]))
        | _, _, _ => M.impossible "wrong number of arguments"
        end.
      
      Axiom Function_full_range :
        M.IsFunction "alloc::collections::btree::navigate::full_range" full_range.
      
      Module Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Immut_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::NodeRef")
            []
            [
              Ty.path "alloc::collections::btree::node::marker::Immut";
              K;
              V;
              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
            ].
        
        (*
            pub fn range_search<Q, R>(self, range: R) -> LeafRange<marker::Immut<'a>, K, V>
            where
                Q: ?Sized + Ord,
                K: Borrow<Q>,
                R: RangeBounds<Q>,
            {
                // SAFETY: our borrow type is immutable.
                unsafe { self.find_leaf_edges_spanning_range(range) }
            }
        *)
        Definition range_search
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ Q; R ], [ self; range ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let range := M.alloc (| range |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::NodeRef")
                    []
                    [
                      Ty.path "alloc::collections::btree::node::marker::Immut";
                      K;
                      V;
                      Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                    ],
                  "find_leaf_edges_spanning_range",
                  [ Q; R ]
                |),
                [ M.read (| self |); M.read (| range |) ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_range_search :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "range_search" (range_search K V).
        
        (*
            pub fn full_range(self) -> LazyLeafRange<marker::Immut<'a>, K, V> {
                full_range(self, self)
            }
        *)
        Definition full_range
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_function (|
                  "alloc::collections::btree::navigate::full_range",
                  [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V ]
                |),
                [ M.read (| self |); M.read (| self |) ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_full_range :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "full_range" (full_range K V).
        (*
            pub fn visit_nodes_in_order<F>(self, mut visit: F)
            where
                F: FnMut(Position<marker::Immut<'a>, K, V>),
            {
                match self.force() {
                    Leaf(leaf) => visit(Position::Leaf(leaf)),
                    Internal(internal) => {
                        visit(Position::Internal(internal));
                        let mut edge = internal.first_edge();
                        loop {
                            edge = match edge.descend().force() {
                                Leaf(leaf) => {
                                    visit(Position::Leaf(leaf));
                                    match edge.next_kv() {
                                        Ok(kv) => {
                                            visit(Position::InternalKV);
                                            kv.right_edge()
                                        }
                                        Err(_) => return,
                                    }
                                }
                                Internal(internal) => {
                                    visit(Position::Internal(internal));
                                    internal.first_edge()
                                }
                            }
                        }
                    }
                }
            }
        *)
        Definition visit_nodes_in_order
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ F ], [ self; visit ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let visit := M.alloc (| visit |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    M.match_operator (|
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                Ty.path "alloc::collections::btree::node::marker::Immut";
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                              ],
                            "force",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |),
                      [
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "alloc::collections::btree::node::ForceResult::Leaf",
                                0
                              |) in
                            let leaf := M.copy (| γ0_0 |) in
                            M.alloc (|
                              M.call_closure (|
                                M.get_trait_method (|
                                  "core::ops::function::FnMut",
                                  F,
                                  [
                                    Ty.tuple
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::navigate::Position")
                                          []
                                          [
                                            Ty.path
                                              "alloc::collections::btree::node::marker::Immut";
                                            K;
                                            V
                                          ]
                                      ]
                                  ],
                                  "call_mut",
                                  []
                                |),
                                [
                                  visit;
                                  Value.Tuple
                                    [
                                      Value.StructTuple
                                        "alloc::collections::btree::navigate::Position::Leaf"
                                        [ M.read (| leaf |) ]
                                    ]
                                ]
                              |)
                            |)));
                        fun γ =>
                          ltac:(M.monadic
                            (let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "alloc::collections::btree::node::ForceResult::Internal",
                                0
                              |) in
                            let internal := M.copy (| γ0_0 |) in
                            let~ _ :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_trait_method (|
                                    "core::ops::function::FnMut",
                                    F,
                                    [
                                      Ty.tuple
                                        [
                                          Ty.apply
                                            (Ty.path
                                              "alloc::collections::btree::navigate::Position")
                                            []
                                            [
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Immut";
                                              K;
                                              V
                                            ]
                                        ]
                                    ],
                                    "call_mut",
                                    []
                                  |),
                                  [
                                    visit;
                                    Value.Tuple
                                      [
                                        Value.StructTuple
                                          "alloc::collections::btree::navigate::Position::Internal"
                                          [ M.read (| internal |) ]
                                      ]
                                  ]
                                |)
                              |) in
                            let~ edge :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Immut";
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Internal"
                                      ],
                                    "first_edge",
                                    []
                                  |),
                                  [ M.read (| internal |) ]
                                |)
                              |) in
                            M.alloc (|
                              M.never_to_any (|
                                M.read (|
                                  M.loop (|
                                    ltac:(M.monadic
                                      (M.write (|
                                        edge,
                                        M.read (|
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Immut";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ],
                                                  "force",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Immut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Internal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "descend",
                                                      []
                                                    |),
                                                    [ M.read (| edge |) ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "alloc::collections::btree::node::ForceResult::Leaf",
                                                      0
                                                    |) in
                                                  let leaf := M.copy (| γ0_0 |) in
                                                  let~ _ :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_trait_method (|
                                                          "core::ops::function::FnMut",
                                                          F,
                                                          [
                                                            Ty.tuple
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::navigate::Position")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Immut";
                                                                    K;
                                                                    V
                                                                  ]
                                                              ]
                                                          ],
                                                          "call_mut",
                                                          []
                                                        |),
                                                        [
                                                          visit;
                                                          Value.Tuple
                                                            [
                                                              Value.StructTuple
                                                                "alloc::collections::btree::navigate::Position::Leaf"
                                                                [ M.read (| leaf |) ]
                                                            ]
                                                        ]
                                                      |)
                                                    |) in
                                                  M.match_operator (|
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_associated_function (|
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::Handle")
                                                            []
                                                            [
                                                              Ty.apply
                                                                (Ty.path
                                                                  "alloc::collections::btree::node::NodeRef")
                                                                []
                                                                [
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::Immut";
                                                                  K;
                                                                  V;
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::Internal"
                                                                ];
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Edge"
                                                            ],
                                                          "next_kv",
                                                          []
                                                        |),
                                                        [ M.read (| edge |) ]
                                                      |)
                                                    |),
                                                    [
                                                      fun γ =>
                                                        ltac:(M.monadic
                                                          (let γ0_0 :=
                                                            M.SubPointer.get_struct_tuple_field (|
                                                              γ,
                                                              "core::result::Result::Ok",
                                                              0
                                                            |) in
                                                          let kv := M.copy (| γ0_0 |) in
                                                          let~ _ :=
                                                            M.alloc (|
                                                              M.call_closure (|
                                                                M.get_trait_method (|
                                                                  "core::ops::function::FnMut",
                                                                  F,
                                                                  [
                                                                    Ty.tuple
                                                                      [
                                                                        Ty.apply
                                                                          (Ty.path
                                                                            "alloc::collections::btree::navigate::Position")
                                                                          []
                                                                          [
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::Immut";
                                                                            K;
                                                                            V
                                                                          ]
                                                                      ]
                                                                  ],
                                                                  "call_mut",
                                                                  []
                                                                |),
                                                                [
                                                                  visit;
                                                                  Value.Tuple
                                                                    [
                                                                      Value.StructTuple
                                                                        "alloc::collections::btree::navigate::Position::InternalKV"
                                                                        []
                                                                    ]
                                                                ]
                                                              |)
                                                            |) in
                                                          M.alloc (|
                                                            M.call_closure (|
                                                              M.get_associated_function (|
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::Handle")
                                                                  []
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path
                                                                        "alloc::collections::btree::node::NodeRef")
                                                                      []
                                                                      [
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::Immut";
                                                                        K;
                                                                        V;
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::Internal"
                                                                      ];
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::KV"
                                                                  ],
                                                                "right_edge",
                                                                []
                                                              |),
                                                              [ M.read (| kv |) ]
                                                            |)
                                                          |)));
                                                      fun γ =>
                                                        ltac:(M.monadic
                                                          (let γ0_0 :=
                                                            M.SubPointer.get_struct_tuple_field (|
                                                              γ,
                                                              "core::result::Result::Err",
                                                              0
                                                            |) in
                                                          M.alloc (|
                                                            M.never_to_any (|
                                                              M.read (|
                                                                M.return_ (| Value.Tuple [] |)
                                                              |)
                                                            |)
                                                          |)))
                                                    ]
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "alloc::collections::btree::node::ForceResult::Internal",
                                                      0
                                                    |) in
                                                  let internal := M.copy (| γ0_0 |) in
                                                  let~ _ :=
                                                    M.alloc (|
                                                      M.call_closure (|
                                                        M.get_trait_method (|
                                                          "core::ops::function::FnMut",
                                                          F,
                                                          [
                                                            Ty.tuple
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::navigate::Position")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Immut";
                                                                    K;
                                                                    V
                                                                  ]
                                                              ]
                                                          ],
                                                          "call_mut",
                                                          []
                                                        |),
                                                        [
                                                          visit;
                                                          Value.Tuple
                                                            [
                                                              Value.StructTuple
                                                                "alloc::collections::btree::navigate::Position::Internal"
                                                                [ M.read (| internal |) ]
                                                            ]
                                                        ]
                                                      |)
                                                    |) in
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::NodeRef")
                                                          []
                                                          [
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Immut";
                                                            K;
                                                            V;
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Internal"
                                                          ],
                                                        "first_edge",
                                                        []
                                                      |),
                                                      [ M.read (| internal |) ]
                                                    |)
                                                  |)))
                                            ]
                                          |)
                                        |)
                                      |)))
                                  |)
                                |)
                              |)
                            |)))
                      ]
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_visit_nodes_in_order :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "visit_nodes_in_order" (visit_nodes_in_order K V).
        
        (*
            pub fn calc_length(self) -> usize {
                let mut result = 0;
                self.visit_nodes_in_order(|pos| match pos {
                    Position::Leaf(node) => result += node.len(),
                    Position::Internal(node) => result += node.len(),
                    Position::InternalKV => (),
                });
                result
            }
        *)
        Definition calc_length
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ result := M.alloc (| Value.Integer IntegerKind.Usize 0 |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Immut";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                          ],
                        "visit_nodes_in_order",
                        [
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::navigate::Position")
                                    []
                                    [ Ty.path "alloc::collections::btree::node::marker::Immut"; K; V
                                    ]
                                ]
                            ]
                            (Ty.tuple [])
                        ]
                      |),
                      [
                        M.read (| self |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let pos := M.copy (| γ |) in
                                          M.read (|
                                            M.match_operator (|
                                              pos,
                                              [
                                                fun γ =>
                                                  ltac:(M.monadic
                                                    (let γ0_0 :=
                                                      M.SubPointer.get_struct_tuple_field (|
                                                        γ,
                                                        "alloc::collections::btree::navigate::Position::Leaf",
                                                        0
                                                      |) in
                                                    let node := M.copy (| γ0_0 |) in
                                                    let β := result in
                                                    M.write (|
                                                      β,
                                                      BinOp.Wrap.add (|
                                                        M.read (| β |),
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Immut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Leaf"
                                                              ],
                                                            "len",
                                                            []
                                                          |),
                                                          [ node ]
                                                        |)
                                                      |)
                                                    |)));
                                                fun γ =>
                                                  ltac:(M.monadic
                                                    (let γ0_0 :=
                                                      M.SubPointer.get_struct_tuple_field (|
                                                        γ,
                                                        "alloc::collections::btree::navigate::Position::Internal",
                                                        0
                                                      |) in
                                                    let node := M.copy (| γ0_0 |) in
                                                    let β := result in
                                                    M.write (|
                                                      β,
                                                      BinOp.Wrap.add (|
                                                        M.read (| β |),
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Immut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Internal"
                                                              ],
                                                            "len",
                                                            []
                                                          |),
                                                          [ node ]
                                                        |)
                                                      |)
                                                    |)));
                                                fun γ =>
                                                  ltac:(M.monadic
                                                    (let _ :=
                                                      M.is_struct_tuple (|
                                                        γ,
                                                        "alloc::collections::btree::navigate::Position::InternalKV"
                                                      |) in
                                                    M.alloc (| Value.Tuple [] |)))
                                              ]
                                            |)
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |)
                  |) in
                result
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_calc_length :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "calc_length" (calc_length K V).
      End Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Immut_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
      
      Module Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_ValMut_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::NodeRef")
            []
            [
              Ty.path "alloc::collections::btree::node::marker::ValMut";
              K;
              V;
              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
            ].
        
        (*
            pub fn range_search<Q, R>(self, range: R) -> LeafRange<marker::ValMut<'a>, K, V>
            where
                Q: ?Sized + Ord,
                K: Borrow<Q>,
                R: RangeBounds<Q>,
            {
                unsafe { self.find_leaf_edges_spanning_range(range) }
            }
        *)
        Definition range_search
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ Q; R ], [ self; range ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let range := M.alloc (| range |) in
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::collections::btree::node::NodeRef")
                    []
                    [
                      Ty.path "alloc::collections::btree::node::marker::ValMut";
                      K;
                      V;
                      Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                    ],
                  "find_leaf_edges_spanning_range",
                  [ Q; R ]
                |),
                [ M.read (| self |); M.read (| range |) ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_range_search :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "range_search" (range_search K V).
        
        (*
            pub fn full_range(self) -> LazyLeafRange<marker::ValMut<'a>, K, V> {
                // We duplicate the root NodeRef here -- we will never visit the same KV
                // twice, and never end up with overlapping value references.
                let self2 = unsafe { ptr::read(&self) };
                full_range(self, self2)
            }
        *)
        Definition full_range
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ self2 :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::ptr::read",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::ValMut";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                            ]
                        ]
                      |),
                      [ self ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_function (|
                      "alloc::collections::btree::navigate::full_range",
                      [ Ty.path "alloc::collections::btree::node::marker::ValMut"; K; V ]
                    |),
                    [ M.read (| self |); M.read (| self2 |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_full_range :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "full_range" (full_range K V).
      End Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_ValMut_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
      
      Module Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Dying_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::NodeRef")
            []
            [
              Ty.path "alloc::collections::btree::node::marker::Dying";
              K;
              V;
              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
            ].
        
        (*
            pub fn full_range(self) -> LazyLeafRange<marker::Dying, K, V> {
                // We duplicate the root NodeRef here -- we will never access it in a way
                // that overlaps references obtained from the root.
                let self2 = unsafe { ptr::read(&self) };
                full_range(self, self2)
            }
        *)
        Definition full_range
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ self2 :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::ptr::read",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::Dying";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                            ]
                        ]
                      |),
                      [ self ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_function (|
                      "alloc::collections::btree::navigate::full_range",
                      [ Ty.path "alloc::collections::btree::node::marker::Dying"; K; V ]
                    |),
                    [ M.read (| self |); M.read (| self2 |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_full_range :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "full_range" (full_range K V).
      End Impl_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Dying_K_V_alloc_collections_btree_node_marker_LeafOrInternal.
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [ BorrowType; K; V; Ty.path "alloc::collections::btree::node::marker::Leaf" ];
              Ty.path "alloc::collections::btree::node::marker::Edge"
            ].
        
        (*
            pub fn next_kv(
                self,
            ) -> Result<
                Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, marker::KV>,
                NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
            > {
                let mut edge = self.forget_node_type();
                loop {
                    edge = match edge.right_kv() {
                        Ok(kv) => return Ok(kv),
                        Err(last_edge) => match last_edge.into_node().ascend() {
                            Ok(parent_edge) => parent_edge.forget_node_type(),
                            Err(root) => return Err(root),
                        },
                    }
                }
            }
        *)
        Definition next_kv
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ edge :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    BorrowType;
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ],
                            "forget_node_type",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.write (|
                                edge,
                                M.read (|
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::LeafOrInternal"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ],
                                          "right_kv",
                                          []
                                        |),
                                        [ M.read (| edge |) ]
                                      |)
                                    |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Ok",
                                              0
                                            |) in
                                          let kv := M.copy (| γ0_0 |) in
                                          M.alloc (|
                                            M.never_to_any (|
                                              M.read (|
                                                M.return_ (|
                                                  Value.StructTuple
                                                    "core::result::Result::Ok"
                                                    [ M.read (| kv |) ]
                                                |)
                                              |)
                                            |)
                                          |)));
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Err",
                                              0
                                            |) in
                                          let last_edge := M.copy (| γ0_0 |) in
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ],
                                                  "ascend",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              BorrowType;
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "into_node",
                                                      []
                                                    |),
                                                    [ M.read (| last_edge |) ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Ok",
                                                      0
                                                    |) in
                                                  let parent_edge := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                BorrowType;
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Internal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Edge"
                                                          ],
                                                        "forget_node_type",
                                                        []
                                                      |),
                                                      [ M.read (| parent_edge |) ]
                                                    |)
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Err",
                                                      0
                                                    |) in
                                                  let root := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (|
                                                        M.return_ (|
                                                          Value.StructTuple
                                                            "core::result::Result::Err"
                                                            [ M.read (| root |) ]
                                                        |)
                                                      |)
                                                    |)
                                                  |)))
                                            ]
                                          |)))
                                    ]
                                  |)
                                |)
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_kv :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "next_kv" (next_kv BorrowType K V).
        
        (*
            pub fn next_back_kv(
                self,
            ) -> Result<
                Handle<NodeRef<BorrowType, K, V, marker::LeafOrInternal>, marker::KV>,
                NodeRef<BorrowType, K, V, marker::LeafOrInternal>,
            > {
                let mut edge = self.forget_node_type();
                loop {
                    edge = match edge.left_kv() {
                        Ok(kv) => return Ok(kv),
                        Err(last_edge) => match last_edge.into_node().ascend() {
                            Ok(parent_edge) => parent_edge.forget_node_type(),
                            Err(root) => return Err(root),
                        },
                    }
                }
            }
        *)
        Definition next_back_kv
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ edge :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    BorrowType;
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ],
                            "forget_node_type",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.write (|
                                edge,
                                M.read (|
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::LeafOrInternal"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ],
                                          "left_kv",
                                          []
                                        |),
                                        [ M.read (| edge |) ]
                                      |)
                                    |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Ok",
                                              0
                                            |) in
                                          let kv := M.copy (| γ0_0 |) in
                                          M.alloc (|
                                            M.never_to_any (|
                                              M.read (|
                                                M.return_ (|
                                                  Value.StructTuple
                                                    "core::result::Result::Ok"
                                                    [ M.read (| kv |) ]
                                                |)
                                              |)
                                            |)
                                          |)));
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Err",
                                              0
                                            |) in
                                          let last_edge := M.copy (| γ0_0 |) in
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ],
                                                  "ascend",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              BorrowType;
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "into_node",
                                                      []
                                                    |),
                                                    [ M.read (| last_edge |) ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Ok",
                                                      0
                                                    |) in
                                                  let parent_edge := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                BorrowType;
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Internal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Edge"
                                                          ],
                                                        "forget_node_type",
                                                        []
                                                      |),
                                                      [ M.read (| parent_edge |) ]
                                                    |)
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Err",
                                                      0
                                                    |) in
                                                  let root := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (|
                                                        M.return_ (|
                                                          Value.StructTuple
                                                            "core::result::Result::Err"
                                                            [ M.read (| root |) ]
                                                        |)
                                                      |)
                                                    |)
                                                  |)))
                                            ]
                                          |)))
                                    ]
                                  |)
                                |)
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_kv :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "next_back_kv" (next_back_kv BorrowType K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_Internal_alloc_collections_btree_node_marker_Edge.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [ BorrowType; K; V; Ty.path "alloc::collections::btree::node::marker::Internal" ];
              Ty.path "alloc::collections::btree::node::marker::Edge"
            ].
        
        (*
            fn next_kv(
                self,
            ) -> Result<
                Handle<NodeRef<BorrowType, K, V, marker::Internal>, marker::KV>,
                NodeRef<BorrowType, K, V, marker::Internal>,
            > {
                let mut edge = self;
                loop {
                    edge = match edge.right_kv() {
                        Ok(internal_kv) => return Ok(internal_kv),
                        Err(last_edge) => match last_edge.into_node().ascend() {
                            Ok(parent_edge) => parent_edge,
                            Err(root) => return Err(root),
                        },
                    }
                }
            }
        *)
        Definition next_kv
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ edge := M.copy (| self |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.write (|
                                edge,
                                M.read (|
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  BorrowType;
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Internal"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ],
                                          "right_kv",
                                          []
                                        |),
                                        [ M.read (| edge |) ]
                                      |)
                                    |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Ok",
                                              0
                                            |) in
                                          let internal_kv := M.copy (| γ0_0 |) in
                                          M.alloc (|
                                            M.never_to_any (|
                                              M.read (|
                                                M.return_ (|
                                                  Value.StructTuple
                                                    "core::result::Result::Ok"
                                                    [ M.read (| internal_kv |) ]
                                                |)
                                              |)
                                            |)
                                          |)));
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Err",
                                              0
                                            |) in
                                          let last_edge := M.copy (| γ0_0 |) in
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      BorrowType;
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Internal"
                                                    ],
                                                  "ascend",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              BorrowType;
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Internal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "into_node",
                                                      []
                                                    |),
                                                    [ M.read (| last_edge |) ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Ok",
                                                      0
                                                    |) in
                                                  let parent_edge := M.copy (| γ0_0 |) in
                                                  parent_edge));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::result::Result::Err",
                                                      0
                                                    |) in
                                                  let root := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (|
                                                        M.return_ (|
                                                          Value.StructTuple
                                                            "core::result::Result::Err"
                                                            [ M.read (| root |) ]
                                                        |)
                                                      |)
                                                    |)
                                                  |)))
                                            ]
                                          |)))
                                    ]
                                  |)
                                |)
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_kv :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction (Self BorrowType K V) "next_kv" (next_kv BorrowType K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_Internal_alloc_collections_btree_node_marker_Edge.
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Dying_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [
                  Ty.path "alloc::collections::btree::node::marker::Dying";
                  K;
                  V;
                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                ];
              Ty.path "alloc::collections::btree::node::marker::Edge"
            ].
        
        (*
            unsafe fn deallocating_next<A: Allocator + Clone>(
                self,
                alloc: A,
            ) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>
            {
                let mut edge = self.forget_node_type();
                loop {
                    edge = match edge.right_kv() {
                        Ok(kv) => return Some((unsafe { ptr::read(&kv) }.next_leaf_edge(), kv)),
                        Err(last_edge) => {
                            match unsafe { last_edge.into_node().deallocate_and_ascend(alloc.clone()) } {
                                Some(parent_edge) => parent_edge.forget_node_type(),
                                None => return None,
                            }
                        }
                    }
                }
            }
        *)
        Definition deallocating_next
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ edge :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Dying";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ],
                            "forget_node_type",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.write (|
                                edge,
                                M.read (|
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Dying";
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::LeafOrInternal"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ],
                                          "right_kv",
                                          []
                                        |),
                                        [ M.read (| edge |) ]
                                      |)
                                    |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Ok",
                                              0
                                            |) in
                                          let kv := M.copy (| γ0_0 |) in
                                          M.alloc (|
                                            M.never_to_any (|
                                              M.read (|
                                                M.return_ (|
                                                  Value.StructTuple
                                                    "core::option::Option::Some"
                                                    [
                                                      Value.Tuple
                                                        [
                                                          M.call_closure (|
                                                            M.get_associated_function (|
                                                              Ty.apply
                                                                (Ty.path
                                                                  "alloc::collections::btree::node::Handle")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::Dying";
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ];
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::KV"
                                                                ],
                                                              "next_leaf_edge",
                                                              []
                                                            |),
                                                            [
                                                              M.call_closure (|
                                                                M.get_function (|
                                                                  "core::ptr::read",
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path
                                                                        "alloc::collections::btree::node::Handle")
                                                                      []
                                                                      [
                                                                        Ty.apply
                                                                          (Ty.path
                                                                            "alloc::collections::btree::node::NodeRef")
                                                                          []
                                                                          [
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::Dying";
                                                                            K;
                                                                            V;
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                          ];
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::KV"
                                                                      ]
                                                                  ]
                                                                |),
                                                                [ kv ]
                                                              |)
                                                            ]
                                                          |);
                                                          M.read (| kv |)
                                                        ]
                                                    ]
                                                |)
                                              |)
                                            |)
                                          |)));
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Err",
                                              0
                                            |) in
                                          let last_edge := M.copy (| γ0_0 |) in
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Dying";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ],
                                                  "deallocate_and_ascend",
                                                  [ A ]
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Dying";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "into_node",
                                                      []
                                                    |),
                                                    [ M.read (| last_edge |) ]
                                                  |);
                                                  M.call_closure (|
                                                    M.get_trait_method (|
                                                      "core::clone::Clone",
                                                      A,
                                                      [],
                                                      "clone",
                                                      []
                                                    |),
                                                    [ alloc ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::option::Option::Some",
                                                      0
                                                    |) in
                                                  let parent_edge := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Dying";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Internal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Edge"
                                                          ],
                                                        "forget_node_type",
                                                        []
                                                      |),
                                                      [ M.read (| parent_edge |) ]
                                                    |)
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let _ :=
                                                    M.is_struct_tuple (|
                                                      γ,
                                                      "core::option::Option::None"
                                                    |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (|
                                                        M.return_ (|
                                                          Value.StructTuple
                                                            "core::option::Option::None"
                                                            []
                                                        |)
                                                      |)
                                                    |)
                                                  |)))
                                            ]
                                          |)))
                                    ]
                                  |)
                                |)
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "deallocating_next" (deallocating_next K V).
        
        (*
            unsafe fn deallocating_next_back<A: Allocator + Clone>(
                self,
                alloc: A,
            ) -> Option<(Self, Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV>)>
            {
                let mut edge = self.forget_node_type();
                loop {
                    edge = match edge.left_kv() {
                        Ok(kv) => return Some((unsafe { ptr::read(&kv) }.next_back_leaf_edge(), kv)),
                        Err(last_edge) => {
                            match unsafe { last_edge.into_node().deallocate_and_ascend(alloc.clone()) } {
                                Some(parent_edge) => parent_edge.forget_node_type(),
                                None => return None,
                            }
                        }
                    }
                }
            }
        *)
        Definition deallocating_next_back
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.catch_return (|
                ltac:(M.monadic
                  (M.read (|
                    let~ edge :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Dying";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ],
                            "forget_node_type",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |) in
                    M.alloc (|
                      M.never_to_any (|
                        M.read (|
                          M.loop (|
                            ltac:(M.monadic
                              (M.write (|
                                edge,
                                M.read (|
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply
                                            (Ty.path "alloc::collections::btree::node::Handle")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                                []
                                                [
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::Dying";
                                                  K;
                                                  V;
                                                  Ty.path
                                                    "alloc::collections::btree::node::marker::LeafOrInternal"
                                                ];
                                              Ty.path
                                                "alloc::collections::btree::node::marker::Edge"
                                            ],
                                          "left_kv",
                                          []
                                        |),
                                        [ M.read (| edge |) ]
                                      |)
                                    |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Ok",
                                              0
                                            |) in
                                          let kv := M.copy (| γ0_0 |) in
                                          M.alloc (|
                                            M.never_to_any (|
                                              M.read (|
                                                M.return_ (|
                                                  Value.StructTuple
                                                    "core::option::Option::Some"
                                                    [
                                                      Value.Tuple
                                                        [
                                                          M.call_closure (|
                                                            M.get_associated_function (|
                                                              Ty.apply
                                                                (Ty.path
                                                                  "alloc::collections::btree::node::Handle")
                                                                []
                                                                [
                                                                  Ty.apply
                                                                    (Ty.path
                                                                      "alloc::collections::btree::node::NodeRef")
                                                                    []
                                                                    [
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::Dying";
                                                                      K;
                                                                      V;
                                                                      Ty.path
                                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                    ];
                                                                  Ty.path
                                                                    "alloc::collections::btree::node::marker::KV"
                                                                ],
                                                              "next_back_leaf_edge",
                                                              []
                                                            |),
                                                            [
                                                              M.call_closure (|
                                                                M.get_function (|
                                                                  "core::ptr::read",
                                                                  [
                                                                    Ty.apply
                                                                      (Ty.path
                                                                        "alloc::collections::btree::node::Handle")
                                                                      []
                                                                      [
                                                                        Ty.apply
                                                                          (Ty.path
                                                                            "alloc::collections::btree::node::NodeRef")
                                                                          []
                                                                          [
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::Dying";
                                                                            K;
                                                                            V;
                                                                            Ty.path
                                                                              "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                          ];
                                                                        Ty.path
                                                                          "alloc::collections::btree::node::marker::KV"
                                                                      ]
                                                                  ]
                                                                |),
                                                                [ kv ]
                                                              |)
                                                            ]
                                                          |);
                                                          M.read (| kv |)
                                                        ]
                                                    ]
                                                |)
                                              |)
                                            |)
                                          |)));
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let γ0_0 :=
                                            M.SubPointer.get_struct_tuple_field (|
                                              γ,
                                              "core::result::Result::Err",
                                              0
                                            |) in
                                          let last_edge := M.copy (| γ0_0 |) in
                                          M.match_operator (|
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::NodeRef")
                                                    []
                                                    [
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::Dying";
                                                      K;
                                                      V;
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::LeafOrInternal"
                                                    ],
                                                  "deallocate_and_ascend",
                                                  [ A ]
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Dying";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "into_node",
                                                      []
                                                    |),
                                                    [ M.read (| last_edge |) ]
                                                  |);
                                                  M.call_closure (|
                                                    M.get_trait_method (|
                                                      "core::clone::Clone",
                                                      A,
                                                      [],
                                                      "clone",
                                                      []
                                                    |),
                                                    [ alloc ]
                                                  |)
                                                ]
                                              |)
                                            |),
                                            [
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let γ0_0 :=
                                                    M.SubPointer.get_struct_tuple_field (|
                                                      γ,
                                                      "core::option::Option::Some",
                                                      0
                                                    |) in
                                                  let parent_edge := M.copy (| γ0_0 |) in
                                                  M.alloc (|
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Dying";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Internal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::Edge"
                                                          ],
                                                        "forget_node_type",
                                                        []
                                                      |),
                                                      [ M.read (| parent_edge |) ]
                                                    |)
                                                  |)));
                                              fun γ =>
                                                ltac:(M.monadic
                                                  (let _ :=
                                                    M.is_struct_tuple (|
                                                      γ,
                                                      "core::option::Option::None"
                                                    |) in
                                                  M.alloc (|
                                                    M.never_to_any (|
                                                      M.read (|
                                                        M.return_ (|
                                                          Value.StructTuple
                                                            "core::option::Option::None"
                                                            []
                                                        |)
                                                      |)
                                                    |)
                                                  |)))
                                            ]
                                          |)))
                                    ]
                                  |)
                                |)
                              |)))
                          |)
                        |)
                      |)
                    |)
                  |)))
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next_back :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "deallocating_next_back" (deallocating_next_back K V).
        
        (*
            fn deallocating_end<A: Allocator + Clone>(self, alloc: A) {
                let mut edge = self.forget_node_type();
                while let Some(parent_edge) =
                    unsafe { edge.into_node().deallocate_and_ascend(alloc.clone()) }
                {
                    edge = parent_edge.forget_node_type();
                }
            }
        *)
        Definition deallocating_end
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.read (|
                let~ edge :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::Handle")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                Ty.path "alloc::collections::btree::node::marker::Dying";
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::Leaf"
                              ];
                            Ty.path "alloc::collections::btree::node::marker::Edge"
                          ],
                        "forget_node_type",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |) in
                M.loop (|
                  ltac:(M.monadic
                    (M.match_operator (|
                      M.alloc (| Value.Tuple [] |),
                      [
                        fun γ =>
                          ltac:(M.monadic
                            (let γ :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::Dying";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ],
                                    "deallocate_and_ascend",
                                    [ A ]
                                  |),
                                  [
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::Handle")
                                          []
                                          [
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::NodeRef")
                                              []
                                              [
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Dying";
                                                K;
                                                V;
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                              ];
                                            Ty.path "alloc::collections::btree::node::marker::Edge"
                                          ],
                                        "into_node",
                                        []
                                      |),
                                      [ M.read (| edge |) ]
                                    |);
                                    M.call_closure (|
                                      M.get_trait_method (|
                                        "core::clone::Clone",
                                        A,
                                        [],
                                        "clone",
                                        []
                                      |),
                                      [ alloc ]
                                    |)
                                  ]
                                |)
                              |) in
                            let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "core::option::Option::Some",
                                0
                              |) in
                            let parent_edge := M.copy (| γ0_0 |) in
                            let~ _ :=
                              M.write (|
                                edge,
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::Handle")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "alloc::collections::btree::node::NodeRef")
                                          []
                                          [
                                            Ty.path
                                              "alloc::collections::btree::node::marker::Dying";
                                            K;
                                            V;
                                            Ty.path
                                              "alloc::collections::btree::node::marker::Internal"
                                          ];
                                        Ty.path "alloc::collections::btree::node::marker::Edge"
                                      ],
                                    "forget_node_type",
                                    []
                                  |),
                                  [ M.read (| parent_edge |) ]
                                |)
                              |) in
                            M.alloc (| Value.Tuple [] |)));
                        fun γ =>
                          ltac:(M.monadic
                            (M.alloc (|
                              M.never_to_any (|
                                M.read (|
                                  let~ _ :=
                                    M.alloc (| M.never_to_any (| M.read (| M.break (||) |) |) |) in
                                  M.alloc (| Value.Tuple [] |)
                                |)
                              |)
                            |)))
                      ]
                    |)))
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_end :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "deallocating_end" (deallocating_end K V).
        (*
            unsafe fn deallocating_next_unchecked<A: Allocator + Clone>(
                &mut self,
                alloc: A,
            ) -> Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV> {
                super::mem::replace(self, |leaf_edge| unsafe {
                    leaf_edge.deallocating_next(alloc).unwrap()
                })
            }
        *)
        Definition deallocating_next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.call_closure (|
                M.get_function (|
                  "alloc::collections::btree::mem::replace",
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Dying";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ];
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Dying";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::KV"
                      ];
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Dying";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Dying";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Dying";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::KV"
                            ]
                        ])
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let leaf_edge := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "core::option::Option")
                                          []
                                          [
                                            Ty.tuple
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Leaf"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Edge"
                                                  ];
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ]
                                              ]
                                          ],
                                        "unwrap",
                                        []
                                      |),
                                      [
                                        M.call_closure (|
                                          M.get_associated_function (|
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::Handle")
                                              []
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Dying";
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Leaf"
                                                  ];
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Edge"
                                              ],
                                            "deallocating_next",
                                            [ A ]
                                          |),
                                          [ M.read (| leaf_edge |); M.read (| alloc |) ]
                                        |)
                                      ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction
            (Self K V)
            "deallocating_next_unchecked"
            (deallocating_next_unchecked K V).
        
        (*
            unsafe fn deallocating_next_back_unchecked<A: Allocator + Clone>(
                &mut self,
                alloc: A,
            ) -> Handle<NodeRef<marker::Dying, K, V, marker::LeafOrInternal>, marker::KV> {
                super::mem::replace(self, |leaf_edge| unsafe {
                    leaf_edge.deallocating_next_back(alloc).unwrap()
                })
            }
        *)
        Definition deallocating_next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [ A ], [ self; alloc ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              let alloc := M.alloc (| alloc |) in
              M.call_closure (|
                M.get_function (|
                  "alloc::collections::btree::mem::replace",
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Dying";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ];
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Dying";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::KV"
                      ];
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Dying";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Dying";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Dying";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::KV"
                            ]
                        ])
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let leaf_edge := M.copy (| γ |) in
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "core::option::Option")
                                          []
                                          [
                                            Ty.tuple
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Leaf"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Edge"
                                                  ];
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Dying";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ]
                                              ]
                                          ],
                                        "unwrap",
                                        []
                                      |),
                                      [
                                        M.call_closure (|
                                          M.get_associated_function (|
                                            Ty.apply
                                              (Ty.path "alloc::collections::btree::node::Handle")
                                              []
                                              [
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::NodeRef")
                                                  []
                                                  [
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Dying";
                                                    K;
                                                    V;
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::Leaf"
                                                  ];
                                                Ty.path
                                                  "alloc::collections::btree::node::marker::Edge"
                                              ],
                                            "deallocating_next_back",
                                            [ A ]
                                          |),
                                          [ M.read (| leaf_edge |); M.read (| alloc |) ]
                                        |)
                                      ]
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_deallocating_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction
            (Self K V)
            "deallocating_next_back_unchecked"
            (deallocating_next_back_unchecked K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Dying_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Immut_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [
                  Ty.path "alloc::collections::btree::node::marker::Immut";
                  K;
                  V;
                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                ];
              Ty.path "alloc::collections::btree::node::marker::Edge"
            ].
        
        (*
            unsafe fn next_unchecked(&mut self) -> (&'a K, &'a V) {
                super::mem::replace(self, |leaf_edge| {
                    let kv = leaf_edge.next_kv().ok().unwrap();
                    (kv.next_leaf_edge(), kv.into_kv())
                })
            }
        *)
        Definition next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_function (|
                  "alloc::collections::btree::mem::replace",
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Immut";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ];
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ];
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Immut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.tuple
                            [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]
                        ])
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let leaf_edge := M.copy (| γ |) in
                                    M.read (|
                                      let~ kv :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "core::option::Option")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::Handle")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Immut";
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ];
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::KV"
                                                    ]
                                                ],
                                              "unwrap",
                                              []
                                            |),
                                            [
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path "core::result::Result")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Immut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::KV"
                                                        ];
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Immut";
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ]
                                                    ],
                                                  "ok",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Immut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Leaf"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "next_kv",
                                                      []
                                                    |),
                                                    [ M.read (| leaf_edge |) ]
                                                  |)
                                                ]
                                              |)
                                            ]
                                          |)
                                        |) in
                                      M.alloc (|
                                        Value.Tuple
                                          [
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Immut";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ],
                                                "next_leaf_edge",
                                                []
                                              |),
                                              [ M.read (| kv |) ]
                                            |);
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Immut";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ],
                                                "into_kv",
                                                []
                                              |),
                                              [ M.read (| kv |) ]
                                            |)
                                          ]
                                      |)
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_unchecked" (next_unchecked K V).
        
        (*
            unsafe fn next_back_unchecked(&mut self) -> (&'a K, &'a V) {
                super::mem::replace(self, |leaf_edge| {
                    let kv = leaf_edge.next_back_kv().ok().unwrap();
                    (kv.next_back_leaf_edge(), kv.into_kv())
                })
            }
        *)
        Definition next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.call_closure (|
                M.get_function (|
                  "alloc::collections::btree::mem::replace",
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::Handle")
                      []
                      [
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::NodeRef")
                          []
                          [
                            Ty.path "alloc::collections::btree::node::marker::Immut";
                            K;
                            V;
                            Ty.path "alloc::collections::btree::node::marker::Leaf"
                          ];
                        Ty.path "alloc::collections::btree::node::marker::Edge"
                      ];
                    Ty.tuple [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ];
                    Ty.function
                      [
                        Ty.tuple
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::Handle")
                              []
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::NodeRef")
                                  []
                                  [
                                    Ty.path "alloc::collections::btree::node::marker::Immut";
                                    K;
                                    V;
                                    Ty.path "alloc::collections::btree::node::marker::Leaf"
                                  ];
                                Ty.path "alloc::collections::btree::node::marker::Edge"
                              ]
                          ]
                      ]
                      (Ty.tuple
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::Immut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.tuple
                            [ Ty.apply (Ty.path "&") [] [ K ]; Ty.apply (Ty.path "&") [] [ V ] ]
                        ])
                  ]
                |),
                [
                  M.read (| self |);
                  M.closure
                    (fun γ =>
                      ltac:(M.monadic
                        match γ with
                        | [ α0 ] =>
                          ltac:(M.monadic
                            (M.match_operator (|
                              M.alloc (| α0 |),
                              [
                                fun γ =>
                                  ltac:(M.monadic
                                    (let leaf_edge := M.copy (| γ |) in
                                    M.read (|
                                      let~ kv :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply
                                                (Ty.path "core::option::Option")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path
                                                      "alloc::collections::btree::node::Handle")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Immut";
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ];
                                                      Ty.path
                                                        "alloc::collections::btree::node::marker::KV"
                                                    ]
                                                ],
                                              "unwrap",
                                              []
                                            |),
                                            [
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply
                                                    (Ty.path "core::result::Result")
                                                    []
                                                    [
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Immut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::KV"
                                                        ];
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::NodeRef")
                                                        []
                                                        [
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Immut";
                                                          K;
                                                          V;
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::LeafOrInternal"
                                                        ]
                                                    ],
                                                  "ok",
                                                  []
                                                |),
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Immut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::Leaf"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::Edge"
                                                        ],
                                                      "next_back_kv",
                                                      []
                                                    |),
                                                    [ M.read (| leaf_edge |) ]
                                                  |)
                                                ]
                                              |)
                                            ]
                                          |)
                                        |) in
                                      M.alloc (|
                                        Value.Tuple
                                          [
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Immut";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ],
                                                "next_back_leaf_edge",
                                                []
                                              |),
                                              [ M.read (| kv |) ]
                                            |);
                                            M.call_closure (|
                                              M.get_associated_function (|
                                                Ty.apply
                                                  (Ty.path
                                                    "alloc::collections::btree::node::Handle")
                                                  []
                                                  [
                                                    Ty.apply
                                                      (Ty.path
                                                        "alloc::collections::btree::node::NodeRef")
                                                      []
                                                      [
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::Immut";
                                                        K;
                                                        V;
                                                        Ty.path
                                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                                      ];
                                                    Ty.path
                                                      "alloc::collections::btree::node::marker::KV"
                                                  ],
                                                "into_kv",
                                                []
                                              |),
                                              [ M.read (| kv |) ]
                                            |)
                                          ]
                                      |)
                                    |)))
                              ]
                            |)))
                        | _ => M.impossible "wrong number of arguments"
                        end))
                ]
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_unchecked" (next_back_unchecked K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_Immut_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_ValMut_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
        Definition Self (K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [
                  Ty.path "alloc::collections::btree::node::marker::ValMut";
                  K;
                  V;
                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                ];
              Ty.path "alloc::collections::btree::node::marker::Edge"
            ].
        
        (*
            unsafe fn next_unchecked(&mut self) -> (&'a K, &'a mut V) {
                let kv = super::mem::replace(self, |leaf_edge| {
                    let kv = leaf_edge.next_kv().ok().unwrap();
                    (unsafe { ptr::read(&kv) }.next_leaf_edge(), kv)
                });
                // Doing this last is faster, according to benchmarks.
                kv.into_kv_valmut()
            }
        *)
        Definition next_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ kv :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "alloc::collections::btree::mem::replace",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::ValMut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::ValMut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::KV"
                            ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::Handle")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          Ty.path "alloc::collections::btree::node::marker::ValMut";
                                          K;
                                          V;
                                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                                        ];
                                      Ty.path "alloc::collections::btree::node::marker::Edge"
                                    ]
                                ]
                            ]
                            (Ty.tuple
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ];
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ])
                        ]
                      |),
                      [
                        M.read (| self |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let leaf_edge := M.copy (| γ |) in
                                          M.read (|
                                            let~ kv :=
                                              M.alloc (|
                                                M.call_closure (|
                                                  M.get_associated_function (|
                                                    Ty.apply
                                                      (Ty.path "core::option::Option")
                                                      []
                                                      [
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::ValMut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::KV"
                                                          ]
                                                      ],
                                                    "unwrap",
                                                    []
                                                  |),
                                                  [
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path "core::result::Result")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ];
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::ValMut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                                              ]
                                                          ],
                                                        "ok",
                                                        []
                                                      |),
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Leaf"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Edge"
                                                              ],
                                                            "next_kv",
                                                            []
                                                          |),
                                                          [ M.read (| leaf_edge |) ]
                                                        |)
                                                      ]
                                                    |)
                                                  ]
                                                |)
                                              |) in
                                            M.alloc (|
                                              Value.Tuple
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::ValMut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::KV"
                                                        ],
                                                      "next_leaf_edge",
                                                      []
                                                    |),
                                                    [
                                                      M.call_closure (|
                                                        M.get_function (|
                                                          "core::ptr::read",
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ]
                                                          ]
                                                        |),
                                                        [ kv ]
                                                      |)
                                                    ]
                                                  |);
                                                  M.read (| kv |)
                                                ]
                                            |)
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::Handle")
                        []
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::ValMut";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                            ];
                          Ty.path "alloc::collections::btree::node::marker::KV"
                        ],
                      "into_kv_valmut",
                      []
                    |),
                    [ M.read (| kv |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_unchecked" (next_unchecked K V).
        
        (*
            unsafe fn next_back_unchecked(&mut self) -> (&'a K, &'a mut V) {
                let kv = super::mem::replace(self, |leaf_edge| {
                    let kv = leaf_edge.next_back_kv().ok().unwrap();
                    (unsafe { ptr::read(&kv) }.next_back_leaf_edge(), kv)
                });
                // Doing this last is faster, according to benchmarks.
                kv.into_kv_valmut()
            }
        *)
        Definition next_back_unchecked
            (K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                let~ kv :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "alloc::collections::btree::mem::replace",
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::ValMut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::Leaf"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::Edge"
                            ];
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::Handle")
                            []
                            [
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  Ty.path "alloc::collections::btree::node::marker::ValMut";
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ];
                              Ty.path "alloc::collections::btree::node::marker::KV"
                            ];
                          Ty.function
                            [
                              Ty.tuple
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::Handle")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          Ty.path "alloc::collections::btree::node::marker::ValMut";
                                          K;
                                          V;
                                          Ty.path "alloc::collections::btree::node::marker::Leaf"
                                        ];
                                      Ty.path "alloc::collections::btree::node::marker::Edge"
                                    ]
                                ]
                            ]
                            (Ty.tuple
                              [
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Leaf"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::Edge"
                                  ];
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        Ty.path "alloc::collections::btree::node::marker::ValMut";
                                        K;
                                        V;
                                        Ty.path
                                          "alloc::collections::btree::node::marker::LeafOrInternal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ]
                              ])
                        ]
                      |),
                      [
                        M.read (| self |);
                        M.closure
                          (fun γ =>
                            ltac:(M.monadic
                              match γ with
                              | [ α0 ] =>
                                ltac:(M.monadic
                                  (M.match_operator (|
                                    M.alloc (| α0 |),
                                    [
                                      fun γ =>
                                        ltac:(M.monadic
                                          (let leaf_edge := M.copy (| γ |) in
                                          M.read (|
                                            let~ kv :=
                                              M.alloc (|
                                                M.call_closure (|
                                                  M.get_associated_function (|
                                                    Ty.apply
                                                      (Ty.path "core::option::Option")
                                                      []
                                                      [
                                                        Ty.apply
                                                          (Ty.path
                                                            "alloc::collections::btree::node::Handle")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::ValMut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                                              ];
                                                            Ty.path
                                                              "alloc::collections::btree::node::marker::KV"
                                                          ]
                                                      ],
                                                    "unwrap",
                                                    []
                                                  |),
                                                  [
                                                    M.call_closure (|
                                                      M.get_associated_function (|
                                                        Ty.apply
                                                          (Ty.path "core::result::Result")
                                                          []
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ];
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::NodeRef")
                                                              []
                                                              [
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::ValMut";
                                                                K;
                                                                V;
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::LeafOrInternal"
                                                              ]
                                                          ],
                                                        "ok",
                                                        []
                                                      |),
                                                      [
                                                        M.call_closure (|
                                                          M.get_associated_function (|
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::Leaf"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::Edge"
                                                              ],
                                                            "next_back_kv",
                                                            []
                                                          |),
                                                          [ M.read (| leaf_edge |) ]
                                                        |)
                                                      ]
                                                    |)
                                                  ]
                                                |)
                                              |) in
                                            M.alloc (|
                                              Value.Tuple
                                                [
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "alloc::collections::btree::node::Handle")
                                                        []
                                                        [
                                                          Ty.apply
                                                            (Ty.path
                                                              "alloc::collections::btree::node::NodeRef")
                                                            []
                                                            [
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::ValMut";
                                                              K;
                                                              V;
                                                              Ty.path
                                                                "alloc::collections::btree::node::marker::LeafOrInternal"
                                                            ];
                                                          Ty.path
                                                            "alloc::collections::btree::node::marker::KV"
                                                        ],
                                                      "next_back_leaf_edge",
                                                      []
                                                    |),
                                                    [
                                                      M.call_closure (|
                                                        M.get_function (|
                                                          "core::ptr::read",
                                                          [
                                                            Ty.apply
                                                              (Ty.path
                                                                "alloc::collections::btree::node::Handle")
                                                              []
                                                              [
                                                                Ty.apply
                                                                  (Ty.path
                                                                    "alloc::collections::btree::node::NodeRef")
                                                                  []
                                                                  [
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::ValMut";
                                                                    K;
                                                                    V;
                                                                    Ty.path
                                                                      "alloc::collections::btree::node::marker::LeafOrInternal"
                                                                  ];
                                                                Ty.path
                                                                  "alloc::collections::btree::node::marker::KV"
                                                              ]
                                                          ]
                                                        |),
                                                        [ kv ]
                                                      |)
                                                    ]
                                                  |);
                                                  M.read (| kv |)
                                                ]
                                            |)
                                          |)))
                                    ]
                                  |)))
                              | _ => M.impossible "wrong number of arguments"
                              end))
                      ]
                    |)
                  |) in
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply
                        (Ty.path "alloc::collections::btree::node::Handle")
                        []
                        [
                          Ty.apply
                            (Ty.path "alloc::collections::btree::node::NodeRef")
                            []
                            [
                              Ty.path "alloc::collections::btree::node::marker::ValMut";
                              K;
                              V;
                              Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                            ];
                          Ty.path "alloc::collections::btree::node::marker::KV"
                        ],
                      "into_kv_valmut",
                      []
                    |),
                    [ M.read (| kv |) ]
                  |)
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_unchecked :
          forall (K V : Ty.t),
          M.IsAssociatedFunction (Self K V) "next_back_unchecked" (next_back_unchecked K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_alloc_collections_btree_node_marker_ValMut_K_V_alloc_collections_btree_node_marker_Leaf_alloc_collections_btree_node_marker_Edge.
      
      
      
      (*
      Enum Position
      {
        const_params := [];
        ty_params := [ "BorrowType"; "K"; "V" ];
        variants :=
          [
            {
              name := "Leaf";
              item :=
                StructTuple
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::NodeRef")
                      []
                      [ BorrowType; K; V; Ty.path "alloc::collections::btree::node::marker::Leaf" ]
                  ];
              discriminant := None;
            };
            {
              name := "Internal";
              item :=
                StructTuple
                  [
                    Ty.apply
                      (Ty.path "alloc::collections::btree::node::NodeRef")
                      []
                      [
                        BorrowType;
                        K;
                        V;
                        Ty.path "alloc::collections::btree::node::marker::Internal"
                      ]
                  ];
              discriminant := None;
            };
            {
              name := "InternalKV";
              item := StructTuple [];
              discriminant := None;
            }
          ];
      }
      *)
      
      
      Module Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_LeafOrInternal_alloc_collections_btree_node_marker_KV.
        Definition Self (BorrowType K V : Ty.t) : Ty.t :=
          Ty.apply
            (Ty.path "alloc::collections::btree::node::Handle")
            []
            [
              Ty.apply
                (Ty.path "alloc::collections::btree::node::NodeRef")
                []
                [
                  BorrowType;
                  K;
                  V;
                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                ];
              Ty.path "alloc::collections::btree::node::marker::KV"
            ].
        
        (*
            pub fn next_leaf_edge(self) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge> {
                match self.force() {
                    Leaf(leaf_kv) => leaf_kv.right_edge(),
                    Internal(internal_kv) => {
                        let next_internal_edge = internal_kv.right_edge();
                        next_internal_edge.descend().first_leaf_edge()
                    }
                }
            }
        *)
        Definition next_leaf_edge
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                M.match_operator (|
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::Handle")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                BorrowType;
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                              ];
                            Ty.path "alloc::collections::btree::node::marker::KV"
                          ],
                        "force",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::node::ForceResult::Leaf",
                            0
                          |) in
                        let leaf_kv := M.copy (| γ0_0 |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      BorrowType;
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::KV"
                                ],
                              "right_edge",
                              []
                            |),
                            [ M.read (| leaf_kv |) ]
                          |)
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::node::ForceResult::Internal",
                            0
                          |) in
                        let internal_kv := M.copy (| γ0_0 |) in
                        let~ next_internal_edge :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Internal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ],
                                "right_edge",
                                []
                              |),
                              [ M.read (| internal_kv |) ]
                            |)
                          |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  BorrowType;
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ],
                              "first_leaf_edge",
                              []
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::Handle")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::Internal"
                                        ];
                                      Ty.path "alloc::collections::btree::node::marker::Edge"
                                    ],
                                  "descend",
                                  []
                                |),
                                [ M.read (| next_internal_edge |) ]
                              |)
                            ]
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_leaf_edge :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "next_leaf_edge"
            (next_leaf_edge BorrowType K V).
        
        (*
            pub fn next_back_leaf_edge(
                self,
            ) -> Handle<NodeRef<BorrowType, K, V, marker::Leaf>, marker::Edge> {
                match self.force() {
                    Leaf(leaf_kv) => leaf_kv.left_edge(),
                    Internal(internal_kv) => {
                        let next_internal_edge = internal_kv.left_edge();
                        next_internal_edge.descend().last_leaf_edge()
                    }
                }
            }
        *)
        Definition next_back_leaf_edge
            (BorrowType K V : Ty.t)
            (ε : list Value.t)
            (τ : list Ty.t)
            (α : list Value.t)
            : M :=
          let Self : Ty.t := Self BorrowType K V in
          match ε, τ, α with
          | [], [], [ self ] =>
            ltac:(M.monadic
              (let self := M.alloc (| self |) in
              M.read (|
                M.match_operator (|
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply
                          (Ty.path "alloc::collections::btree::node::Handle")
                          []
                          [
                            Ty.apply
                              (Ty.path "alloc::collections::btree::node::NodeRef")
                              []
                              [
                                BorrowType;
                                K;
                                V;
                                Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                              ];
                            Ty.path "alloc::collections::btree::node::marker::KV"
                          ],
                        "force",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::node::ForceResult::Leaf",
                            0
                          |) in
                        let leaf_kv := M.copy (| γ0_0 |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::Handle")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::NodeRef")
                                    []
                                    [
                                      BorrowType;
                                      K;
                                      V;
                                      Ty.path "alloc::collections::btree::node::marker::Leaf"
                                    ];
                                  Ty.path "alloc::collections::btree::node::marker::KV"
                                ],
                              "left_edge",
                              []
                            |),
                            [ M.read (| leaf_kv |) ]
                          |)
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "alloc::collections::btree::node::ForceResult::Internal",
                            0
                          |) in
                        let internal_kv := M.copy (| γ0_0 |) in
                        let~ next_internal_edge :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply
                                  (Ty.path "alloc::collections::btree::node::Handle")
                                  []
                                  [
                                    Ty.apply
                                      (Ty.path "alloc::collections::btree::node::NodeRef")
                                      []
                                      [
                                        BorrowType;
                                        K;
                                        V;
                                        Ty.path "alloc::collections::btree::node::marker::Internal"
                                      ];
                                    Ty.path "alloc::collections::btree::node::marker::KV"
                                  ],
                                "left_edge",
                                []
                              |),
                              [ M.read (| internal_kv |) ]
                            |)
                          |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply
                                (Ty.path "alloc::collections::btree::node::NodeRef")
                                []
                                [
                                  BorrowType;
                                  K;
                                  V;
                                  Ty.path "alloc::collections::btree::node::marker::LeafOrInternal"
                                ],
                              "last_leaf_edge",
                              []
                            |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply
                                    (Ty.path "alloc::collections::btree::node::Handle")
                                    []
                                    [
                                      Ty.apply
                                        (Ty.path "alloc::collections::btree::node::NodeRef")
                                        []
                                        [
                                          BorrowType;
                                          K;
                                          V;
                                          Ty.path
                                            "alloc::collections::btree::node::marker::Internal"
                                        ];
                                      Ty.path "alloc::collections::btree::node::marker::Edge"
                                    ],
                                  "descend",
                                  []
                                |),
                                [ M.read (| next_internal_edge |) ]
                              |)
                            ]
                          |)
                        |)))
                  ]
                |)
              |)))
          | _, _, _ => M.impossible "wrong number of arguments"
          end.
        
        Axiom AssociatedFunction_next_back_leaf_edge :
          forall (BorrowType K V : Ty.t),
          M.IsAssociatedFunction
            (Self BorrowType K V)
            "next_back_leaf_edge"
            (next_back_leaf_edge BorrowType K V).
      End Impl_alloc_collections_btree_node_Handle_alloc_collections_btree_node_NodeRef_BorrowType_K_V_alloc_collections_btree_node_marker_LeafOrInternal_alloc_collections_btree_node_marker_KV.
      
    End navigate.
  End btree.
End collections.
