# The census of loop_exits_gcc_x64_O2: what `aa; pdd` renders for each function `afl` lists.
# Regenerate with `scripts/census.py golden` when `afl` moves, then bless.

NAME=afl
FILE=tests/fixtures/loop_exits_gcc_x64_O2
CMDS=afl
EXPECT=<<EOF
0x00401000    1     51 sym.main
0x00401040    8     76 sym.find_then_choose
0x004010a0   10     81 sym.skip_then_find
EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x00401000
FILE=tests/fixtures/loop_exits_gcc_x64_O2
CMDS=aa; pdd @ 0x00401000
EXPECT=<<EOF
uint32_t fcn_401000(void)
{
    uint64_t find_then_choose(uint64_t, uint32_t, uint32_t);
    uint64_t skip_then_find(uint64_t, uint32_t, uint32_t);

    uint64_t rax_1;
    uint64_t rax_2;

    /* r2dec proof: no individual construct is marked; 33 source obligations: 23 rendered, 10 elided, 0 refused; 3 statements rendered */
    /* symbol `main`; C allows that name no other prototype */
    {
        rax_1 = find_then_choose(0x402000, 98, 1);
        rax_2 = skip_then_find(0x402004, 120, 4);
        return (uint32_t)((uint32_t)((uint64_t)rax_1 >> 0U) + (uint32_t)((uint64_t)rax_2 >> 0U));
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x00401040
FILE=tests/fixtures/loop_exits_gcc_x64_O2
CMDS=aa; pdd @ 0x00401040
EXPECT=<<EOF
uint64_t find_then_choose(uint64_t arg0, uint32_t arg1, uint32_t arg2)
{
    extern char sink[];

    uint64_t rdi_1;
    uint8_t tmp_40105e_0_1;
    uint32_t tmp_lane_40105e_1_0_1;

    /* r2dec proof: no individual construct is marked; 44 source obligations: 34 rendered, 10 elided, 0 refused; 16 statements rendered; 1 data object type refused */
    {
        rdi_1 = arg0;
        for (; ; ) {
            tmp_40105e_0_1 = r2sleigh_load_u8((void*)rdi_1);
            tmp_lane_40105e_1_0_1 = (uint32_t)(int8_t)tmp_40105e_0_1;
            if ((uint8_t)((uint8_t)tmp_40105e_0_1 != (uint8_t)0U)) {
                r2sleigh_store_u32((void*)&sink, (uint32_t)tmp_lane_40105e_1_0_1);
                if ((uint8_t)((uint32_t)tmp_lane_40105e_1_0_1 == (uint32_t)arg1)) {
                    if ((uint8_t)((uint32_t)arg2 == (uint32_t)0U)) {
                        r2sleigh_store_u32((void*)&sink, (uint32_t)2U);
                        return 20;
                    } else {
                        r2sleigh_store_u32((void*)&sink, (uint32_t)1U);
                        return 10;
                    }
                } else {
                    rdi_1 = (uint64_t)((uint64_t)rdi_1 + (uint64_t)1U);
                }
            } else {
                break;
            }
        }
        {
            r2sleigh_store_u32((void*)&sink, (uint32_t)3U);
            return 0;
        }
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x004010a0
FILE=tests/fixtures/loop_exits_gcc_x64_O2
CMDS=aa; pdd @ 0x004010a0
EXPECT=<<EOF
uint64_t skip_then_find(uint64_t arg0, uint32_t arg1, uint32_t arg2)
{
    extern char sink[];

    uint64_t rcx_2;
    uint64_t rdi_1;
    uint8_t tmp_4010bb_0_1;
    uint64_t rax_1;
    uint64_t rax_3;
    uint64_t rdx_2;
    uint32_t tmp_lane_4010e2_2_0_1;
    uint8_t tmp_4010d0_8_1;
    uint32_t tmp_lane_4010b0_6_0_1;

    /* r2dec proof: no individual construct is marked; 79 source obligations: 69 rendered, 10 elided, 0 refused; 26 statements rendered; 1 data object type refused */
    {
        rcx_2 = 0;
        rdi_1 = arg0;
        for (; ; ) {
            tmp_4010bb_0_1 = r2sleigh_load_u8((void*)rdi_1);
            rax_1 = (uint64_t)(uint32_t)(int8_t)tmp_4010bb_0_1;
            if ((uint8_t)((uint8_t)tmp_4010bb_0_1 == (uint8_t)32U)) {
                tmp_lane_4010b0_6_0_1 = (uint32_t)((uint32_t)((uint64_t)rcx_2 >> 0U) + (uint32_t)1U);
                if ((uint8_t)((int32_t)arg2 < (int32_t)tmp_lane_4010b0_6_0_1)) {
                    r2sleigh_store_u32((void*)&sink, (uint32_t)tmp_lane_4010b0_6_0_1);
                    return (uint64_t)0xffffffffU;
                } else {
                    rcx_2 = (uint64_t)(uint32_t)tmp_lane_4010b0_6_0_1;
                    rdi_1 = (uint64_t)((uint64_t)rdi_1 + (uint64_t)1U);
                }
            } else {
                break;
            }
        }
        {
            if ((uint8_t)((uint8_t)tmp_4010bb_0_1 == (uint8_t)0U)) {
            } else {
                rax_3 = rax_1;
                rdx_2 = rdi_1;
                while ((uint8_t)((uint32_t)((uint64_t)rax_3 >> 0U) != (uint32_t)arg1)) {
                    tmp_4010d0_8_1 = r2sleigh_load_u8((void*)(uint64_t)((uint64_t)rdx_2 + (uint64_t)1U));
                    if ((uint8_t)((uint8_t)tmp_4010d0_8_1 == (uint8_t)0U)) {
                        return 0;
                    } else {
                        rax_3 = (uint64_t)(uint32_t)(int8_t)tmp_4010d0_8_1;
                        rdx_2 = (uint64_t)((uint64_t)rdx_2 + (uint64_t)1U);
                    }
                }
                {
                    tmp_lane_4010e2_2_0_1 = (uint32_t)((uint64_t)((uint64_t)(uint32_t)((uint32_t)((uint64_t)rcx_2 >> 0U) - (uint32_t)((uint64_t)rdi_1 >> 0U)) + (uint64_t)rdx_2) >> 0U);
                    r2sleigh_store_u32((void*)&sink, (uint32_t)tmp_lane_4010e2_2_0_1);
                    return (uint64_t)(uint32_t)((uint32_t)tmp_lane_4010e2_2_0_1 + (uint32_t)100U);
                }
            }
            {
                return 0;
            }
        }
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN
