// File: /workspace/github_c_makefile_star2_O1/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 0x11ffc
cmpl $0x406f, %r9d           # imm = 0x406F
jb 0x1207c
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0x12071
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rax
orq %rdi, %rax
je 0x12071
movq %rdi, %rdx
movq %rsi, %rcx
callq 0x12261
jmp 0x1225a
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
ja 0x120f0
leaq (%rsi,%rsi), %rax
orq %rdi, %rax
je 0x12071
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orb $0x20, 0x2(%r8)
movq %rsi, %rdx
andq %rcx, %rdx
movzbl 0x1(%r8), %r8d
xorl %eax, %eax
cmpq $0x4, %r8
ja 0x1225a
leaq 0x4881(%rip), %r10      # 0x168c0
movslq (%r10,%r8,4), %r8
addq %r10, %r8
jmpq *%r8
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
jne 0x12211
movabsq $0xffffffffffff, %rax   # imm = 0xFFFFFFFFFFFF
andq %rsi, %rax
orq %rdi, %rax
jne 0x12201
jmp 0x12211
movq %rdi, %rax
movq %rsi, %rdx
jmp 0x1225a
movb $0x6e, %cl
subb %r9b, %cl
movl $0x2, %eax
shlq %cl, %rax
movzbl 0x1(%r8), %ecx
cmpq $0x4, %rcx
ja 0x1225c
leaq -0x1(%rax), %r10
leaq 0x4831(%rip), %rdx      # 0x168d4
movslq (%rdx,%rcx,4), %r11
addq %rdx, %r11
movq %rsi, %rdx
movq %rdi, %rcx
jmpq *%r11
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x12227
movq %rsi, %rdx
movq %rdi, %rcx
testq %rdi, %rdi
jns 0x12245
leaq 0x1(%rsi), %rcx
movabsq $-0x8000000000000000, %r9 # imm = 0x8000000000000000
decq %r9
movq %rcx, %rdx
andq $-0x2, %rdx
testq %r9, %rdi
cmovneq %rcx, %rdx
jmp 0x1215b
movb $0x2f, %cl
subb %r9b, %cl
movl $0x1, %edx
shlq %cl, %rdx
movzbl 0x1(%r8), %ecx
cmpq $0x4, %rcx
ja 0x1225c
leaq -0x1(%rdx), %rax
leaq 0x4795(%rip), %r9       # 0x168ac
movslq (%r9,%rcx,4), %r10
addq %r9, %r10
movq %rsi, %rcx
jmpq *%r10
movq %rdx, %rcx
shrq %rcx
addq %rsi, %rcx
andq %rcx, %rax
orq %rdi, %rax
jne 0x121c3
movq %rdx, %rax
notq %rax
andq %rax, %rcx
jmp 0x121c3
cmpl $0x402f, %r9d           # imm = 0x402F
jne 0x12215
movq %rdi, %rdx
shrq $0x3f, %rdx
addq %rsi, %rdx
movq %rdi, %rcx
jmp 0x12245
movq %rdx, %rcx
shrq %rcx
addq %rsi, %rcx
jmp 0x121c3
movq %rsi, %rdx
movq %rdi, %rcx
testq %rsi, %rsi
jns 0x12245
jmp 0x12198
movq %rsi, %rcx
testq %rsi, %rsi
jns 0x121c3
jmp 0x121b2
movq %rsi, %rdx
movq %rdi, %rcx
testq %rsi, %rsi
js 0x12245
addq %rdi, %r10
movq %rsi, %rdx
adcq $0x0, %rdx
movq %r10, %rcx
jmp 0x12245
movq %rsi, %rcx
testq %rsi, %rsi
js 0x121c3
xorl %ecx, %ecx
testq %rdi, %rdi
setne %cl
orq %rsi, %rcx
addq %rcx, %rax
movq %rax, %rcx
negq %rdx
andq %rcx, %rdx
xorl %eax, %eax
jmp 0x1224b
testq %rsi, %rsi
movabsq $0x3fff000000000000, %rax # imm = 0x3FFF000000000000
cmovnsq %rax, %rcx
xorl %eax, %eax
movq %rcx, %rdx
jmp 0x1225a
sarq $0x3f, %rsi
movabsq $-0x4001000000000000, %rdx # imm = 0xBFFF000000000000
andq %rsi, %rdx
jmp 0x12211
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
jne 0x12211
andq %rcx, %rsi
movabsq $0x3fff000000000000, %rdx # imm = 0x3FFF000000000000
orq %rsi, %rdx
xorl %eax, %eax
jmp 0x1225a
movq %rax, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rdx
adcq $0x0, %rdx
jmp 0x12245
movq %rax, %rcx
shrq %rcx
addq %rdi, %rcx
movq %rsi, %rdx
adcq $0x0, %rdx
testq %r10, %rcx
jne 0x12245
movq %rax, %r9
notq %r9
andq %r9, %rcx
negq %rax
andq %rcx, %rax
cmpq %rdi, %rax
jne 0x12255
cmpq %rsi, %rdx
je 0x1225a
orb $0x20, 0x2(%r8)
popq %rcx
retq
callq 0x1040