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

Module vec.
  (* StructRecord
    {
      name := "Vec";
      const_params := [];
      ty_params := [ "T"; "A" ];
      fields :=
        [ ("buf", Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ]); ("len", Ty.path "usize")
        ];
    } *)
  
  Module Impl_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        pub const fn new() -> Self {
            Vec { buf: RawVec::new(), len: 0 }
        }
    *)
    Definition new (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [] =>
        ltac:(M.monadic
          (Value.StructRecord
            "alloc::vec::Vec"
            [
              ("buf",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "alloc::raw_vec::RawVec")
                      []
                      [ T; Ty.path "alloc::alloc::Global" ],
                    "new",
                    []
                  |),
                  []
                |));
              ("len", Value.Integer IntegerKind.Usize 0)
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_new : forall (T : Ty.t), M.IsAssociatedFunction (Self T) "new" (new T).
    
    (*
        pub fn with_capacity(capacity: usize) -> Self {
            Self::with_capacity_in(capacity, Global)
        }
    *)
    Definition with_capacity (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ capacity ] =>
        ltac:(M.monadic
          (let capacity := M.alloc (| capacity |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              "with_capacity_in",
              []
            |),
            [ M.read (| capacity |); Value.StructTuple "alloc::alloc::Global" [] ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_with_capacity :
      forall (T : Ty.t),
      M.IsAssociatedFunction (Self T) "with_capacity" (with_capacity T).
    
    (*
        pub fn try_with_capacity(capacity: usize) -> Result<Self, TryReserveError> {
            Self::try_with_capacity_in(capacity, Global)
        }
    *)
    Definition try_with_capacity
        (T : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ capacity ] =>
        ltac:(M.monadic
          (let capacity := M.alloc (| capacity |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              "try_with_capacity_in",
              []
            |),
            [ M.read (| capacity |); Value.StructTuple "alloc::alloc::Global" [] ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_try_with_capacity :
      forall (T : Ty.t),
      M.IsAssociatedFunction (Self T) "try_with_capacity" (try_with_capacity T).
    
    (*
        pub unsafe fn from_raw_parts(ptr: *mut T, length: usize, capacity: usize) -> Self {
            unsafe { Self::from_raw_parts_in(ptr, length, capacity, Global) }
        }
    *)
    Definition from_raw_parts
        (T : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ ptr; length; capacity ] =>
        ltac:(M.monadic
          (let ptr := M.alloc (| ptr |) in
          let length := M.alloc (| length |) in
          let capacity := M.alloc (| capacity |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              "from_raw_parts_in",
              []
            |),
            [
              M.read (| ptr |);
              M.read (| length |);
              M.read (| capacity |);
              Value.StructTuple "alloc::alloc::Global" []
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_from_raw_parts :
      forall (T : Ty.t),
      M.IsAssociatedFunction (Self T) "from_raw_parts" (from_raw_parts T).
    
    (*
        pub unsafe fn from_parts(ptr: NonNull<T>, length: usize, capacity: usize) -> Self {
            unsafe { Self::from_parts_in(ptr, length, capacity, Global) }
        }
    *)
    Definition from_parts (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ ptr; length; capacity ] =>
        ltac:(M.monadic
          (let ptr := M.alloc (| ptr |) in
          let length := M.alloc (| length |) in
          let capacity := M.alloc (| capacity |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              "from_parts_in",
              []
            |),
            [
              M.read (| ptr |);
              M.read (| length |);
              M.read (| capacity |);
              Value.StructTuple "alloc::alloc::Global" []
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_from_parts :
      forall (T : Ty.t),
      M.IsAssociatedFunction (Self T) "from_parts" (from_parts T).
  End Impl_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        pub const fn new_in(alloc: A) -> Self {
            Vec { buf: RawVec::new_in(alloc), len: 0 }
        }
    *)
    Definition new_in (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ alloc ] =>
        ltac:(M.monadic
          (let alloc := M.alloc (| alloc |) in
          Value.StructRecord
            "alloc::vec::Vec"
            [
              ("buf",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "new_in",
                    []
                  |),
                  [ M.read (| alloc |) ]
                |));
              ("len", Value.Integer IntegerKind.Usize 0)
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_new_in :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "new_in" (new_in T A).
    
    (*
        pub fn with_capacity_in(capacity: usize, alloc: A) -> Self {
            Vec { buf: RawVec::with_capacity_in(capacity, alloc), len: 0 }
        }
    *)
    Definition with_capacity_in
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ capacity; alloc ] =>
        ltac:(M.monadic
          (let capacity := M.alloc (| capacity |) in
          let alloc := M.alloc (| alloc |) in
          Value.StructRecord
            "alloc::vec::Vec"
            [
              ("buf",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "with_capacity_in",
                    []
                  |),
                  [ M.read (| capacity |); M.read (| alloc |) ]
                |));
              ("len", Value.Integer IntegerKind.Usize 0)
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_with_capacity_in :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "with_capacity_in" (with_capacity_in T A).
    
    (*
        pub fn try_with_capacity_in(capacity: usize, alloc: A) -> Result<Self, TryReserveError> {
            Ok(Vec { buf: RawVec::try_with_capacity_in(capacity, alloc)?, len: 0 })
        }
    *)
    Definition try_with_capacity_in
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ capacity; alloc ] =>
        ltac:(M.monadic
          (let capacity := M.alloc (| capacity |) in
          let alloc := M.alloc (| alloc |) in
          M.catch_return (|
            ltac:(M.monadic
              (Value.StructTuple
                "core::result::Result::Ok"
                [
                  Value.StructRecord
                    "alloc::vec::Vec"
                    [
                      ("buf",
                        M.read (|
                          M.match_operator (|
                            M.alloc (|
                              M.call_closure (|
                                M.get_trait_method (|
                                  "core::ops::try_trait::Try",
                                  Ty.apply
                                    (Ty.path "core::result::Result")
                                    []
                                    [
                                      Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ];
                                      Ty.path "alloc::collections::TryReserveError"
                                    ],
                                  [],
                                  "branch",
                                  []
                                |),
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                                      "try_with_capacity_in",
                                      []
                                    |),
                                    [ M.read (| capacity |); M.read (| alloc |) ]
                                  |)
                                ]
                              |)
                            |),
                            [
                              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::result::Result")
                                                []
                                                [
                                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ];
                                                  Ty.path "alloc::collections::TryReserveError"
                                                ],
                                              [
                                                Ty.apply
                                                  (Ty.path "core::result::Result")
                                                  []
                                                  [
                                                    Ty.path "core::convert::Infallible";
                                                    Ty.path "alloc::collections::TryReserveError"
                                                  ]
                                              ],
                                              "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))
                            ]
                          |)
                        |));
                      ("len", Value.Integer IntegerKind.Usize 0)
                    ]
                ]))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_try_with_capacity_in :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "try_with_capacity_in" (try_with_capacity_in T A).
    
    (*
        pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self {
            unsafe { Vec { buf: RawVec::from_raw_parts_in(ptr, capacity, alloc), len: length } }
        }
    *)
    Definition from_raw_parts_in
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ ptr; length; capacity; alloc ] =>
        ltac:(M.monadic
          (let ptr := M.alloc (| ptr |) in
          let length := M.alloc (| length |) in
          let capacity := M.alloc (| capacity |) in
          let alloc := M.alloc (| alloc |) in
          Value.StructRecord
            "alloc::vec::Vec"
            [
              ("buf",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "from_raw_parts_in",
                    []
                  |),
                  [ M.read (| ptr |); M.read (| capacity |); M.read (| alloc |) ]
                |));
              ("len", M.read (| length |))
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_from_raw_parts_in :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "from_raw_parts_in" (from_raw_parts_in T A).
    
    (*
        pub unsafe fn from_parts_in(ptr: NonNull<T>, length: usize, capacity: usize, alloc: A) -> Self {
            unsafe { Vec { buf: RawVec::from_nonnull_in(ptr, capacity, alloc), len: length } }
        }
    *)
    Definition from_parts_in
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ ptr; length; capacity; alloc ] =>
        ltac:(M.monadic
          (let ptr := M.alloc (| ptr |) in
          let length := M.alloc (| length |) in
          let capacity := M.alloc (| capacity |) in
          let alloc := M.alloc (| alloc |) in
          Value.StructRecord
            "alloc::vec::Vec"
            [
              ("buf",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "from_nonnull_in",
                    []
                  |),
                  [ M.read (| ptr |); M.read (| capacity |); M.read (| alloc |) ]
                |));
              ("len", M.read (| length |))
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_from_parts_in :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "from_parts_in" (from_parts_in T A).
    
    (*
        pub fn into_raw_parts(self) -> ( *mut T, usize, usize) {
            let mut me = ManuallyDrop::new(self);
            (me.as_mut_ptr(), me.len(), me.capacity())
        }
    *)
    Definition into_raw_parts
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ me :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "core::mem::manually_drop::ManuallyDrop")
                      []
                      [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                    "new",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            M.alloc (|
              Value.Tuple
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "as_mut_ptr",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::DerefMut",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref_mut",
                          []
                        |),
                        [ me ]
                      |)
                    ]
                  |);
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "len",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |)
                    ]
                  |);
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "capacity",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |)
                    ]
                  |)
                ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_raw_parts :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "into_raw_parts" (into_raw_parts T A).
    
    (*
        pub fn into_parts(self) -> (NonNull<T>, usize, usize) {
            let (ptr, len, capacity) = self.into_raw_parts();
            // SAFETY: A `Vec` always has a non-null pointer.
            (unsafe { NonNull::new_unchecked(ptr) }, len, capacity)
        }
    *)
    Definition into_parts (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A 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::vec::Vec") [] [ T; A ],
                    "into_raw_parts",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |),
              [
                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 γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in
                    let ptr := M.copy (| γ0_0 |) in
                    let len := M.copy (| γ0_1 |) in
                    let capacity := M.copy (| γ0_2 |) in
                    M.alloc (|
                      Value.Tuple
                        [
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "core::ptr::non_null::NonNull") [] [ T ],
                              "new_unchecked",
                              []
                            |),
                            [ M.read (| ptr |) ]
                          |);
                          M.read (| len |);
                          M.read (| capacity |)
                        ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_parts :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "into_parts" (into_parts T A).
    
    (*
        pub fn into_raw_parts_with_alloc(self) -> ( *mut T, usize, usize, A) {
            let mut me = ManuallyDrop::new(self);
            let len = me.len();
            let capacity = me.capacity();
            let ptr = me.as_mut_ptr();
            let alloc = unsafe { ptr::read(me.allocator()) };
            (ptr, len, capacity, alloc)
        }
    *)
    Definition into_raw_parts_with_alloc
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ me :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "core::mem::manually_drop::ManuallyDrop")
                      []
                      [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                    "new",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::ops::deref::Deref",
                        Ty.apply
                          (Ty.path "core::mem::manually_drop::ManuallyDrop")
                          []
                          [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                        [],
                        "deref",
                        []
                      |),
                      [ me ]
                    |)
                  ]
                |)
              |) in
            let~ capacity :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "capacity",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::ops::deref::Deref",
                        Ty.apply
                          (Ty.path "core::mem::manually_drop::ManuallyDrop")
                          []
                          [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                        [],
                        "deref",
                        []
                      |),
                      [ me ]
                    |)
                  ]
                |)
              |) in
            let~ ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "as_mut_ptr",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::ops::deref::DerefMut",
                        Ty.apply
                          (Ty.path "core::mem::manually_drop::ManuallyDrop")
                          []
                          [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                        [],
                        "deref_mut",
                        []
                      |),
                      [ me ]
                    |)
                  ]
                |)
              |) in
            let~ alloc :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::ptr::read", [ A ] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "allocator",
                        []
                      |),
                      [
                        M.call_closure (|
                          M.get_trait_method (|
                            "core::ops::deref::Deref",
                            Ty.apply
                              (Ty.path "core::mem::manually_drop::ManuallyDrop")
                              []
                              [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                            [],
                            "deref",
                            []
                          |),
                          [ me ]
                        |)
                      ]
                    |)
                  ]
                |)
              |) in
            M.alloc (|
              Value.Tuple
                [ M.read (| ptr |); M.read (| len |); M.read (| capacity |); M.read (| alloc |) ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_raw_parts_with_alloc :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "into_raw_parts_with_alloc" (into_raw_parts_with_alloc T A).
    
    (*
        pub fn into_parts_with_alloc(self) -> (NonNull<T>, usize, usize, A) {
            let (ptr, len, capacity, alloc) = self.into_raw_parts_with_alloc();
            // SAFETY: A `Vec` always has a non-null pointer.
            (unsafe { NonNull::new_unchecked(ptr) }, len, capacity, alloc)
        }
    *)
    Definition into_parts_with_alloc
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A 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::vec::Vec") [] [ T; A ],
                    "into_raw_parts_with_alloc",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |),
              [
                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 γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in
                    let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in
                    let ptr := M.copy (| γ0_0 |) in
                    let len := M.copy (| γ0_1 |) in
                    let capacity := M.copy (| γ0_2 |) in
                    let alloc := M.copy (| γ0_3 |) in
                    M.alloc (|
                      Value.Tuple
                        [
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "core::ptr::non_null::NonNull") [] [ T ],
                              "new_unchecked",
                              []
                            |),
                            [ M.read (| ptr |) ]
                          |);
                          M.read (| len |);
                          M.read (| capacity |);
                          M.read (| alloc |)
                        ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_parts_with_alloc :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "into_parts_with_alloc" (into_parts_with_alloc T A).
    
    (*
        pub fn capacity(&self) -> usize {
            self.buf.capacity()
        }
    *)
    Definition capacity (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A 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::raw_vec::RawVec") [] [ T; A ],
              "capacity",
              []
            |),
            [ M.SubPointer.get_struct_record_field (| M.read (| self |), "alloc::vec::Vec", "buf" |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_capacity :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "capacity" (capacity T A).
    
    (*
        pub fn reserve(&mut self, additional: usize) {
            self.buf.reserve(self.len, additional);
        }
    *)
    Definition reserve (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "buf"
                    |);
                    M.read (|
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |)
                    |);
                    M.read (| additional |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_reserve :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "reserve" (reserve T A).
    
    (*
        pub fn reserve_exact(&mut self, additional: usize) {
            self.buf.reserve_exact(self.len, additional);
        }
    *)
    Definition reserve_exact
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "reserve_exact",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "buf"
                    |);
                    M.read (|
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |)
                    |);
                    M.read (| additional |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_reserve_exact :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "reserve_exact" (reserve_exact T A).
    
    (*
        pub fn try_reserve(&mut self, additional: usize) -> Result<(), TryReserveError> {
            self.buf.try_reserve(self.len, additional)
        }
    *)
    Definition try_reserve (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
              "try_reserve",
              []
            |),
            [
              M.SubPointer.get_struct_record_field (|
                M.read (| self |),
                "alloc::vec::Vec",
                "buf"
              |);
              M.read (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |)
              |);
              M.read (| additional |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_try_reserve :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "try_reserve" (try_reserve T A).
    
    (*
        pub fn try_reserve_exact(&mut self, additional: usize) -> Result<(), TryReserveError> {
            self.buf.try_reserve_exact(self.len, additional)
        }
    *)
    Definition try_reserve_exact
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
              "try_reserve_exact",
              []
            |),
            [
              M.SubPointer.get_struct_record_field (|
                M.read (| self |),
                "alloc::vec::Vec",
                "buf"
              |);
              M.read (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |)
              |);
              M.read (| additional |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_try_reserve_exact :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "try_reserve_exact" (try_reserve_exact T A).
    
    (*
        pub fn shrink_to_fit(&mut self) {
            // The capacity is never less than the length, and there's nothing to do when
            // they are equal, so we can avoid the panic case in `RawVec::shrink_to_fit`
            // by only calling it with a greater capacity.
            if self.capacity() > self.len {
                self.buf.shrink_to_fit(self.len);
            }
        }
    *)
    Definition shrink_to_fit
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use
                        (M.alloc (|
                          BinOp.gt (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                "capacity",
                                []
                              |),
                              [ M.read (| self |) ]
                            |),
                            M.read (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::vec::Vec",
                                "len"
                              |)
                            |)
                          |)
                        |)) in
                    let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                            "shrink_to_fit",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::vec::Vec",
                              "buf"
                            |);
                            M.read (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::vec::Vec",
                                "len"
                              |)
                            |)
                          ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)));
                fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_shrink_to_fit :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "shrink_to_fit" (shrink_to_fit T A).
    
    (*
        pub fn shrink_to(&mut self, min_capacity: usize) {
            if self.capacity() > min_capacity {
                self.buf.shrink_to_fit(cmp::max(self.len, min_capacity));
            }
        }
    *)
    Definition shrink_to (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; min_capacity ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let min_capacity := M.alloc (| min_capacity |) in
          M.read (|
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use
                        (M.alloc (|
                          BinOp.gt (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                "capacity",
                                []
                              |),
                              [ M.read (| self |) ]
                            |),
                            M.read (| min_capacity |)
                          |)
                        |)) in
                    let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                            "shrink_to_fit",
                            []
                          |),
                          [
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::vec::Vec",
                              "buf"
                            |);
                            M.call_closure (|
                              M.get_function (| "core::cmp::max", [ Ty.path "usize" ] |),
                              [
                                M.read (|
                                  M.SubPointer.get_struct_record_field (|
                                    M.read (| self |),
                                    "alloc::vec::Vec",
                                    "len"
                                  |)
                                |);
                                M.read (| min_capacity |)
                              ]
                            |)
                          ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)));
                fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_shrink_to :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "shrink_to" (shrink_to T A).
    
    (*
        pub fn into_boxed_slice(mut self) -> Box<[T], A> {
            unsafe {
                self.shrink_to_fit();
                let me = ManuallyDrop::new(self);
                let buf = ptr::read(&me.buf);
                let len = me.len();
                buf.into_box(len).assume_init()
            }
        }
    *)
    Definition into_boxed_slice
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "shrink_to_fit",
                    []
                  |),
                  [ self ]
                |)
              |) in
            let~ me :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "core::mem::manually_drop::ManuallyDrop")
                      []
                      [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                    "new",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ buf :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (|
                    "core::ptr::read",
                    [ Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ] ]
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |),
                      "alloc::vec::Vec",
                      "buf"
                    |)
                  ]
                |)
              |) in
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::ops::deref::Deref",
                        Ty.apply
                          (Ty.path "core::mem::manually_drop::ManuallyDrop")
                          []
                          [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                        [],
                        "deref",
                        []
                      |),
                      [ me ]
                    |)
                  ]
                |)
              |) in
            M.alloc (|
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::boxed::Box")
                    []
                    [
                      Ty.apply
                        (Ty.path "slice")
                        []
                        [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ];
                      A
                    ],
                  "assume_init",
                  []
                |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                      "into_box",
                      []
                    |),
                    [ M.read (| buf |); M.read (| len |) ]
                  |)
                ]
              |)
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_boxed_slice :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "into_boxed_slice" (into_boxed_slice T A).
    
    (*
        pub fn truncate(&mut self, len: usize) {
            // This is safe because:
            //
            // * the slice passed to `drop_in_place` is valid; the `len > self.len`
            //   case avoids creating an invalid slice, and
            // * the `len` of the vector is shrunk before calling `drop_in_place`,
            //   such that no value will be dropped twice in case `drop_in_place`
            //   were to panic once (if it panics twice, the program aborts).
            unsafe {
                // Note: It's intentional that this is `>` and not `>=`.
                //       Changing it to `>=` has negative performance
                //       implications in some cases. See #78884 for more.
                if len > self.len {
                    return;
                }
                let remaining_len = self.len - len;
                let s = ptr::slice_from_raw_parts_mut(self.as_mut_ptr().add(len), remaining_len);
                self.len = len;
                ptr::drop_in_place(s);
            }
        }
    *)
    Definition truncate (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; len ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let len := M.alloc (| len |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.gt (|
                                  M.read (| len |),
                                  M.read (|
                                    M.SubPointer.get_struct_record_field (|
                                      M.read (| self |),
                                      "alloc::vec::Vec",
                                      "len"
                                    |)
                                  |)
                                |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ remaining_len :=
                  M.alloc (|
                    BinOp.Wrap.sub (|
                      M.read (|
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::vec::Vec",
                          "len"
                        |)
                      |),
                      M.read (| len |)
                    |)
                  |) in
                let~ s :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (| "core::ptr::slice_from_raw_parts_mut", [ T ] |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "*mut") [] [ T ],
                            "add",
                            []
                          |),
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                "as_mut_ptr",
                                []
                              |),
                              [ M.read (| self |) ]
                            |);
                            M.read (| len |)
                          ]
                        |);
                        M.read (| remaining_len |)
                      ]
                    |)
                  |) in
                let~ _ :=
                  M.write (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "len"
                    |),
                    M.read (| len |)
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::ptr::drop_in_place",
                        [ Ty.apply (Ty.path "slice") [] [ T ] ]
                      |),
                      [ M.read (| s |) ]
                    |)
                  |) in
                M.alloc (| Value.Tuple [] |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_truncate :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "truncate" (truncate T A).
    
    (*
        pub fn as_slice(&self) -> &[T] {
            self
        }
    *)
    Definition as_slice (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::deref::Deref",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [],
              "deref",
              []
            |),
            [ M.read (| self |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_as_slice :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "as_slice" (as_slice T A).
    
    (*
        pub fn as_mut_slice(&mut self) -> &mut [T] {
            self
        }
    *)
    Definition as_mut_slice
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::deref::DerefMut",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [],
              "deref_mut",
              []
            |),
            [ M.read (| self |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_as_mut_slice :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "as_mut_slice" (as_mut_slice T A).
    
    (*
        pub fn as_ptr(&self) -> *const T {
            // We shadow the slice method of the same name to avoid going through
            // `deref`, which creates an intermediate reference.
            self.buf.ptr()
        }
    *)
    Definition as_ptr (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          (* MutToConstPointer *)
          M.pointer_coercion
            (M.call_closure (|
              M.get_associated_function (|
                Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                "ptr",
                []
              |),
              [
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "buf"
                |)
              ]
            |))))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_as_ptr :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "as_ptr" (as_ptr T A).
    
    (*
        pub fn as_mut_ptr(&mut self) -> *mut T {
            // We shadow the slice method of the same name to avoid going through
            // `deref_mut`, which creates an intermediate reference.
            self.buf.ptr()
        }
    *)
    Definition as_mut_ptr (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A 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::raw_vec::RawVec") [] [ T; A ],
              "ptr",
              []
            |),
            [ M.SubPointer.get_struct_record_field (| M.read (| self |), "alloc::vec::Vec", "buf" |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_as_mut_ptr :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "as_mut_ptr" (as_mut_ptr T A).
    
    (*
        pub fn as_non_null(&mut self) -> NonNull<T> {
            // SAFETY: A `Vec` always has a non-null pointer.
            unsafe { NonNull::new_unchecked(self.as_mut_ptr()) }
        }
    *)
    Definition as_non_null (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "core::ptr::non_null::NonNull") [] [ T ],
              "new_unchecked",
              []
            |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  "as_mut_ptr",
                  []
                |),
                [ M.read (| self |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_as_non_null :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "as_non_null" (as_non_null T A).
    
    (*
        pub fn allocator(&self) -> &A {
            self.buf.allocator()
        }
    *)
    Definition allocator (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A 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::raw_vec::RawVec") [] [ T; A ],
              "allocator",
              []
            |),
            [ M.SubPointer.get_struct_record_field (| M.read (| self |), "alloc::vec::Vec", "buf" |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_allocator :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "allocator" (allocator T A).
    
    (*
        pub unsafe fn set_len(&mut self, new_len: usize) {
            debug_assert!(new_len <= self.capacity());
    
            self.len = new_len;
        }
    *)
    Definition set_len (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; new_len ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let new_len := M.alloc (| new_len |) 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 (|
                                        BinOp.le (|
                                          M.read (| new_len |),
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                              "capacity",
                                              []
                                            |),
                                            [ M.read (| self |) ]
                                          |)
                                        |)
                                      |)
                                    |)) 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: new_len <= self.capacity()"
                                        |)
                                      ]
                                    |)
                                  |)
                                |)));
                            fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                          ]
                        |) in
                      M.alloc (| Value.Tuple [] |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ _ :=
              M.write (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |),
                M.read (| new_len |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_set_len :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "set_len" (set_len T A).
    
    (*
        pub fn swap_remove(&mut self, index: usize) -> T {
            #[cold]
            #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
            #[track_caller]
            #[optimize(size)]
            fn assert_failed(index: usize, len: usize) -> ! {
                panic!("swap_remove index (is {index}) should be < len (is {len})");
            }
    
            let len = self.len();
            if index >= len {
                assert_failed(index, len);
            }
            unsafe {
                // We replace self[index] with the last element. Note that if the
                // bounds check above succeeds there must be a last element (which
                // can be self[index] itself).
                let value = ptr::read(self.as_ptr().add(index));
                let base_ptr = self.as_mut_ptr();
                ptr::copy(base_ptr.add(len - 1), base_ptr.add(index), 1);
                self.set_len(len - 1);
                value
            }
        }
    *)
    Definition swap_remove (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; index ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let index := M.alloc (| index |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use (M.alloc (| BinOp.ge (| M.read (| index |), M.read (| len |) |) |)) 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_associated_function (| Self, "assert_failed.swap_remove", [] |),
                            [ M.read (| index |); M.read (| len |) ]
                          |)
                        |)
                      |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ value :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::ptr::read", [ T ] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "*const") [] [ T ],
                        "add",
                        []
                      |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "as_ptr",
                            []
                          |),
                          [ M.read (| self |) ]
                        |);
                        M.read (| index |)
                      ]
                    |)
                  ]
                |)
              |) in
            let~ base_ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "as_mut_ptr",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::intrinsics::copy", [ T ] |),
                  [
                    (* MutToConstPointer *)
                    M.pointer_coercion
                      (M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "*mut") [] [ T ],
                          "add",
                          []
                        |),
                        [
                          M.read (| base_ptr |);
                          BinOp.Wrap.sub (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                        ]
                      |));
                    M.call_closure (|
                      M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                      [ M.read (| base_ptr |); M.read (| index |) ]
                    |);
                    Value.Integer IntegerKind.Usize 1
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "set_len",
                    []
                  |),
                  [
                    M.read (| self |);
                    BinOp.Wrap.sub (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                  ]
                |)
              |) in
            value
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_swap_remove :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "swap_remove" (swap_remove T A).
    
    (*
        pub fn insert(&mut self, index: usize, element: T) {
            #[cold]
            #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
            #[track_caller]
            #[optimize(size)]
            fn assert_failed(index: usize, len: usize) -> ! {
                panic!("insertion index (is {index}) should be <= len (is {len})");
            }
    
            let len = self.len();
            if index > len {
                assert_failed(index, len);
            }
    
            // space for the new element
            if len == self.buf.capacity() {
                self.buf.grow_one();
            }
    
            unsafe {
                // infallible
                // The spot to put the new value
                {
                    let p = self.as_mut_ptr().add(index);
                    if index < len {
                        // Shift everything over to make space. (Duplicating the
                        // `index`th element into two consecutive places.)
                        ptr::copy(p, p.add(1), len - index);
                    }
                    // Write it in, overwriting the first copy of the `index`th
                    // element.
                    ptr::write(p, element);
                }
                self.set_len(len + 1);
            }
        }
    *)
    Definition insert (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; index; element ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let index := M.alloc (| index |) in
          let element := M.alloc (| element |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use (M.alloc (| BinOp.gt (| M.read (| index |), M.read (| len |) |) |)) 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_associated_function (| Self, "assert_failed.insert", [] |),
                            [ M.read (| index |); M.read (| len |) ]
                          |)
                        |)
                      |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use
                          (M.alloc (|
                            BinOp.eq (|
                              M.read (| len |),
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                                  "capacity",
                                  []
                                |),
                                [
                                  M.SubPointer.get_struct_record_field (|
                                    M.read (| self |),
                                    "alloc::vec::Vec",
                                    "buf"
                                  |)
                                ]
                              |)
                            |)
                          |)) in
                      let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                      let~ _ :=
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                              "grow_one",
                              []
                            |),
                            [
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::vec::Vec",
                                "buf"
                              |)
                            ]
                          |)
                        |) in
                      M.alloc (| Value.Tuple [] |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ _ :=
              let~ p :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                          "as_mut_ptr",
                          []
                        |),
                        [ M.read (| self |) ]
                      |);
                      M.read (| index |)
                    ]
                  |)
                |) in
              let~ _ :=
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use
                            (M.alloc (| BinOp.lt (| M.read (| index |), M.read (| len |) |) |)) in
                        let _ :=
                          M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                        let~ _ :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_function (| "core::intrinsics::copy", [ T ] |),
                              [
                                (* MutToConstPointer *) M.pointer_coercion (M.read (| p |));
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "*mut") [] [ T ],
                                    "add",
                                    []
                                  |),
                                  [ M.read (| p |); Value.Integer IntegerKind.Usize 1 ]
                                |);
                                BinOp.Wrap.sub (| M.read (| len |), M.read (| index |) |)
                              ]
                            |)
                          |) in
                        M.alloc (| Value.Tuple [] |)));
                    fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                  ]
                |) in
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_function (| "core::ptr::write", [ T ] |),
                    [ M.read (| p |); M.read (| element |) ]
                  |)
                |) in
              M.alloc (| Value.Tuple [] |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "set_len",
                    []
                  |),
                  [
                    M.read (| self |);
                    BinOp.Wrap.add (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_insert :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "insert" (insert T A).
    
    (*
        pub fn remove(&mut self, index: usize) -> T {
            #[cold]
            #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
            #[track_caller]
            #[optimize(size)]
            fn assert_failed(index: usize, len: usize) -> ! {
                panic!("removal index (is {index}) should be < len (is {len})");
            }
    
            let len = self.len();
            if index >= len {
                assert_failed(index, len);
            }
            unsafe {
                // infallible
                let ret;
                {
                    // the place we are taking from.
                    let ptr = self.as_mut_ptr().add(index);
                    // copy it out, unsafely having a copy of the value on
                    // the stack and in the vector at the same time.
                    ret = ptr::read(ptr);
    
                    // Shift everything down to fill in that spot.
                    ptr::copy(ptr.add(1), ptr, len - index - 1);
                }
                self.set_len(len - 1);
                ret
            }
        }
    *)
    Definition remove (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; index ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let index := M.alloc (| index |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use (M.alloc (| BinOp.ge (| M.read (| index |), M.read (| len |) |) |)) 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_associated_function (| Self, "assert_failed.remove", [] |),
                            [ M.read (| index |); M.read (| len |) ]
                          |)
                        |)
                      |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ ret := M.copy (| Value.DeclaredButUndefined |) in
            let~ _ :=
              let~ ptr :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                          "as_mut_ptr",
                          []
                        |),
                        [ M.read (| self |) ]
                      |);
                      M.read (| index |)
                    ]
                  |)
                |) in
              let~ _ :=
                M.write (|
                  ret,
                  M.call_closure (|
                    M.get_function (| "core::ptr::read", [ T ] |),
                    [ (* MutToConstPointer *) M.pointer_coercion (M.read (| ptr |)) ]
                  |)
                |) in
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_function (| "core::intrinsics::copy", [ T ] |),
                    [
                      (* MutToConstPointer *)
                      M.pointer_coercion
                        (M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "*mut") [] [ T ],
                            "add",
                            []
                          |),
                          [ M.read (| ptr |); Value.Integer IntegerKind.Usize 1 ]
                        |));
                      M.read (| ptr |);
                      BinOp.Wrap.sub (|
                        BinOp.Wrap.sub (| M.read (| len |), M.read (| index |) |),
                        Value.Integer IntegerKind.Usize 1
                      |)
                    ]
                  |)
                |) in
              M.alloc (| Value.Tuple [] |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "set_len",
                    []
                  |),
                  [
                    M.read (| self |);
                    BinOp.Wrap.sub (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                  ]
                |)
              |) in
            ret
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_remove :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "remove" (remove T A).
    
    (*
        pub fn retain<F>(&mut self, mut f: F)
        where
            F: FnMut(&T) -> bool,
        {
            self.retain_mut(|elem| f(elem));
        }
    *)
    Definition retain (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; f ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let f := M.alloc (| f |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "retain_mut",
                    [
                      Ty.function
                        [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ T ] ] ]
                        (Ty.path "bool")
                    ]
                  |),
                  [
                    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 elem := M.copy (| γ |) in
                                      M.call_closure (|
                                        M.get_trait_method (|
                                          "core::ops::function::FnMut",
                                          F,
                                          [ Ty.tuple [ Ty.apply (Ty.path "&") [] [ T ] ] ],
                                          "call_mut",
                                          []
                                        |),
                                        [ f; Value.Tuple [ M.read (| elem |) ] ]
                                      |)))
                                ]
                              |)))
                          | _ => M.impossible "wrong number of arguments"
                          end))
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_retain :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "retain" (retain T A).
    
    (*
        pub fn retain_mut<F>(&mut self, mut f: F)
        where
            F: FnMut(&mut T) -> bool,
        {
            let original_len = self.len();
    
            if original_len == 0 {
                // Empty case: explicit return allows better optimization, vs letting compiler infer it
                return;
            }
    
            // Avoid double drop if the drop guard is not executed,
            // since we may make some holes during the process.
            unsafe { self.set_len(0) };
    
            // Vec: [Kept, Kept, Hole, Hole, Hole, Hole, Unchecked, Unchecked]
            //      |<-              processed len   ->| ^- next to check
            //                  |<-  deleted cnt     ->|
            //      |<-              original_len                          ->|
            // Kept: Elements which predicate returns true on.
            // Hole: Moved or dropped element slot.
            // Unchecked: Unchecked valid elements.
            //
            // This drop guard will be invoked when predicate or `drop` of element panicked.
            // It shifts unchecked elements to cover holes and `set_len` to the correct length.
            // In cases when predicate and `drop` never panick, it will be optimized out.
            struct BackshiftOnDrop<'a, T, A: Allocator> {
                v: &'a mut Vec<T, A>,
                processed_len: usize,
                deleted_cnt: usize,
                original_len: usize,
            }
    
            impl<T, A: Allocator> Drop for BackshiftOnDrop<'_, T, A> {
                fn drop(&mut self) {
                    if self.deleted_cnt > 0 {
                        // SAFETY: Trailing unchecked items must be valid since we never touch them.
                        unsafe {
                            ptr::copy(
                                self.v.as_ptr().add(self.processed_len),
                                self.v.as_mut_ptr().add(self.processed_len - self.deleted_cnt),
                                self.original_len - self.processed_len,
                            );
                        }
                    }
                    // SAFETY: After filling holes, all items are in contiguous memory.
                    unsafe {
                        self.v.set_len(self.original_len - self.deleted_cnt);
                    }
                }
            }
    
            let mut g = BackshiftOnDrop { v: self, processed_len: 0, deleted_cnt: 0, original_len };
    
            fn process_loop<F, T, A: Allocator, const DELETED: bool>(
                original_len: usize,
                f: &mut F,
                g: &mut BackshiftOnDrop<'_, T, A>,
            ) where
                F: FnMut(&mut T) -> bool,
            {
                while g.processed_len != original_len {
                    // SAFETY: Unchecked element must be valid.
                    let cur = unsafe { &mut *g.v.as_mut_ptr().add(g.processed_len) };
                    if !f(cur) {
                        // Advance early to avoid double drop if `drop_in_place` panicked.
                        g.processed_len += 1;
                        g.deleted_cnt += 1;
                        // SAFETY: We never touch this element again after dropped.
                        unsafe { ptr::drop_in_place(cur) };
                        // We already advanced the counter.
                        if DELETED {
                            continue;
                        } else {
                            break;
                        }
                    }
                    if DELETED {
                        // SAFETY: `deleted_cnt` > 0, so the hole slot must not overlap with current element.
                        // We use copy for move, and never touch this element again.
                        unsafe {
                            let hole_slot = g.v.as_mut_ptr().add(g.processed_len - g.deleted_cnt);
                            ptr::copy_nonoverlapping(cur, hole_slot, 1);
                        }
                    }
                    g.processed_len += 1;
                }
            }
    
            // Stage 1: Nothing was deleted.
            process_loop::<F, T, A, false>(original_len, &mut f, &mut g);
    
            // Stage 2: Some elements were deleted.
            process_loop::<F, T, A, true>(original_len, &mut f, &mut g);
    
            // All item are processed. This can be optimized to `set_len` by LLVM.
            drop(g);
        }
    *)
    Definition retain_mut (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; f ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let f := M.alloc (| f |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ original_len :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "len",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |) in
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.eq (|
                                  M.read (| original_len |),
                                  Value.Integer IntegerKind.Usize 0
                                |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "set_len",
                        []
                      |),
                      [ M.read (| self |); Value.Integer IntegerKind.Usize 0 ]
                    |)
                  |) in
                let~ g :=
                  M.alloc (|
                    Value.StructRecord
                      "alloc::vec::retain_mut::BackshiftOnDrop"
                      [
                        ("v", M.read (| self |));
                        ("processed_len", Value.Integer IntegerKind.Usize 0);
                        ("deleted_cnt", Value.Integer IntegerKind.Usize 0);
                        ("original_len", M.read (| original_len |))
                      ]
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (| Self, "process_loop.retain_mut", [] |),
                      [ M.read (| original_len |); f; g ]
                    |)
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (| Self, "process_loop.retain_mut", [] |),
                      [ M.read (| original_len |); f; g ]
                    |)
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::mem::drop",
                        [ Ty.apply (Ty.path "alloc::vec::retain_mut::BackshiftOnDrop") [] [ T; A ] ]
                      |),
                      [ M.read (| g |) ]
                    |)
                  |) in
                M.alloc (| Value.Tuple [] |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_retain_mut :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "retain_mut" (retain_mut T A).
    
    (*
        pub fn dedup_by_key<F, K>(&mut self, mut key: F)
        where
            F: FnMut(&mut T) -> K,
            K: PartialEq,
        {
            self.dedup_by(|a, b| key(a) == key(b))
        }
    *)
    Definition dedup_by_key
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F; K ], [ self; key ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let key := M.alloc (| key |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              "dedup_by",
              [
                Ty.function
                  [
                    Ty.tuple
                      [ Ty.apply (Ty.path "&mut") [] [ T ]; Ty.apply (Ty.path "&mut") [] [ T ] ]
                  ]
                  (Ty.path "bool")
              ]
            |),
            [
              M.read (| self |);
              M.closure
                (fun γ =>
                  ltac:(M.monadic
                    match γ with
                    | [ α0; α1 ] =>
                      ltac:(M.monadic
                        (M.match_operator (|
                          M.alloc (| α0 |),
                          [
                            fun γ =>
                              ltac:(M.monadic
                                (let a := M.copy (| γ |) in
                                M.match_operator (|
                                  M.alloc (| α1 |),
                                  [
                                    fun γ =>
                                      ltac:(M.monadic
                                        (let b := M.copy (| γ |) in
                                        M.call_closure (|
                                          M.get_trait_method (|
                                            "core::cmp::PartialEq",
                                            K,
                                            [ K ],
                                            "eq",
                                            []
                                          |),
                                          [
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_trait_method (|
                                                  "core::ops::function::FnMut",
                                                  F,
                                                  [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ T ] ]
                                                  ],
                                                  "call_mut",
                                                  []
                                                |),
                                                [ key; Value.Tuple [ M.read (| a |) ] ]
                                              |)
                                            |);
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_trait_method (|
                                                  "core::ops::function::FnMut",
                                                  F,
                                                  [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ T ] ]
                                                  ],
                                                  "call_mut",
                                                  []
                                                |),
                                                [ key; Value.Tuple [ M.read (| b |) ] ]
                                              |)
                                            |)
                                          ]
                                        |)))
                                  ]
                                |)))
                          ]
                        |)))
                    | _ => M.impossible "wrong number of arguments"
                    end))
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_dedup_by_key :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "dedup_by_key" (dedup_by_key T A).
    
    (*
        pub fn dedup_by<F>(&mut self, mut same_bucket: F)
        where
            F: FnMut(&mut T, &mut T) -> bool,
        {
            let len = self.len();
            if len <= 1 {
                return;
            }
    
            // Check if we ever want to remove anything.
            // This allows to use copy_non_overlapping in next cycle.
            // And avoids any memory writes if we don't need to remove anything.
            let mut first_duplicate_idx: usize = 1;
            let start = self.as_mut_ptr();
            while first_duplicate_idx != len {
                let found_duplicate = unsafe {
                    // SAFETY: first_duplicate always in range [1..len)
                    // Note that we start iteration from 1 so we never overflow.
                    let prev = start.add(first_duplicate_idx.wrapping_sub(1));
                    let current = start.add(first_duplicate_idx);
                    // We explicitly say in docs that references are reversed.
                    same_bucket(&mut *current, &mut *prev)
                };
                if found_duplicate {
                    break;
                }
                first_duplicate_idx += 1;
            }
            // Don't need to remove anything.
            // We cannot get bigger than len.
            if first_duplicate_idx == len {
                return;
            }
    
            /* INVARIANT: vec.len() > read > write > write-1 >= 0 */
            struct FillGapOnDrop<'a, T, A: core::alloc::Allocator> {
                /* Offset of the element we want to check if it is duplicate */
                read: usize,
    
                /* Offset of the place where we want to place the non-duplicate
                 * when we find it. */
                write: usize,
    
                /* The Vec that would need correction if `same_bucket` panicked */
                vec: &'a mut Vec<T, A>,
            }
    
            impl<'a, T, A: core::alloc::Allocator> Drop for FillGapOnDrop<'a, T, A> {
                fn drop(&mut self) {
                    /* This code gets executed when `same_bucket` panics */
    
                    /* SAFETY: invariant guarantees that `read - write`
                     * and `len - read` never overflow and that the copy is always
                     * in-bounds. */
                    unsafe {
                        let ptr = self.vec.as_mut_ptr();
                        let len = self.vec.len();
    
                        /* How many items were left when `same_bucket` panicked.
                         * Basically vec[read..].len() */
                        let items_left = len.wrapping_sub(self.read);
    
                        /* Pointer to first item in vec[write..write+items_left] slice */
                        let dropped_ptr = ptr.add(self.write);
                        /* Pointer to first item in vec[read..] slice */
                        let valid_ptr = ptr.add(self.read);
    
                        /* Copy `vec[read..]` to `vec[write..write+items_left]`.
                         * The slices can overlap, so `copy_nonoverlapping` cannot be used */
                        ptr::copy(valid_ptr, dropped_ptr, items_left);
    
                        /* How many items have been already dropped
                         * Basically vec[read..write].len() */
                        let dropped = self.read.wrapping_sub(self.write);
    
                        self.vec.set_len(len - dropped);
                    }
                }
            }
    
            /* Drop items while going through Vec, it should be more efficient than
             * doing slice partition_dedup + truncate */
    
            // Construct gap first and then drop item to avoid memory corruption if `T::drop` panics.
            let mut gap =
                FillGapOnDrop { read: first_duplicate_idx + 1, write: first_duplicate_idx, vec: self };
            unsafe {
                // SAFETY: we checked that first_duplicate_idx in bounds before.
                // If drop panics, `gap` would remove this item without drop.
                ptr::drop_in_place(start.add(first_duplicate_idx));
            }
    
            /* SAFETY: Because of the invariant, read_ptr, prev_ptr and write_ptr
             * are always in-bounds and read_ptr never aliases prev_ptr */
            unsafe {
                while gap.read < len {
                    let read_ptr = start.add(gap.read);
                    let prev_ptr = start.add(gap.write.wrapping_sub(1));
    
                    // We explicitly say in docs that references are reversed.
                    let found_duplicate = same_bucket(&mut *read_ptr, &mut *prev_ptr);
                    if found_duplicate {
                        // Increase `gap.read` now since the drop may panic.
                        gap.read += 1;
                        /* We have found duplicate, drop it in-place */
                        ptr::drop_in_place(read_ptr);
                    } else {
                        let write_ptr = start.add(gap.write);
    
                        /* read_ptr cannot be equal to write_ptr because at this point
                         * we guaranteed to skip at least one element (before loop starts).
                         */
                        ptr::copy_nonoverlapping(read_ptr, write_ptr, 1);
    
                        /* We have filled that place, so go further */
                        gap.write += 1;
                        gap.read += 1;
                    }
                }
    
                /* Technically we could let `gap` clean up with its Drop, but
                 * when `same_bucket` is guaranteed to not panic, this bloats a little
                 * the codegen, so we just do it manually */
                gap.vec.set_len(gap.write);
                mem::forget(gap);
            }
        }
    *)
    Definition dedup_by (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; same_bucket ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let same_bucket := M.alloc (| same_bucket |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ len :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "len",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |) in
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.le (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ first_duplicate_idx := M.alloc (| Value.Integer IntegerKind.Usize 1 |) in
                let~ start :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "as_mut_ptr",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  |) in
                let~ _ :=
                  M.loop (|
                    ltac:(M.monadic
                      (M.match_operator (|
                        M.alloc (| Value.Tuple [] |),
                        [
                          fun γ =>
                            ltac:(M.monadic
                              (let γ :=
                                M.use
                                  (M.alloc (|
                                    BinOp.ne (|
                                      M.read (| first_duplicate_idx |),
                                      M.read (| len |)
                                    |)
                                  |)) in
                              let _ :=
                                M.is_constant_or_break_match (|
                                  M.read (| γ |),
                                  Value.Bool true
                                |) in
                              let~ found_duplicate :=
                                M.copy (|
                                  let~ prev :=
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply (Ty.path "*mut") [] [ T ],
                                          "add",
                                          []
                                        |),
                                        [
                                          M.read (| start |);
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.path "usize",
                                              "wrapping_sub",
                                              []
                                            |),
                                            [
                                              M.read (| first_duplicate_idx |);
                                              Value.Integer IntegerKind.Usize 1
                                            ]
                                          |)
                                        ]
                                      |)
                                    |) in
                                  let~ current :=
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.apply (Ty.path "*mut") [] [ T ],
                                          "add",
                                          []
                                        |),
                                        [ M.read (| start |); M.read (| first_duplicate_idx |) ]
                                      |)
                                    |) in
                                  M.alloc (|
                                    M.call_closure (|
                                      M.get_trait_method (|
                                        "core::ops::function::FnMut",
                                        F,
                                        [
                                          Ty.tuple
                                            [
                                              Ty.apply (Ty.path "&mut") [] [ T ];
                                              Ty.apply (Ty.path "&mut") [] [ T ]
                                            ]
                                        ],
                                        "call_mut",
                                        []
                                      |),
                                      [
                                        same_bucket;
                                        Value.Tuple [ M.read (| current |); M.read (| prev |) ]
                                      ]
                                    |)
                                  |)
                                |) in
                              let~ _ :=
                                M.match_operator (|
                                  M.alloc (| Value.Tuple [] |),
                                  [
                                    fun γ =>
                                      ltac:(M.monadic
                                        (let γ := M.use found_duplicate in
                                        let _ :=
                                          M.is_constant_or_break_match (|
                                            M.read (| γ |),
                                            Value.Bool true
                                          |) in
                                        M.alloc (|
                                          M.never_to_any (| M.read (| M.break (||) |) |)
                                        |)));
                                    fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                                  ]
                                |) in
                              let~ _ :=
                                let β := first_duplicate_idx in
                                M.write (|
                                  β,
                                  BinOp.Wrap.add (|
                                    M.read (| β |),
                                    Value.Integer IntegerKind.Usize 1
                                  |)
                                |) 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 [] |)
                                  |)
                                |)
                              |)))
                        ]
                      |)))
                  |) in
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.eq (| M.read (| first_duplicate_idx |), M.read (| len |) |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (| M.read (| M.return_ (| Value.Tuple [] |) |) |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ gap :=
                  M.alloc (|
                    Value.StructRecord
                      "alloc::vec::dedup_by::FillGapOnDrop"
                      [
                        ("read",
                          BinOp.Wrap.add (|
                            M.read (| first_duplicate_idx |),
                            Value.Integer IntegerKind.Usize 1
                          |));
                        ("write", M.read (| first_duplicate_idx |));
                        ("vec", M.read (| self |))
                      ]
                  |) in
                let~ _ :=
                  let~ _ :=
                    M.alloc (|
                      M.call_closure (|
                        M.get_function (| "core::ptr::drop_in_place", [ T ] |),
                        [
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "*mut") [] [ T ],
                              "add",
                              []
                            |),
                            [ M.read (| start |); M.read (| first_duplicate_idx |) ]
                          |)
                        ]
                      |)
                    |) in
                  M.alloc (| Value.Tuple [] |) in
                let~ _ :=
                  M.loop (|
                    ltac:(M.monadic
                      (M.match_operator (|
                        M.alloc (| Value.Tuple [] |),
                        [
                          fun γ =>
                            ltac:(M.monadic
                              (let γ :=
                                M.use
                                  (M.alloc (|
                                    BinOp.lt (|
                                      M.read (|
                                        M.SubPointer.get_struct_record_field (|
                                          gap,
                                          "alloc::vec::dedup_by::FillGapOnDrop",
                                          "read"
                                        |)
                                      |),
                                      M.read (| len |)
                                    |)
                                  |)) in
                              let _ :=
                                M.is_constant_or_break_match (|
                                  M.read (| γ |),
                                  Value.Bool true
                                |) in
                              let~ read_ptr :=
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "*mut") [] [ T ],
                                      "add",
                                      []
                                    |),
                                    [
                                      M.read (| start |);
                                      M.read (|
                                        M.SubPointer.get_struct_record_field (|
                                          gap,
                                          "alloc::vec::dedup_by::FillGapOnDrop",
                                          "read"
                                        |)
                                      |)
                                    ]
                                  |)
                                |) in
                              let~ prev_ptr :=
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "*mut") [] [ T ],
                                      "add",
                                      []
                                    |),
                                    [
                                      M.read (| start |);
                                      M.call_closure (|
                                        M.get_associated_function (|
                                          Ty.path "usize",
                                          "wrapping_sub",
                                          []
                                        |),
                                        [
                                          M.read (|
                                            M.SubPointer.get_struct_record_field (|
                                              gap,
                                              "alloc::vec::dedup_by::FillGapOnDrop",
                                              "write"
                                            |)
                                          |);
                                          Value.Integer IntegerKind.Usize 1
                                        ]
                                      |)
                                    ]
                                  |)
                                |) in
                              let~ found_duplicate :=
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_trait_method (|
                                      "core::ops::function::FnMut",
                                      F,
                                      [
                                        Ty.tuple
                                          [
                                            Ty.apply (Ty.path "&mut") [] [ T ];
                                            Ty.apply (Ty.path "&mut") [] [ T ]
                                          ]
                                      ],
                                      "call_mut",
                                      []
                                    |),
                                    [
                                      same_bucket;
                                      Value.Tuple [ M.read (| read_ptr |); M.read (| prev_ptr |) ]
                                    ]
                                  |)
                                |) in
                              M.match_operator (|
                                M.alloc (| Value.Tuple [] |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ := M.use found_duplicate in
                                      let _ :=
                                        M.is_constant_or_break_match (|
                                          M.read (| γ |),
                                          Value.Bool true
                                        |) in
                                      let~ _ :=
                                        let β :=
                                          M.SubPointer.get_struct_record_field (|
                                            gap,
                                            "alloc::vec::dedup_by::FillGapOnDrop",
                                            "read"
                                          |) in
                                        M.write (|
                                          β,
                                          BinOp.Wrap.add (|
                                            M.read (| β |),
                                            Value.Integer IntegerKind.Usize 1
                                          |)
                                        |) in
                                      let~ _ :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_function (| "core::ptr::drop_in_place", [ T ] |),
                                            [ M.read (| read_ptr |) ]
                                          |)
                                        |) in
                                      M.alloc (| Value.Tuple [] |)));
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let~ write_ptr :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply (Ty.path "*mut") [] [ T ],
                                              "add",
                                              []
                                            |),
                                            [
                                              M.read (| start |);
                                              M.read (|
                                                M.SubPointer.get_struct_record_field (|
                                                  gap,
                                                  "alloc::vec::dedup_by::FillGapOnDrop",
                                                  "write"
                                                |)
                                              |)
                                            ]
                                          |)
                                        |) in
                                      let~ _ :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_function (|
                                              "core::intrinsics::copy_nonoverlapping",
                                              [ T ]
                                            |),
                                            [
                                              (* MutToConstPointer *)
                                              M.pointer_coercion (M.read (| read_ptr |));
                                              M.read (| write_ptr |);
                                              Value.Integer IntegerKind.Usize 1
                                            ]
                                          |)
                                        |) in
                                      let~ _ :=
                                        let β :=
                                          M.SubPointer.get_struct_record_field (|
                                            gap,
                                            "alloc::vec::dedup_by::FillGapOnDrop",
                                            "write"
                                          |) in
                                        M.write (|
                                          β,
                                          BinOp.Wrap.add (|
                                            M.read (| β |),
                                            Value.Integer IntegerKind.Usize 1
                                          |)
                                        |) in
                                      let~ _ :=
                                        let β :=
                                          M.SubPointer.get_struct_record_field (|
                                            gap,
                                            "alloc::vec::dedup_by::FillGapOnDrop",
                                            "read"
                                          |) in
                                        M.write (|
                                          β,
                                          BinOp.Wrap.add (|
                                            M.read (| β |),
                                            Value.Integer IntegerKind.Usize 1
                                          |)
                                        |) 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 [] |)
                                  |)
                                |)
                              |)))
                        ]
                      |)))
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "set_len",
                        []
                      |),
                      [
                        M.read (|
                          M.SubPointer.get_struct_record_field (|
                            gap,
                            "alloc::vec::dedup_by::FillGapOnDrop",
                            "vec"
                          |)
                        |);
                        M.read (|
                          M.SubPointer.get_struct_record_field (|
                            gap,
                            "alloc::vec::dedup_by::FillGapOnDrop",
                            "write"
                          |)
                        |)
                      ]
                    |)
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::mem::forget",
                        [ Ty.apply (Ty.path "alloc::vec::dedup_by::FillGapOnDrop") [] [ T; A ] ]
                      |),
                      [ M.read (| gap |) ]
                    |)
                  |) in
                M.alloc (| Value.Tuple [] |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_dedup_by :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "dedup_by" (dedup_by T A).
    
    (*
        pub fn push(&mut self, value: T) {
            // Inform codegen that the length does not change across grow_one().
            let len = self.len;
            // This will panic or abort if we would allocate > isize::MAX bytes
            // or if the length increment would overflow for zero-sized types.
            if len == self.buf.capacity() {
                self.buf.grow_one();
            }
            unsafe {
                let end = self.as_mut_ptr().add(len);
                ptr::write(end, value);
                self.len = len + 1;
            }
        }
    *)
    Definition push (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; value ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let value := M.alloc (| value |) in
          M.read (|
            let~ len :=
              M.copy (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |)
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use
                          (M.alloc (|
                            BinOp.eq (|
                              M.read (| len |),
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                                  "capacity",
                                  []
                                |),
                                [
                                  M.SubPointer.get_struct_record_field (|
                                    M.read (| self |),
                                    "alloc::vec::Vec",
                                    "buf"
                                  |)
                                ]
                              |)
                            |)
                          |)) in
                      let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                      let~ _ :=
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                              "grow_one",
                              []
                            |),
                            [
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::vec::Vec",
                                "buf"
                              |)
                            ]
                          |)
                        |) in
                      M.alloc (| Value.Tuple [] |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ end_ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "as_mut_ptr",
                        []
                      |),
                      [ M.read (| self |) ]
                    |);
                    M.read (| len |)
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::ptr::write", [ T ] |),
                  [ M.read (| end_ |); M.read (| value |) ]
                |)
              |) in
            let~ _ :=
              M.write (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |),
                BinOp.Wrap.add (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_push :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "push" (push T A).
    
    (*
        pub fn push_within_capacity(&mut self, value: T) -> Result<(), T> {
            if self.len == self.buf.capacity() {
                return Err(value);
            }
            unsafe {
                let end = self.as_mut_ptr().add(self.len);
                ptr::write(end, value);
                self.len += 1;
            }
            Ok(())
        }
    *)
    Definition push_within_capacity
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; value ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let value := M.alloc (| value |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.eq (|
                                  M.read (|
                                    M.SubPointer.get_struct_record_field (|
                                      M.read (| self |),
                                      "alloc::vec::Vec",
                                      "len"
                                    |)
                                  |),
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                                      "capacity",
                                      []
                                    |),
                                    [
                                      M.SubPointer.get_struct_record_field (|
                                        M.read (| self |),
                                        "alloc::vec::Vec",
                                        "buf"
                                      |)
                                    ]
                                  |)
                                |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (|
                              M.read (|
                                M.return_ (|
                                  Value.StructTuple
                                    "core::result::Result::Err"
                                    [ M.read (| value |) ]
                                |)
                              |)
                            |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ _ :=
                  let~ end_ :=
                    M.alloc (|
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "*mut") [] [ T ],
                          "add",
                          []
                        |),
                        [
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "as_mut_ptr",
                              []
                            |),
                            [ M.read (| self |) ]
                          |);
                          M.read (|
                            M.SubPointer.get_struct_record_field (|
                              M.read (| self |),
                              "alloc::vec::Vec",
                              "len"
                            |)
                          |)
                        ]
                      |)
                    |) in
                  let~ _ :=
                    M.alloc (|
                      M.call_closure (|
                        M.get_function (| "core::ptr::write", [ T ] |),
                        [ M.read (| end_ |); M.read (| value |) ]
                      |)
                    |) in
                  let~ _ :=
                    let β :=
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |) in
                    M.write (|
                      β,
                      BinOp.Wrap.add (| M.read (| β |), Value.Integer IntegerKind.Usize 1 |)
                    |) in
                  M.alloc (| Value.Tuple [] |) in
                M.alloc (| Value.StructTuple "core::result::Result::Ok" [ Value.Tuple [] ] |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_push_within_capacity :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "push_within_capacity" (push_within_capacity T A).
    
    (*
        pub fn pop(&mut self) -> Option<T> {
            if self.len == 0 {
                None
            } else {
                unsafe {
                    self.len -= 1;
                    core::hint::assert_unchecked(self.len < self.capacity());
                    Some(ptr::read(self.as_ptr().add(self.len())))
                }
            }
        }
    *)
    Definition pop (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use
                        (M.alloc (|
                          BinOp.eq (|
                            M.read (|
                              M.SubPointer.get_struct_record_field (|
                                M.read (| self |),
                                "alloc::vec::Vec",
                                "len"
                              |)
                            |),
                            Value.Integer IntegerKind.Usize 0
                          |)
                        |)) 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
                    (let~ _ :=
                      let β :=
                        M.SubPointer.get_struct_record_field (|
                          M.read (| self |),
                          "alloc::vec::Vec",
                          "len"
                        |) in
                      M.write (|
                        β,
                        BinOp.Wrap.sub (| M.read (| β |), Value.Integer IntegerKind.Usize 1 |)
                      |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_function (| "core::hint::assert_unchecked", [] |),
                          [
                            BinOp.lt (|
                              M.read (|
                                M.SubPointer.get_struct_record_field (|
                                  M.read (| self |),
                                  "alloc::vec::Vec",
                                  "len"
                                |)
                              |),
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                  "capacity",
                                  []
                                |),
                                [ M.read (| self |) ]
                              |)
                            |)
                          ]
                        |)
                      |) in
                    M.alloc (|
                      Value.StructTuple
                        "core::option::Option::Some"
                        [
                          M.call_closure (|
                            M.get_function (| "core::ptr::read", [ T ] |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "*const") [] [ T ],
                                  "add",
                                  []
                                |),
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                      "as_ptr",
                                      []
                                    |),
                                    [ M.read (| self |) ]
                                  |);
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                      "len",
                                      []
                                    |),
                                    [ M.read (| self |) ]
                                  |)
                                ]
                              |)
                            ]
                          |)
                        ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_pop :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "pop" (pop T A).
    
    (*
        pub fn pop_if<F>(&mut self, f: F) -> Option<T>
        where
            F: FnOnce(&mut T) -> bool,
        {
            let last = self.last_mut()?;
            if f(last) { self.pop() } else { None }
        }
    *)
    Definition pop_if (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; f ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let f := M.alloc (| f |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ last :=
                  M.copy (|
                    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 "&mut") [] [ T ] ],
                            [],
                            "branch",
                            []
                          |),
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "slice") [] [ T ],
                                "last_mut",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_trait_method (|
                                    "core::ops::deref::DerefMut",
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    [],
                                    "deref_mut",
                                    []
                                  |),
                                  [ M.read (| self |) ]
                                |)
                              ]
                            |)
                          ]
                        |)
                      |),
                      [
                        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") [] [ T ],
                                        [
                                          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))
                      ]
                    |)
                  |) in
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use
                            (M.alloc (|
                              M.call_closure (|
                                M.get_trait_method (|
                                  "core::ops::function::FnOnce",
                                  F,
                                  [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ T ] ] ],
                                  "call_once",
                                  []
                                |),
                                [ M.read (| f |); Value.Tuple [ M.read (| last |) ] ]
                              |)
                            |)) in
                        let _ :=
                          M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "pop",
                              []
                            |),
                            [ M.read (| self |) ]
                          |)
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (M.alloc (| Value.StructTuple "core::option::Option::None" [] |)))
                  ]
                |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_pop_if :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "pop_if" (pop_if T A).
    
    (*
        pub fn append(&mut self, other: &mut Self) {
            unsafe {
                self.append_elements(other.as_slice() as _);
                other.set_len(0);
            }
        }
    *)
    Definition append (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; other ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let other := M.alloc (| other |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "append_elements",
                    []
                  |),
                  [
                    M.read (| self |);
                    M.read (|
                      M.use
                        (M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "as_slice",
                              []
                            |),
                            [ M.read (| other |) ]
                          |)
                        |))
                    |)
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "set_len",
                    []
                  |),
                  [ M.read (| other |); Value.Integer IntegerKind.Usize 0 ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_append :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "append" (append T A).
    
    (*
        unsafe fn append_elements(&mut self, other: *const [T]) {
            let count = unsafe { ( *other).len() };
            self.reserve(count);
            let len = self.len();
            unsafe { ptr::copy_nonoverlapping(other as *const T, self.as_mut_ptr().add(len), count) };
            self.len += count;
        }
    *)
    Definition append_elements
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; other ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let other := M.alloc (| other |) in
          M.read (|
            let~ count :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "len", [] |),
                  [ M.read (| other |) ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [ M.read (| self |); M.read (| count |) ]
                |)
              |) in
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::intrinsics::copy_nonoverlapping", [ T ] |),
                  [
                    M.rust_cast (M.read (| other |));
                    M.call_closure (|
                      M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "as_mut_ptr",
                            []
                          |),
                          [ M.read (| self |) ]
                        |);
                        M.read (| len |)
                      ]
                    |);
                    M.read (| count |)
                  ]
                |)
              |) in
            let~ _ :=
              let β :=
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |) in
              M.write (| β, BinOp.Wrap.add (| M.read (| β |), M.read (| count |) |) |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_append_elements :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "append_elements" (append_elements T A).
    
    (*
        pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, A>
        where
            R: RangeBounds<usize>,
        {
            // Memory safety
            //
            // When the Drain is first created, it shortens the length of
            // the source vector to make sure no uninitialized or moved-from elements
            // are accessible at all if the Drain's destructor never gets to run.
            //
            // Drain will ptr::read out the values to remove.
            // When finished, remaining tail of the vec is copied back to cover
            // the hole, and the vector length is restored to the new length.
            //
            let len = self.len();
            let Range { start, end } = slice::range(range, ..len);
    
            unsafe {
                // set self.vec length's to start, to be safe in case Drain is leaked
                self.set_len(start);
                let range_slice = slice::from_raw_parts(self.as_ptr().add(start), end - start);
                Drain {
                    tail_start: end,
                    tail_len: len - end,
                    iter: range_slice.iter(),
                    vec: NonNull::from(self),
                }
            }
        }
    *)
    Definition drain (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ R ], [ self; range ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let range := M.alloc (| range |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            M.match_operator (|
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::slice::index::range", [ R ] |),
                  [
                    M.read (| range |);
                    Value.StructRecord "core::ops::range::RangeTo" [ ("end_", M.read (| len |)) ]
                  ]
                |)
              |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ0_0 :=
                      M.SubPointer.get_struct_record_field (|
                        γ,
                        "core::ops::range::Range",
                        "start"
                      |) in
                    let γ0_1 :=
                      M.SubPointer.get_struct_record_field (|
                        γ,
                        "core::ops::range::Range",
                        "end"
                      |) in
                    let start := M.copy (| γ0_0 |) in
                    let end_ := M.copy (| γ0_1 |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "set_len",
                            []
                          |),
                          [ M.read (| self |); M.read (| start |) ]
                        |)
                      |) in
                    let~ range_slice :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_function (| "core::slice::raw::from_raw_parts", [ T ] |),
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "*const") [] [ T ],
                                "add",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    "as_ptr",
                                    []
                                  |),
                                  [ M.read (| self |) ]
                                |);
                                M.read (| start |)
                              ]
                            |);
                            BinOp.Wrap.sub (| M.read (| end_ |), M.read (| start |) |)
                          ]
                        |)
                      |) in
                    M.alloc (|
                      Value.StructRecord
                        "alloc::vec::drain::Drain"
                        [
                          ("tail_start", M.read (| end_ |));
                          ("tail_len", BinOp.Wrap.sub (| M.read (| len |), M.read (| end_ |) |));
                          ("iter",
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "slice") [] [ T ],
                                "iter",
                                []
                              |),
                              [ M.read (| range_slice |) ]
                            |));
                          ("vec",
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::convert::From",
                                Ty.apply
                                  (Ty.path "core::ptr::non_null::NonNull")
                                  []
                                  [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                                [
                                  Ty.apply
                                    (Ty.path "&mut")
                                    []
                                    [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ]
                                ],
                                "from",
                                []
                              |),
                              [ M.read (| self |) ]
                            |))
                        ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_drain :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "drain" (drain T A).
    
    (*
        pub fn clear(&mut self) {
            let elems: *mut [T] = self.as_mut_slice();
    
            // SAFETY:
            // - `elems` comes directly from `as_mut_slice` and is therefore valid.
            // - Setting `self.len` before calling `drop_in_place` means that,
            //   if an element's `Drop` impl panics, the vector's `Drop` impl will
            //   do nothing (leaking the rest of the elements) instead of dropping
            //   some twice.
            unsafe {
                self.len = 0;
                ptr::drop_in_place(elems);
            }
        }
    *)
    Definition clear (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ elems :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "as_mut_slice",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.write (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |),
                Value.Integer IntegerKind.Usize 0
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (|
                    "core::ptr::drop_in_place",
                    [ Ty.apply (Ty.path "slice") [] [ T ] ]
                  |),
                  [ M.read (| elems |) ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_clear :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "clear" (clear T A).
    
    (*
        pub fn len(&self) -> usize {
            self.len
        }
    *)
    Definition len (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            M.SubPointer.get_struct_record_field (| M.read (| self |), "alloc::vec::Vec", "len" |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_len :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "len" (len T A).
    
    (*
        pub fn is_empty(&self) -> bool {
            self.len() == 0
        }
    *)
    Definition is_empty (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          BinOp.eq (|
            M.call_closure (|
              M.get_associated_function (|
                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                "len",
                []
              |),
              [ M.read (| self |) ]
            |),
            Value.Integer IntegerKind.Usize 0
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_is_empty :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "is_empty" (is_empty T A).
    
    (*
        pub fn split_off(&mut self, at: usize) -> Self
        where
            A: Clone,
        {
            #[cold]
            #[cfg_attr(not(feature = "panic_immediate_abort"), inline(never))]
            #[track_caller]
            #[optimize(size)]
            fn assert_failed(at: usize, len: usize) -> ! {
                panic!("`at` split index (is {at}) should be <= len (is {len})");
            }
    
            if at > self.len() {
                assert_failed(at, self.len());
            }
    
            let other_len = self.len - at;
            let mut other = Vec::with_capacity_in(other_len, self.allocator().clone());
    
            // Unsafely `set_len` and copy items to `other`.
            unsafe {
                self.set_len(at);
                other.set_len(other_len);
    
                ptr::copy_nonoverlapping(self.as_ptr().add(at), other.as_mut_ptr(), other.len());
            }
            other
        }
    *)
    Definition split_off (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; at_ ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let at_ := M.alloc (| at_ |) in
          M.read (|
            let~ _ :=
              M.match_operator (|
                M.alloc (| Value.Tuple [] |),
                [
                  fun γ =>
                    ltac:(M.monadic
                      (let γ :=
                        M.use
                          (M.alloc (|
                            BinOp.gt (|
                              M.read (| at_ |),
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                  "len",
                                  []
                                |),
                                [ M.read (| self |) ]
                              |)
                            |)
                          |)) 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_associated_function (| Self, "assert_failed.split_off", [] |),
                            [
                              M.read (| at_ |);
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                  "len",
                                  []
                                |),
                                [ M.read (| self |) ]
                              |)
                            ]
                          |)
                        |)
                      |)));
                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ other_len :=
              M.alloc (|
                BinOp.Wrap.sub (|
                  M.read (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "len"
                    |)
                  |),
                  M.read (| at_ |)
                |)
              |) in
            let~ other :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "with_capacity_in",
                    []
                  |),
                  [
                    M.read (| other_len |);
                    M.call_closure (|
                      M.get_trait_method (| "core::clone::Clone", A, [], "clone", [] |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "allocator",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      ]
                    |)
                  ]
                |)
              |) in
            let~ _ :=
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "set_len",
                      []
                    |),
                    [ M.read (| self |); M.read (| at_ |) ]
                  |)
                |) in
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "set_len",
                      []
                    |),
                    [ other; M.read (| other_len |) ]
                  |)
                |) in
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_function (| "core::intrinsics::copy_nonoverlapping", [ T ] |),
                    [
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "*const") [] [ T ],
                          "add",
                          []
                        |),
                        [
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "as_ptr",
                              []
                            |),
                            [ M.read (| self |) ]
                          |);
                          M.read (| at_ |)
                        ]
                      |);
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                          "as_mut_ptr",
                          []
                        |),
                        [ other ]
                      |);
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                          "len",
                          []
                        |),
                        [ other ]
                      |)
                    ]
                  |)
                |) in
              M.alloc (| Value.Tuple [] |) in
            other
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_split_off :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "split_off" (split_off T A).
    
    (*
        pub fn resize_with<F>(&mut self, new_len: usize, f: F)
        where
            F: FnMut() -> T,
        {
            let len = self.len();
            if new_len > len {
                self.extend_trusted(iter::repeat_with(f).take(new_len - len));
            } else {
                self.truncate(new_len);
            }
        }
    *)
    Definition resize_with (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; new_len; f ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let new_len := M.alloc (| new_len |) in
          let f := M.alloc (| f |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use (M.alloc (| BinOp.gt (| M.read (| new_len |), M.read (| len |) |) |)) in
                    let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "extend_trusted",
                            [
                              Ty.apply
                                (Ty.path "core::iter::adapters::take::Take")
                                []
                                [
                                  Ty.apply
                                    (Ty.path "core::iter::sources::repeat_with::RepeatWith")
                                    []
                                    [ F ]
                                ]
                            ]
                          |),
                          [
                            M.read (| self |);
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::iter::traits::iterator::Iterator",
                                Ty.apply
                                  (Ty.path "core::iter::sources::repeat_with::RepeatWith")
                                  []
                                  [ F ],
                                [],
                                "take",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_function (|
                                    "core::iter::sources::repeat_with::repeat_with",
                                    [ T; F ]
                                  |),
                                  [ M.read (| f |) ]
                                |);
                                BinOp.Wrap.sub (| M.read (| new_len |), M.read (| len |) |)
                              ]
                            |)
                          ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)));
                fun γ =>
                  ltac:(M.monadic
                    (let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "truncate",
                            []
                          |),
                          [ M.read (| self |); M.read (| new_len |) ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_resize_with :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "resize_with" (resize_with T A).
    
    (*
        pub fn leak<'a>(self) -> &'a mut [T]
        where
            A: 'a,
        {
            let mut me = ManuallyDrop::new(self);
            unsafe { slice::from_raw_parts_mut(me.as_mut_ptr(), me.len) }
        }
    *)
    Definition leak (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ me :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "core::mem::manually_drop::ManuallyDrop")
                      []
                      [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                    "new",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            M.alloc (|
              M.call_closure (|
                M.get_function (| "core::slice::raw::from_raw_parts_mut", [ T ] |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "as_mut_ptr",
                      []
                    |),
                    [
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::DerefMut",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref_mut",
                          []
                        |),
                        [ me ]
                      |)
                    ]
                  |);
                  M.read (|
                    M.SubPointer.get_struct_record_field (|
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |),
                      "alloc::vec::Vec",
                      "len"
                    |)
                  |)
                ]
              |)
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_leak :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "leak" (leak T A).
    
    (*
        pub fn spare_capacity_mut(&mut self) -> &mut [MaybeUninit<T>] {
            // Note:
            // This method is not implemented in terms of `split_at_spare_mut`,
            // to prevent invalidation of pointers to the buffer.
            unsafe {
                slice::from_raw_parts_mut(
                    self.as_mut_ptr().add(self.len) as *mut MaybeUninit<T>,
                    self.buf.capacity() - self.len,
                )
            }
        }
    *)
    Definition spare_capacity_mut
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_function (|
              "core::slice::raw::from_raw_parts_mut",
              [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ]
            |),
            [
              M.rust_cast
                (M.call_closure (|
                  M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "as_mut_ptr",
                        []
                      |),
                      [ M.read (| self |) ]
                    |);
                    M.read (|
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |)
                    |)
                  ]
                |));
              BinOp.Wrap.sub (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "capacity",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "buf"
                    |)
                  ]
                |),
                M.read (|
                  M.SubPointer.get_struct_record_field (|
                    M.read (| self |),
                    "alloc::vec::Vec",
                    "len"
                  |)
                |)
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_spare_capacity_mut :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "spare_capacity_mut" (spare_capacity_mut T A).
    
    (*
        pub fn split_at_spare_mut(&mut self) -> (&mut [T], &mut [MaybeUninit<T>]) {
            // SAFETY:
            // - len is ignored and so never changed
            let (init, spare, _) = unsafe { self.split_at_spare_mut_with_len() };
            (init, spare)
        }
    *)
    Definition split_at_spare_mut
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A 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::vec::Vec") [] [ T; A ],
                    "split_at_spare_mut_with_len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |),
              [
                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 γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in
                    let init := M.copy (| γ0_0 |) in
                    let spare := M.copy (| γ0_1 |) in
                    M.alloc (| Value.Tuple [ M.read (| init |); M.read (| spare |) ] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_split_at_spare_mut :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "split_at_spare_mut" (split_at_spare_mut T A).
    
    (*
        unsafe fn split_at_spare_mut_with_len(
            &mut self,
        ) -> (&mut [T], &mut [MaybeUninit<T>], &mut usize) {
            let ptr = self.as_mut_ptr();
            // SAFETY:
            // - `ptr` is guaranteed to be valid for `self.len` elements
            // - but the allocation extends out to `self.buf.capacity()` elements, possibly
            // uninitialized
            let spare_ptr = unsafe { ptr.add(self.len) };
            let spare_ptr = spare_ptr.cast::<MaybeUninit<T>>();
            let spare_len = self.buf.capacity() - self.len;
    
            // SAFETY:
            // - `ptr` is guaranteed to be valid for `self.len` elements
            // - `spare_ptr` is pointing one element past the buffer, so it doesn't overlap with `initialized`
            unsafe {
                let initialized = slice::from_raw_parts_mut(ptr, self.len);
                let spare = slice::from_raw_parts_mut(spare_ptr, spare_len);
    
                (initialized, spare, &mut self.len)
            }
        }
    *)
    Definition split_at_spare_mut_with_len
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "as_mut_ptr",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ spare_ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                  [
                    M.read (| ptr |);
                    M.read (|
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |)
                    |)
                  ]
                |)
              |) in
            let~ spare_ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "*mut") [] [ T ],
                    "cast",
                    [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ]
                  |),
                  [ M.read (| spare_ptr |) ]
                |)
              |) in
            let~ spare_len :=
              M.alloc (|
                BinOp.Wrap.sub (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                      "capacity",
                      []
                    |),
                    [
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "buf"
                      |)
                    ]
                  |),
                  M.read (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "len"
                    |)
                  |)
                |)
              |) in
            let~ initialized :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::slice::raw::from_raw_parts_mut", [ T ] |),
                  [
                    M.read (| ptr |);
                    M.read (|
                      M.SubPointer.get_struct_record_field (|
                        M.read (| self |),
                        "alloc::vec::Vec",
                        "len"
                      |)
                    |)
                  ]
                |)
              |) in
            let~ spare :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (|
                    "core::slice::raw::from_raw_parts_mut",
                    [ Ty.apply (Ty.path "core::mem::maybe_uninit::MaybeUninit") [] [ T ] ]
                  |),
                  [ M.read (| spare_ptr |); M.read (| spare_len |) ]
                |)
              |) in
            M.alloc (|
              Value.Tuple
                [
                  M.read (| initialized |);
                  M.read (| spare |);
                  M.SubPointer.get_struct_record_field (|
                    M.read (| self |),
                    "alloc::vec::Vec",
                    "len"
                  |)
                ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_split_at_spare_mut_with_len :
      forall (T A : Ty.t),
      M.IsAssociatedFunction
        (Self T A)
        "split_at_spare_mut_with_len"
        (split_at_spare_mut_with_len T A).
    (*
        pub fn resize(&mut self, new_len: usize, value: T) {
            let len = self.len();
    
            if new_len > len {
                self.extend_with(new_len - len, value)
            } else {
                self.truncate(new_len);
            }
        }
    *)
    Definition resize (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; new_len; value ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let new_len := M.alloc (| new_len |) in
          let value := M.alloc (| value |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use (M.alloc (| BinOp.gt (| M.read (| new_len |), M.read (| len |) |) |)) in
                    let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                    M.alloc (|
                      M.call_closure (|
                        M.get_associated_function (|
                          Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                          "extend_with",
                          []
                        |),
                        [
                          M.read (| self |);
                          BinOp.Wrap.sub (| M.read (| new_len |), M.read (| len |) |);
                          M.read (| value |)
                        ]
                      |)
                    |)));
                fun γ =>
                  ltac:(M.monadic
                    (let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "truncate",
                            []
                          |),
                          [ M.read (| self |); M.read (| new_len |) ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_resize :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "resize" (resize T A).
    
    (*
        pub fn extend_from_slice(&mut self, other: &[T]) {
            self.spec_extend(other.iter())
        }
    *)
    Definition extend_from_slice
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; other ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let other := M.alloc (| other |) in
          M.call_closure (|
            M.get_trait_method (|
              "alloc::vec::spec_extend::SpecExtend",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [
                Ty.apply (Ty.path "&") [] [ T ];
                Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ]
              ],
              "spec_extend",
              []
            |),
            [
              M.read (| self |);
              M.call_closure (|
                M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "iter", [] |),
                [ M.read (| other |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_extend_from_slice :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extend_from_slice" (extend_from_slice T A).
    
    (*
        pub fn extend_from_within<R>(&mut self, src: R)
        where
            R: RangeBounds<usize>,
        {
            let range = slice::range(src, ..self.len());
            self.reserve(range.len());
    
            // SAFETY:
            // - `slice::range` guarantees that the given range is valid for indexing self
            unsafe {
                self.spec_extend_from_within(range);
            }
        }
    *)
    Definition extend_from_within
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ R ], [ self; src ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let src := M.alloc (| src |) in
          M.read (|
            let~ range :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::slice::index::range", [ R ] |),
                  [
                    M.read (| src |);
                    Value.StructRecord
                      "core::ops::range::RangeTo"
                      [
                        ("end_",
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "len",
                              []
                            |),
                            [ M.read (| self |) ]
                          |))
                      ]
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [
                    M.read (| self |);
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::iter::traits::exact_size::ExactSizeIterator",
                        Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ],
                        [],
                        "len",
                        []
                      |),
                      [ range ]
                    |)
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_trait_method (|
                    "alloc::vec::ExtendFromWithinSpec",
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    [],
                    "spec_extend_from_within",
                    []
                  |),
                  [ M.read (| self |); M.read (| range |) ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_extend_from_within :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extend_from_within" (extend_from_within T A).
    (*
        fn extend_with(&mut self, n: usize, value: T) {
            self.reserve(n);
    
            unsafe {
                let mut ptr = self.as_mut_ptr().add(self.len());
                // Use SetLenOnDrop to work around bug where compiler
                // might not realize the store through `ptr` through self.set_len()
                // don't alias.
                let mut local_len = SetLenOnDrop::new(&mut self.len);
    
                // Write all elements except the last one
                for _ in 1..n {
                    ptr::write(ptr, value.clone());
                    ptr = ptr.add(1);
                    // Increment the length in every step in case clone() panics
                    local_len.increment_len(1);
                }
    
                if n > 0 {
                    // We can write the last element directly without cloning needlessly
                    ptr::write(ptr, value);
                    local_len.increment_len(1);
                }
    
                // len set by scope guard
            }
        }
    *)
    Definition extend_with (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; n; value ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let n := M.alloc (| n |) in
          let value := M.alloc (| value |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [ M.read (| self |); M.read (| n |) ]
                |)
              |) in
            let~ ptr :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "as_mut_ptr",
                        []
                      |),
                      [ M.read (| self |) ]
                    |);
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "len",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  ]
                |)
              |) in
            let~ local_len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.path "alloc::vec::set_len_on_drop::SetLenOnDrop",
                    "new",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "len"
                    |)
                  ]
                |)
              |) in
            let~ _ :=
              M.use
                (M.match_operator (|
                  M.alloc (|
                    M.call_closure (|
                      M.get_trait_method (|
                        "core::iter::traits::collect::IntoIterator",
                        Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ],
                        [],
                        "into_iter",
                        []
                      |),
                      [
                        Value.StructRecord
                          "core::ops::range::Range"
                          [ ("start", Value.Integer IntegerKind.Usize 1); ("end_", M.read (| n |)) ]
                      ]
                    |)
                  |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let iter := M.copy (| γ |) in
                        M.loop (|
                          ltac:(M.monadic
                            (let~ _ :=
                              M.match_operator (|
                                M.alloc (|
                                  M.call_closure (|
                                    M.get_trait_method (|
                                      "core::iter::traits::iterator::Iterator",
                                      Ty.apply
                                        (Ty.path "core::ops::range::Range")
                                        []
                                        [ Ty.path "usize" ],
                                      [],
                                      "next",
                                      []
                                    |),
                                    [ iter ]
                                  |)
                                |),
                                [
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let _ :=
                                        M.is_struct_tuple (| γ, "core::option::Option::None" |) in
                                      M.alloc (|
                                        M.never_to_any (| M.read (| M.break (||) |) |)
                                      |)));
                                  fun γ =>
                                    ltac:(M.monadic
                                      (let γ0_0 :=
                                        M.SubPointer.get_struct_tuple_field (|
                                          γ,
                                          "core::option::Option::Some",
                                          0
                                        |) in
                                      let~ _ :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_function (| "core::ptr::write", [ T ] |),
                                            [
                                              M.read (| ptr |);
                                              M.call_closure (|
                                                M.get_trait_method (|
                                                  "core::clone::Clone",
                                                  T,
                                                  [],
                                                  "clone",
                                                  []
                                                |),
                                                [ value ]
                                              |)
                                            ]
                                          |)
                                        |) in
                                      let~ _ :=
                                        M.write (|
                                          ptr,
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply (Ty.path "*mut") [] [ T ],
                                              "add",
                                              []
                                            |),
                                            [ M.read (| ptr |); Value.Integer IntegerKind.Usize 1 ]
                                          |)
                                        |) in
                                      let~ _ :=
                                        M.alloc (|
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.path "alloc::vec::set_len_on_drop::SetLenOnDrop",
                                              "increment_len",
                                              []
                                            |),
                                            [ local_len; Value.Integer IntegerKind.Usize 1 ]
                                          |)
                                        |) in
                                      M.alloc (| Value.Tuple [] |)))
                                ]
                              |) in
                            M.alloc (| Value.Tuple [] |)))
                        |)))
                  ]
                |)) in
            M.match_operator (|
              M.alloc (| Value.Tuple [] |),
              [
                fun γ =>
                  ltac:(M.monadic
                    (let γ :=
                      M.use
                        (M.alloc (|
                          BinOp.gt (| M.read (| n |), Value.Integer IntegerKind.Usize 0 |)
                        |)) in
                    let _ := M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_function (| "core::ptr::write", [ T ] |),
                          [ M.read (| ptr |); M.read (| value |) ]
                        |)
                      |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.path "alloc::vec::set_len_on_drop::SetLenOnDrop",
                            "increment_len",
                            []
                          |),
                          [ local_len; Value.Integer IntegerKind.Usize 1 ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)));
                fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_extend_with :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extend_with" (extend_with T A).
    (*
        pub fn dedup(&mut self) {
            self.dedup_by(|a, b| a == b)
        }
    *)
    Definition dedup (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A 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::vec::Vec") [] [ T; A ],
              "dedup_by",
              [
                Ty.function
                  [
                    Ty.tuple
                      [ Ty.apply (Ty.path "&mut") [] [ T ]; Ty.apply (Ty.path "&mut") [] [ T ] ]
                  ]
                  (Ty.path "bool")
              ]
            |),
            [
              M.read (| self |);
              M.closure
                (fun γ =>
                  ltac:(M.monadic
                    match γ with
                    | [ α0; α1 ] =>
                      ltac:(M.monadic
                        (M.match_operator (|
                          M.alloc (| α0 |),
                          [
                            fun γ =>
                              ltac:(M.monadic
                                (let a := M.copy (| γ |) in
                                M.match_operator (|
                                  M.alloc (| α1 |),
                                  [
                                    fun γ =>
                                      ltac:(M.monadic
                                        (let b := M.copy (| γ |) in
                                        M.call_closure (|
                                          M.get_trait_method (|
                                            "core::cmp::PartialEq",
                                            Ty.apply (Ty.path "&mut") [] [ T ],
                                            [ Ty.apply (Ty.path "&mut") [] [ T ] ],
                                            "eq",
                                            []
                                          |),
                                          [ a; b ]
                                        |)))
                                  ]
                                |)))
                          ]
                        |)))
                    | _ => M.impossible "wrong number of arguments"
                    end))
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_dedup :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "dedup" (dedup T A).
    (*
        fn extend_desugared<I: Iterator<Item = T>>(&mut self, mut iterator: I) {
            // This is the case for a general iterator.
            //
            // This function should be the moral equivalent of:
            //
            //      for item in iterator {
            //          self.push(item);
            //      }
            while let Some(element) = iterator.next() {
                let len = self.len();
                if len == self.capacity() {
                    let (lower, _) = iterator.size_hint();
                    self.reserve(lower.saturating_add(1));
                }
                unsafe {
                    ptr::write(self.as_mut_ptr().add(len), element);
                    // Since next() executes user code which can panic we have to bump the length
                    // after each step.
                    // NB can't overflow since we would have had to alloc the address space
                    self.set_len(len + 1);
                }
            }
        }
    *)
    Definition extend_desugared
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ _ as I ], [ self; iterator ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let iterator := M.alloc (| iterator |) in
          M.read (|
            M.loop (|
              ltac:(M.monadic
                (M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::iter::traits::iterator::Iterator",
                                I,
                                [],
                                "next",
                                []
                              |),
                              [ iterator ]
                            |)
                          |) in
                        let γ0_0 :=
                          M.SubPointer.get_struct_tuple_field (|
                            γ,
                            "core::option::Option::Some",
                            0
                          |) in
                        let element := M.copy (| γ0_0 |) in
                        let~ len :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                "len",
                                []
                              |),
                              [ M.read (| self |) ]
                            |)
                          |) in
                        let~ _ :=
                          M.match_operator (|
                            M.alloc (| Value.Tuple [] |),
                            [
                              fun γ =>
                                ltac:(M.monadic
                                  (let γ :=
                                    M.use
                                      (M.alloc (|
                                        BinOp.eq (|
                                          M.read (| len |),
                                          M.call_closure (|
                                            M.get_associated_function (|
                                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                              "capacity",
                                              []
                                            |),
                                            [ M.read (| self |) ]
                                          |)
                                        |)
                                      |)) in
                                  let _ :=
                                    M.is_constant_or_break_match (|
                                      M.read (| γ |),
                                      Value.Bool true
                                    |) in
                                  M.match_operator (|
                                    M.alloc (|
                                      M.call_closure (|
                                        M.get_trait_method (|
                                          "core::iter::traits::iterator::Iterator",
                                          I,
                                          [],
                                          "size_hint",
                                          []
                                        |),
                                        [ iterator ]
                                      |)
                                    |),
                                    [
                                      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 lower := M.copy (| γ0_0 |) in
                                          let~ _ :=
                                            M.alloc (|
                                              M.call_closure (|
                                                M.get_associated_function (|
                                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                                  "reserve",
                                                  []
                                                |),
                                                [
                                                  M.read (| self |);
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.path "usize",
                                                      "saturating_add",
                                                      []
                                                    |),
                                                    [
                                                      M.read (| lower |);
                                                      Value.Integer IntegerKind.Usize 1
                                                    ]
                                                  |)
                                                ]
                                              |)
                                            |) in
                                          M.alloc (| Value.Tuple [] |)))
                                    ]
                                  |)));
                              fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                            ]
                          |) in
                        let~ _ :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_function (| "core::ptr::write", [ T ] |),
                              [
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "*mut") [] [ T ],
                                    "add",
                                    []
                                  |),
                                  [
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                        "as_mut_ptr",
                                        []
                                      |),
                                      [ M.read (| self |) ]
                                    |);
                                    M.read (| len |)
                                  ]
                                |);
                                M.read (| element |)
                              ]
                            |)
                          |) in
                        let~ _ :=
                          M.alloc (|
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                "set_len",
                                []
                              |),
                              [
                                M.read (| self |);
                                BinOp.Wrap.add (|
                                  M.read (| len |),
                                  Value.Integer IntegerKind.Usize 1
                                |)
                              ]
                            |)
                          |) 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_extend_desugared :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extend_desugared" (extend_desugared T A).
    
    (*
        fn extend_trusted(&mut self, iterator: impl iter::TrustedLen<Item = T>) {
            let (low, high) = iterator.size_hint();
            if let Some(additional) = high {
                debug_assert_eq!(
                    low,
                    additional,
                    "TrustedLen iterator's size hint is not exact: {:?}",
                    (low, high)
                );
                self.reserve(additional);
                unsafe {
                    let ptr = self.as_mut_ptr();
                    let mut local_len = SetLenOnDrop::new(&mut self.len);
                    iterator.for_each(move |element| {
                        ptr::write(ptr.add(local_len.current_len()), element);
                        // Since the loop executes user code which can panic we have to update
                        // the length every step to correctly drop what we've written.
                        // NB can't overflow since we would have had to alloc the address space
                        local_len.increment_len(1);
                    });
                }
            } else {
                // Per TrustedLen contract a `None` upper bound means that the iterator length
                // truly exceeds usize::MAX, which would eventually lead to a capacity overflow anyway.
                // Since the other branch already panics eagerly (via `reserve()`) we do the same here.
                // This avoids additional codegen for a fallback code path which would eventually
                // panic anyway.
                panic!("capacity overflow");
            }
        }
    *)
    Definition extend_trusted
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ impl_iter_TrustedLen_Item___T_ ], [ self; iterator ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let iterator := M.alloc (| iterator |) in
          M.read (|
            M.match_operator (|
              M.alloc (|
                M.call_closure (|
                  M.get_trait_method (|
                    "core::iter::traits::iterator::Iterator",
                    impl_iter_TrustedLen_Item___T_,
                    [],
                    "size_hint",
                    []
                  |),
                  [ iterator ]
                |)
              |),
              [
                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 low := M.copy (| γ0_0 |) in
                    let high := M.copy (| γ0_1 |) in
                    M.match_operator (|
                      M.alloc (| Value.Tuple [] |),
                      [
                        fun γ =>
                          ltac:(M.monadic
                            (let γ := high in
                            let γ0_0 :=
                              M.SubPointer.get_struct_tuple_field (|
                                γ,
                                "core::option::Option::Some",
                                0
                              |) in
                            let additional := M.copy (| γ0_0 |) in
                            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 [ low; additional ] |),
                                          [
                                            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 left_val := M.copy (| γ0_0 |) in
                                                let right_val := M.copy (| γ0_1 |) in
                                                M.match_operator (|
                                                  M.alloc (| Value.Tuple [] |),
                                                  [
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (let γ :=
                                                          M.use
                                                            (M.alloc (|
                                                              UnOp.not (|
                                                                BinOp.eq (|
                                                                  M.read (|
                                                                    M.read (| left_val |)
                                                                  |),
                                                                  M.read (|
                                                                    M.read (| right_val |)
                                                                  |)
                                                                |)
                                                              |)
                                                            |)) in
                                                        let _ :=
                                                          M.is_constant_or_break_match (|
                                                            M.read (| γ |),
                                                            Value.Bool true
                                                          |) in
                                                        M.alloc (|
                                                          M.never_to_any (|
                                                            M.read (|
                                                              let~ kind :=
                                                                M.alloc (|
                                                                  Value.StructTuple
                                                                    "core::panicking::AssertKind::Eq"
                                                                    []
                                                                |) in
                                                              M.alloc (|
                                                                M.call_closure (|
                                                                  M.get_function (|
                                                                    "core::panicking::assert_failed",
                                                                    [
                                                                      Ty.path "usize";
                                                                      Ty.path "usize"
                                                                    ]
                                                                  |),
                                                                  [
                                                                    M.read (| kind |);
                                                                    M.read (| left_val |);
                                                                    M.read (| right_val |);
                                                                    Value.StructTuple
                                                                      "core::option::Option::Some"
                                                                      [
                                                                        M.call_closure (|
                                                                          M.get_associated_function (|
                                                                            Ty.path
                                                                              "core::fmt::Arguments",
                                                                            "new_v1",
                                                                            []
                                                                          |),
                                                                          [
                                                                            M.alloc (|
                                                                              Value.Array
                                                                                [
                                                                                  M.read (|
                                                                                    Value.String
                                                                                      "TrustedLen iterator's size hint is not exact: "
                                                                                  |)
                                                                                ]
                                                                            |);
                                                                            M.alloc (|
                                                                              Value.Array
                                                                                [
                                                                                  M.call_closure (|
                                                                                    M.get_associated_function (|
                                                                                      Ty.path
                                                                                        "core::fmt::rt::Argument",
                                                                                      "new_debug",
                                                                                      [
                                                                                        Ty.tuple
                                                                                          [
                                                                                            Ty.path
                                                                                              "usize";
                                                                                            Ty.apply
                                                                                              (Ty.path
                                                                                                "core::option::Option")
                                                                                              []
                                                                                              [
                                                                                                Ty.path
                                                                                                  "usize"
                                                                                              ]
                                                                                          ]
                                                                                      ]
                                                                                    |),
                                                                                    [
                                                                                      M.alloc (|
                                                                                        Value.Tuple
                                                                                          [
                                                                                            M.read (|
                                                                                              low
                                                                                            |);
                                                                                            M.read (|
                                                                                              high
                                                                                            |)
                                                                                          ]
                                                                                      |)
                                                                                    ]
                                                                                  |)
                                                                                ]
                                                                            |)
                                                                          ]
                                                                        |)
                                                                      ]
                                                                  ]
                                                                |)
                                                              |)
                                                            |)
                                                          |)
                                                        |)));
                                                    fun γ =>
                                                      ltac:(M.monadic
                                                        (M.alloc (| Value.Tuple [] |)))
                                                  ]
                                                |)))
                                          ]
                                        |) in
                                      M.alloc (| Value.Tuple [] |)));
                                  fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                                ]
                              |) in
                            let~ _ :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    "reserve",
                                    []
                                  |),
                                  [ M.read (| self |); M.read (| additional |) ]
                                |)
                              |) in
                            let~ ptr :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    "as_mut_ptr",
                                    []
                                  |),
                                  [ M.read (| self |) ]
                                |)
                              |) in
                            let~ local_len :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.path "alloc::vec::set_len_on_drop::SetLenOnDrop",
                                    "new",
                                    []
                                  |),
                                  [
                                    M.SubPointer.get_struct_record_field (|
                                      M.read (| self |),
                                      "alloc::vec::Vec",
                                      "len"
                                    |)
                                  ]
                                |)
                              |) in
                            let~ _ :=
                              M.alloc (|
                                M.call_closure (|
                                  M.get_trait_method (|
                                    "core::iter::traits::iterator::Iterator",
                                    impl_iter_TrustedLen_Item___T_,
                                    [],
                                    "for_each",
                                    [ Ty.function [ Ty.tuple [ T ] ] (Ty.tuple []) ]
                                  |),
                                  [
                                    M.read (| iterator |);
                                    M.closure
                                      (fun γ =>
                                        ltac:(M.monadic
                                          match γ with
                                          | [ α0 ] =>
                                            ltac:(M.monadic
                                              (M.match_operator (|
                                                M.alloc (| α0 |),
                                                [
                                                  fun γ =>
                                                    ltac:(M.monadic
                                                      (let element := M.copy (| γ |) in
                                                      M.read (|
                                                        let~ _ :=
                                                          M.alloc (|
                                                            M.call_closure (|
                                                              M.get_function (|
                                                                "core::ptr::write",
                                                                [ T ]
                                                              |),
                                                              [
                                                                M.call_closure (|
                                                                  M.get_associated_function (|
                                                                    Ty.apply
                                                                      (Ty.path "*mut")
                                                                      []
                                                                      [ T ],
                                                                    "add",
                                                                    []
                                                                  |),
                                                                  [
                                                                    M.read (| ptr |);
                                                                    M.call_closure (|
                                                                      M.get_associated_function (|
                                                                        Ty.path
                                                                          "alloc::vec::set_len_on_drop::SetLenOnDrop",
                                                                        "current_len",
                                                                        []
                                                                      |),
                                                                      [ local_len ]
                                                                    |)
                                                                  ]
                                                                |);
                                                                M.read (| element |)
                                                              ]
                                                            |)
                                                          |) in
                                                        let~ _ :=
                                                          M.alloc (|
                                                            M.call_closure (|
                                                              M.get_associated_function (|
                                                                Ty.path
                                                                  "alloc::vec::set_len_on_drop::SetLenOnDrop",
                                                                "increment_len",
                                                                []
                                                              |),
                                                              [
                                                                local_len;
                                                                Value.Integer IntegerKind.Usize 1
                                                              ]
                                                            |)
                                                          |) in
                                                        M.alloc (| Value.Tuple [] |)
                                                      |)))
                                                ]
                                              |)))
                                          | _ => M.impossible "wrong number of arguments"
                                          end))
                                  ]
                                |)
                              |) 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_const",
                                        []
                                      |),
                                      [
                                        M.alloc (|
                                          Value.Array
                                            [ M.read (| Value.String "capacity overflow" |) ]
                                        |)
                                      ]
                                    |)
                                  ]
                                |)
                              |)
                            |)))
                      ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_extend_trusted :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extend_trusted" (extend_trusted T A).
    
    (*
        pub fn splice<R, I>(&mut self, range: R, replace_with: I) -> Splice<'_, I::IntoIter, A>
        where
            R: RangeBounds<usize>,
            I: IntoIterator<Item = T>,
        {
            Splice { drain: self.drain(range), replace_with: replace_with.into_iter() }
        }
    *)
    Definition splice (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ R; _ as I ], [ self; range; replace_with ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let range := M.alloc (| range |) in
          let replace_with := M.alloc (| replace_with |) in
          Value.StructRecord
            "alloc::vec::splice::Splice"
            [
              ("drain",
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "drain",
                    [ R ]
                  |),
                  [ M.read (| self |); M.read (| range |) ]
                |));
              ("replace_with",
                M.call_closure (|
                  M.get_trait_method (|
                    "core::iter::traits::collect::IntoIterator",
                    I,
                    [],
                    "into_iter",
                    []
                  |),
                  [ M.read (| replace_with |) ]
                |))
            ]))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_splice :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "splice" (splice T A).
    
    (*
        pub fn extract_if<F>(&mut self, filter: F) -> ExtractIf<'_, T, F, A>
        where
            F: FnMut(&mut T) -> bool,
        {
            let old_len = self.len();
    
            // Guard against us getting leaked (leak amplification)
            unsafe {
                self.set_len(0);
            }
    
            ExtractIf { vec: self, idx: 0, del: 0, old_len, pred: filter }
        }
    *)
    Definition extract_if (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ F ], [ self; filter ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let filter := M.alloc (| filter |) in
          M.read (|
            let~ old_len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              let~ _ :=
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "set_len",
                      []
                    |),
                    [ M.read (| self |); Value.Integer IntegerKind.Usize 0 ]
                  |)
                |) in
              M.alloc (| Value.Tuple [] |) in
            M.alloc (|
              Value.StructRecord
                "alloc::vec::extract_if::ExtractIf"
                [
                  ("vec", M.read (| self |));
                  ("idx", Value.Integer IntegerKind.Usize 0);
                  ("del", Value.Integer IntegerKind.Usize 0);
                  ("old_len", M.read (| old_len |));
                  ("pred", M.read (| filter |))
                ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_extract_if :
      forall (T A : Ty.t),
      M.IsAssociatedFunction (Self T A) "extract_if" (extract_if T A).
  End Impl_alloc_vec_Vec_T_A.
  
  
  Module Impl_alloc_vec_Vec_array_N_T_A.
    Definition Self (N : Value.t) (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.apply (Ty.path "array") [ N ] [ T ]; A ].
    
    (*
        pub fn into_flattened(self) -> Vec<T, A> {
            let (ptr, len, cap, alloc) = self.into_raw_parts_with_alloc();
            let (new_len, new_cap) = if T::IS_ZST {
                (len.checked_mul(N).expect("vec len overflow"), usize::MAX)
            } else {
                // SAFETY:
                // - `cap * N` cannot overflow because the allocation is already in
                // the address space.
                // - Each `[T; N]` has `N` valid elements, so there are `len * N`
                // valid elements in the allocation.
                unsafe { (len.unchecked_mul(N), cap.unchecked_mul(N)) }
            };
            // SAFETY:
            // - `ptr` was allocated by `self`
            // - `ptr` is well-aligned because `[T; N]` has the same alignment as `T`.
            // - `new_cap` refers to the same sized allocation as `cap` because
            // `new_cap * size_of::<T>()` == `cap * size_of::<[T; N]>()`
            // - `len` <= `cap`, so `len * N` <= `cap * N`.
            unsafe { Vec::<T, A>::from_raw_parts_in(ptr.cast(), new_len, new_cap, alloc) }
        }
    *)
    Definition into_flattened
        (N : Value.t)
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self N T A 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::vec::Vec")
                      []
                      [ Ty.apply (Ty.path "array") [ N ] [ T ]; A ],
                    "into_raw_parts_with_alloc",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |),
              [
                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 γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in
                    let γ0_3 := M.SubPointer.get_tuple_field (| γ, 3 |) in
                    let ptr := M.copy (| γ0_0 |) in
                    let len := M.copy (| γ0_1 |) in
                    let cap := M.copy (| γ0_2 |) in
                    let alloc := M.copy (| γ0_3 |) in
                    M.match_operator (|
                      M.match_operator (|
                        M.alloc (| Value.Tuple [] |),
                        [
                          fun γ =>
                            ltac:(M.monadic
                              (let γ :=
                                M.use
                                  (M.get_constant (| "core::mem::SizedTypeProperties::IS_ZST" |)) in
                              let _ :=
                                M.is_constant_or_break_match (|
                                  M.read (| γ |),
                                  Value.Bool true
                                |) in
                              M.alloc (|
                                Value.Tuple
                                  [
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.apply
                                          (Ty.path "core::option::Option")
                                          []
                                          [ Ty.path "usize" ],
                                        "expect",
                                        []
                                      |),
                                      [
                                        M.call_closure (|
                                          M.get_associated_function (|
                                            Ty.path "usize",
                                            "checked_mul",
                                            []
                                          |),
                                          [
                                            M.read (| len |);
                                            M.read (| M.get_constant (| "alloc::vec::N" |) |)
                                          ]
                                        |);
                                        M.read (| Value.String "vec len overflow" |)
                                      ]
                                    |);
                                    M.read (| M.get_constant (| "core::num::MAX" |) |)
                                  ]
                              |)));
                          fun γ =>
                            ltac:(M.monadic
                              (M.alloc (|
                                Value.Tuple
                                  [
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.path "usize",
                                        "unchecked_mul",
                                        []
                                      |),
                                      [
                                        M.read (| len |);
                                        M.read (| M.get_constant (| "alloc::vec::N" |) |)
                                      ]
                                    |);
                                    M.call_closure (|
                                      M.get_associated_function (|
                                        Ty.path "usize",
                                        "unchecked_mul",
                                        []
                                      |),
                                      [
                                        M.read (| cap |);
                                        M.read (| M.get_constant (| "alloc::vec::N" |) |)
                                      ]
                                    |)
                                  ]
                              |)))
                        ]
                      |),
                      [
                        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 new_len := M.copy (| γ0_0 |) in
                            let new_cap := M.copy (| γ0_1 |) in
                            M.alloc (|
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                  "from_raw_parts_in",
                                  []
                                |),
                                [
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply
                                        (Ty.path "*mut")
                                        []
                                        [ Ty.apply (Ty.path "array") [ N ] [ T ] ],
                                      "cast",
                                      [ T ]
                                    |),
                                    [ M.read (| ptr |) ]
                                  |);
                                  M.read (| new_len |);
                                  M.read (| new_cap |);
                                  M.read (| alloc |)
                                ]
                              |)
                            |)))
                      ]
                    |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom AssociatedFunction_into_flattened :
      forall (N : Value.t) (T A : Ty.t),
      M.IsAssociatedFunction (Self N T A) "into_flattened" (into_flattened N T A).
  End Impl_alloc_vec_Vec_array_N_T_A.
  
  
  
  (*
  pub fn from_elem<T: Clone>(elem: T, n: usize) -> Vec<T> {
      <T as SpecFromElem>::from_elem(elem, n, Global)
  }
  *)
  Definition from_elem (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [ T ], [ elem; n ] =>
      ltac:(M.monadic
        (let elem := M.alloc (| elem |) in
        let n := M.alloc (| n |) in
        M.call_closure (|
          M.get_trait_method (|
            "alloc::vec::spec_from_elem::SpecFromElem",
            T,
            [],
            "from_elem",
            [ Ty.path "alloc::alloc::Global" ]
          |),
          [ M.read (| elem |); M.read (| n |); Value.StructTuple "alloc::alloc::Global" [] ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_from_elem : M.IsFunction "alloc::vec::from_elem" from_elem.
  
  (*
  pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<T, A> {
      <T as SpecFromElem>::from_elem(elem, n, alloc)
  }
  *)
  Definition from_elem_in (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [ T; A ], [ elem; n; alloc ] =>
      ltac:(M.monadic
        (let elem := M.alloc (| elem |) in
        let n := M.alloc (| n |) in
        let alloc := M.alloc (| alloc |) in
        M.call_closure (|
          M.get_trait_method (|
            "alloc::vec::spec_from_elem::SpecFromElem",
            T,
            [],
            "from_elem",
            [ A ]
          |),
          [ M.read (| elem |); M.read (| n |); M.read (| alloc |) ]
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_from_elem_in : M.IsFunction "alloc::vec::from_elem_in" from_elem_in.
  
  (* Trait *)
  (* Empty module 'ExtendFromWithinSpec' *)
  
  Module Impl_alloc_vec_ExtendFromWithinSpec_where_core_clone_Clone_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        default unsafe fn spec_extend_from_within(&mut self, src: Range<usize>) {
            // SAFETY:
            // - len is increased only after initializing elements
            let (this, spare, len) = unsafe { self.split_at_spare_mut_with_len() };
    
            // SAFETY:
            // - caller guarantees that src is a valid index
            let to_clone = unsafe { this.get_unchecked(src) };
    
            iter::zip(to_clone, spare)
                .map(|(src, dst)| dst.write(src.clone()))
                // Note:
                // - Element was just initialized with `MaybeUninit::write`, so it's ok to increase len
                // - len is increased after each element to prevent leaks (see issue #82533)
                .for_each(|_| *len += 1);
        }
    *)
    Definition spec_extend_from_within
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; src ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let src := M.alloc (| src |) in
          M.read (|
            M.match_operator (|
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "split_at_spare_mut_with_len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |),
              [
                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 γ0_2 := M.SubPointer.get_tuple_field (| γ, 2 |) in
                    let this := M.copy (| γ0_0 |) in
                    let spare := M.copy (| γ0_1 |) in
                    let len := M.copy (| γ0_2 |) in
                    let~ to_clone :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "slice") [] [ T ],
                            "get_unchecked",
                            [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ] ]
                          |),
                          [ M.read (| this |); M.read (| src |) ]
                        |)
                      |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_trait_method (|
                            "core::iter::traits::iterator::Iterator",
                            Ty.apply
                              (Ty.path "core::iter::adapters::map::Map")
                              []
                              [
                                Ty.apply
                                  (Ty.path "core::iter::adapters::zip::Zip")
                                  []
                                  [
                                    Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ];
                                    Ty.apply
                                      (Ty.path "core::slice::iter::IterMut")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                          []
                                          [ T ]
                                      ]
                                  ];
                                Ty.function
                                  [
                                    Ty.tuple
                                      [
                                        Ty.tuple
                                          [
                                            Ty.apply (Ty.path "&") [] [ T ];
                                            Ty.apply
                                              (Ty.path "&mut")
                                              []
                                              [
                                                Ty.apply
                                                  (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                                  []
                                                  [ T ]
                                              ]
                                          ]
                                      ]
                                  ]
                                  (Ty.apply (Ty.path "&mut") [] [ T ])
                              ],
                            [],
                            "for_each",
                            [
                              Ty.function
                                [ Ty.tuple [ Ty.apply (Ty.path "&mut") [] [ T ] ] ]
                                (Ty.tuple [])
                            ]
                          |),
                          [
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::iter::traits::iterator::Iterator",
                                Ty.apply
                                  (Ty.path "core::iter::adapters::zip::Zip")
                                  []
                                  [
                                    Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ];
                                    Ty.apply
                                      (Ty.path "core::slice::iter::IterMut")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                          []
                                          [ T ]
                                      ]
                                  ],
                                [],
                                "map",
                                [
                                  Ty.apply (Ty.path "&mut") [] [ T ];
                                  Ty.function
                                    [
                                      Ty.tuple
                                        [
                                          Ty.tuple
                                            [
                                              Ty.apply (Ty.path "&") [] [ T ];
                                              Ty.apply
                                                (Ty.path "&mut")
                                                []
                                                [
                                                  Ty.apply
                                                    (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                                    []
                                                    [ T ]
                                                ]
                                            ]
                                        ]
                                    ]
                                    (Ty.apply (Ty.path "&mut") [] [ T ])
                                ]
                              |),
                              [
                                M.call_closure (|
                                  M.get_function (|
                                    "core::iter::adapters::zip::zip",
                                    [
                                      Ty.apply
                                        (Ty.path "&")
                                        []
                                        [ Ty.apply (Ty.path "slice") [] [ T ] ];
                                      Ty.apply
                                        (Ty.path "&mut")
                                        []
                                        [
                                          Ty.apply
                                            (Ty.path "slice")
                                            []
                                            [
                                              Ty.apply
                                                (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                                []
                                                [ T ]
                                            ]
                                        ]
                                    ]
                                  |),
                                  [ M.read (| to_clone |); M.read (| spare |) ]
                                |);
                                M.closure
                                  (fun γ =>
                                    ltac:(M.monadic
                                      match γ with
                                      | [ α0 ] =>
                                        ltac:(M.monadic
                                          (M.match_operator (|
                                            M.alloc (| α0 |),
                                            [
                                              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 src := M.copy (| γ0_0 |) in
                                                  let dst := M.copy (| γ0_1 |) in
                                                  M.call_closure (|
                                                    M.get_associated_function (|
                                                      Ty.apply
                                                        (Ty.path
                                                          "core::mem::maybe_uninit::MaybeUninit")
                                                        []
                                                        [ T ],
                                                      "write",
                                                      []
                                                    |),
                                                    [
                                                      M.read (| dst |);
                                                      M.call_closure (|
                                                        M.get_trait_method (|
                                                          "core::clone::Clone",
                                                          T,
                                                          [],
                                                          "clone",
                                                          []
                                                        |),
                                                        [ M.read (| src |) ]
                                                      |)
                                                    ]
                                                  |)))
                                            ]
                                          |)))
                                      | _ => M.impossible "wrong number of arguments"
                                      end))
                              ]
                            |);
                            M.closure
                              (fun γ =>
                                ltac:(M.monadic
                                  match γ with
                                  | [ α0 ] =>
                                    ltac:(M.monadic
                                      (M.match_operator (|
                                        M.alloc (| α0 |),
                                        [
                                          fun γ =>
                                            ltac:(M.monadic
                                              (M.read (|
                                                let β := M.read (| len |) in
                                                M.write (|
                                                  β,
                                                  BinOp.Wrap.add (|
                                                    M.read (| β |),
                                                    Value.Integer IntegerKind.Usize 1
                                                  |)
                                                |)
                                              |)))
                                        ]
                                      |)))
                                  | _ => M.impossible "wrong number of arguments"
                                  end))
                          ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)))
              ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "alloc::vec::ExtendFromWithinSpec"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [ ("spec_extend_from_within", InstanceField.Method (spec_extend_from_within T A)) ].
  End Impl_alloc_vec_ExtendFromWithinSpec_where_core_clone_Clone_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_alloc_vec_ExtendFromWithinSpec_where_core_marker_Copy_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        unsafe fn spec_extend_from_within(&mut self, src: Range<usize>) {
            let count = src.len();
            {
                let (init, spare) = self.split_at_spare_mut();
    
                // SAFETY:
                // - caller guarantees that `src` is a valid index
                let source = unsafe { init.get_unchecked(src) };
    
                // SAFETY:
                // - Both pointers are created from unique slice references (`&mut [_]`)
                //   so they are valid and do not overlap.
                // - Elements are :Copy so it's OK to copy them, without doing
                //   anything with the original values
                // - `count` is equal to the len of `source`, so source is valid for
                //   `count` reads
                // - `.reserve(count)` guarantees that `spare.len() >= count` so spare
                //   is valid for `count` writes
                unsafe { ptr::copy_nonoverlapping(source.as_ptr(), spare.as_mut_ptr() as _, count) };
            }
    
            // SAFETY:
            // - The elements were just initialized by `copy_nonoverlapping`
            self.len += count;
        }
    *)
    Definition spec_extend_from_within
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; src ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let src := M.alloc (| src |) in
          M.read (|
            let~ count :=
              M.alloc (|
                M.call_closure (|
                  M.get_trait_method (|
                    "core::iter::traits::exact_size::ExactSizeIterator",
                    Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ],
                    [],
                    "len",
                    []
                  |),
                  [ src ]
                |)
              |) in
            let~ _ :=
              M.match_operator (|
                M.alloc (|
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "split_at_spare_mut",
                      []
                    |),
                    [ M.read (| self |) ]
                  |)
                |),
                [
                  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 init := M.copy (| γ0_0 |) in
                      let spare := M.copy (| γ0_1 |) in
                      let~ source :=
                        M.alloc (|
                          M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "slice") [] [ T ],
                              "get_unchecked",
                              [ Ty.apply (Ty.path "core::ops::range::Range") [] [ Ty.path "usize" ]
                              ]
                            |),
                            [ M.read (| init |); M.read (| src |) ]
                          |)
                        |) in
                      let~ _ :=
                        M.alloc (|
                          M.call_closure (|
                            M.get_function (| "core::intrinsics::copy_nonoverlapping", [ T ] |),
                            [
                              M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "slice") [] [ T ],
                                  "as_ptr",
                                  []
                                |),
                                [ M.read (| source |) ]
                              |);
                              M.rust_cast
                                (M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply
                                      (Ty.path "slice")
                                      []
                                      [
                                        Ty.apply
                                          (Ty.path "core::mem::maybe_uninit::MaybeUninit")
                                          []
                                          [ T ]
                                      ],
                                    "as_mut_ptr",
                                    []
                                  |),
                                  [ M.read (| spare |) ]
                                |));
                              M.read (| count |)
                            ]
                          |)
                        |) in
                      M.alloc (| Value.Tuple [] |)))
                ]
              |) in
            let~ _ :=
              let β :=
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |) in
              M.write (| β, BinOp.Wrap.add (| M.read (| β |), M.read (| count |) |) |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "alloc::vec::ExtendFromWithinSpec"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [ ("spec_extend_from_within", InstanceField.Method (spec_extend_from_within T A)) ].
  End Impl_alloc_vec_ExtendFromWithinSpec_where_core_marker_Copy_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_deref_Deref_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*     type Target = [T]; *)
    Definition _Target (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "slice") [] [ T ].
    
    (*
        fn deref(&self) -> &[T] {
            unsafe { slice::from_raw_parts(self.as_ptr(), self.len) }
        }
    *)
    Definition deref (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_function (| "core::slice::raw::from_raw_parts", [ T ] |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  "as_ptr",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |)
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::ops::deref::Deref"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [ ("Target", InstanceField.Ty (_Target T A)); ("deref", InstanceField.Method (deref T A)) ].
  End Impl_core_ops_deref_Deref_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_deref_DerefMut_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn deref_mut(&mut self) -> &mut [T] {
            unsafe { slice::from_raw_parts_mut(self.as_mut_ptr(), self.len) }
        }
    *)
    Definition deref_mut (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_function (| "core::slice::raw::from_raw_parts_mut", [ T ] |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  "as_mut_ptr",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (|
                M.SubPointer.get_struct_record_field (|
                  M.read (| self |),
                  "alloc::vec::Vec",
                  "len"
                |)
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::ops::deref::DerefMut"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("deref_mut", InstanceField.Method (deref_mut T A)) ].
  End Impl_core_ops_deref_DerefMut_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_deref_DerefPure_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::ops::deref::DerefPure"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [].
  End Impl_core_ops_deref_DerefPure_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_clone_Clone_where_core_clone_Clone_T_where_core_alloc_Allocator_A_where_core_clone_Clone_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn clone(&self) -> Self {
            let alloc = self.allocator().clone();
            <[T]>::to_vec_in(&**self, alloc)
        }
    *)
    Definition clone (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ alloc :=
              M.alloc (|
                M.call_closure (|
                  M.get_trait_method (| "core::clone::Clone", A, [], "clone", [] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "allocator",
                        []
                      |),
                      [ M.read (| self |) ]
                    |)
                  ]
                |)
              |) in
            M.alloc (|
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "slice") [] [ T ],
                  "to_vec_in",
                  [ A ]
                |),
                [
                  M.call_closure (|
                    M.get_trait_method (|
                      "core::ops::deref::Deref",
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      [],
                      "deref",
                      []
                    |),
                    [ M.read (| self |) ]
                  |);
                  M.read (| alloc |)
                ]
              |)
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        fn clone_from(&mut self, source: &Self) {
            crate::slice::SpecCloneIntoVec::clone_into(source.as_slice(), self);
        }
    *)
    Definition clone_from (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; source ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let source := M.alloc (| source |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_trait_method (|
                    "alloc::slice::SpecCloneIntoVec",
                    Ty.apply (Ty.path "slice") [] [ T ],
                    [ T; A ],
                    "clone_into",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "as_slice",
                        []
                      |),
                      [ M.read (| source |) ]
                    |);
                    M.read (| self |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::clone::Clone"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [
          ("clone", InstanceField.Method (clone T A));
          ("clone_from", InstanceField.Method (clone_from T A))
        ].
  End Impl_core_clone_Clone_where_core_clone_Clone_T_where_core_alloc_Allocator_A_where_core_clone_Clone_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_hash_Hash_where_core_hash_Hash_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn hash<H: Hasher>(&self, state: &mut H) {
            Hash::hash(&**self, state)
        }
    *)
    Definition hash (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ H ], [ self; state ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let state := M.alloc (| state |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::hash::Hash",
              Ty.apply (Ty.path "slice") [] [ T ],
              [],
              "hash",
              [ H ]
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (| state |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::hash::Hash"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("hash", InstanceField.Method (hash T A)) ].
  End Impl_core_hash_Hash_where_core_hash_Hash_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
    Definition Self (T I A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*     type Output = I::Output; *)
    Definition _Output (T I A : Ty.t) : Ty.t := Ty.associated.
    
    (*
        fn index(&self, index: I) -> &Self::Output {
            Index::index(&**self, index)
        }
    *)
    Definition index (T I A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T I A in
      match ε, τ, α with
      | [], [], [ self; index ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let index := M.alloc (| index |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::index::Index",
              Ty.apply (Ty.path "slice") [] [ T ],
              [ I ],
              "index",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (| index |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T I A : Ty.t),
      M.IsTraitInstance
        "core::ops::index::Index"
        (Self T I A)
        (* Trait polymorphic types *) [ (* Idx *) I ]
        (* Instance *)
        [
          ("Output", InstanceField.Ty (_Output T I A));
          ("index", InstanceField.Method (index T I A))
        ].
  End Impl_core_ops_index_Index_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_index_IndexMut_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
    Definition Self (T I A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn index_mut(&mut self, index: I) -> &mut Self::Output {
            IndexMut::index_mut(&mut **self, index)
        }
    *)
    Definition index_mut (T I A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T I A in
      match ε, τ, α with
      | [], [], [ self; index ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let index := M.alloc (| index |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::index::IndexMut",
              Ty.apply (Ty.path "slice") [] [ T ],
              [ I ],
              "index_mut",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::DerefMut",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref_mut",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (| index |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T I A : Ty.t),
      M.IsTraitInstance
        "core::ops::index::IndexMut"
        (Self T I A)
        (* Trait polymorphic types *) [ (* Idx *) I ]
        (* Instance *) [ ("index_mut", InstanceField.Method (index_mut T I A)) ].
  End Impl_core_ops_index_IndexMut_where_core_slice_index_SliceIndex_I_slice_T_where_core_alloc_Allocator_A_I_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_iter_traits_collect_FromIterator_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec<T> {
            <Self as SpecFromIter<T, I::IntoIter>>::from_iter(iter.into_iter())
        }
    *)
    Definition from_iter (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [ _ as I ], [ iter ] =>
        ltac:(M.monadic
          (let iter := M.alloc (| iter |) in
          M.call_closure (|
            M.get_trait_method (|
              "alloc::vec::spec_from_iter::SpecFromIter",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              [ T; Ty.associated ],
              "from_iter",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::collect::IntoIterator",
                  I,
                  [],
                  "into_iter",
                  []
                |),
                [ M.read (| iter |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::FromIterator"
        (Self T)
        (* Trait polymorphic types *) [ (* A *) T ]
        (* Instance *) [ ("from_iter", InstanceField.Method (from_iter T)) ].
  End Impl_core_iter_traits_collect_FromIterator_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*     type Item = T; *)
    Definition _Item (T A : Ty.t) : Ty.t := T.
    
    (*     type IntoIter = IntoIter<T, A>; *)
    Definition _IntoIter (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::into_iter::IntoIter") [] [ T; A ].
    
    (*
        fn into_iter(self) -> Self::IntoIter {
            unsafe {
                let me = ManuallyDrop::new(self);
                let alloc = ManuallyDrop::new(ptr::read(me.allocator()));
                let buf = me.buf.non_null();
                let begin = buf.as_ptr();
                let end = if T::IS_ZST {
                    begin.wrapping_byte_add(me.len())
                } else {
                    begin.add(me.len()) as *const T
                };
                let cap = me.buf.capacity();
                IntoIter { buf, phantom: PhantomData, cap, alloc, ptr: buf, end }
            }
        }
    *)
    Definition into_iter (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (|
            let~ me :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply
                      (Ty.path "core::mem::manually_drop::ManuallyDrop")
                      []
                      [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                    "new",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ alloc :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "core::mem::manually_drop::ManuallyDrop") [] [ A ],
                    "new",
                    []
                  |),
                  [
                    M.call_closure (|
                      M.get_function (| "core::ptr::read", [ A ] |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "allocator",
                            []
                          |),
                          [
                            M.call_closure (|
                              M.get_trait_method (|
                                "core::ops::deref::Deref",
                                Ty.apply
                                  (Ty.path "core::mem::manually_drop::ManuallyDrop")
                                  []
                                  [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                                [],
                                "deref",
                                []
                              |),
                              [ me ]
                            |)
                          ]
                        |)
                      ]
                    |)
                  ]
                |)
              |) in
            let~ buf :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "non_null",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |),
                      "alloc::vec::Vec",
                      "buf"
                    |)
                  ]
                |)
              |) in
            let~ begin :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "core::ptr::non_null::NonNull") [] [ T ],
                    "as_ptr",
                    []
                  |),
                  [ M.read (| buf |) ]
                |)
              |) in
            let~ end_ :=
              M.copy (|
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use (M.get_constant (| "core::mem::SizedTypeProperties::IS_ZST" |)) in
                        let _ :=
                          M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                        M.alloc (|
                          (* MutToConstPointer *)
                          M.pointer_coercion
                            (M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "*mut") [] [ T ],
                                "wrapping_byte_add",
                                []
                              |),
                              [
                                M.read (| begin |);
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    "len",
                                    []
                                  |),
                                  [
                                    M.call_closure (|
                                      M.get_trait_method (|
                                        "core::ops::deref::Deref",
                                        Ty.apply
                                          (Ty.path "core::mem::manually_drop::ManuallyDrop")
                                          []
                                          [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                                        [],
                                        "deref",
                                        []
                                      |),
                                      [ me ]
                                    |)
                                  ]
                                |)
                              ]
                            |))
                        |)));
                    fun γ =>
                      ltac:(M.monadic
                        (M.alloc (|
                          M.rust_cast
                            (* MutToConstPointer *)
                            (M.pointer_coercion
                              (M.call_closure (|
                                M.get_associated_function (|
                                  Ty.apply (Ty.path "*mut") [] [ T ],
                                  "add",
                                  []
                                |),
                                [
                                  M.read (| begin |);
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                      "len",
                                      []
                                    |),
                                    [
                                      M.call_closure (|
                                        M.get_trait_method (|
                                          "core::ops::deref::Deref",
                                          Ty.apply
                                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                                            []
                                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                                          [],
                                          "deref",
                                          []
                                        |),
                                        [ me ]
                                      |)
                                    ]
                                  |)
                                ]
                              |)))
                        |)))
                  ]
                |)
              |) in
            let~ cap :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::raw_vec::RawVec") [] [ T; A ],
                    "capacity",
                    []
                  |),
                  [
                    M.SubPointer.get_struct_record_field (|
                      M.call_closure (|
                        M.get_trait_method (|
                          "core::ops::deref::Deref",
                          Ty.apply
                            (Ty.path "core::mem::manually_drop::ManuallyDrop")
                            []
                            [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ],
                          [],
                          "deref",
                          []
                        |),
                        [ me ]
                      |),
                      "alloc::vec::Vec",
                      "buf"
                    |)
                  ]
                |)
              |) in
            M.alloc (|
              Value.StructRecord
                "alloc::vec::into_iter::IntoIter"
                [
                  ("buf", M.read (| buf |));
                  ("phantom", Value.StructTuple "core::marker::PhantomData" []);
                  ("cap", M.read (| cap |));
                  ("alloc", M.read (| alloc |));
                  ("ptr", M.read (| buf |));
                  ("end_", M.read (| end_ |))
                ]
            |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::IntoIterator"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [
          ("Item", InstanceField.Ty (_Item T A));
          ("IntoIter", InstanceField.Ty (_IntoIter T A));
          ("into_iter", InstanceField.Method (into_iter T A))
        ].
  End Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_ref__alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ].
    
    (*     type Item = &'a T; *)
    Definition _Item (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "&") [] [ T ].
    
    (*     type IntoIter = slice::Iter<'a, T>; *)
    Definition _IntoIter (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "core::slice::iter::Iter") [] [ T ].
    
    (*
        fn into_iter(self) -> Self::IntoIter {
            self.iter()
        }
    *)
    Definition into_iter (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "iter", [] |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::IntoIterator"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [
          ("Item", InstanceField.Ty (_Item T A));
          ("IntoIter", InstanceField.Ty (_IntoIter T A));
          ("into_iter", InstanceField.Method (into_iter T A))
        ].
  End Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_ref__alloc_vec_Vec_T_A.
  
  Module Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_ref_mut_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ].
    
    (*     type Item = &'a mut T; *)
    Definition _Item (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "&mut") [] [ T ].
    
    (*     type IntoIter = slice::IterMut<'a, T>; *)
    Definition _IntoIter (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "core::slice::iter::IterMut") [] [ T ].
    
    (*
        fn into_iter(self) -> Self::IntoIter {
            self.iter_mut()
        }
    *)
    Definition into_iter (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "iter_mut", [] |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::DerefMut",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref_mut",
                  []
                |),
                [ M.read (| self |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::IntoIterator"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *)
        [
          ("Item", InstanceField.Ty (_Item T A));
          ("IntoIter", InstanceField.Ty (_IntoIter T A));
          ("into_iter", InstanceField.Method (into_iter T A))
        ].
  End Impl_core_iter_traits_collect_IntoIterator_where_core_alloc_Allocator_A_for_ref_mut_alloc_vec_Vec_T_A.
  
  Module Impl_core_iter_traits_collect_Extend_where_core_alloc_Allocator_A_T_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
            <Self as SpecExtend<T, I::IntoIter>>::spec_extend(self, iter.into_iter())
        }
    *)
    Definition extend (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ _ as I ], [ self; iter ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let iter := M.alloc (| iter |) in
          M.call_closure (|
            M.get_trait_method (|
              "alloc::vec::spec_extend::SpecExtend",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [ T; Ty.associated ],
              "spec_extend",
              []
            |),
            [
              M.read (| self |);
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::collect::IntoIterator",
                  I,
                  [],
                  "into_iter",
                  []
                |),
                [ M.read (| iter |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        fn extend_one(&mut self, item: T) {
            self.push(item);
        }
    *)
    Definition extend_one (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; item ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let item := M.alloc (| item |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "push",
                    []
                  |),
                  [ M.read (| self |); M.read (| item |) ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        fn extend_reserve(&mut self, additional: usize) {
            self.reserve(additional);
        }
    *)
    Definition extend_reserve
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [ M.read (| self |); M.read (| additional |) ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        unsafe fn extend_one_unchecked(&mut self, item: T) {
            // SAFETY: Our preconditions ensure the space has been reserved, and `extend_reserve` is implemented correctly.
            unsafe {
                let len = self.len();
                ptr::write(self.as_mut_ptr().add(len), item);
                self.set_len(len + 1);
            }
        }
    *)
    Definition extend_one_unchecked
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; item ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let item := M.alloc (| item |) in
          M.read (|
            let~ len :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "len",
                    []
                  |),
                  [ M.read (| self |) ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_function (| "core::ptr::write", [ T ] |),
                  [
                    M.call_closure (|
                      M.get_associated_function (| Ty.apply (Ty.path "*mut") [] [ T ], "add", [] |),
                      [
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "as_mut_ptr",
                            []
                          |),
                          [ M.read (| self |) ]
                        |);
                        M.read (| len |)
                      ]
                    |);
                    M.read (| item |)
                  ]
                |)
              |) in
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "set_len",
                    []
                  |),
                  [
                    M.read (| self |);
                    BinOp.Wrap.add (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                  ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::Extend"
        (Self T A)
        (* Trait polymorphic types *) [ (* A *) T ]
        (* Instance *)
        [
          ("extend", InstanceField.Method (extend T A));
          ("extend_one", InstanceField.Method (extend_one T A));
          ("extend_reserve", InstanceField.Method (extend_reserve T A));
          ("extend_one_unchecked", InstanceField.Method (extend_one_unchecked T A))
        ].
  End Impl_core_iter_traits_collect_Extend_where_core_alloc_Allocator_A_T_for_alloc_vec_Vec_T_A.
  
  
  Module Impl_core_iter_traits_collect_Extend_where_core_marker_Copy_T_where_core_alloc_Allocator_A_ref__T_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
            self.spec_extend(iter.into_iter())
        }
    *)
    Definition extend (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [ _ as I ], [ self; iter ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let iter := M.alloc (| iter |) in
          M.call_closure (|
            M.get_trait_method (|
              "alloc::vec::spec_extend::SpecExtend",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [ Ty.apply (Ty.path "&") [] [ T ]; Ty.associated ],
              "spec_extend",
              []
            |),
            [
              M.read (| self |);
              M.call_closure (|
                M.get_trait_method (|
                  "core::iter::traits::collect::IntoIterator",
                  I,
                  [],
                  "into_iter",
                  []
                |),
                [ M.read (| iter |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        fn extend_one(&mut self, &item: &'a T) {
            self.push(item);
        }
    *)
    Definition extend_one (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; β1 ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let β1 := M.alloc (| β1 |) in
          M.match_operator (|
            β1,
            [
              fun γ =>
                ltac:(M.monadic
                  (let γ := M.read (| γ |) in
                  let item := M.copy (| γ |) in
                  M.read (|
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "push",
                            []
                          |),
                          [ M.read (| self |); M.read (| item |) ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)
                  |)))
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        fn extend_reserve(&mut self, additional: usize) {
            self.reserve(additional);
        }
    *)
    Definition extend_reserve
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; additional ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let additional := M.alloc (| additional |) in
          M.read (|
            let~ _ :=
              M.alloc (|
                M.call_closure (|
                  M.get_associated_function (|
                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                    "reserve",
                    []
                  |),
                  [ M.read (| self |); M.read (| additional |) ]
                |)
              |) in
            M.alloc (| Value.Tuple [] |)
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    (*
        unsafe fn extend_one_unchecked(&mut self, &item: &'a T) {
            // SAFETY: Our preconditions ensure the space has been reserved, and `extend_reserve` is implemented correctly.
            unsafe {
                let len = self.len();
                ptr::write(self.as_mut_ptr().add(len), item);
                self.set_len(len + 1);
            }
        }
    *)
    Definition extend_one_unchecked
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; β1 ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let β1 := M.alloc (| β1 |) in
          M.match_operator (|
            β1,
            [
              fun γ =>
                ltac:(M.monadic
                  (let γ := M.read (| γ |) in
                  let item := M.copy (| γ |) in
                  M.read (|
                    let~ len :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "len",
                            []
                          |),
                          [ M.read (| self |) ]
                        |)
                      |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_function (| "core::ptr::write", [ T ] |),
                          [
                            M.call_closure (|
                              M.get_associated_function (|
                                Ty.apply (Ty.path "*mut") [] [ T ],
                                "add",
                                []
                              |),
                              [
                                M.call_closure (|
                                  M.get_associated_function (|
                                    Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                    "as_mut_ptr",
                                    []
                                  |),
                                  [ M.read (| self |) ]
                                |);
                                M.read (| len |)
                              ]
                            |);
                            M.read (| item |)
                          ]
                        |)
                      |) in
                    let~ _ :=
                      M.alloc (|
                        M.call_closure (|
                          M.get_associated_function (|
                            Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                            "set_len",
                            []
                          |),
                          [
                            M.read (| self |);
                            BinOp.Wrap.add (| M.read (| len |), Value.Integer IntegerKind.Usize 1 |)
                          ]
                        |)
                      |) in
                    M.alloc (| Value.Tuple [] |)
                  |)))
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::iter::traits::collect::Extend"
        (Self T A)
        (* Trait polymorphic types *) [ (* A *) Ty.apply (Ty.path "&") [] [ T ] ]
        (* Instance *)
        [
          ("extend", InstanceField.Method (extend T A));
          ("extend_one", InstanceField.Method (extend_one T A));
          ("extend_reserve", InstanceField.Method (extend_reserve T A));
          ("extend_one_unchecked", InstanceField.Method (extend_one_unchecked T A))
        ].
  End Impl_core_iter_traits_collect_Extend_where_core_marker_Copy_T_where_core_alloc_Allocator_A_ref__T_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_T_where_core_alloc_Allocator_A1_where_core_alloc_Allocator_A2_alloc_vec_Vec_T_A2_for_alloc_vec_Vec_T_A1.
    Definition Self (T A1 A2 : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A1 ].
    
    (*
        fn partial_cmp(&self, other: &Vec<T, A2>) -> Option<Ordering> {
            PartialOrd::partial_cmp(&**self, &**other)
        }
    *)
    Definition partial_cmp
        (T A1 A2 : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self T A1 A2 in
      match ε, τ, α with
      | [], [], [ self; other ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let other := M.alloc (| other |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::cmp::PartialOrd",
              Ty.apply (Ty.path "slice") [] [ T ],
              [ Ty.apply (Ty.path "slice") [] [ T ] ],
              "partial_cmp",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A1 ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A2 ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| other |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A1 A2 : Ty.t),
      M.IsTraitInstance
        "core::cmp::PartialOrd"
        (Self T A1 A2)
        (* Trait polymorphic types *)
        [ (* Rhs *) Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A2 ] ]
        (* Instance *) [ ("partial_cmp", InstanceField.Method (partial_cmp T A1 A2)) ].
  End Impl_core_cmp_PartialOrd_where_core_cmp_PartialOrd_T_where_core_alloc_Allocator_A1_where_core_alloc_Allocator_A2_alloc_vec_Vec_T_A2_for_alloc_vec_Vec_T_A1.
  
  Module Impl_core_cmp_Eq_where_core_cmp_Eq_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::cmp::Eq"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [].
  End Impl_core_cmp_Eq_where_core_cmp_Eq_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_cmp_Ord_where_core_cmp_Ord_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn cmp(&self, other: &Self) -> Ordering {
            Ord::cmp(&**self, &**other)
        }
    *)
    Definition cmp (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; other ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let other := M.alloc (| other |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::cmp::Ord",
              Ty.apply (Ty.path "slice") [] [ T ],
              [],
              "cmp",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| other |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::cmp::Ord"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("cmp", InstanceField.Method (cmp T A)) ].
  End Impl_core_cmp_Ord_where_core_cmp_Ord_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_ops_drop_Drop_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn drop(&mut self) {
            unsafe {
                // use drop for [T]
                // use a raw slice to refer to the elements of the vector as weakest necessary type;
                // could avoid questions of validity in certain cases
                ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.as_mut_ptr(), self.len))
            }
            // RawVec handles deallocation
        }
    *)
    Definition drop (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_function (|
              "core::ptr::drop_in_place",
              [ Ty.apply (Ty.path "slice") [] [ T ] ]
            |),
            [
              M.call_closure (|
                M.get_function (| "core::ptr::slice_from_raw_parts_mut", [ T ] |),
                [
                  M.call_closure (|
                    M.get_associated_function (|
                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                      "as_mut_ptr",
                      []
                    |),
                    [ M.read (| self |) ]
                  |);
                  M.read (|
                    M.SubPointer.get_struct_record_field (|
                      M.read (| self |),
                      "alloc::vec::Vec",
                      "len"
                    |)
                  |)
                ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::ops::drop::Drop"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("drop", InstanceField.Method (drop T A)) ].
  End Impl_core_ops_drop_Drop_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_default_Default_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn default() -> Vec<T> {
            Vec::new()
        }
    *)
    Definition default (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [] =>
        ltac:(M.monadic
          (M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              "new",
              []
            |),
            []
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T : Ty.t),
      M.IsTraitInstance
        "core::default::Default"
        (Self T)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("default", InstanceField.Method (default T)) ].
  End Impl_core_default_Default_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_fmt_Debug_where_core_fmt_Debug_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
            fmt::Debug::fmt(&**self, f)
        }
    *)
    Definition fmt (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self; f ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          let f := M.alloc (| f |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::fmt::Debug",
              Ty.apply (Ty.path "slice") [] [ T ],
              [],
              "fmt",
              []
            |),
            [
              M.call_closure (|
                M.get_trait_method (|
                  "core::ops::deref::Deref",
                  Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                  [],
                  "deref",
                  []
                |),
                [ M.read (| self |) ]
              |);
              M.read (| f |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::fmt::Debug"
        (Self T A)
        (* Trait polymorphic types *) []
        (* Instance *) [ ("fmt", InstanceField.Method (fmt T A)) ].
  End Impl_core_fmt_Debug_where_core_fmt_Debug_T_where_core_alloc_Allocator_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_AsRef_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn as_ref(&self) -> &Vec<T, A> {
            self
        }
    *)
    Definition as_ref (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (| self |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::AsRef"
        (Self T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ]
        (* Instance *) [ ("as_ref", InstanceField.Method (as_ref T A)) ].
  End Impl_core_convert_AsRef_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_AsMut_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn as_mut(&mut self) -> &mut Vec<T, A> {
            self
        }
    *)
    Definition as_mut (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.read (| self |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::AsMut"
        (Self T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ]
        (* Instance *) [ ("as_mut", InstanceField.Method (as_mut T A)) ].
  End Impl_core_convert_AsMut_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_AsRef_where_core_alloc_Allocator_A_slice_T_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn as_ref(&self) -> &[T] {
            self
        }
    *)
    Definition as_ref (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::deref::Deref",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [],
              "deref",
              []
            |),
            [ M.read (| self |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::AsRef"
        (Self T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "slice") [] [ T ] ]
        (* Instance *) [ ("as_ref", InstanceField.Method (as_ref T A)) ].
  End Impl_core_convert_AsRef_where_core_alloc_Allocator_A_slice_T_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_AsMut_where_core_alloc_Allocator_A_slice_T_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn as_mut(&mut self) -> &mut [T] {
            self
        }
    *)
    Definition as_mut (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ self ] =>
        ltac:(M.monadic
          (let self := M.alloc (| self |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::ops::deref::DerefMut",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              [],
              "deref_mut",
              []
            |),
            [ M.read (| self |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::AsMut"
        (Self T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "slice") [] [ T ] ]
        (* Instance *) [ ("as_mut", InstanceField.Method (as_mut T A)) ].
  End Impl_core_convert_AsMut_where_core_alloc_Allocator_A_slice_T_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_From_where_core_clone_Clone_T_ref__slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: &[T]) -> Vec<T> {
            s.to_vec()
        }
    *)
    Definition from (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "to_vec", [] |),
            [ M.read (| s |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self T)
        (* Trait polymorphic types *)
        [ (* T *) Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ]
        (* Instance *) [ ("from", InstanceField.Method (from T)) ].
  End Impl_core_convert_From_where_core_clone_Clone_T_ref__slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_where_core_clone_Clone_T_ref_mut_slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: &mut [T]) -> Vec<T> {
            s.to_vec()
        }
    *)
    Definition from (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "to_vec", [] |),
            [ M.read (| s |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self T)
        (* Trait polymorphic types *)
        [ (* T *) Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ]
        (* Instance *) [ ("from", InstanceField.Method (from T)) ].
  End Impl_core_convert_From_where_core_clone_Clone_T_ref_mut_slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_where_core_clone_Clone_T_ref__array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (N : Value.t) (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: &[T; N]) -> Vec<T> {
            Self::from(s.as_slice())
        }
    *)
    Definition from
        (N : Value.t)
        (T : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self N T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::convert::From",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ],
              "from",
              []
            |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "array") [ N ] [ T ],
                  "as_slice",
                  []
                |),
                [ M.read (| s |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (N : Value.t) (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self N T)
        (* Trait polymorphic types *)
        [ (* T *) Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "array") [ N ] [ T ] ] ]
        (* Instance *) [ ("from", InstanceField.Method (from N T)) ].
  End Impl_core_convert_From_where_core_clone_Clone_T_ref__array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_where_core_clone_Clone_T_ref_mut_array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (N : Value.t) (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: &mut [T; N]) -> Vec<T> {
            Self::from(s.as_mut_slice())
        }
    *)
    Definition from
        (N : Value.t)
        (T : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self N T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::convert::From",
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ],
              [ Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "slice") [] [ T ] ] ],
              "from",
              []
            |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply (Ty.path "array") [ N ] [ T ],
                  "as_mut_slice",
                  []
                |),
                [ M.read (| s |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (N : Value.t) (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self N T)
        (* Trait polymorphic types *)
        [ (* T *) Ty.apply (Ty.path "&mut") [] [ Ty.apply (Ty.path "array") [ N ] [ T ] ] ]
        (* Instance *) [ ("from", InstanceField.Method (from N T)) ].
  End Impl_core_convert_From_where_core_clone_Clone_T_ref_mut_array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (N : Value.t) (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: [T; N]) -> Vec<T> {
            <[T]>::into_vec(Box::new(s))
        }
    *)
    Definition from
        (N : Value.t)
        (T : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self N T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "slice") [] [ T ],
              "into_vec",
              [ Ty.path "alloc::alloc::Global" ]
            |),
            [
              M.call_closure (|
                M.get_associated_function (|
                  Ty.apply
                    (Ty.path "alloc::boxed::Box")
                    []
                    [ Ty.apply (Ty.path "array") [ N ] [ T ]; Ty.path "alloc::alloc::Global" ],
                  "new",
                  []
                |),
                [ M.read (| s |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (N : Value.t) (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self N T)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "array") [ N ] [ T ] ]
        (* Instance *) [ ("from", InstanceField.Method (from N T)) ].
  End Impl_core_convert_From_array_N_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_where_alloc_borrow_ToOwned_slice_T_alloc_borrow_Cow_slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
    Definition Self (T : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: Cow<'a, [T]>) -> Vec<T> {
            s.into_owned()
        }
    *)
    Definition from (T : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::borrow::Cow") [] [ Ty.apply (Ty.path "slice") [] [ T ] ],
              "into_owned",
              []
            |),
            [ M.read (| s |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self T)
        (* Trait polymorphic types *)
        [ (* T *) Ty.apply (Ty.path "alloc::borrow::Cow") [] [ Ty.apply (Ty.path "slice") [] [ T ] ]
        ]
        (* Instance *) [ ("from", InstanceField.Method (from T)) ].
  End Impl_core_convert_From_where_alloc_borrow_ToOwned_slice_T_alloc_borrow_Cow_slice_T_for_alloc_vec_Vec_T_alloc_alloc_Global.
  
  Module Impl_core_convert_From_where_core_alloc_Allocator_A_alloc_boxed_Box_slice_T_A_for_alloc_vec_Vec_T_A.
    Definition Self (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn from(s: Box<[T], A>) -> Self {
            s.into_vec()
        }
    *)
    Definition from (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_associated_function (| Ty.apply (Ty.path "slice") [] [ T ], "into_vec", [ A ] |),
            [ M.read (| s |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self T A)
        (* Trait polymorphic types *)
        [
          (* T *)
          Ty.apply (Ty.path "alloc::boxed::Box") [] [ Ty.apply (Ty.path "slice") [] [ T ]; A ]
        ]
        (* Instance *) [ ("from", InstanceField.Method (from T A)) ].
  End Impl_core_convert_From_where_core_alloc_Allocator_A_alloc_boxed_Box_slice_T_A_for_alloc_vec_Vec_T_A.
  
  Module Impl_core_convert_From_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_boxed_Box_slice_T_A.
    Definition Self (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::boxed::Box") [] [ Ty.apply (Ty.path "slice") [] [ T ]; A ].
    
    (*
        fn from(v: Vec<T, A>) -> Self {
            v.into_boxed_slice()
        }
    *)
    Definition from (T A : Ty.t) (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      let Self : Ty.t := Self T A in
      match ε, τ, α with
      | [], [], [ v ] =>
        ltac:(M.monadic
          (let v := M.alloc (| v |) in
          M.call_closure (|
            M.get_associated_function (|
              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
              "into_boxed_slice",
              []
            |),
            [ M.read (| v |) ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::From"
        (Self T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ]
        (* Instance *) [ ("from", InstanceField.Method (from T A)) ].
  End Impl_core_convert_From_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_alloc_boxed_Box_slice_T_A.
  
  Module Impl_core_convert_From_ref__str_for_alloc_vec_Vec_u8_alloc_alloc_Global.
    Definition Self : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ].
    
    (*
        fn from(s: &str) -> Vec<u8> {
            From::from(s.as_bytes())
        }
    *)
    Definition from (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
      match ε, τ, α with
      | [], [], [ s ] =>
        ltac:(M.monadic
          (let s := M.alloc (| s |) in
          M.call_closure (|
            M.get_trait_method (|
              "core::convert::From",
              Ty.apply
                (Ty.path "alloc::vec::Vec")
                []
                [ Ty.path "u8"; Ty.path "alloc::alloc::Global" ],
              [ Ty.apply (Ty.path "&") [] [ Ty.apply (Ty.path "slice") [] [ Ty.path "u8" ] ] ],
              "from",
              []
            |),
            [
              M.call_closure (|
                M.get_associated_function (| Ty.path "str", "as_bytes", [] |),
                [ M.read (| s |) ]
              |)
            ]
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      M.IsTraitInstance
        "core::convert::From"
        Self
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "&") [] [ Ty.path "str" ] ]
        (* Instance *) [ ("from", InstanceField.Method from) ].
  End Impl_core_convert_From_ref__str_for_alloc_vec_Vec_u8_alloc_alloc_Global.
  
  Module Impl_core_convert_TryFrom_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_array_N_T.
    Definition Self (N : Value.t) (T A : Ty.t) : Ty.t := Ty.apply (Ty.path "array") [ N ] [ T ].
    
    (*     type Error = Vec<T, A>; *)
    Definition _Error (N : Value.t) (T A : Ty.t) : Ty.t :=
      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ].
    
    (*
        fn try_from(mut vec: Vec<T, A>) -> Result<[T; N], Vec<T, A>> {
            if vec.len() != N {
                return Err(vec);
            }
    
            // SAFETY: `.set_len(0)` is always sound.
            unsafe { vec.set_len(0) };
    
            // SAFETY: A `Vec`'s pointer is always aligned properly, and
            // the alignment the array needs is the same as the items.
            // We checked earlier that we have sufficient items.
            // The items will not double-drop as the `set_len`
            // tells the `Vec` not to also drop them.
            let array = unsafe { ptr::read(vec.as_ptr() as *const [T; N]) };
            Ok(array)
        }
    *)
    Definition try_from
        (N : Value.t)
        (T A : Ty.t)
        (ε : list Value.t)
        (τ : list Ty.t)
        (α : list Value.t)
        : M :=
      let Self : Ty.t := Self N T A in
      match ε, τ, α with
      | [], [], [ vec ] =>
        ltac:(M.monadic
          (let vec := M.alloc (| vec |) in
          M.catch_return (|
            ltac:(M.monadic
              (M.read (|
                let~ _ :=
                  M.match_operator (|
                    M.alloc (| Value.Tuple [] |),
                    [
                      fun γ =>
                        ltac:(M.monadic
                          (let γ :=
                            M.use
                              (M.alloc (|
                                BinOp.ne (|
                                  M.call_closure (|
                                    M.get_associated_function (|
                                      Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                                      "len",
                                      []
                                    |),
                                    [ vec ]
                                  |),
                                  M.read (| M.get_constant (| "alloc::vec::N" |) |)
                                |)
                              |)) in
                          let _ :=
                            M.is_constant_or_break_match (| M.read (| γ |), Value.Bool true |) in
                          M.alloc (|
                            M.never_to_any (|
                              M.read (|
                                M.return_ (|
                                  Value.StructTuple "core::result::Result::Err" [ M.read (| vec |) ]
                                |)
                              |)
                            |)
                          |)));
                      fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                    ]
                  |) in
                let~ _ :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_associated_function (|
                        Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                        "set_len",
                        []
                      |),
                      [ vec; Value.Integer IntegerKind.Usize 0 ]
                    |)
                  |) in
                let~ array :=
                  M.alloc (|
                    M.call_closure (|
                      M.get_function (|
                        "core::ptr::read",
                        [ Ty.apply (Ty.path "array") [ N ] [ T ] ]
                      |),
                      [
                        M.rust_cast
                          (M.call_closure (|
                            M.get_associated_function (|
                              Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ],
                              "as_ptr",
                              []
                            |),
                            [ vec ]
                          |))
                      ]
                    |)
                  |) in
                M.alloc (| Value.StructTuple "core::result::Result::Ok" [ M.read (| array |) ] |)
              |)))
          |)))
      | _, _, _ => M.impossible "wrong number of arguments"
      end.
    
    Axiom Implements :
      forall (N : Value.t) (T A : Ty.t),
      M.IsTraitInstance
        "core::convert::TryFrom"
        (Self N T A)
        (* Trait polymorphic types *) [ (* T *) Ty.apply (Ty.path "alloc::vec::Vec") [] [ T; A ] ]
        (* Instance *)
        [
          ("Error", InstanceField.Ty (_Error N T A));
          ("try_from", InstanceField.Method (try_from N T A))
        ].
  End Impl_core_convert_TryFrom_where_core_alloc_Allocator_A_alloc_vec_Vec_T_A_for_array_N_T.
End vec.
