// File: /workspace/github_c_makefile_star2_O3/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 0x98a8
cmpl $0x4, %r9d
je 0x98a8
cmpl $0x1, %r9d
jne 0x9891
movb $0x1, %r10b
xorl %eax, %eax
jmp 0x98a8
movl %r9d, %eax
andl $0x1, %eax
xorl %ecx, %ecx
cmpl %edi, %eax
sete %r10b
movl $0x3ff, %eax            # imm = 0x3FF
cmoveq %rcx, %rax
testl %esi, %esi
jle 0x98ba
movl %edx, %r11d
andl $0x3ff, %r11d           # imm = 0x3FF
movl %esi, %ecx
jmp 0x9927
pushq %rbx
setne %cl
movq %rax, %r11
addq %rdx, %r11
setns %bl
orb %cl, %bl
movl $0x1, %ecx
subl %esi, %ecx
cmpl $0x40, %ecx
jb 0x98df
xorl %ecx, %ecx
testq %rdx, %rdx
setne %cl
jmp 0x98fd
movq $-0x1, %rsi
shlq %cl, %rsi
notq %rsi
movq %rdx, %r11
shrq %cl, %r11
xorl %ecx, %ecx
testq %rdx, %rsi
setne %cl
orq %r11, %rcx
movq %rcx, %rdx
movl %edx, %r11d
andl $0x3ff, %r11d           # imm = 0x3FF
setne %cl
andb %cl, %bl
movl $0x1, %ecx
cmpb $0x1, %bl
popq %rbx
jne 0x9927
movl (%r8), %esi
orl $0x2, %esi
movl $0x1, %ecx
jmp 0x992f
testl %r11d, %r11d
je 0x9942
movl (%r8), %esi
orl $0x1, %esi
movl %esi, (%r8)
cmpl $0x200, %r11d           # imm = 0x200
sete %r11b
jmp 0x9945
xorl %r11d, %r11d
movabsq $0xfffffffffffff, %rsi  # imm = 0xFFFFFFFFFFFFF
addq %rax, %rdx
shrq $0xa, %rdx
movq %rdx, %rax
andq $-0x2, %rax
testb %r11b, %r11b
cmoveq %rdx, %rax
testl %r9d, %r9d
cmovneq %rdx, %rax
leaq 0x1(%rsi), %rdx
cmpq %rdx, %rax
jae 0x9978
xorl %edx, %edx
jmp 0x99a2
movq %rax, %rdx
shrq $0x35, %rdx
addq %rcx, %rdx
cmpl $0x7ff, %edx            # imm = 0x7FF
jl 0x99a2
xorl %eax, %eax
testb %r10b, %r10b
cmovneq %rsi, %rax
movzbl %r10b, %edx
xorq $0x7ff, %rdx            # imm = 0x7FF
orb $0x5, (%r8)
shlq $0x3f, %rdi
shlq $0x34, %rdx
andq %rsi, %rax
orq %rdi, %rax
orq %rdx, %rax
retq