//! > Test simple inlining.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(n: felt252) -> felt252 {
    -n
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- core::Felt252Neg::neg(v0)
End:
  Return(v1)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
  (v2: core::felt252) <- -1
  (v3: core::felt252) <- core::felt252_mul(v0, v2)
End:
  Goto(blk1, {v3 -> v1})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test generic function inlining.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(val: Option::<felt252>) -> felt252 {
    bar(val, 2)
}

//! > function_name
foo

//! > module_code
/// If `val` is `Option::Some(x)`, returns `x`. Otherwise, panics.
#[inline]
fn bar<T, impl TDrop: Drop<T>>(val: Option::<T>, val2: T) -> T {
    match val {
        Option::Some(x) => x,
        Option::None => val2,
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::option::Option::<core::felt252>
blk0 (root):
Statements:
  (v1: core::felt252) <- 2
  (v2: core::felt252) <- test::bar::<core::felt252, core::felt252Drop>(v0, v1)
End:
  Return(v2)

//! > after
Parameters: v0: core::option::Option::<core::felt252>
blk0 (root):
Statements:
  (v1: core::felt252) <- 2
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v2)

blk2:
Statements:
End:
  Match(match_enum(v0) {
    Option::Some(v3) => blk3,
    Option::None(v4) => blk4,
  })

blk3:
Statements:
End:
  Goto(blk1, {v3 -> v2})

blk4:
Statements:
End:
  Goto(blk1, {v1 -> v2})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test inlining same arg twice.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(n: felt252) -> felt252 {
    bar(n, n)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn bar(a: felt252, b: felt252) -> felt252 {
    a + b
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0, v0)
End:
  Return(v1)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
  (v2: core::felt252) <- core::felt252_add(v0, v0)
End:
  Goto(blk1, {v2 -> v1})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test inlining.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: felt252, b: felt252) -> felt252 {
    bar(a + b, b)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn bar(a: felt252, b: felt252) -> felt252 implicits() {
    bar2(a, b) + bar2(b, a)
}

#[inline(always)]
fn bar2(a: felt252, b: felt252) -> felt252 implicits() {
    a * b
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252, v1: core::felt252
blk0 (root):
Statements:
  (v2: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v3: core::felt252) <- test::bar(v2, v1)
End:
  Return(v3)

//! > after
Parameters: v0: core::felt252, v1: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Goto(blk4, {})

blk2:
Statements:
  (v4: core::felt252) <- core::felt252_add(v0, v1)
End:
  Goto(blk1, {v4 -> v2})

blk3:
Statements:
End:
  Return(v3)

blk4:
Statements:
  (v5: core::felt252) <- core::felt252_mul(v2, v1)
  (v6: core::felt252) <- core::felt252_mul(v1, v2)
  (v7: core::felt252) <- core::felt252_add(v5, v6)
End:
  Goto(blk3, {v7 -> v3})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test recursive inlining.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: felt252) -> felt252 {
    first(a)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn first(a: felt252) -> felt252 {
    second(a)
}

#[inline(always)]
fn second(a: felt252) -> felt252 {
    third(a)
}

#[inline(always)]
fn third(a: felt252) -> felt252 {
    a * a
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::first(v0)
End:
  Return(v1)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
  (v2: core::felt252) <- core::felt252_mul(v0, v0)
End:
  Goto(blk1, {v2 -> v1})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test impl inlining.

//! > test_runner_name
test_function_inlining

//! > function
fn foo() {
    let mut arr = array![];
    arr.append(5)
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > before
Parameters:
blk0 (root):
Statements:
  (v0: core::array::Array::<core::felt252>) <- core::array::ArrayImpl::<core::felt252>::new()
  (v1: core::felt252) <- 5
  (v3: core::array::Array::<core::felt252>) <- core::array::ArrayImpl::<core::felt252>::append(v0, v1)
  (v2: ()) <- struct_construct()
  () <- struct_destructure(v2)
End:
  Return()

//! > after
Parameters:
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
  (v1: core::felt252) <- 5
End:
  Goto(blk4, {})

blk2:
Statements:
  (v4: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
End:
  Goto(blk1, {v4 -> v0})

blk3:
Statements:
  (v2: ()) <- struct_construct()
  () <- struct_destructure(v2)
End:
  Return()

blk4:
Statements:
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v0, v1)
End:
  Goto(blk3, {v5 -> v3})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test inlining of a function with an early return.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: felt252) -> felt252 {
    if a == 2 {
        bar(a)
    } else {
        a
    }
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn bar(a: felt252) -> felt252 {
    if a == 0 {
        return 1;
    }
    0
}

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
  (v3: core::felt252) <- 2
  (v4: core::felt252, v5: @core::felt252) <- snapshot(v3)
  (v6: core::bool) <- core::Felt252PartialEq::eq(v2, v5)
End:
  Match(match_enum(v6) {
    bool::False(v9) => blk2,
    bool::True(v7) => blk1,
  })

blk1:
Statements:
  (v8: core::felt252) <- test::bar(v1)
End:
  Goto(blk3, {v8 -> v10})

blk2:
Statements:
End:
  Goto(blk3, {v1 -> v10})

blk3:
Statements:
End:
  Return(v10)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252, v2: @core::felt252) <- snapshot(v0)
  (v3: core::felt252) <- 2
  (v4: core::felt252, v5: @core::felt252) <- snapshot(v3)
End:
  Goto(blk5, {})

blk1:
Statements:
End:
  Goto(blk9, {})

blk2:
Statements:
End:
  Goto(blk3, {v1 -> v10})

blk3:
Statements:
End:
  Return(v10)

blk4:
Statements:
End:
  Match(match_enum(v6) {
    bool::False(v9) => blk2,
    bool::True(v7) => blk1,
  })

blk5:
Statements:
  (v11: core::felt252) <- desnap(v2)
  (v12: core::felt252) <- desnap(v5)
  (v13: core::felt252) <- core::felt252_sub(v11, v12)
End:
  Match(match core::felt252_is_zero(v13) {
    IsZeroResult::Zero => blk6,
    IsZeroResult::NonZero(v14) => blk7,
  })

blk6:
Statements:
  (v15: ()) <- struct_construct()
  (v16: core::bool) <- bool::True(v15)
End:
  Goto(blk4, {v16 -> v6})

blk7:
Statements:
  (v17: ()) <- struct_construct()
  (v18: core::bool) <- bool::False(v17)
End:
  Goto(blk4, {v18 -> v6})

blk8:
Statements:
End:
  Goto(blk3, {v8 -> v10})

blk9:
Statements:
End:
  Match(match core::felt252_is_zero(v1) {
    IsZeroResult::Zero => blk10,
    IsZeroResult::NonZero(v19) => blk11,
  })

blk10:
Statements:
  (v20: core::felt252) <- 1
End:
  Goto(blk8, {v20 -> v8})

blk11:
Statements:
  (v21: core::felt252) <- 0
End:
  Goto(blk8, {v21 -> v8})

//! > lowering_diagnostics

//! > semantic_diagnostics

//! > ==========================================================================

//! > Test inlining heuristic

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: felt252) -> felt252 {
    bar(a) + bar2(a)
}

//! > function_name
foo

//! > module_code
fn bar(a: felt252) -> felt252 {
    bar2(a)
}

fn bar2(a: felt252) -> felt252 {
    1
}

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0)
  (v2: core::felt252) <- test::bar2(v0)
  (v3: core::felt252) <- core::Felt252Add::add(v1, v2)
End:
  Return(v3)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Goto(blk4, {})

blk2:
Statements:
  (v4: core::felt252) <- 1
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
End:
  Goto(blk6, {})

blk4:
Statements:
  (v5: core::felt252) <- 1
End:
  Goto(blk3, {v5 -> v2})

blk5:
Statements:
End:
  Return(v3)

blk6:
Statements:
  (v6: core::felt252) <- core::felt252_add(v1, v2)
End:
  Goto(blk5, {v6 -> v3})

//! > lowering_diagnostics

//! > semantic_diagnostics

//! > ==========================================================================

//! > Test preventing inlining heuristic

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: felt252) -> felt252 {
    bar(a) + bar2(a)
}

//! > function_name
foo

//! > module_code
#[inline(never)]
fn bar(a: felt252) -> felt252 {
    bar2(a)
}

#[inline(never)]
fn bar2(a: felt252) -> felt252 {
    1
}

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0)
  (v2: core::felt252) <- test::bar2(v0)
  (v3: core::felt252) <- core::Felt252Add::add(v1, v2)
End:
  Return(v3)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0)
  (v2: core::felt252) <- test::bar2(v0)
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v3)

blk2:
Statements:
  (v4: core::felt252) <- core::felt252_add(v1, v2)
End:
  Goto(blk1, {v4 -> v3})

//! > lowering_diagnostics

//! > semantic_diagnostics

//! > ==========================================================================

//! > Test returning an input variable as is (not in the last block).

//! > test_runner_name
test_function_inlining

//! > function
fn foo() -> felt252 {
    bar(0)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn bar(a: felt252) -> felt252 {
    if a == 0 {
        return a;
    }
    1
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > before
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 0
  (v1: core::felt252) <- test::bar(v0)
End:
  Return(v1)

//! > after
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 0
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk3,
    IsZeroResult::NonZero(v2) => blk4,
  })

blk3:
Statements:
End:
  Goto(blk1, {v0 -> v1})

blk4:
Statements:
  (v3: core::felt252) <- 1
End:
  Goto(blk1, {v3 -> v1})

//! > ==========================================================================

//! > Test inlining of identity function.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(n: felt252) -> felt252 {
    identity(n)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn identity(n: felt252) -> felt252 {
    n
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::identity(v0)
End:
  Return(v1)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
End:
  Goto(blk1, {v0 -> v1})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test match where is there is a return in one branch.

//! > Motivation:
// The goal of this test is to test the block renaming logic.
// A panicable function can have a block with a low `block_id` with a match_arm that goes
// to a higher 'block_id'.
// We want to test this outside of the outer scope as the last block is rebuild last.

//! > test_runner_name
test_function_inlining

//! > function
fn foo(a: u128, b: u128) -> u128 {
    bar1(a, b)
}

//! > function_name
foo

//! > module_code
#[inline(always)]
fn bar1(a: u128, b: u128) -> u128 {
    if a == 1_u128 {
        return bar2(b, a);
    }
    a
}

#[inline(always)]
fn bar2(a: u128, b: u128) -> u128 {
    a + b
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::integer::u128, v1: core::integer::u128
blk0 (root):
Statements:
  (v3: core::panics::PanicResult::<(core::integer::u128,)>) <- test::bar1(v0, v1)
End:
  Match(match_enum(v3) {
    PanicResult::Ok(v4) => blk2,
    PanicResult::Err(v6) => blk3,
  })

blk1:
Statements:
  (v7: (core::integer::u128,)) <- struct_construct(v2)
  (v8: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Ok(v7)
End:
  Return(v8)

blk2:
Statements:
  (v5: core::integer::u128) <- struct_destructure(v4)
End:
  Goto(blk1, {v5 -> v2})

blk3:
Statements:
  (v9: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Err(v6)
End:
  Return(v9)

//! > after
Parameters: v0: core::integer::u128, v1: core::integer::u128
blk0 (root):
Statements:
End:
  Goto(blk5, {})

blk1:
Statements:
  (v7: (core::integer::u128,)) <- struct_construct(v2)
  (v8: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Ok(v7)
End:
  Return(v8)

blk2:
Statements:
  (v5: core::integer::u128) <- struct_destructure(v4)
End:
  Goto(blk1, {v5 -> v2})

blk3:
Statements:
  (v9: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Err(v6)
End:
  Return(v9)

blk4:
Statements:
End:
  Match(match_enum(v3) {
    PanicResult::Ok(v4) => blk2,
    PanicResult::Err(v6) => blk3,
  })

blk5:
Statements:
  (v10: core::integer::u128) <- 1
End:
  Match(match core::integer::u128_eq(v0, v10) {
    bool::False => blk6,
    bool::True => blk7,
  })

blk6:
Statements:
  (v11: (core::integer::u128,)) <- struct_construct(v0)
  (v12: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Ok(v11)
End:
  Goto(blk4, {v12 -> v3})

blk7:
Statements:
End:
  Match(match core::integer::u128_overflowing_add(v1, v0) {
    Result::Ok(v13) => blk8,
    Result::Err(v14) => blk9,
  })

blk8:
Statements:
  (v15: (core::integer::u128,)) <- struct_construct(v13)
  (v16: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Ok(v15)
End:
  Goto(blk4, {v16 -> v3})

blk9:
Statements:
  (v17: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v18: core::felt252) <- 39878429859757942499084499860145094553463
  (v19: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v17, v18)
  (v20: core::panics::Panic) <- struct_construct()
  (v21: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v20, v19)
  (v22: core::panics::PanicResult::<(core::integer::u128,)>) <- PanicResult::Err(v21)
End:
  Goto(blk4, {v22 -> v3})

//! > lowering_diagnostics

//! > ==========================================================================

//! > Test inlining a function where the root block does not return.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline(always)]
fn bar(n: felt252) -> felt252 {
    if n == 0 {
        return 1;
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0)
End:
  Return(v1)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Return(v1)

blk2:
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk3,
    IsZeroResult::NonZero(v2) => blk4,
  })

blk3:
Statements:
  (v3: core::felt252) <- 1
End:
  Goto(blk1, {v3 -> v1})

blk4:
Statements:
  (v4: core::felt252) <- 1
End:
  Goto(blk1, {v4 -> v1})

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with indirect self call.

//! > Motivation:
//! #[inline] functions should inline a function unless it is recursively called by itself, even
//! indirectly. In this case, the function bar should be inlined, but not the inner call to foo.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    if n == 0 {
        foo(n - 1)
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
End:
  Goto(blk7, {})

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

blk6:
Statements:
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk7:
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk8,
    IsZeroResult::NonZero(v15) => blk9,
  })

blk8:
Statements:
  (v16: core::felt252) <- 1
  (v17: core::felt252) <- core::felt252_sub(v0, v16)
  (v18: core::panics::PanicResult::<(core::felt252,)>) <- test::foo(v17)
End:
  Goto(blk6, {v18 -> v7})

blk9:
Statements:
  (v19: core::felt252) <- 1
  (v20: (core::felt252,)) <- struct_construct(v19)
  (v21: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v20)
End:
  Goto(blk6, {v21 -> v7})

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with direct self call.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    foo(n)
}

//! > module_code

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- test::foo(v0)
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- test::foo(v0)
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with direct self call in a called function.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    if n == 0 {
        bar(n - 1)
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v2: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v2: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with direct self call inside two levels of called functions.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    baz(n)
}

#[inline]
fn baz(n: felt252) -> felt252 {
    if n == 0 {
        baz(n - 1)
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v2: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk5, {})

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

blk4:
Statements:
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk5:
Statements:
  (v9: core::panics::PanicResult::<(core::felt252,)>) <- test::baz(v0)
End:
  Goto(blk4, {v9 -> v2})

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with call a callee from a called function.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    baz(n)
}

#[inline]
fn baz(n: felt252) -> felt252 {
    if n == 0 {
        bar(n - 1)
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v2: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v2: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v2) {
    PanicResult::Ok(v3) => blk2,
    PanicResult::Err(v5) => blk3,
  })

blk1:
Statements:
  (v6: (core::felt252,)) <- struct_construct(v1)
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v6)
End:
  Return(v7)

blk2:
Statements:
  (v4: core::felt252) <- struct_destructure(v3)
End:
  Goto(blk1, {v4 -> v1})

blk3:
Statements:
  (v8: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v5)
End:
  Return(v8)

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with call a two levels above callee from a called function.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
#[inline]
fn foo(n: felt252) -> felt252 {
    bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    baz(n)
}

#[inline]
fn baz(n: felt252) -> felt252 {
    if n == 0 {
        foo(n - 1)
    } else {
        return 1;
    }
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
  (v7: core::panics::PanicResult::<(core::felt252,)>) <- test::bar(v0)
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas() {
    Option::Some => blk1,
    Option::None => blk2,
  })

blk1:
Statements:
End:
  Goto(blk7, {})

blk2:
Statements:
  (v2: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v3: core::felt252) <- 375233589013918064796019
  (v5: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v2, v3)
  (v4: core::panics::Panic) <- struct_construct()
  (v6: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v4, v5)
  (v11: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v6)
End:
  Return(v11)

blk3:
Statements:
  (v12: (core::felt252,)) <- struct_construct(v1)
  (v13: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v12)
End:
  Return(v13)

blk4:
Statements:
  (v9: core::felt252) <- struct_destructure(v8)
End:
  Goto(blk3, {v9 -> v1})

blk5:
Statements:
  (v14: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Err(v10)
End:
  Return(v14)

blk6:
Statements:
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk4,
    PanicResult::Err(v10) => blk5,
  })

blk7:
Statements:
End:
  Match(match core::felt252_is_zero(v0) {
    IsZeroResult::Zero => blk8,
    IsZeroResult::NonZero(v15) => blk9,
  })

blk8:
Statements:
  (v16: core::felt252) <- 1
  (v17: core::felt252) <- core::felt252_sub(v0, v16)
  (v18: core::panics::PanicResult::<(core::felt252,)>) <- test::foo(v17)
End:
  Goto(blk6, {v18 -> v7})

blk9:
Statements:
  (v19: core::felt252) <- 1
  (v20: (core::felt252,)) <- struct_construct(v19)
  (v21: core::panics::PanicResult::<(core::felt252,)>) <- PanicResult::Ok(v20)
End:
  Goto(blk6, {v21 -> v7})

//! > lowering_diagnostics

//! > ==========================================================================

//! > test #[inline] with call a function twice.

//! > test_runner_name
test_function_inlining

//! > function_name
foo

//! > function
fn foo(n: felt252) -> felt252 {
    bar(n) + bar(n)
}

//! > module_code
#[inline]
fn bar(n: felt252) -> felt252 {
    n
}

//! > semantic_diagnostics

//! > before
Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- test::bar(v0)
  (v2: core::felt252) <- test::bar(v0)
  (v3: core::felt252) <- core::Felt252Add::add(v1, v2)
End:
  Return(v3)

//! > after
Parameters: v0: core::felt252
blk0 (root):
Statements:
End:
  Goto(blk2, {})

blk1:
Statements:
End:
  Goto(blk4, {})

blk2:
Statements:
End:
  Goto(blk1, {v0 -> v1})

blk3:
Statements:
End:
  Goto(blk6, {})

blk4:
Statements:
End:
  Goto(blk3, {v0 -> v2})

blk5:
Statements:
End:
  Return(v3)

blk6:
Statements:
  (v4: core::felt252) <- core::felt252_add(v1, v2)
End:
  Goto(blk5, {v4 -> v3})

//! > lowering_diagnostics
