// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %r15
movl %esi, %ebx
movq %rcx, 0x8(%rsp)
movq %r8, 0x10(%rsp)
movzbl 0x1(%r9), %ebp
cmpl $0x40, %edi
je 0xf2a7
cmpl $0x20, %edi
jne 0xf2ea
movabsq $0xffffffffff, %r14     # imm = 0xFFFFFFFFFF
movabsq $0x8000000000, %r13     # imm = 0x8000000000
jmp 0xf2b3
movl $0x7ff, %r14d           # imm = 0x7FF
movl $0x400, %r13d           # imm = 0x400
xorl %edi, %edi
testq %r8, %r8
setne %dil
orq %rcx, %rdi
movq %rdi, 0x8(%rsp)
cmpl $0x4, %ebp
ja 0xf640
movl %ebp, %eax
leaq 0x559a(%rip), %rcx      # 0x14870
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %r13d, %r13d
testb %bl, %bl
cmovneq %r14, %r13
jmp 0xf320
cmpl $0x4, %ebp
ja 0xf640
movl %ebp, %r12d
leaq 0x5587(%rip), %rax      # 0x14884
movslq (%rax,%r12,4), %rsi
addq %rax, %rsi
jmpq *%rsi
movq %r8, %r13
shrq $0x3f, %r13
jmp 0xf3bf
xorl %r13d, %r13d
jmp 0xf320
xorl %r13d, %r13d
testb %bl, %bl
cmoveq %r14, %r13
movl $0xffff8002, %eax       # imm = 0xFFFF8002
leal (%rdx,%rax), %ecx
cmpl %eax, %ecx
ja 0xf351
cmpl $0x7ffe, %edx           # imm = 0x7FFE
jg 0xf3f1
movq %rdi, %rax
notq %rax
jne 0xf349
cmpq %rax, %r13
ja 0xf3f1
testl %edx, %edx
jle 0xf4a8
movq %r14, %rax
andq %rdi, %rax
je 0xf35e
orb $0x20, 0x2(%r15)
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
incq %rcx
addq %rdi, %r13
cmovbq %rcx, %r13
adcl $0x0, %edx
leaq 0x1(%r14), %rcx
addq %rax, %rax
xorl %esi, %esi
cmpq %rcx, %rax
cmovneq %rsi, %rcx
testl %ebp, %ebp
cmovneq %rsi, %rcx
orq %r14, %rcx
notq %rcx
andq %r13, %rcx
cmovel %esi, %edx
movzbl %bl, %esi
shll $0xf, %esi
addl %edx, %esi
movq %rcx, %r14
jmp 0xf423
xorl %r13d, %r13d
jmp 0xf3bf
testb %bl, %bl
setne %al
jmp 0xf3b5
testb %bl, %bl
sete %al
testq %r8, %r8
setne %r13b
andb %al, %r13b
movl $0xffff8002, %eax       # imm = 0xFFFF8002
leal (%rdx,%rax), %esi
cmpl %eax, %esi
ja 0xf453
cmpl $0x7ffe, %edx           # imm = 0x7FFE
jg 0xf3ee
sete %al
cmpq $-0x1, %rcx
sete %sil
andb %al, %sil
andb %r13b, %sil
cmpb $0x1, %sil
jne 0xf44f
xorl %r14d, %r14d
orb $0x28, 0x2(%r15)
cmpl $0x3, %ebp
je 0xf414
testb %bl, %bl
setne %al
cmpb $0x2, %bpl
sete %cl
testb %cl, %al
jne 0xf414
xorb $0x1, %bpl
orb %bl, %bpl
jne 0xf437
notq %r14
movzbl %bl, %esi
shll $0xf, %esi
orl $0x7ffe, %esi           # imm = 0x7FFE
movq %r14, %rax
movl %esi, %edx
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movzbl %bl, %esi
shll $0xf, %esi
orl $0x7fff, %esi           # imm = 0x7FFF
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
jmp 0xf423
testl %edx, %edx
jle 0xf4c2
testq %r8, %r8
je 0xf45d
orb $0x20, 0x2(%r15)
testb %r13b, %r13b
je 0xf47e
movabsq $0x7fffffffffffffff, %rax # imm = 0x7FFFFFFFFFFFFFFF
incq %rcx
jne 0xf48b
incl %edx
incq %rax
movq %rax, %rcx
jmp 0xf397
xorl %eax, %eax
testq %rcx, %rcx
cmovel %eax, %edx
jmp 0xf397
testl %ebp, %ebp
sete %sil
testq %rax, %r8
sete %al
andb %sil, %al
movzbl %al, %eax
notq %rax
andq %rax, %rcx
jmp 0xf397
cmpb $0x0, 0x4(%r15)
je 0xf51f
orb $-0x80, 0x2(%r15)
movzbl %bl, %esi
shll $0xf, %esi
xorl %r14d, %r14d
jmp 0xf423
cmpb $0x1, (%r15)
setne %al
testl %edx, %edx
sete %sil
andb %sil, %r13b
andb %al, %r13b
cmpq $-0x1, %rcx
setne %al
notb %r13b
orb %al, %r13b
pushq $0x1
popq %rax
subl %edx, %eax
leaq 0x8(%rsp), %r9
leaq 0x10(%rsp), %r14
movq %rcx, %rdi
movq %r8, %rsi
movq %rax, %rdx
movq %r9, %rcx
movq %r14, %r8
callq 0x9cb8
movq (%r14), %rax
testq %rax, %rax
setne %cl
andb %r13b, %cl
cmpb $0x1, %cl
jne 0xf56a
movb 0x2(%r15), %cl
orb $0x10, %cl
jmp 0xf573
cmpb $0x1, (%r15)
sete %cl
testl %edx, %edx
setne %sil
orb %cl, %sil
cmpq %rax, %r13
setbe %r12b
orb %sil, %r12b
pushq $0x1
popq %rsi
subl %edx, %esi
leaq 0x8(%rsp), %rdx
callq 0x93e7
leaq 0x8(%rsp), %rax
movq (%rax), %rax
movq %rax, %rcx
andq %r14, %rcx
setne %dl
andb %r12b, %dl
cmpb $0x1, %dl
jne 0xf593
movb 0x2(%r15), %dl
orb $0x10, %dl
jmp 0xf59c
testq %rax, %rax
je 0xf57a
movb 0x2(%r15), %cl
orb $0x20, %cl
movb %cl, 0x2(%r15)
leaq 0x5317(%rip), %rcx      # 0x14898
movslq (%rcx,%r12,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq %rax, %rcx
shrq $0x3f, %rcx
jmp 0xf5fd
testq %rcx, %rcx
je 0xf5a3
movb 0x2(%r15), %dl
orb $0x20, %dl
movb %dl, 0x2(%r15)
addq %r13, %rax
movq %rax, %rdx
shrq $0x3f, %rdx
leaq 0x1(%r14), %rdi
addq %rcx, %rcx
xorl %esi, %esi
cmpq %rdi, %rcx
cmovneq %rsi, %rdi
testl %ebp, %ebp
cmovneq %rsi, %rdi
orq %r14, %rdi
notq %rdi
andq %rax, %rdi
movzbl %bl, %esi
shll $0xf, %esi
orl %edx, %esi
movq %rdi, %r14
jmp 0xf423
movq 0x8(%rsp), %r14
jmp 0xf62e
testq %rax, %rax
setne %dl
testb %bl, %bl
setne %cl
jmp 0xf5fb
testq %rax, %rax
setne %dl
testb %bl, %bl
sete %cl
andb %dl, %cl
movq 0x8(%rsp), %r14
testb %cl, %cl
je 0xf62e
testl %ebp, %ebp
sete %cl
incq %r14
shlq %rax
testq %rax, %rax
sete %al
andb %cl, %al
movzbl %al, %ecx
notq %rcx
andq %r14, %rcx
shrq $0x3f, %r14
movl %r14d, %eax
movq %rcx, %r14
jmp 0xf630
xorl %eax, %eax
movzbl %bl, %ecx
shll $0xf, %ecx
movzwl %ax, %esi
orl %ecx, %esi
jmp 0xf423
callq 0x1040