// File: /workspace/github_c_makefile_star2_O3/mbitsnbites[P]SoftFP/softfloat.c
// Function: roundAndPackFloat128
static float128 roundAndPackFloat128(flag zSign, int32 zExp,
                                     uint64_t zSig0, uint64_t zSig1,
                                     uint64_t zSig2, float_status *status)
{
    int8 roundingMode;
    flag roundNearestEven, increment, isTiny;

    roundingMode = status->float_rounding_mode;
    roundNearestEven = ( roundingMode == float_round_nearest_even );
    switch (roundingMode) {
    case float_round_nearest_even:
    case float_round_ties_away:
        increment = ((int64_t)zSig2 < 0);
        break;
    case float_round_to_zero:
        increment = 0;
        break;
    case float_round_up:
        increment = !zSign && zSig2;
        break;
    case float_round_down:
        increment = zSign && zSig2;
        break;
    default:
        abort();
    }
    if ( 0x7FFD <= (uint32_t) zExp ) {
        if (    ( 0x7FFD < zExp )
             || (    ( zExp == 0x7FFD )
                  && eq128(
                         LIT64( 0x0001FFFFFFFFFFFF ),
                         LIT64( 0xFFFFFFFFFFFFFFFF ),
                         zSig0,
                         zSig1
                     )
                  && increment
                )
           ) {
            float_raise(float_flag_overflow | float_flag_inexact, status);
            if (    ( roundingMode == float_round_to_zero )
                 || ( zSign && ( roundingMode == float_round_up ) )
                 || ( ! zSign && ( roundingMode == float_round_down ) )
               ) {
                return
                    packFloat128(
                        zSign,
                        0x7FFE,
                        LIT64( 0x0000FFFFFFFFFFFF ),
                        LIT64( 0xFFFFFFFFFFFFFFFF )
                    );
            }
            return packFloat128( zSign, 0x7FFF, 0, 0 );
        }
        if ( zExp < 0 ) {
            if (status->flush_to_zero) {
                float_raise(float_flag_output_denormal, status);
                return packFloat128(zSign, 0, 0, 0);
            }
            isTiny =
                   (status->float_detect_tininess
                    == float_tininess_before_rounding)
                || ( zExp < -1 )
                || ! increment
                || lt128(
                       zSig0,
                       zSig1,
                       LIT64( 0x0001FFFFFFFFFFFF ),
                       LIT64( 0xFFFFFFFFFFFFFFFF )
                   );
            shift128ExtraRightJamming(
                zSig0, zSig1, zSig2, - zExp, &zSig0, &zSig1, &zSig2 );
            zExp = 0;
            if (isTiny && zSig2) {
                float_raise(float_flag_underflow, status);
            }
            switch (roundingMode) {
            case float_round_nearest_even:
            case float_round_ties_away:
                increment = ((int64_t)zSig2 < 0);
                break;
            case float_round_to_zero:
                increment = 0;
                break;
            case float_round_up:
                increment = !zSign && zSig2;
                break;
            case float_round_down:
                increment = zSign && zSig2;
                break;
            default:
                abort();
            }
        }
    }
    if (zSig2) {
        status->float_exception_flags |= float_flag_inexact;
    }
    if ( increment ) {
        add128( zSig0, zSig1, 0, 1, &zSig0, &zSig1 );
        zSig1 &= ~ ( ( zSig2 + zSig2 == 0 ) & roundNearestEven );
    }
    else {
        if ( ( zSig0 | zSig1 ) == 0 ) zExp = 0;
    }
    return packFloat128( zSign, zExp, zSig0, zSig1 );

}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movzbl 0x1(%r9), %r11d
cmpq $0x4, %r11
ja 0x13043
movq %rcx, %rax
leaq 0x3aec(%rip), %rcx      # 0x168e8
movslq (%rcx,%r11,4), %r10
addq %rcx, %r10
jmpq *%r10
movq %r8, %rcx
shrq $0x3f, %rcx
jmp 0x12e2c
xorl %ecx, %ecx
jmp 0x12e2c
testb %dil, %dil
setne %r10b
jmp 0x12e23
testb %dil, %dil
sete %r10b
testq %r8, %r8
setne %cl
andb %r10b, %cl
cmpl $0x7ffd, %esi           # imm = 0x7FFD
jb 0x12ea3
jle 0x12e7d
movabsq $0x7ffeffffffffffff, %rcx # imm = 0x7FFEFFFFFFFFFFFF
orb $0x28, 0x2(%r9)
cmpl $0x3, %r11d
je 0x12e69
testb %dil, %dil
setne %al
cmpl $0x2, %r11d
sete %dl
testb %dl, %al
jne 0x12e69
xorb $0x1, %r11b
orb %dil, %r11b
jne 0x12f18
movzbl %dil, %esi
shlq $0x3f, %rsi
orq %rcx, %rsi
movq $-0x1, %rax
jmp 0x12ef5
jne 0x12e9f
movabsq $0x1ffffffffffff, %r10  # imm = 0x1FFFFFFFFFFFF
movl $0x7ffd, %esi           # imm = 0x7FFD
cmpq %r10, %rdx
jne 0x12ea3
cmpq $-0x1, %rax
jne 0x12ea3
testb %cl, %cl
jne 0x12e36
jmp 0x12ea3
testl %esi, %esi
js 0x12f00
testq %r8, %r8
je 0x12ead
orb $0x20, 0x2(%r9)
testb %cl, %cl
je 0x12ed8
testl %r11d, %r11d
sete %cl
addq $0x1, %rax
adcq $0x0, %rdx
shlq %r8
testq %r8, %r8
sete %r8b
andb %cl, %r8b
movzbl %r8b, %ecx
notq %rcx
andq %rcx, %rax
jmp 0x12ee3
xorl %ecx, %ecx
movq %rax, %r8
orq %rdx, %r8
cmovel %ecx, %esi
movzbl %dil, %ecx
shlq $0x3f, %rcx
shlq $0x30, %rsi
addq %rcx, %rsi
addq %rdx, %rsi
movq %rsi, %rdx
addq $0x8, %rsp
popq %rbx
popq %r14
retq
cmpb $0x0, 0x4(%r9)
je 0x12f2d
orb $-0x80, 0x2(%r9)
movzbl %dil, %esi
shlq $0x3f, %rsi
xorl %eax, %eax
jmp 0x12ef5
movzbl %dil, %eax
shlq $0x3f, %rax
incq %rcx
orq %rax, %rcx
xorl %eax, %eax
movq %rcx, %rsi
jmp 0x12ef5
cmpl $-0x1, %esi
jne 0x12f66
cmpb $0x1, (%r9)
je 0x12f66
testb %cl, %cl
je 0x12f66
movabsq $0x1ffffffffffff, %rcx  # imm = 0x1FFFFFFFFFFFF
cmpq %rcx, %rdx
setb %cl
sete %sil
cmpq $-0x1, %rax
setne %bl
andb %sil, %bl
orb %cl, %bl
movl $0x1, %r10d
movb $0x3f, %cl
jmp 0x12f79
movl %esi, %r10d
negl %r10d
movl %esi, %ecx
andb $0x3f, %cl
movb $0x1, %bl
cmpl $0x40, %r10d
jae 0x12fd3
movq %rax, %rsi
shlq %cl, %rsi
movq %rdx, %r14
shlq %cl, %r14
movl %r10d, %ecx
shrq %cl, %rax
shrq %cl, %rdx
orq %r14, %rax
movq %rdx, %r10
movq %rax, %r14
movq %rsi, %rax
xorl %ecx, %ecx
testq %r8, %r8
setne %cl
movq %rcx, %r8
orq %rax, %r8
testb %bl, %bl
je 0x12fb6
testq %r8, %r8
je 0x12fb6
orb $0x10, 0x2(%r9)
xorl %esi, %esi
movl %r11d, %ecx
leaq 0x393a(%rip), %rdx      # 0x168fc
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrq $0x3f, %rax
movl %eax, %ecx
jmp 0x1301e
cmpl $-0x40, %esi
je 0x12fed
orq %rax, %r8
cmpl $0x7f, %r10d
ja 0x13029
movq %rdx, %rax
shlq %cl, %rax
movl %r10d, %ecx
shrq %cl, %rdx
xorl %r10d, %r10d
movq %rdx, %r14
jmp 0x12f9a
movq %r10, %rdx
movq %r14, %rax
xorl %ecx, %ecx
jmp 0x12ea3
testq %r8, %r8
setne %al
testb %dil, %dil
setne %cl
jmp 0x1301c
testq %r8, %r8
setne %al
testb %dil, %dil
sete %cl
andb %al, %cl
movq %r10, %rdx
movq %r14, %rax
jmp 0x12ea3
xorl %eax, %eax
testq %rdx, %rdx
setne %al
cmpl $-0x80, %esi
cmoveq %rdx, %rax
xorl %r10d, %r10d
xorl %r14d, %r14d
jmp 0x12f9a
callq 0x1040