// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r8, %r14
movl %ecx, %ebp
movl %edi, %ebx
movl $0x200, %r12d           # imm = 0x200
xorl %r15d, %r15d
testl %ecx, %ecx
je 0x8d7c
cmpl $0x4, %ebp
je 0x8d7c
cmpl $0x1, %ebp
jne 0x8d65
movb $0x1, %r15b
xorl %r12d, %r12d
jmp 0x8d7c
movl %ebp, %eax
andl $0x1, %eax
xorl %ecx, %ecx
cmpl %ebx, %eax
sete %r15b
movl $0x3ff, %r12d           # imm = 0x3FF
cmoveq %rcx, %r12
testl %esi, %esi
jle 0x8d8b
movl %edx, %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %esi, %ecx
jmp 0x8dcb
setne %al
movq %r12, %rcx
addq %rdx, %rcx
setns %r13b
orb %al, %r13b
pushq $0x1
popq %rax
subl %esi, %eax
movq %rdx, %rdi
movl %eax, %esi
callq 0x59ff
movq %rax, %rdx
andl $0x3ff, %eax            # imm = 0x3FF
setne %cl
andb %r13b, %cl
cmpb $0x1, %cl
jne 0x8dc8
movl (%r14), %esi
orl $0x2, %esi
pushq $0x1
popq %rcx
jmp 0x8dd2
pushq $0x1
popq %rcx
testl %eax, %eax
je 0x8de3
movl (%r14), %esi
orl $0x1, %esi
movl %esi, (%r14)
cmpl $0x200, %eax            # imm = 0x200
sete %dil
jmp 0x8de5
xorl %edi, %edi
movabsq $0xfffffffffffff, %rsi  # imm = 0xFFFFFFFFFFFFF
addq %r12, %rdx
shrq $0xa, %rdx
movq %rdx, %rax
andq $-0x2, %rax
testb %dil, %dil
cmoveq %rdx, %rax
testl %ebp, %ebp
cmovneq %rdx, %rax
leaq 0x1(%rsi), %rdx
cmpq %rdx, %rax
jae 0x8e17
xorl %edx, %edx
jmp 0x8e41
movq %rax, %rdx
shrq $0x35, %rdx
addq %rcx, %rdx
cmpl $0x7ff, %edx            # imm = 0x7FF
jl 0x8e41
xorl %eax, %eax
testb %r15b, %r15b
cmovneq %rsi, %rax
movzbl %r15b, %edx
xorq $0x7ff, %rdx            # imm = 0x7FF
orb $0x5, (%r14)
shlq $0x3f, %rbx
shlq $0x34, %rdx
andq %rsi, %rax
orq %rbx, %rax
orq %rdx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq