// File: /workspace/github_c_makefile_star2_O0/mbitsnbites[P]SoftFP/./softfp_template.h
// Function: roundpack_sf32
static F_UINT round_pack_sf(uint32_t a_sign, int a_exp, F_UINT a_mant,
                            RoundingModeEnum rm, uint32_t *pfflags)
{
    int diff;
    uint32_t addend, rnd_bits;

    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:
        //        printf("s=%d rm=%d m=%x\n", a_sign, rm, a_mant);
        if (a_sign ^ (rm & 1))
            addend = (1 << RND_SIZE) - 1;
        else
            addend = 0;
        break;
    }

    /* potentially subnormal */
    if (a_exp <= 0) {
        BOOL is_subnormal;
        /* Note: we set the underflow flag if the rounded result
           is subnormal and inexact */
        is_subnormal = (a_exp < 0 || 
                        (a_mant + addend) < ((F_UINT)1 << (F_SIZE - 1)));
        diff = 1 - a_exp;
        a_mant = rshift_rnd(a_mant, diff);
        rnd_bits = a_mant & ((1 << RND_SIZE ) - 1);
        if (is_subnormal && rnd_bits != 0) {
            *pfflags |= FFLAG_UNDERFLOW;
        }
        a_exp = 1;
    } else {
        rnd_bits = a_mant & ((1 << RND_SIZE ) - 1);
    }
    if (rnd_bits != 0)
        *pfflags |= FFLAG_INEXACT;
    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;
    /* Note the rounding adds at least 1, so this is the maximum
       value */
    a_exp += a_mant >> (MANT_SIZE + 1);
    if (a_mant <= MANT_MASK) {
        /* denormalized or zero */
        a_exp = 0;
    } else if (a_exp >= EXP_MASK) {
        /* overflow */
        if (addend == 0) {
            a_exp = EXP_MASK - 1;
            a_mant = MANT_MASK;
        } else {
            /* infinity */
            a_exp = EXP_MASK;
            a_mant = 0;
        }
        *pfflags |= FFLAG_OVERFLOW | FFLAG_INEXACT;
    }
    return pack_sf(a_sign, a_exp, a_mant);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movl %esi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movq %r8, -0x18(%rbp)
movl -0x10(%rbp), %eax
movq %rax, -0x30(%rbp)
subq $0x4, %rax
ja 0x10a4b
movq -0x30(%rbp), %rax
leaq 0x14b58(%rip), %rcx     # 0x25588
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x40, -0x20(%rbp)
jmp 0x10a6f
movl $0x0, -0x20(%rbp)
jmp 0x10a6f
jmp 0x10a4d
movl -0x4(%rbp), %eax
movl -0x10(%rbp), %ecx
andl $0x1, %ecx
xorl %ecx, %eax
cmpl $0x0, %eax
je 0x10a66
movl $0x7f, -0x20(%rbp)
jmp 0x10a6d
movl $0x0, -0x20(%rbp)
jmp 0x10a6f
cmpl $0x0, -0x8(%rbp)
jg 0x10ade
movb $0x1, %al
cmpl $0x0, -0x8(%rbp)
movb %al, -0x31(%rbp)
jl 0x10a91
movl -0xc(%rbp), %eax
addl -0x20(%rbp), %eax
cmpl $0x80000000, %eax       # imm = 0x80000000
setb %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movl $0x1, %eax
subl -0x8(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0xc(%rbp), %edi
movl -0x1c(%rbp), %esi
callq 0x6e50
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x28(%rbp)
je 0x10ad5
cmpl $0x0, -0x24(%rbp)
je 0x10ad5
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movl $0x1, -0x8(%rbp)
jmp 0x10ae7
movl -0xc(%rbp), %eax
andl $0x7f, %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x10af8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movl -0xc(%rbp), %eax
addl -0x20(%rbp), %eax
shrl $0x7, %eax
movl %eax, -0xc(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x10b19
cmpl $0x40, -0x24(%rbp)
jne 0x10b19
movl -0xc(%rbp), %eax
andl $-0x2, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %eax
shrl $0x18, %eax
addl -0x8(%rbp), %eax
movl %eax, -0x8(%rbp)
cmpl $0x7fffff, -0xc(%rbp)   # imm = 0x7FFFFF
ja 0x10b37
movl $0x0, -0x8(%rbp)
jmp 0x10b71
cmpl $0xff, -0x8(%rbp)
jl 0x10b6f
cmpl $0x0, -0x20(%rbp)
jne 0x10b56
movl $0xfe, -0x8(%rbp)
movl $0x7fffff, -0xc(%rbp)   # imm = 0x7FFFFF
jmp 0x10b64
movl $0xff, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
orl $0x5, %ecx
movl %ecx, (%rax)
jmp 0x10b71
movl -0x4(%rbp), %edi
movl -0x8(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x7160
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)