// File: /workspace/github_c_makefile_star2_O3/mbitsnbites[P]SoftFP/softfloat.c
// Function: float128_round_to_int
float128 float128_round_to_int(float128 a, float_status *status)
{
    flag aSign;
    int32 aExp;
    uint64_t lastBitMask, roundBitsMask;
    float128 z;

    aExp = extractFloat128Exp( a );
    if ( 0x402F <= aExp ) {
        if ( 0x406F <= aExp ) {
            if (    ( aExp == 0x7FFF )
                 && ( extractFloat128Frac0( a ) | extractFloat128Frac1( a ) )
               ) {
                return propagateFloat128NaN(a, a, status);
            }
            return a;
        }
        lastBitMask = 1;
        lastBitMask = ( lastBitMask<<( 0x406E - aExp ) )<<1;
        roundBitsMask = lastBitMask - 1;
        z = a;
        switch (status->float_rounding_mode) {
        case float_round_nearest_even:
            if ( lastBitMask ) {
                add128( z.high, z.low, 0, lastBitMask>>1, &z.high, &z.low );
                if ( ( z.low & roundBitsMask ) == 0 ) z.low &= ~ lastBitMask;
            }
            else {
                if ( (int64_t) z.low < 0 ) {
                    ++z.high;
                    if ( (uint64_t) ( z.low<<1 ) == 0 ) z.high &= ~1;
                }
            }
            break;
        case float_round_ties_away:
            if (lastBitMask) {
                add128(z.high, z.low, 0, lastBitMask >> 1, &z.high, &z.low);
            } else {
                if ((int64_t) z.low < 0) {
                    ++z.high;
                }
            }
            break;
        case float_round_to_zero:
            break;
        case float_round_up:
            if (!extractFloat128Sign(z)) {
                add128(z.high, z.low, 0, roundBitsMask, &z.high, &z.low);
            }
            break;
        case float_round_down:
            if (extractFloat128Sign(z)) {
                add128(z.high, z.low, 0, roundBitsMask, &z.high, &z.low);
            }
            break;
        default:
            abort();
        }
        z.low &= ~ roundBitsMask;
    }
    else {
        if ( aExp < 0x3FFF ) {
            if ( ( ( (uint64_t) ( a.high<<1 ) ) | a.low ) == 0 ) return a;
            status->float_exception_flags |= float_flag_inexact;
            aSign = extractFloat128Sign( a );
            switch (status->float_rounding_mode) {
             case float_round_nearest_even:
                if (    ( aExp == 0x3FFE )
                     && (   extractFloat128Frac0( a )
                          | extractFloat128Frac1( a ) )
                   ) {
                    return packFloat128( aSign, 0x3FFF, 0, 0 );
                }
                break;
            case float_round_ties_away:
                if (aExp == 0x3FFE) {
                    return packFloat128(aSign, 0x3FFF, 0, 0);
                }
                break;
             case float_round_down:
                return
                      aSign ? packFloat128( 1, 0x3FFF, 0, 0 )
                    : packFloat128( 0, 0, 0, 0 );
             case float_round_up:
                return
                      aSign ? packFloat128( 1, 0, 0, 0 )
                    : packFloat128( 0, 0x3FFF, 0, 0 );
            }
            return packFloat128( aSign, 0, 0, 0 );
        }
        lastBitMask = 1;
        lastBitMask <<= 0x402F - aExp;
        roundBitsMask = lastBitMask - 1;
        z.low = 0;
        z.high = a.high;
        switch (status->float_rounding_mode) {
        case float_round_nearest_even:
            z.high += lastBitMask>>1;
            if ( ( ( z.high & roundBitsMask ) | a.low ) == 0 ) {
                z.high &= ~ lastBitMask;
            }
            break;
        case float_round_ties_away:
            z.high += lastBitMask>>1;
            break;
        case float_round_to_zero:
            break;
        case float_round_up:
            if (!extractFloat128Sign(z)) {
                z.high |= ( a.low != 0 );
                z.high += roundBitsMask;
            }
            break;
        case float_round_down:
            if (extractFloat128Sign(z)) {
                z.high |= (a.low != 0);
                z.high += roundBitsMask;
            }
            break;
        default:
            abort();
        }
        z.high &= ~ roundBitsMask;
    }
    if ( ( z.low != a.low ) || ( z.high != a.high ) ) {
        status->float_exception_flags |= float_flag_inexact;
    }
    return z;

}

// Assembly:
pushq %rax
movq %rdx, %r8
movq %rsi, %r9
shrq $0x30, %r9
andl $0x7fff, %r9d           # imm = 0x7FFF
cmpl $0x402f, %r9d           # imm = 0x402F
jb 0x1202e
cmpl $0x406f, %r9d           # imm = 0x406F
jb 0x120af
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0x122a4
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rax
orq %rdi, %rax
je 0x122a4
movq %rdi, %rdx
movq %rsi, %rcx
callq 0x122b1
movq %rax, %rdi
movq %rdx, %rsi
jmp 0x122a4
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
ja 0x1212b
leaq (%rsi,%rsi), %rax
orq %rdi, %rax
je 0x122a4
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orb $0x20, 0x2(%r8)
movq %rsi, %rax
andq %rcx, %rax
movzbl 0x1(%r8), %edx
cmpq $0x4, %rdx
ja 0x1220b
leaq 0x484d(%rip), %r8       # 0x168c0
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
jne 0x1220b
movabsq $0xffffffffffff, %rcx   # imm = 0xFFFFFFFFFFFF
andq %rcx, %rsi
movabsq $0x3fff000000000000, %rcx # imm = 0x3FFF000000000000
orq %rax, %rcx
orq %rdi, %rsi
cmoveq %rax, %rcx
jmp 0x12223
movb $0x6e, %cl
subb %r9b, %cl
movl $0x2, %edx
shlq %cl, %rdx
movzbl 0x1(%r8), %eax
cmpq $0x4, %rax
ja 0x122ac
leaq -0x1(%rdx), %r10
leaq 0x47fe(%rip), %rcx      # 0x168d4
movslq (%rcx,%rax,4), %r11
addq %rcx, %r11
movq %rsi, %rax
movq %rdi, %rcx
jmpq *%r11
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x1226b
movq %rsi, %rax
movq %rdi, %rcx
testq %rdi, %rdi
jns 0x12289
leaq 0x1(%rsi), %r9
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq -0x1(%rcx), %r10
movq %r9, %rax
andq $-0x2, %rax
testq %r10, %rdi
cmovneq %r9, %rax
cmovneq %rdi, %rcx
jmp 0x12289
movb $0x2f, %cl
subb %r9b, %cl
movl $0x1, %eax
shlq %cl, %rax
movzbl 0x1(%r8), %edx
cmpq $0x4, %rdx
ja 0x122ac
leaq -0x1(%rax), %rcx
leaq 0x475a(%rip), %r9       # 0x168ac
movslq (%r9,%rdx,4), %r10
addq %r9, %r10
movq %rsi, %rdx
jmpq *%r10
movq %rax, %rdx
shrq %rdx
addq %rsi, %rdx
andq %rdx, %rcx
orq %rdi, %rcx
jne 0x121fe
movq %rax, %rcx
notq %rcx
andq %rcx, %rdx
jmp 0x121fe
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x12259
movq %rdi, %rax
shrq $0x3f, %rax
addq %rsi, %rax
movq %rdi, %rcx
jmp 0x12289
movq %rax, %rdx
shrq %rdx
addq %rsi, %rdx
jmp 0x121fe
movq %rsi, %rax
movq %rdi, %rcx
testq %rsi, %rsi
jns 0x12289
jmp 0x121d3
movq %rsi, %rdx
testq %rsi, %rsi
jns 0x121fe
jmp 0x121ed
movq %rsi, %rax
movq %rdi, %rcx
testq %rsi, %rsi
js 0x12289
addq %rdi, %r10
movq %rsi, %rax
adcq $0x0, %rax
movq %r10, %rcx
jmp 0x12289
movq %rsi, %rdx
testq %rsi, %rsi
js 0x121fe
xorl %edx, %edx
testq %rdi, %rdi
setne %dl
orq %rsi, %rdx
addq %rdx, %rcx
movq %rcx, %rdx
negq %rax
andq %rdx, %rax
xorl %edx, %edx
jmp 0x1228f
xorl %edi, %edi
jmp 0x122a1
testq %rsi, %rsi
movabsq $0x3fff000000000000, %rax # imm = 0x3FFF000000000000
cmovnsq %rax, %rcx
xorl %edi, %edi
movq %rcx, %rsi
jmp 0x122a4
sarq $0x3f, %rsi
movabsq $-0x4001000000000000, %rax # imm = 0xBFFF000000000000
andq %rax, %rsi
jmp 0x12255
movabsq $0x3fff000000000000, %rsi # imm = 0x3FFF000000000000
orq %rax, %rsi
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
cmovneq %rax, %rsi
xorl %edi, %edi
jmp 0x122a4
movq %rdx, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rax
adcq $0x0, %rax
jmp 0x12289
movq %rdx, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rax
adcq $0x0, %rax
testq %r10, %rcx
jne 0x12289
movq %rdx, %r9
notq %r9
andq %r9, %rcx
negq %rdx
andq %rcx, %rdx
cmpq %rdi, %rdx
jne 0x12299
cmpq %rsi, %rax
je 0x122a4
orb $0x20, 0x2(%r8)
movq %rdx, %rdi
movq %rax, %rsi
movq %rdi, %rax
movq %rsi, %rdx
popq %rcx
retq
callq 0x1040