// File: /workspace/github_c_makefile_star2_O2/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 0x10a22
cmpl $0x406f, %r9d           # imm = 0x406F
jb 0x10aa3
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0x10c94
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rax
orq %rdi, %rax
je 0x10c94
movq %rdi, %rdx
movq %rsi, %rcx
callq 0x10ca1
movq %rax, %rdi
movq %rdx, %rsi
jmp 0x10c94
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
ja 0x10b1d
leaq (%rsi,%rsi), %rax
orq %rdi, %rax
je 0x10c94
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orb $0x20, 0x2(%r8)
movq %rsi, %rax
andq %rcx, %rax
movzbl 0x1(%r8), %edx
cmpq $0x4, %rdx
ja 0x10bfb
leaq 0x3e59(%rip), %r8       # 0x148c0
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
jne 0x10bfb
movabsq $0xffffffffffff, %rcx   # imm = 0xFFFFFFFFFFFF
andq %rcx, %rsi
movabsq $0x3fff000000000000, %rcx # imm = 0x3FFF000000000000
orq %rax, %rcx
orq %rdi, %rsi
cmoveq %rax, %rcx
jmp 0x10c13
movb $0x6e, %cl
subb %r9b, %cl
pushq $0x2
popq %rdx
shlq %cl, %rdx
movzbl 0x1(%r8), %eax
cmpq $0x4, %rax
ja 0x10c9c
leaq -0x1(%rdx), %r10
leaq 0x3e0c(%rip), %rcx      # 0x148d4
movslq (%rcx,%rax,4), %r11
addq %rcx, %r11
movq %rsi, %rax
movq %rdi, %rcx
jmpq *%r11
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x10c5b
movq %rsi, %rax
movq %rdi, %rcx
testq %rdi, %rdi
jns 0x10c79
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 0x10c79
movb $0x2f, %cl
subb %r9b, %cl
pushq $0x1
popq %rax
shlq %cl, %rax
movzbl 0x1(%r8), %edx
cmpq $0x4, %rdx
ja 0x10c9c
leaq -0x1(%rax), %rcx
leaq 0x3d6a(%rip), %r9       # 0x148ac
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 0x10bee
movq %rax, %rcx
notq %rcx
andq %rcx, %rdx
jmp 0x10bee
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x10c49
movq %rdi, %rax
shrq $0x3f, %rax
addq %rsi, %rax
movq %rdi, %rcx
jmp 0x10c79
movq %rax, %rdx
shrq %rdx
addq %rsi, %rdx
jmp 0x10bee
movq %rsi, %rax
movq %rdi, %rcx
testq %rsi, %rsi
jns 0x10c79
jmp 0x10bc3
movq %rsi, %rdx
testq %rsi, %rsi
jns 0x10bee
jmp 0x10bdd
movq %rsi, %rax
movq %rdi, %rcx
testq %rsi, %rsi
js 0x10c79
addq %rdi, %r10
movq %rsi, %rax
adcq $0x0, %rax
movq %r10, %rcx
jmp 0x10c79
movq %rsi, %rdx
testq %rsi, %rsi
js 0x10bee
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 0x10c7f
xorl %edi, %edi
jmp 0x10c91
testq %rsi, %rsi
movabsq $0x3fff000000000000, %rax # imm = 0x3FFF000000000000
cmovnsq %rax, %rcx
xorl %edi, %edi
movq %rcx, %rsi
jmp 0x10c94
sarq $0x3f, %rsi
movabsq $-0x4001000000000000, %rax # imm = 0xBFFF000000000000
andq %rax, %rsi
jmp 0x10c45
movabsq $0x3fff000000000000, %rsi # imm = 0x3FFF000000000000
orq %rax, %rsi
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
cmovneq %rax, %rsi
xorl %edi, %edi
jmp 0x10c94
movq %rdx, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rax
adcq $0x0, %rax
jmp 0x10c79
movq %rdx, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rax
adcq $0x0, %rax
testq %r10, %rcx
jne 0x10c79
movq %rdx, %r9
notq %r9
andq %r9, %rcx
negq %rdx
andq %rcx, %rdx
cmpq %rdi, %rdx
jne 0x10c89
cmpq %rsi, %rax
je 0x10c94
orb $0x20, 0x2(%r8)
movq %rdx, %rdi
movq %rax, %rsi
movq %rdi, %rax
movq %rsi, %rdx
popq %rcx
retq
callq 0x1040