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

Module identity.
  Definition value_FUN : Value.t :=
    M.run
      ltac:(M.monadic
        (M.alloc (|
          Value.StructTuple
            "revm_precompile::PrecompileWithAddress"
            [
              M.call_closure (|
                M.get_function (| "revm_precompile::u64_to_address", [] |),
                [ Value.Integer IntegerKind.U64 4 ]
              |);
              Value.StructTuple
                "revm_primitives::precompile::Precompile::Standard"
                [
                  (* ReifyFnPointer *)
                  M.pointer_coercion
                    (M.get_function (| "revm_precompile::identity::identity_run", [] |))
                ]
            ]
        |))).
  
  Definition value_IDENTITY_BASE : Value.t :=
    M.run ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 15 |))).
  
  Definition value_IDENTITY_PER_WORD : Value.t :=
    M.run ltac:(M.monadic (M.alloc (| Value.Integer IntegerKind.U64 3 |))).
  
  (*
  pub fn identity_run(input: &Bytes, gas_limit: u64) -> PrecompileResult {
      let gas_used = calc_linear_cost_u32(input.len(), IDENTITY_BASE, IDENTITY_PER_WORD);
      if gas_used > gas_limit {
          return Err(Error::OutOfGas);
      }
      Ok((gas_used, input.clone()))
  }
  *)
  Definition identity_run (ε : list Value.t) (τ : list Ty.t) (α : list Value.t) : M :=
    match ε, τ, α with
    | [], [], [ input; gas_limit ] =>
      ltac:(M.monadic
        (let input := M.alloc (| input |) in
        let gas_limit := M.alloc (| gas_limit |) in
        M.catch_return (|
          ltac:(M.monadic
            (M.read (|
              let~ gas_used :=
                M.alloc (|
                  M.call_closure (|
                    M.get_function (| "revm_precompile::calc_linear_cost_u32", [] |),
                    [
                      M.call_closure (|
                        M.get_associated_function (| Ty.path "bytes::bytes::Bytes", "len", [] |),
                        [
                          M.call_closure (|
                            M.get_trait_method (|
                              "core::ops::deref::Deref",
                              Ty.path "alloy_primitives::bytes_::Bytes",
                              [],
                              "deref",
                              []
                            |),
                            [ M.read (| input |) ]
                          |)
                        ]
                      |);
                      M.read (| M.get_constant (| "revm_precompile::identity::IDENTITY_BASE" |) |);
                      M.read (|
                        M.get_constant (| "revm_precompile::identity::IDENTITY_PER_WORD" |)
                      |)
                    ]
                  |)
                |) in
              let~ _ :=
                M.match_operator (|
                  M.alloc (| Value.Tuple [] |),
                  [
                    fun γ =>
                      ltac:(M.monadic
                        (let γ :=
                          M.use
                            (M.alloc (|
                              BinOp.gt (| M.read (| gas_used |), M.read (| gas_limit |) |)
                            |)) 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"
                                  [
                                    Value.StructTuple
                                      "revm_primitives::precompile::PrecompileError::OutOfGas"
                                      []
                                  ]
                              |)
                            |)
                          |)
                        |)));
                    fun γ => ltac:(M.monadic (M.alloc (| Value.Tuple [] |)))
                  ]
                |) in
              M.alloc (|
                Value.StructTuple
                  "core::result::Result::Ok"
                  [
                    Value.Tuple
                      [
                        M.read (| gas_used |);
                        M.call_closure (|
                          M.get_trait_method (|
                            "core::clone::Clone",
                            Ty.path "alloy_primitives::bytes_::Bytes",
                            [],
                            "clone",
                            []
                          |),
                          [ M.read (| input |) ]
                        |)
                      ]
                  ]
              |)
            |)))
        |)))
    | _, _, _ => M.impossible "wrong number of arguments"
    end.
  
  Axiom Function_identity_run : M.IsFunction "revm_precompile::identity::identity_run" identity_run.
End identity.
