// File: /workspace/github_c_makefile_star2_O3/mbitsnbites[P]SoftFP/softfloat.c
// Function: roundAndPackFloatx80
static floatx80 roundAndPackFloatx80(int8 roundingPrecision, flag zSign,
                                     int32 zExp, uint64_t zSig0, uint64_t zSig1,
                                     float_status *status)
{
    int8 roundingMode;
    flag roundNearestEven, increment, isTiny;
    int64 roundIncrement, roundMask, roundBits;

    roundingMode = status->float_rounding_mode;
    roundNearestEven = ( roundingMode == float_round_nearest_even );
    if ( roundingPrecision == 80 ) goto precision80;
    if ( roundingPrecision == 64 ) {
        roundIncrement = LIT64( 0x0000000000000400 );
        roundMask = LIT64( 0x00000000000007FF );
    }
    else if ( roundingPrecision == 32 ) {
        roundIncrement = LIT64( 0x0000008000000000 );
        roundMask = LIT64( 0x000000FFFFFFFFFF );
    }
    else {
        goto precision80;
    }
    zSig0 |= ( zSig1 != 0 );
    switch (roundingMode) {
    case float_round_nearest_even:
    case float_round_ties_away:
        break;
    case float_round_to_zero:
        roundIncrement = 0;
        break;
    case float_round_up:
        roundIncrement = zSign ? 0 : roundMask;
        break;
    case float_round_down:
        roundIncrement = zSign ? roundMask : 0;
        break;
    default:
        abort();
    }
    roundBits = zSig0 & roundMask;
    if ( 0x7FFD <= (uint32_t) ( zExp - 1 ) ) {
        if (    ( 0x7FFE < zExp )
             || ( ( zExp == 0x7FFE ) && ( zSig0 + roundIncrement < zSig0 ) )
           ) {
            goto overflow;
        }
        if ( zExp <= 0 ) {
            if (status->flush_to_zero) {
                float_raise(float_flag_output_denormal, status);
                return packFloatx80(zSign, 0, 0);
            }
            isTiny =
                   (status->float_detect_tininess
                    == float_tininess_before_rounding)
                || ( zExp < 0 )
                || ( zSig0 <= zSig0 + roundIncrement );
            shift64RightJamming( zSig0, 1 - zExp, &zSig0 );
            zExp = 0;
            roundBits = zSig0 & roundMask;
            if (isTiny && roundBits) {
                float_raise(float_flag_underflow, status);
            }
            if (roundBits) {
                status->float_exception_flags |= float_flag_inexact;
            }
            zSig0 += roundIncrement;
            if ( (int64_t) zSig0 < 0 ) zExp = 1;
            roundIncrement = roundMask + 1;
            if ( roundNearestEven && ( roundBits<<1 == roundIncrement ) ) {
                roundMask |= roundIncrement;
            }
            zSig0 &= ~ roundMask;
            return packFloatx80( zSign, zExp, zSig0 );
        }
    }
    if (roundBits) {
        status->float_exception_flags |= float_flag_inexact;
    }
    zSig0 += roundIncrement;
    if ( zSig0 < roundIncrement ) {
        ++zExp;
        zSig0 = LIT64( 0x8000000000000000 );
    }
    roundIncrement = roundMask + 1;
    if ( roundNearestEven && ( roundBits<<1 == roundIncrement ) ) {
        roundMask |= roundIncrement;
    }
    zSig0 &= ~ roundMask;
    if ( zSig0 == 0 ) zExp = 0;
    return packFloatx80( zSign, zExp, zSig0 );
 precision80:
    switch (roundingMode) {
    case float_round_nearest_even:
    case float_round_ties_away:
        increment = ((int64_t)zSig1 < 0);
        break;
    case float_round_to_zero:
        increment = 0;
        break;
    case float_round_up:
        increment = !zSign && zSig1;
        break;
    case float_round_down:
        increment = zSign && zSig1;
        break;
    default:
        abort();
    }
    if ( 0x7FFD <= (uint32_t) ( zExp - 1 ) ) {
        if (    ( 0x7FFE < zExp )
             || (    ( zExp == 0x7FFE )
                  && ( zSig0 == LIT64( 0xFFFFFFFFFFFFFFFF ) )
                  && increment
                )
           ) {
            roundMask = 0;
 overflow:
            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 packFloatx80( zSign, 0x7FFE, ~ roundMask );
            }
            return packFloatx80( zSign, 0x7FFF, LIT64( 0x8000000000000000 ) );
        }
        if ( zExp <= 0 ) {
            isTiny =
                   (status->float_detect_tininess
                    == float_tininess_before_rounding)
                || ( zExp < 0 )
                || ! increment
                || ( zSig0 < LIT64( 0xFFFFFFFFFFFFFFFF ) );
            shift64ExtraRightJamming( zSig0, zSig1, 1 - zExp, &zSig0, &zSig1 );
            zExp = 0;
            if (isTiny && zSig1) {
                float_raise(float_flag_underflow, status);
            }
            if (zSig1) {
                status->float_exception_flags |= float_flag_inexact;
            }
            switch (roundingMode) {
            case float_round_nearest_even:
            case float_round_ties_away:
                increment = ((int64_t)zSig1 < 0);
                break;
            case float_round_to_zero:
                increment = 0;
                break;
            case float_round_up:
                increment = !zSign && zSig1;
                break;
            case float_round_down:
                increment = zSign && zSig1;
                break;
            default:
                abort();
            }
            if ( increment ) {
                ++zSig0;
                zSig0 &=
                    ~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven );
                if ( (int64_t) zSig0 < 0 ) zExp = 1;
            }
            return packFloatx80( zSign, zExp, zSig0 );
        }
    }
    if (zSig1) {
        status->float_exception_flags |= float_flag_inexact;
    }
    if ( increment ) {
        ++zSig0;
        if ( zSig0 == 0 ) {
            ++zExp;
            zSig0 = LIT64( 0x8000000000000000 );
        }
        else {
            zSig0 &= ~ ( ( (uint64_t) ( zSig1<<1 ) == 0 ) & roundNearestEven );
        }
    }
    else {
        if ( zSig0 == 0 ) zExp = 0;
    }
    return packFloatx80( zSign, zExp, zSig0 );

}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rcx, %r10
movzbl 0x1(%r9), %r11d
cmpl $0x40, %edi
je 0x10641
cmpl $0x20, %edi
jne 0x1067d
movabsq $0xffffffffff, %rax     # imm = 0xFFFFFFFFFF
movabsq $0x8000000000, %rdi     # imm = 0x8000000000
jmp 0x1064b
movl $0x7ff, %eax            # imm = 0x7FF
movl $0x400, %edi            # imm = 0x400
xorl %ebx, %ebx
testq %r8, %r8
setne %cl
cmpl $0x4, %r11d
ja 0x10a00
movb %cl, %bl
movl %r11d, %ecx
leaq 0x6207(%rip), %r8       # 0x16870
movslq (%r8,%rcx,4), %rcx
addq %r8, %rcx
jmpq *%rcx
xorl %edi, %edi
testb %sil, %sil
cmovneq %rax, %rdi
jmp 0x106b3
cmpl $0x4, %r11d
ja 0x10a00
movl %r11d, %edi
leaq 0x61f3(%rip), %rax      # 0x16884
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movq %r8, %rbx
shrq $0x3f, %rbx
jmp 0x1075d
xorl %edi, %edi
jmp 0x106b3
xorl %edi, %edi
testb %sil, %sil
cmoveq %rax, %rdi
orq %r10, %rbx
movl $0xffff8002, %ecx       # imm = 0xFFFF8002
leal (%rdx,%rcx), %r8d
cmpl %ecx, %r8d
ja 0x106e9
cmpl $0x7ffe, %edx           # imm = 0x7FFE
jg 0x10786
movq %rbx, %rcx
notq %rcx
jne 0x106e1
cmpq %rcx, %rdi
ja 0x10786
testl %edx, %edx
jle 0x10838
movq %rax, %rcx
andq %rbx, %rcx
je 0x106f6
orb $0x20, 0x2(%r9)
movabsq $0x7fffffffffffffff, %r8 # imm = 0x7FFFFFFFFFFFFFFF
incq %r8
addq %rbx, %rdi
cmovbq %r8, %rdi
adcl $0x0, %edx
leaq 0x1(%rax), %r8
addq %rcx, %rcx
xorl %r9d, %r9d
cmpq %r8, %rcx
cmovneq %r9, %r8
testl %r11d, %r11d
cmovneq %r9, %r8
orq %rax, %r8
notq %r8
andq %rdi, %r8
cmovel %r9d, %edx
movzbl %sil, %ecx
shll $0xf, %ecx
addl %edx, %ecx
movq %r8, %rax
jmp 0x1082e
xorl %ebx, %ebx
jmp 0x1075d
testb %sil, %sil
setne %al
jmp 0x10755
testb %sil, %sil
sete %al
testq %r8, %r8
setne %bl
andb %al, %bl
movl $0xffff8002, %eax       # imm = 0xFFFF8002
leal (%rdx,%rax), %ecx
cmpl %eax, %ecx
ja 0x107da
cmpl $0x7ffe, %edx           # imm = 0x7FFE
jg 0x10784
sete %al
cmpq $-0x1, %r10
sete %cl
andb %al, %cl
andb %bl, %cl
cmpb $0x1, %cl
jne 0x107d6
xorl %eax, %eax
orb $0x28, 0x2(%r9)
cmpl $0x3, %r11d
je 0x107ab
testb %sil, %sil
setne %cl
cmpb $0x2, %r11b
sete %dl
testb %dl, %cl
jne 0x107ab
xorb $0x1, %r11b
orb %sil, %r11b
jne 0x107bd
notq %rax
movzbl %sil, %ecx
shll $0xf, %ecx
orl $0x7ffe, %ecx           # imm = 0x7FFE
jmp 0x1082e
movzbl %sil, %ecx
shll $0xf, %ecx
orl $0x7fff, %ecx           # imm = 0x7FFF
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
jmp 0x1082e
testl %edx, %edx
jle 0x1084f
testq %r8, %r8
je 0x107e4
orb $0x20, 0x2(%r9)
testb %bl, %bl
je 0x10801
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
incq %r10
jne 0x1080b
incl %edx
incq %rax
movq %rax, %r10
jmp 0x10822
xorl %eax, %eax
testq %r10, %r10
cmovel %eax, %edx
jmp 0x10822
testl %r11d, %r11d
sete %cl
testq %rax, %r8
sete %al
andb %cl, %al
movzbl %al, %eax
notq %rax
andq %rax, %r10
movzbl %sil, %ecx
shll $0xf, %ecx
addl %edx, %ecx
movq %r10, %rax
movl %ecx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
retq
cmpb $0x0, 0x4(%r9)
je 0x10899
orb $-0x80, 0x2(%r9)
movzbl %sil, %ecx
shll $0xf, %ecx
xorl %eax, %eax
jmp 0x1082e
cmpb $0x1, (%r9)
setne %al
testl %edx, %edx
sete %cl
andb %cl, %bl
andb %al, %bl
cmpq $-0x1, %r10
setne %al
xorb $0x1, %bl
orb %al, %bl
movl $0x1, %eax
subl %edx, %eax
cmpl $0x3f, %eax
ja 0x108d8
movl %eax, %ecx
negb %cl
movq %r10, %r14
shlq %cl, %r14
xorl %edx, %edx
testq %r8, %r8
setne %dl
orq %r14, %rdx
movl %eax, %ecx
shrq %cl, %r10
movq %r10, %rax
jmp 0x10963
cmpb $0x1, (%r9)
sete %r8b
testl %edx, %edx
setne %r10b
orb %r8b, %r10b
cmpq %rcx, %rdi
setbe %r8b
orb %r10b, %r8b
movl $0x1, %ecx
subl %edx, %ecx
cmpl $0x3f, %ecx
ja 0x108ea
movq %rbx, %rdx
shrq %cl, %rdx
negb %cl
shlq %cl, %rbx
xorl %ecx, %ecx
testq %rbx, %rbx
setne %cl
orq %rdx, %rcx
jmp 0x108f2
cmpl $-0x3f, %edx
jne 0x10959
xorl %edx, %edx
testq %r8, %r8
setne %dl
orq %r10, %rdx
jmp 0x10961
xorl %ecx, %ecx
testq %rbx, %rbx
setne %cl
movq %rcx, %rdx
andq %rax, %rdx
setne %r10b
andb %r10b, %r8b
cmpb $0x1, %r8b
jne 0x1090f
movb 0x2(%r9), %r8b
orb $0x10, %r8b
jmp 0x10918
testq %rdx, %rdx
je 0x10920
movb 0x2(%r9), %r8b
orb $0x20, %r8b
movb %r8b, 0x2(%r9)
addq %rdi, %rcx
movq %rcx, %rdi
shrq $0x3f, %rdi
leaq 0x1(%rax), %r8
addq %rdx, %rdx
xorl %r9d, %r9d
cmpq %r8, %rdx
cmovneq %r9, %r8
testl %r11d, %r11d
cmovneq %r9, %r8
orq %rax, %r8
notq %r8
andq %rcx, %r8
movzbl %sil, %ecx
shll $0xf, %ecx
orl %edi, %ecx
jmp 0x1073b
xorl %edx, %edx
orq %r10, %r8
setne %dl
xorl %eax, %eax
testq %rdx, %rdx
setne %cl
andb %cl, %bl
cmpb $0x1, %bl
jne 0x10979
movb 0x2(%r9), %cl
orb $0x10, %cl
jmp 0x10982
testq %rdx, %rdx
je 0x10989
movb 0x2(%r9), %cl
orb $0x20, %cl
movb %cl, 0x2(%r9)
leaq 0x5f08(%rip), %rcx      # 0x16898
movslq (%rcx,%rdi,4), %rdi
addq %rcx, %rdi
jmpq *%rdi
movq %rdx, %rcx
shrq $0x3f, %rcx
jmp 0x109c1
testq %rdx, %rdx
setne %dil
testb %sil, %sil
sete %cl
jmp 0x109be
testq %rdx, %rdx
setne %dil
testb %sil, %sil
setne %cl
andb %dil, %cl
testb %cl, %cl
je 0x109ed
testl %r11d, %r11d
sete %cl
incq %rax
shlq %rdx
testq %rdx, %rdx
sete %dl
andb %cl, %dl
movzbl %dl, %edx
notq %rdx
andq %rax, %rdx
shrq $0x3f, %rax
movl %eax, %ecx
movq %rdx, %rax
jmp 0x109ef
xorl %ecx, %ecx
movzbl %sil, %edx
shll $0xf, %edx
movzwl %cx, %ecx
orl %edx, %ecx
jmp 0x1082e
callq 0x1040