# The census of float_calls_zig_x86_64_O2g: 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/float_calls_zig_x86_64_O2g
CMDS=afl
EXPECT=<<EOF
0x010014e0    1     42 sym._start
0x01001510    1     14 sym.store
0x01001520    1     18 sym.call_store
0x01001540    1     46 sym.forward
0x01001570    1     43 sym.main
0x010015a0    4    102 sym.__libc_csu_init
0x01001610    1      6 sym.__libc_csu_fini
EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x010014e0
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x010014e0
EXPECT=<<EOF
void _start(void)
{
    uint64_t tmp_10014e5_0_2;

    /* r2dec proof: 5 constructs are marked below; 27 source obligations: 0 rendered, 5 elided, 0 refused, 22 residual; 1 statements rendered; 1 held from entry, read as residuals (stack_p0) */
    {
        tmp_10014e5_0_2 = r2sleigh_residual_u64(1);
        r2sleigh_residual_void(2); /* r2dec gap: StoreNotSpelled at 0x10014e0:29 covering 1 op (render::values) */
        r2sleigh_residual_void(3); /* r2dec gap: StoreNotSpelled at 0x10014e0:32 covering 1 op (render::values) */
        r2sleigh_residual_void(4); /* r2dec gap: CallNotRendered at 0x10014e0:46 covering 1 op (render::values): call to __libc_start_main: the import's declaration has an argument this convention does not place */
        r2sleigh_residual_void(5); /* r2dec gap: TransferNotFollowed at 0x10014e0 (render::control) */
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x01001510
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x01001510
EXPECT=<<EOF
void store(double x, double* p)
{
    /* r2dec proof: no individual construct is marked; 9 source obligations: 3 rendered, 6 elided, 0 refused; 2 statements rendered */
    {
        r2sleigh_store_u64((void*)(uint64_t)p, (uint64_t)r2sleigh_float_to_bits_64(x + x));
        return;
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x01001520
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x01001520
EXPECT=<<EOF
void call_store(double* p)
{
    void store(double, double*);

    /* r2dec proof: no individual construct is marked; 6 source obligations: 4 rendered, 2 elided, 0 refused; 2 statements rendered; 1 callee prototype supplied by the source */
    {
        store(r2sleigh_float_from_bits_64((uint64_t)0x3ff4000000000000U), p);
        return;
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x01001540
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x01001540
EXPECT=<<EOF
void forward(double x, double* p)
{
    void store(double, double*);

    /* r2dec proof: no individual construct is marked; 16 source obligations: 9 rendered, 7 elided, 0 refused; 3 statements rendered; 2 callee prototypes supplied by the source */
    {
        store(x, p);
        store(x + r2sleigh_float_from_bits_64((uint64_t)0x3ff0000000000000U), p);
        return;
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x01001570
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x01001570
EXPECT=<<EOF
int32_t main(int32_t argc, char** argv)
{
    void call_store(double*);
    void forward(double, double*);

    uint64_t tmp_1001582_8_1;
    uint64_t tmp_100158f_18_1;
    uint64_t tmp_100158f_18_2;
    uint8_t tmp_100158f_22_1;
    uint64_t tmp_100158f_18_3;
    double tmp_100158f_2b_1;
    uint64_t tmp_100158f_23_2;
    _Alignas(16) uint8_t frame[40];

    /* r2dec proof: 2 constructs are marked below; 50 source obligations: 29 rendered, 18 elided, 0 refused, 3 residual; 11 statements rendered; 1 held from entry, read as residuals (RAX_0); 2 callee prototypes supplied by the source */
    {
        r2sleigh_store_u64((void*)(uint64_t)(frame + 16U), (uint64_t)r2sleigh_residual_u64(1));
        call_store((double*)(uint64_t)(frame + 16U));
        tmp_1001582_8_1 = r2sleigh_load_u64((void*)(uint64_t)(frame + 16U));
        forward(r2sleigh_float_from_bits_64(tmp_1001582_8_1), (double*)(uint64_t)(frame + 16U));
        tmp_100158f_18_1 = r2sleigh_load_u64((void*)(uint64_t)(frame + 16U));
        tmp_100158f_18_2 = r2sleigh_load_u64((void*)(uint64_t)(frame + 16U));
        tmp_100158f_22_1 = (uint8_t)((uint32_t)(uint8_t)((double)(int64_t)0xffffffff7fffffffU < r2sleigh_float_from_bits_64(tmp_100158f_18_1)) & (uint32_t)(uint8_t)(r2sleigh_float_from_bits_64(tmp_100158f_18_2) < (double)(int64_t)0x80000000U));
        tmp_100158f_18_3 = r2sleigh_load_u64((void*)(uint64_t)(frame + 16U));
        tmp_100158f_2b_1 = (double)(int32_t)0U;
        tmp_100158f_23_2 = tmp_100158f_22_1 ? (uint64_t)tmp_100158f_18_3 : (uint64_t)r2sleigh_float_to_bits_64(tmp_100158f_2b_1);
        return (int32_t)((uint32_t)(r2sleigh_float_from_bits_64(tmp_100158f_23_2) > -2147483649.0 && r2sleigh_float_from_bits_64(tmp_100158f_23_2) < 2147483648.0 ? (int32_t)r2sleigh_float_from_bits_64(tmp_100158f_23_2) : r2sleigh_residual_i32(2)) | (uint32_t)((uint32_t)(uint8_t)((uint32_t)tmp_100158f_22_1 ^ (uint32_t)(uint8_t)1U) * (uint32_t)0x80000000U));
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x010015a0
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x010015a0
EXPECT=<<EOF
void __libc_csu_init(int32_t argc, char** argv, char** envp)
{
    /* r2dec proof: no individual construct is marked; 26 source obligations: 2 rendered, 24 elided, 0 refused; 1 statements rendered */
    {
        {
            return;
        }
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN

NAME=0x01001610
FILE=tests/fixtures/float_calls_zig_x86_64_O2g
CMDS=aa; pdd @ 0x01001610
EXPECT=<<EOF
void __libc_csu_fini(void)
{
    /* r2dec proof: no individual construct is marked; 7 source obligations: 1 rendered, 6 elided, 0 refused; 1 statements rendered */
    {
        return;
    }
}

EOF
EXPECT_ERR=<<EOF
EOF
RUN
