//! > Test loop.

//! > test_runner_name
test_generated_function

//! > function
fn foo() -> bool {
    let mut x = 5;
    loop {
        let y = x + 1;
        x = y;
        if y == 10 {
            break true;
        };
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 5
  (v2: core::felt252, v1: core::bool) <- test::foo[expr17](v0)
End:
  Return(v1)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::felt252) <- 5
  (v3: core::RangeCheck, v4: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr17](v0, v1, v2)
End:
  Match(match_enum(v5) {
    PanicResult::Ok(v6) => blk1,
    PanicResult::Err(v7) => blk2,
  })

blk1:
Statements:
  (v8: core::felt252, v9: core::bool) <- struct_destructure(v6)
  (v10: (core::bool,)) <- struct_construct(v9)
  (v11: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v10)
End:
  Return(v3, v4, v11)

blk2:
Statements:
  (v12: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
  Return(v3, v4, v12)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- 1
  (v2: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
  (v5: core::felt252) <- 10
  (v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
  (v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
  Match(match_enum(v8) {
    bool::False(v12) => blk2,
    bool::True(v9) => blk1,
  })

blk1:
Statements:
  (v10: ()) <- struct_construct()
  (v11: core::bool) <- bool::True(v10)
End:
  Return(v2, v11)

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

blk3:
Statements:
  (v14: core::felt252, v13: core::bool) <- test::foo[expr17](v2)
End:
  Return(v14, v13)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk4,
  })

blk1:
Statements:
  (v7: core::felt252) <- 1
  (v8: core::felt252) <- core::felt252_add(v2, v7)
  (v9: core::felt252) <- 10
  (v10: core::felt252) <- core::felt252_sub(v8, v9)
End:
  Match(match core::felt252_is_zero(v10) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v11) => blk3,
  })

blk2:
Statements:
  (v12: ()) <- struct_construct()
  (v13: core::bool) <- bool::True(v12)
  (v14: (core::felt252, core::bool)) <- struct_construct(v8, v13)
  (v15: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v14)
End:
  Return(v3, v4, v15)

blk3:
Statements:
  (v16: core::RangeCheck, v17: core::gas::GasBuiltin, v18: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr17](v3, v4, v8)
End:
  Return(v16, v17, v18)

blk4:
Statements:
  (v19: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v20: core::felt252) <- 375233589013918064796019
  (v21: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v19, v20)
  (v22: core::panics::Panic) <- struct_construct()
  (v23: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v22, v21)
  (v24: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v23)
End:
  Return(v5, v6, v24)

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

//! > Test loop with duplicate member path.

//! > test_runner_name
test_generated_function

//! > function
fn foo() -> bool {
    let mut x = 5;
    loop {
        x = x + 1;
        if x == 10 {
            break true;
        };
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 5
  (v2: core::felt252, v1: core::bool) <- test::foo[expr16](v0)
End:
  Return(v1)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::felt252) <- 5
  (v3: core::RangeCheck, v4: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr16](v0, v1, v2)
End:
  Match(match_enum(v5) {
    PanicResult::Ok(v6) => blk1,
    PanicResult::Err(v7) => blk2,
  })

blk1:
Statements:
  (v8: core::felt252, v9: core::bool) <- struct_destructure(v6)
  (v10: (core::bool,)) <- struct_construct(v9)
  (v11: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v10)
End:
  Return(v3, v4, v11)

blk2:
Statements:
  (v12: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
  Return(v3, v4, v12)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- 1
  (v2: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
  (v5: core::felt252) <- 10
  (v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
  (v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
  Match(match_enum(v8) {
    bool::False(v12) => blk2,
    bool::True(v9) => blk1,
  })

blk1:
Statements:
  (v10: ()) <- struct_construct()
  (v11: core::bool) <- bool::True(v10)
End:
  Return(v3, v11)

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

blk3:
Statements:
  (v14: core::felt252, v13: core::bool) <- test::foo[expr16](v3)
End:
  Return(v14, v13)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk4,
  })

blk1:
Statements:
  (v7: core::felt252) <- 1
  (v8: core::felt252) <- core::felt252_add(v2, v7)
  (v9: core::felt252) <- 10
  (v10: core::felt252) <- core::felt252_sub(v8, v9)
End:
  Match(match core::felt252_is_zero(v10) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v11) => blk3,
  })

blk2:
Statements:
  (v12: ()) <- struct_construct()
  (v13: core::bool) <- bool::True(v12)
  (v14: (core::felt252, core::bool)) <- struct_construct(v8, v13)
  (v15: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v14)
End:
  Return(v3, v4, v15)

blk3:
Statements:
  (v16: core::RangeCheck, v17: core::gas::GasBuiltin, v18: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr16](v3, v4, v8)
End:
  Return(v16, v17, v18)

blk4:
Statements:
  (v19: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v20: core::felt252) <- 375233589013918064796019
  (v21: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v19, v20)
  (v22: core::panics::Panic) <- struct_construct()
  (v23: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v22, v21)
  (v24: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v23)
End:
  Return(v5, v6, v24)

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

//! > Test loop with member path borrowing.

//! > test_runner_name
test_generated_function

//! > function
fn foo(mut a: A, ref b: A) {
    let c = 5_usize;
    loop {
        let mut h = 0;
        a.b.c = c;
        if true {
            h = 1;
            let mut x = 4;
            x = 5;
            b = A { b: a.b, x };
            break b;
        };
    };
}

//! > function_name
foo

//! > module_code
#[derive(Copy, Drop)]
struct A {
    b: B,
    x: felt252,
}
#[derive(Copy, Drop)]
struct B {
    c: usize,
    y: u128,
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters: v0: test::A, v1: test::A
blk0 (root):
Statements:
  (v2: core::integer::u32) <- 5
  (v3: test::B, v4: core::felt252) <- struct_destructure(v0)
  (v6: core::integer::u32, v7: test::A, v5: test::A) <- test::foo[expr26](v2, v3, v1)
  (v8: core::integer::u32, v9: core::integer::u128) <- struct_destructure(v3)
  (v10: ()) <- struct_construct()
End:
  Return(v7, v10)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: test::A, v3: test::A
blk0 (root):
Statements:
  (v4: core::integer::u32) <- 5
  (v5: test::B, v6: core::felt252) <- struct_destructure(v2)
  (v7: core::RangeCheck, v8: core::gas::GasBuiltin, v9: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- test::foo[expr26](v0, v1, v4, v5, v3)
End:
  Match(match_enum(v9) {
    PanicResult::Ok(v10) => blk1,
    PanicResult::Err(v11) => blk2,
  })

blk1:
Statements:
  (v12: core::integer::u32, v13: test::A, v14: test::A) <- struct_destructure(v10)
  (v15: ()) <- struct_construct()
  (v16: (test::A, ())) <- struct_construct(v13, v15)
  (v17: core::panics::PanicResult::<(test::A, ())>) <- PanicResult::Ok(v16)
End:
  Return(v7, v8, v17)

blk2:
Statements:
  (v18: core::panics::PanicResult::<(test::A, ())>) <- PanicResult::Err(v11)
End:
  Return(v7, v8, v18)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::integer::u32, v1: test::B, v2: test::A
blk0 (root):
Statements:
  (v3: core::felt252) <- 0
  (v4: core::integer::u32, v5: core::integer::u128) <- struct_destructure(v1)
  (v6: ()) <- struct_construct()
  (v7: core::bool) <- bool::True(v6)
End:
  Match(match_enum(v7) {
    bool::False(v16) => blk2,
    bool::True(v8) => blk1,
  })

blk1:
Statements:
  (v9: core::felt252) <- 1
  (v10: core::felt252) <- 4
  (v11: core::felt252) <- 5
  (v12: test::B) <- struct_construct(v0, v5)
  (v13: test::A) <- struct_construct(v12, v11)
  (v14: core::integer::u32, v15: core::integer::u128) <- struct_destructure(v12)
End:
  Return(v14, v13, v13)

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

blk3:
Statements:
  (v17: test::B) <- struct_construct(v0, v5)
  (v19: core::integer::u32, v20: test::A, v18: test::A) <- test::foo[expr26](v0, v17, v2)
  (v21: core::integer::u32, v22: core::integer::u128) <- struct_destructure(v17)
End:
  Return(v19, v20, v18)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::integer::u32, v3: test::B, v4: test::A
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v5, v6) => blk1,
    Option::None(v7, v8) => blk2,
  })

blk1:
Statements:
  (v9: core::integer::u32, v10: core::integer::u128) <- struct_destructure(v3)
  (v11: core::felt252) <- 5
  (v12: test::B) <- struct_construct(v2, v10)
  (v13: test::A) <- struct_construct(v12, v11)
  (v14: (core::integer::u32, test::A, test::A)) <- struct_construct(v2, v13, v13)
  (v15: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- PanicResult::Ok(v14)
End:
  Return(v5, v6, v15)

blk2:
Statements:
  (v16: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v17: core::felt252) <- 375233589013918064796019
  (v18: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v16, v17)
  (v19: core::panics::Panic) <- struct_construct()
  (v20: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v19, v18)
  (v21: core::panics::PanicResult::<(core::integer::u32, test::A, test::A)>) <- PanicResult::Err(v20)
End:
  Return(v7, v8, v21)

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

//! > Test loop with continue.

//! > test_runner_name
test_generated_function

//! > function
fn foo() -> bool {
    let mut x = 5;
    loop {
        let y = x + 1;
        x = y;
        if y == 7 {
            continue;
        }
        if y == 10 {
            break true;
        };
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 5
  (v2: core::felt252, v1: core::bool) <- test::foo[expr24](v0)
End:
  Return(v1)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::felt252) <- 5
  (v3: core::RangeCheck, v4: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v0, v1, v2)
End:
  Match(match_enum(v5) {
    PanicResult::Ok(v6) => blk1,
    PanicResult::Err(v7) => blk2,
  })

blk1:
Statements:
  (v8: core::felt252, v9: core::bool) <- struct_destructure(v6)
  (v10: (core::bool,)) <- struct_construct(v9)
  (v11: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Ok(v10)
End:
  Return(v3, v4, v11)

blk2:
Statements:
  (v12: core::panics::PanicResult::<(core::bool,)>) <- PanicResult::Err(v7)
End:
  Return(v3, v4, v12)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::felt252
blk0 (root):
Statements:
  (v1: core::felt252) <- 1
  (v2: core::felt252) <- core::Felt252Add::add(v0, v1)
  (v3: core::felt252, v4: @core::felt252) <- snapshot(v2)
  (v5: core::felt252) <- 7
  (v6: core::felt252, v7: @core::felt252) <- snapshot(v5)
  (v8: core::bool) <- core::Felt252PartialEq::eq(v4, v7)
End:
  Match(match_enum(v8) {
    bool::False(v12) => blk2,
    bool::True(v9) => blk1,
  })

blk1:
Statements:
  (v11: core::felt252, v10: core::bool) <- test::foo[expr24](v2)
End:
  Return(v11, v10)

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

blk3:
Statements:
  (v13: core::felt252, v14: @core::felt252) <- snapshot(v3)
  (v15: core::felt252) <- 10
  (v16: core::felt252, v17: @core::felt252) <- snapshot(v15)
  (v18: core::bool) <- core::Felt252PartialEq::eq(v14, v17)
End:
  Match(match_enum(v18) {
    bool::False(v22) => blk5,
    bool::True(v19) => blk4,
  })

blk4:
Statements:
  (v20: ()) <- struct_construct()
  (v21: core::bool) <- bool::True(v20)
End:
  Return(v2, v21)

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

blk6:
Statements:
  (v24: core::felt252, v23: core::bool) <- test::foo[expr24](v2)
End:
  Return(v24, v23)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk6,
  })

blk1:
Statements:
  (v7: core::felt252) <- 1
  (v8: core::felt252) <- core::felt252_add(v2, v7)
  (v9: core::felt252) <- 7
  (v10: core::felt252) <- core::felt252_sub(v8, v9)
End:
  Match(match core::felt252_is_zero(v10) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v11) => blk3,
  })

blk2:
Statements:
  (v12: core::RangeCheck, v13: core::gas::GasBuiltin, v14: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v3, v4, v8)
End:
  Return(v12, v13, v14)

blk3:
Statements:
  (v15: core::felt252) <- 10
  (v16: core::felt252) <- core::felt252_sub(v8, v15)
End:
  Match(match core::felt252_is_zero(v16) {
    IsZeroResult::Zero => blk4,
    IsZeroResult::NonZero(v17) => blk5,
  })

blk4:
Statements:
  (v18: ()) <- struct_construct()
  (v19: core::bool) <- bool::True(v18)
  (v20: (core::felt252, core::bool)) <- struct_construct(v8, v19)
  (v21: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Ok(v20)
End:
  Return(v3, v4, v21)

blk5:
Statements:
  (v22: core::RangeCheck, v23: core::gas::GasBuiltin, v24: core::panics::PanicResult::<(core::felt252, core::bool)>) <- test::foo[expr24](v3, v4, v8)
End:
  Return(v22, v23, v24)

blk6:
Statements:
  (v25: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v26: core::felt252) <- 375233589013918064796019
  (v27: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v25, v26)
  (v28: core::panics::Panic) <- struct_construct()
  (v29: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v28, v27)
  (v30: core::panics::PanicResult::<(core::felt252, core::bool)>) <- PanicResult::Err(v29)
End:
  Return(v5, v6, v30)

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

//! > Test loop with break;

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    loop {
        break;
    }
}

//! > function_name
foo

//! > module_code

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: ()) <- test::foo[expr1]()
End:
  Return(v0)


Final lowering:
Parameters:
blk0 (root):
Statements:
End:
  Return()


Generated loop lowering for source location:
    loop {
    ^****^

Parameters:
blk0 (root):
Statements:
  (v0: ()) <- struct_construct()
End:
  Return(v0)


Final lowering:
Parameters:
blk0 (root):
Statements:
End:
  Return()

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

//! > Change in block merge in loop.

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    let mut x = A { a: 3, b: 4 };
    loop {
        if (true) {
            x.a = 0;
        } else {
            x.a = 0;
        }

        if x.a == 0 {
            break;
        };
    };
}

//! > function_name
foo

//! > module_code
#[derive(Copy, Drop, Debug)]
struct A {
    a: u8,
    b: u8,
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u8) <- 3
  (v1: core::integer::u8) <- 4
  (v2: test::A) <- struct_construct(v0, v1)
  (v3: core::integer::u8, v4: core::integer::u8) <- struct_destructure(v2)
  (v6: core::integer::u8, v5: ()) <- test::foo[expr25](v3)
  (v7: ()) <- struct_construct()
End:
  Return(v7)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::integer::u8) <- 3
  (v3: core::RangeCheck, v4: core::gas::GasBuiltin, v5: core::panics::PanicResult::<(core::integer::u8, ())>) <- test::foo[expr25](v0, v1, v2)
End:
  Match(match_enum(v5) {
    PanicResult::Ok(v6) => blk1,
    PanicResult::Err(v7) => blk2,
  })

blk1:
Statements:
  (v8: ()) <- struct_construct()
  (v9: ((),)) <- struct_construct(v8)
  (v10: core::panics::PanicResult::<((),)>) <- PanicResult::Ok(v9)
End:
  Return(v3, v4, v10)

blk2:
Statements:
  (v11: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v7)
End:
  Return(v3, v4, v11)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::integer::u8
blk0 (root):
Statements:
  (v1: ()) <- struct_construct()
  (v2: core::bool) <- bool::True(v1)
End:
  Match(match_enum(v2) {
    bool::False(v5) => blk2,
    bool::True(v3) => blk1,
  })

blk1:
Statements:
  (v4: core::integer::u8) <- 0
End:
  Goto(blk3, {v4 -> v7})

blk2:
Statements:
  (v6: core::integer::u8) <- 0
End:
  Goto(blk3, {v6 -> v7})

blk3:
Statements:
  (v8: core::integer::u8, v9: @core::integer::u8) <- snapshot(v7)
  (v10: core::integer::u8) <- 0
  (v11: core::integer::u8, v12: @core::integer::u8) <- snapshot(v10)
  (v13: core::bool) <- core::integer::U8PartialEq::eq(v9, v12)
End:
  Match(match_enum(v13) {
    bool::False(v16) => blk5,
    bool::True(v14) => blk4,
  })

blk4:
Statements:
  (v15: ()) <- struct_construct()
End:
  Return(v8, v15)

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

blk6:
Statements:
  (v18: core::integer::u8, v17: ()) <- test::foo[expr25](v8)
End:
  Return(v18, v17)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::integer::u8
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v3, v4) => blk1,
    Option::None(v5, v6) => blk4,
  })

blk1:
Statements:
  (v7: core::integer::u8) <- 0
End:
  Match(match core::integer::u8_is_zero(v7) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v8) => blk3,
  })

blk2:
Statements:
  (v9: ()) <- struct_construct()
  (v10: (core::integer::u8, ())) <- struct_construct(v7, v9)
  (v11: core::panics::PanicResult::<(core::integer::u8, ())>) <- PanicResult::Ok(v10)
End:
  Return(v3, v4, v11)

blk3:
Statements:
  (v12: core::RangeCheck, v13: core::gas::GasBuiltin, v14: core::panics::PanicResult::<(core::integer::u8, ())>) <- test::foo[expr25](v3, v4, v7)
End:
  Return(v12, v13, v14)

blk4:
Statements:
  (v15: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v16: core::felt252) <- 375233589013918064796019
  (v17: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v15, v16)
  (v18: core::panics::Panic) <- struct_construct()
  (v19: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v18, v17)
  (v20: core::panics::PanicResult::<(core::integer::u8, ())>) <- PanicResult::Err(v19)
End:
  Return(v5, v6, v20)

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

//! > Test snap usage after loop.

//! > test_runner_name
test_generated_function

//! > function
fn foo() -> bool {
    let mut s = S {};
    loop {
        s.foo();
        break;
    };
    s.foo();
    false
}

//! > function_name
foo

//! > module_code
#[derive(Drop)]
struct S {}
trait T {
    fn foo(self: @S);
}
impl I of T {
    fn foo(self: @S) {}
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: test::S) <- struct_construct()
  (v1: test::S, v2: @test::S) <- snapshot(v0)
  (v3: ()) <- test::foo[expr5](v2)
  (v4: ()) <- test::I::foo(v2)
  (v5: ()) <- struct_construct()
  (v6: core::bool) <- bool::False(v5)
End:
  Return(v6)


Final lowering:
Parameters:
blk0 (root):
Statements:
  (v0: ()) <- struct_construct()
  (v1: core::bool) <- bool::False(v0)
End:
  Return(v1)


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: @test::S
blk0 (root):
Statements:
  (v1: ()) <- test::I::foo(v0)
  (v2: ()) <- struct_construct()
End:
  Return(v2)


Final lowering:
Parameters: v0: @test::S
blk0 (root):
Statements:
End:
  Return()

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

//! > Test snap usage after loop of member.

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    let t = T { s: S {} };
    loop {
        TT::f1oo(@t.s);
        break;
    };
    TT::f1oo(@t.s);
}

//! > function_name
foo

//! > module_code
#[derive(Drop)]
struct S {}
#[derive(Drop)]
struct T {
    s: S
}
trait TT {
    fn f1oo(self: @S);
}
impl STT of TT {
    fn f1oo(self: @S) {}
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: test::S) <- struct_construct()
  (v1: test::T) <- struct_construct(v0)
  (v2: test::S) <- struct_destructure(v1)
  (v3: test::S, v4: @test::S) <- snapshot(v2)
  (v5: ()) <- test::foo[expr7](v4)
  (v6: ()) <- test::STT::f1oo(v4)
  (v7: ()) <- struct_construct()
End:
  Return(v7)


Final lowering:
Parameters:
blk0 (root):
Statements:
End:
  Return()


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: @test::S
blk0 (root):
Statements:
  (v1: ()) <- test::STT::f1oo(v0)
  (v2: ()) <- struct_construct()
End:
  Return(v2)


Final lowering:
Parameters: v0: @test::S
blk0 (root):
Statements:
End:
  Return()

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

//! > Test real usage of inner with snap usage of outer.

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    let a = A { b: B { c: 3 } };
    loop {
        let _x = @a.b;
        ex1(_x);
        loop {
            let _y = a.b.c;
            ex(_y);
            break;
        };
        break;
    };
}

//! > function_name
foo

//! > module_code
extern fn ex(a: u32) nopanic;
extern fn ex1(a: @B) nopanic;
#[derive(Drop)]
struct B {
    c: u32
}
#[derive(Drop)]
struct A {
    b: B
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u32) <- 3
  (v1: test::B) <- struct_construct(v0)
  (v2: test::A) <- struct_construct(v1)
  (v3: test::B) <- struct_destructure(v2)
  (v4: test::B, v5: @test::B) <- snapshot(v3)
  (v6: core::integer::u32) <- struct_destructure(v4)
  (v7: test::B) <- struct_construct(v6)
  (v8: ()) <- test::foo[expr16](v6, v5)
  (v9: ()) <- struct_construct()
End:
  Return(v9)


Final lowering:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u32) <- 3
  (v1: test::B) <- struct_construct(v0)
  (v2: test::B, v3: @test::B) <- snapshot(v1)
  () <- test::ex1(v3)
  (v4: core::integer::u32) <- struct_destructure(v2)
  () <- test::ex(v4)
End:
  Return()


Generated loop lowering for source location:
        loop {
        ^****^

Parameters: v0: core::integer::u32
blk0 (root):
Statements:
  () <- test::ex(v0)
  (v1: ()) <- struct_construct()
End:
  Return(v1)


Final lowering:
Parameters: v0: core::integer::u32
blk0 (root):
Statements:
  () <- test::ex(v0)
End:
  Return()


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: core::integer::u32, v1: @test::B
blk0 (root):
Statements:
  () <- test::ex1(v1)
  (v2: ()) <- test::foo[expr14](v0)
  (v3: ()) <- struct_construct()
End:
  Return(v3)


Final lowering:
Parameters: v0: core::integer::u32, v1: @test::B
blk0 (root):
Statements:
  () <- test::ex1(v1)
  () <- test::ex(v0)
End:
  Return()

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

//! > Test snap usage of inner with real usage of outer.

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    let a = A { b: B { c: 3 } };
    loop {
        let _x = a.b;
        ex1(_x);
        loop {
            let _y = @a.b.c;
            ex(_y);
            break;
        };
        break;
    };
}

//! > function_name
foo

//! > module_code
extern fn ex(a: @u32) nopanic;
extern fn ex1(a: B) nopanic;
#[derive(Drop, Copy)]
struct B {
    c: u32
}
#[derive(Drop)]
struct A {
    b: B
}

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u32) <- 3
  (v1: test::B) <- struct_construct(v0)
  (v2: test::A) <- struct_construct(v1)
  (v3: test::B) <- struct_destructure(v2)
  (v4: ()) <- test::foo[expr16](v3)
  (v5: ()) <- struct_construct()
End:
  Return(v5)


Final lowering:
Parameters:
blk0 (root):
Statements:
  (v0: core::integer::u32) <- 3
  (v1: test::B) <- struct_construct(v0)
  () <- test::ex1(v1)
  (v2: core::integer::u32, v3: @core::integer::u32) <- snapshot(v0)
  () <- test::ex(v3)
End:
  Return()


Generated loop lowering for source location:
        loop {
        ^****^

Parameters: v0: @core::integer::u32
blk0 (root):
Statements:
  () <- test::ex(v0)
  (v1: ()) <- struct_construct()
End:
  Return(v1)


Final lowering:
Parameters: v0: @core::integer::u32
blk0 (root):
Statements:
  () <- test::ex(v0)
End:
  Return()


Generated loop lowering for source location:
    loop {
    ^****^

Parameters: v0: test::B
blk0 (root):
Statements:
  () <- test::ex1(v0)
  (v1: core::integer::u32) <- struct_destructure(v0)
  (v2: core::integer::u32, v3: @core::integer::u32) <- snapshot(v1)
  (v4: ()) <- test::foo[expr14](v3)
  (v5: ()) <- struct_construct()
End:
  Return(v5)


Final lowering:
Parameters: v0: test::B
blk0 (root):
Statements:
  () <- test::ex1(v0)
  (v1: core::integer::u32) <- struct_destructure(v0)
  (v2: core::integer::u32, v3: @core::integer::u32) <- snapshot(v1)
  () <- test::ex(v3)
End:
  Return()

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

//! > Test change usage of inner with snap usage of outer.

//! > test_runner_name
test_generated_function

//! > function
fn foo() {
    let mut a = A { x: 0 };
    let mut i = 0;
    while i != 5 {
        a.x = i;
        use_a(@a);
        i += 1;
    };
}

//! > function_name
foo

//! > module_code
#[derive(Drop)]
struct A {
    x: felt252,
}
extern fn use_a(a: @A) nopanic;

//! > semantic_diagnostics

//! > lowering_diagnostics

//! > lowering_flat
Parameters:

//! > lowering
Main:
Parameters:
blk0 (root):
Statements:
  (v0: core::felt252) <- 0
  (v1: test::A) <- struct_construct(v0)
  (v2: core::felt252) <- 0
  (v4: test::A, v5: core::felt252, v3: ()) <- test::foo[expr19](v2, v1)
  (v6: ()) <- struct_construct()
End:
  Return(v6)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin
blk0 (root):
Statements:
  (v2: core::felt252) <- 0
  (v3: core::felt252) <- 0
  (v4: test::A) <- struct_construct(v2)
  (v5: core::RangeCheck, v6: core::gas::GasBuiltin, v7: core::panics::PanicResult::<(test::A, core::felt252, ())>) <- test::foo[expr19](v0, v1, v3, v4)
End:
  Match(match_enum(v7) {
    PanicResult::Ok(v8) => blk1,
    PanicResult::Err(v9) => blk2,
  })

blk1:
Statements:
  (v10: ()) <- struct_construct()
  (v11: ((),)) <- struct_construct(v10)
  (v12: core::panics::PanicResult::<((),)>) <- PanicResult::Ok(v11)
End:
  Return(v5, v6, v12)

blk2:
Statements:
  (v13: core::panics::PanicResult::<((),)>) <- PanicResult::Err(v9)
End:
  Return(v5, v6, v13)


Generated loop lowering for source location:
    while i != 5 {
    ^************^

Parameters: v0: core::felt252, v1: test::A
blk0 (root):
Statements:
  (v2: core::felt252, v3: @core::felt252) <- snapshot(v0)
  (v4: core::felt252) <- 5
  (v5: core::felt252, v6: @core::felt252) <- snapshot(v4)
  (v7: core::bool) <- core::Felt252PartialEq::ne(v3, v6)
End:
  Match(match_enum(v7) {
    bool::False(v19) => blk2,
    bool::True(v8) => blk1,
  })

blk1:
Statements:
  (v9: core::felt252) <- struct_destructure(v1)
  (v10: test::A) <- struct_construct(v2)
  (v11: test::A, v12: @test::A) <- snapshot(v10)
  () <- test::use_a(v12)
  (v13: core::felt252) <- 1
  (v15: core::felt252, v14: ()) <- core::ops::arith::DeprecatedAddAssign::<core::felt252, core::Felt252AddEq>::add_assign(v2, v13)
  (v17: test::A, v18: core::felt252, v16: ()) <- test::foo[expr19](v15, v11)
End:
  Goto(blk3, {v17 -> v21, v18 -> v22, v16 -> v20})

blk2:
Statements:
  (v23: ()) <- struct_construct()
End:
  Goto(blk3, {v1 -> v21, v2 -> v22, v23 -> v20})

blk3:
Statements:
End:
  Return(v21, v22, v20)


Final lowering:
Parameters: v0: core::RangeCheck, v1: core::gas::GasBuiltin, v2: core::felt252, v3: test::A
blk0 (root):
Statements:
End:
  Match(match core::gas::withdraw_gas(v0, v1) {
    Option::Some(v4, v5) => blk1,
    Option::None(v6, v7) => blk4,
  })

blk1:
Statements:
  (v8: core::felt252) <- 5
  (v9: core::felt252) <- core::felt252_sub(v2, v8)
End:
  Match(match core::felt252_is_zero(v9) {
    IsZeroResult::Zero => blk2,
    IsZeroResult::NonZero(v10) => blk3,
  })

blk2:
Statements:
  (v11: ()) <- struct_construct()
  (v12: (test::A, core::felt252, ())) <- struct_construct(v3, v2, v11)
  (v13: core::panics::PanicResult::<(test::A, core::felt252, ())>) <- PanicResult::Ok(v12)
End:
  Return(v4, v5, v13)

blk3:
Statements:
  (v14: test::A) <- struct_construct(v2)
  (v15: test::A, v16: @test::A) <- snapshot(v14)
  () <- test::use_a(v16)
  (v17: core::felt252) <- 1
  (v18: core::felt252) <- core::felt252_add(v2, v17)
  (v19: core::RangeCheck, v20: core::gas::GasBuiltin, v21: core::panics::PanicResult::<(test::A, core::felt252, ())>) <- test::foo[expr19](v4, v5, v18, v15)
End:
  Return(v19, v20, v21)

blk4:
Statements:
  (v22: core::array::Array::<core::felt252>) <- core::array::array_new::<core::felt252>()
  (v23: core::felt252) <- 375233589013918064796019
  (v24: core::array::Array::<core::felt252>) <- core::array::array_append::<core::felt252>(v22, v23)
  (v25: core::panics::Panic) <- struct_construct()
  (v26: (core::panics::Panic, core::array::Array::<core::felt252>)) <- struct_construct(v25, v24)
  (v27: core::panics::PanicResult::<(test::A, core::felt252, ())>) <- PanicResult::Err(v26)
End:
  Return(v6, v7, v27)
