// File: /workspace/github_c_makefile_star2_O0/mbitsnbites[P]SoftFP/./softfp_template_icvt.h
// Function: internal_cvt_sf32_i32
static ICVT_INT glue(glue(glue(internal_cvt_sf, F_SIZE), _i), ICVT_SIZE)(F_UINT a, RoundingModeEnum rm,
                                                                         uint32_t *pfflags, BOOL is_unsigned)
{
    uint32_t a_sign, addend, rnd_bits;
    int32_t a_exp;
    F_UINT a_mant;
    ICVT_UINT r, r_max;

    a_sign = a >> (F_SIZE - 1);
    a_exp = (a >> MANT_SIZE) & EXP_MASK;
    a_mant = a & MANT_MASK;
    if (a_exp == EXP_MASK && a_mant != 0)
        a_sign = 0; /* NaN is like +infinity */
    if (a_exp == 0) {
        a_exp = 1;
    } else {
        a_mant |= (F_UINT)1 << MANT_SIZE;
    }
    a_mant <<= RND_SIZE;
    a_exp = a_exp - (EXP_MASK / 2) - MANT_SIZE;

    if (is_unsigned)
        r_max = (ICVT_UINT)a_sign - 1;
    else
        r_max = ((ICVT_UINT)1 << (ICVT_SIZE - 1)) - (ICVT_UINT)(a_sign ^ 1);
    if (a_exp >= 0) {
        if (a_exp <= (ICVT_SIZE - 1 - MANT_SIZE)) {
            r = (ICVT_UINT)(a_mant >> RND_SIZE) << a_exp;
            if (r > r_max)
                goto overflow;
        } else {
        overflow:
            *pfflags |= FFLAG_INVALID_OP;
            return r_max;
        }
    } else {
        a_mant = rshift_rnd(a_mant, -a_exp);

        switch(rm) {
        case RM_RNE:
        case RM_RMM:
            addend = (1 << (RND_SIZE - 1));
            break;
        case RM_RTZ:
            addend = 0;
            break;
        default:
        case RM_RDN:
        case RM_RUP:
            if (a_sign ^ (rm & 1))
                addend = (1 << RND_SIZE) - 1;
            else
                addend = 0;
            break;
        }
        
        rnd_bits = a_mant & ((1 << RND_SIZE ) - 1);
        a_mant = (a_mant + addend) >> RND_SIZE;
        /* half way: select even result */
        if (rm == RM_RNE && rnd_bits == (1 << (RND_SIZE - 1)))
            a_mant &= ~1;
        if (a_mant > r_max)
            goto overflow;
        r = a_mant;
        if (rnd_bits != 0)
            *pfflags |= FFLAG_INEXACT;
    }
    if (a_sign)
        r = -r;
    return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl -0x8(%rbp), %eax
shrl $0x1f, %eax
movl %eax, -0x20(%rbp)
movl -0x8(%rbp), %eax
shrl $0x17, %eax
andl $0xff, %eax
movl %eax, -0x2c(%rbp)
movl -0x8(%rbp), %eax
andl $0x7fffff, %eax         # imm = 0x7FFFFF
movl %eax, -0x30(%rbp)
cmpl $0xff, -0x2c(%rbp)
jne 0x822d
cmpl $0x0, -0x30(%rbp)
je 0x822d
movl $0x0, -0x20(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x823c
movl $0x1, -0x2c(%rbp)
jmp 0x8247
movl -0x30(%rbp), %eax
orl $0x800000, %eax         # imm = 0x800000
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
shll $0x7, %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
subl $0x7f, %eax
subl $0x17, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x1c(%rbp)
je 0x826d
movl -0x20(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x827d
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
movl $0x80000000, %eax       # imm = 0x80000000
subl %ecx, %eax
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x2c(%rbp)
jl 0x82c0
cmpl $0x8, -0x2c(%rbp)
jg 0x82a3
movl -0x30(%rbp), %eax
shrl $0x7, %eax
movl -0x2c(%rbp), %ecx
shll %cl, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jbe 0x82a1
jmp 0x82a5
jmp 0x82bb
jmp 0x82a5
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x10, %ecx
movl %ecx, (%rax)
movl -0x38(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x838b
jmp 0x8377
movl -0x30(%rbp), %edi
movl -0x2c(%rbp), %esi
negl %esi
callq 0x6e50
movl %eax, -0x30(%rbp)
movl -0xc(%rbp), %eax
movq %rax, -0x40(%rbp)
subq $0x4, %rax
ja 0x8303
movq -0x40(%rbp), %rax
leaq 0x1d1ec(%rip), %rcx     # 0x254d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x40, -0x24(%rbp)
jmp 0x8327
movl $0x0, -0x24(%rbp)
jmp 0x8327
jmp 0x8305
movl -0x20(%rbp), %eax
movl -0xc(%rbp), %ecx
andl $0x1, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x831e
movl $0x7f, -0x24(%rbp)
jmp 0x8325
movl $0x0, -0x24(%rbp)
jmp 0x8327
movl -0x30(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl -0x24(%rbp), %eax
shrl $0x7, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0xc(%rbp)
jne 0x8351
cmpl $0x40, -0x28(%rbp)
jne 0x8351
movl -0x30(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jbe 0x835e
jmp 0x82a5
movl -0x30(%rbp), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x8375
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x8377
cmpl $0x0, -0x20(%rbp)
je 0x8385
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)