// File: /workspace/github_c_makefile_star2_O3/mbitsnbites[P]SoftFP/softfloat.c
// Function: roundAndPackFloat64
static float64 roundAndPackFloat64(flag zSign, int_fast16_t zExp, uint64_t zSig,
                                   float_status *status)
{
    int8 roundingMode;
    flag roundNearestEven;
    int_fast16_t roundIncrement, roundBits;
    flag isTiny;

    roundingMode = status->float_rounding_mode;
    roundNearestEven = ( roundingMode == float_round_nearest_even );
    switch (roundingMode) {
    case float_round_nearest_even:
    case float_round_ties_away:
        roundIncrement = 0x200;
        break;
    case float_round_to_zero:
        roundIncrement = 0;
        break;
    case float_round_up:
        roundIncrement = zSign ? 0 : 0x3ff;
        break;
    case float_round_down:
        roundIncrement = zSign ? 0x3ff : 0;
        break;
    default:
        abort();
    }
    roundBits = zSig & 0x3FF;
    if ( 0x7FD <= (uint16_t) zExp ) {
        if (    ( 0x7FD < zExp )
             || (    ( zExp == 0x7FD )
                  && ( (int64_t) ( zSig + roundIncrement ) < 0 ) )
           ) {
            float_raise(float_flag_overflow | float_flag_inexact, status);
            return packFloat64( zSign, 0x7FF, - ( roundIncrement == 0 ));
        }
        if ( zExp < 0 ) {
            if (status->flush_to_zero) {
                float_raise(float_flag_output_denormal, status);
                return packFloat64(zSign, 0, 0);
            }
            isTiny =
                   (status->float_detect_tininess
                    == float_tininess_before_rounding)
                || ( zExp < -1 )
                || ( zSig + roundIncrement < LIT64( 0x8000000000000000 ) );
            shift64RightJamming( zSig, - zExp, &zSig );
            zExp = 0;
            roundBits = zSig & 0x3FF;
            if (isTiny && roundBits) {
                float_raise(float_flag_underflow, status);
            }
        }
    }
    if (roundBits) {
        status->float_exception_flags |= float_flag_inexact;
    }
    zSig = ( zSig + roundIncrement )>>10;
    zSig &= ~ ( ( ( roundBits ^ 0x200 ) == 0 ) & roundNearestEven );
    if ( zSig == 0 ) zExp = 0;
    return packFloat64( zSign, zExp, zSig );

}

// Assembly:
pushq %rbx
movzbl 0x1(%rcx), %r8d
cmpq $0x4, %r8
ja 0xa3e1
movq %rcx, %rax
leaq 0xc51b(%rip), %rcx      # 0x16794
movslq (%rcx,%r8,4), %r9
addq %rcx, %r9
jmpq *%r9
movl $0x200, %r9d            # imm = 0x200
jmp 0xa2b0
xorl %r9d, %r9d
jmp 0xa2b0
xorl %ecx, %ecx
testb %dil, %dil
movl $0x3ff, %r9d            # imm = 0x3FF
cmoveq %rcx, %r9
jmp 0xa2b0
xorl %ecx, %ecx
testb %dil, %dil
movl $0x3ff, %r9d            # imm = 0x3FF
cmovneq %rcx, %r9
movl %edx, %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movzwl %si, %r10d
cmpl $0x7fd, %r10d           # imm = 0x7FD
jb 0xa308
cmpq $0x7fd, %rsi            # imm = 0x7FD
jg 0xa2e0
setne %r11b
movq %r9, %r10
addq %rdx, %r10
setns %bl
orb %r11b, %bl
jne 0xa303
orb $0x28, 0x2(%rax)
movzbl %dil, %ecx
shlq $0x3f, %rcx
cmpq $0x1, %r9
sbbq $0x0, %rcx
movabsq $0x7ff0000000000000, %rax # imm = 0x7FF0000000000000
addq %rcx, %rax
jmp 0xa357
testq %rsi, %rsi
js 0xa359
testq %rcx, %rcx
je 0xa324
movb 0x2(%rax), %r10b
orb $0x20, %r10b
movb %r10b, 0x2(%rax)
cmpl $0x200, %ecx            # imm = 0x200
sete %al
jmp 0xa326
xorl %eax, %eax
testb %r8b, %r8b
sete %cl
addq %r9, %rdx
shrq $0xa, %rdx
andb %al, %cl
movzbl %cl, %ecx
notq %rcx
andq %rdx, %rcx
shlq $0x34, %rsi
movzbl %dil, %eax
shlq $0x3f, %rax
testq %rcx, %rcx
cmoveq %rcx, %rsi
orq %rcx, %rax
addq %rsi, %rax
popq %rbx
retq
cmpb $0x0, 0x4(%rax)
je 0xa36d
orb $-0x80, 0x2(%rax)
movzbl %dil, %eax
shlq $0x3f, %rax
jmp 0xa357
cmpb $0x1, (%rax)
sete %cl
cmpq $-0x1, %rsi
setne %r11b
testq %r10, %r10
setns %r10b
orb %r11b, %r10b
orb %cl, %r10b
movq %rsi, %rcx
negq %rcx
cmpq $0x3f, %rcx
ja 0xa3ac
movq %rdx, %r11
shrq %cl, %r11
movl %esi, %ecx
shlq %cl, %rdx
xorl %ecx, %ecx
testq %rdx, %rdx
setne %cl
orq %r11, %rcx
jmp 0xa3b4
xorl %ecx, %ecx
testq %rdx, %rdx
setne %cl
movq %rcx, %rdx
andq $0x3ff, %rcx            # imm = 0x3FF
setne %sil
andb %sil, %r10b
cmpb $0x1, %r10b
jne 0xa3da
movb 0x2(%rax), %r10b
orb $0x10, %r10b
xorl %esi, %esi
jmp 0xa311
xorl %esi, %esi
jmp 0xa308
callq 0x1040