// File: /workspace/github_c_makefile_star2_O1/mbitsnbites[P]SoftFP/./softfp_template.h
// Function: roundpack_sf64
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:
movl %ecx, %r9d
movl $0x200, %eax            # imm = 0x200
xorl %r10d, %r10d
testl %ecx, %ecx
je 0x9812
cmpl $0x4, %r9d
je 0x9812
cmpl $0x1, %r9d
jne 0x97fb
movb $0x1, %r10b
xorl %eax, %eax
jmp 0x9812
movl %r9d, %eax
andl $0x1, %eax
xorl %ecx, %ecx
cmpl %edi, %eax
sete %r10b
movl $0x3ff, %eax            # imm = 0x3FF
cmoveq %rcx, %rax
pushq %rbx
testl %esi, %esi
jle 0x9823
movl %edx, %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
movl %esi, %esi
jmp 0x9885
setne %cl
movq %rax, %r11
addq %rdx, %r11
setns %r11b
orb %cl, %r11b
cmpl $-0x3f, %esi
jg 0x9842
xorl %ecx, %ecx
testq %rdx, %rdx
setne %cl
jmp 0x9865
movb $0x1, %cl
subb %sil, %cl
movq $-0x1, %rsi
shlq %cl, %rsi
notq %rsi
movq %rdx, %rbx
shrq %cl, %rbx
xorl %ecx, %ecx
testq %rdx, %rsi
setne %cl
orq %rbx, %rcx
movq %rcx, %rdx
movl %edx, %ebx
andl $0x3ff, %ebx            # imm = 0x3FF
setne %cl
andb %cl, %r11b
movl $0x1, %esi
cmpb $0x1, %r11b
jne 0x9885
orb $0x2, (%r8)
testl %ebx, %ebx
je 0x988d
orb $0x1, (%r8)
movabsq $0xfffffffffffff, %rcx  # imm = 0xFFFFFFFFFFFFF
addq %rax, %rdx
shrq $0xa, %rdx
xorl $0x200, %ebx            # imm = 0x200
movq %rdx, %rax
andq $-0x2, %rax
orl %ebx, %r9d
cmovneq %rdx, %rax
leaq 0x1(%rcx), %rdx
cmpq %rdx, %rax
popq %rbx
jae 0x98c0
xorl %edx, %edx
jmp 0x98ea
movq %rax, %rdx
shrq $0x35, %rdx
addq %rsi, %rdx
cmpl $0x7ff, %edx            # imm = 0x7FF
jl 0x98ea
xorl %eax, %eax
testb %r10b, %r10b
cmovneq %rcx, %rax
movzbl %r10b, %edx
xorq $0x7ff, %rdx            # imm = 0x7FF
orb $0x5, (%r8)
shlq $0x3f, %rdi
shlq $0x34, %rdx
andq %rcx, %rax
orq %rdi, %rax
orq %rdx, %rax
retq