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

    aExp = extractFloatx80Exp( a );
    if ( 0x403E <= aExp ) {
        if ( ( aExp == 0x7FFF ) && (uint64_t) ( extractFloatx80Frac( a )<<1 ) ) {
            return propagateFloatx80NaN(a, a, status);
        }
        return a;
    }
    if ( aExp < 0x3FFF ) {
        if (    ( aExp == 0 )
             && ( (uint64_t) ( extractFloatx80Frac( a )<<1 ) == 0 ) ) {
            return a;
        }
        status->float_exception_flags |= float_flag_inexact;
        aSign = extractFloatx80Sign( a );
        switch (status->float_rounding_mode) {
         case float_round_nearest_even:
            if ( ( aExp == 0x3FFE ) && (uint64_t) ( extractFloatx80Frac( a )<<1 )
               ) {
                return
                    packFloatx80( aSign, 0x3FFF, LIT64( 0x8000000000000000 ) );
            }
            break;
        case float_round_ties_away:
            if (aExp == 0x3FFE) {
                return packFloatx80(aSign, 0x3FFF, LIT64(0x8000000000000000));
            }
            break;
         case float_round_down:
            return
                  aSign ?
                      packFloatx80( 1, 0x3FFF, LIT64( 0x8000000000000000 ) )
                : packFloatx80( 0, 0, 0 );
         case float_round_up:
            return
                  aSign ? packFloatx80( 1, 0, 0 )
                : packFloatx80( 0, 0x3FFF, LIT64( 0x8000000000000000 ) );
        }
        return packFloatx80( aSign, 0, 0 );
    }
    lastBitMask = 1;
    lastBitMask <<= 0x403E - aExp;
    roundBitsMask = lastBitMask - 1;
    z = a;
    switch (status->float_rounding_mode) {
    case float_round_nearest_even:
        z.low += lastBitMask>>1;
        if ((z.low & roundBitsMask) == 0) {
            z.low &= ~lastBitMask;
        }
        break;
    case float_round_ties_away:
        z.low += lastBitMask >> 1;
        break;
    case float_round_to_zero:
        break;
    case float_round_up:
        if (!extractFloatx80Sign(z)) {
            z.low += roundBitsMask;
        }
        break;
    case float_round_down:
        if (extractFloatx80Sign(z)) {
            z.low += roundBitsMask;
        }
        break;
    default:
        abort();
    }
    z.low &= ~ roundBitsMask;
    if ( z.low == 0 ) {
        ++z.high;
        z.low = LIT64( 0x8000000000000000 );
    }
    if (z.low != a.low) {
        status->float_exception_flags |= float_flag_inexact;
    }
    return z;

}

// Assembly:
pushq %rax
movq %rdx, %r8
movl %esi, %r9d
andl $0x7fff, %r9d           # imm = 0x7FFF
cmpw $0x403e, %r9w           # imm = 0x403E
jb 0xeae0
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0xebf2
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
decq %rax
andq %rdi, %rax
je 0xebf2
movq %rdi, %rdx
movl %esi, %ecx
callq 0xec53
movl %edx, %esi
jmp 0xebf5
cmpw $0x3ffe, %r9w           # imm = 0x3FFE
ja 0xeb62
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq -0x1(%rcx), %r10
movq %rdi, %rax
andq %r10, %rax
orq %r9, %rax
je 0xebf2
orb $0x20, 0x2(%r8)
movl %esi, %edx
andl $0x8000, %edx           # imm = 0x8000
movzbl 0x1(%r8), %r8d
xorl %eax, %eax
cmpq $0x4, %r8
ja 0xec4a
leaq 0x5d32(%rip), %r11      # 0x1485c
movslq (%r11,%r8,4), %r8
addq %r11, %r8
jmpq *%r8
testq %r10, %rdi
sete %al
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
setne %dil
orb %al, %dil
orl $0x3fff, %esi           # imm = 0x3FFF
xorl %eax, %eax
testb %dil, %dil
cmovneq %rax, %rcx
cmovel %esi, %edx
movq %rcx, %rax
jmp 0xec4a
movb $0x3e, %cl
subb %r9b, %cl
pushq $0x1
popq %rdx
shlq %cl, %rdx
movzbl 0x1(%r8), %eax
cmpq $0x4, %rax
ja 0xec4e
leaq -0x1(%rdx), %rcx
leaq 0x5cc1(%rip), %r9       # 0x14848
movslq (%r9,%rax,4), %r10
addq %r9, %r10
movq %rdi, %rax
jmpq *%r10
movq %rdx, %rax
shrq %rax
addq %rdi, %rax
testq %rcx, %rax
jne 0xebd2
movq %rdx, %rcx
notq %rcx
andq %rcx, %rax
jmp 0xebd2
movq %rdx, %rax
shrq %rax
jmp 0xebbe
xorl %eax, %eax
testw %si, %si
cmovsq %rcx, %rax
addq %rdi, %rax
jmp 0xebd2
xorl %eax, %eax
testw %si, %si
cmovsq %rax, %rcx
addq %rdi, %rcx
movq %rcx, %rax
negq %rdx
xorl %ecx, %ecx
andq %rax, %rdx
sete %cl
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
cmovneq %rdx, %rax
addl %ecx, %esi
cmpq %rdi, %rax
jne 0xebf9
movq %rdi, %rax
movl %esi, %edx
popq %rcx
retq
orb $0x20, 0x2(%r8)
jmp 0xebf5
xorl %eax, %eax
testw %si, %si
movl $0x3fff, %edx           # imm = 0x3FFF
movl $0x8000, %esi           # imm = 0x8000
cmovnsl %edx, %esi
cmovnsq %rcx, %rax
jmp 0xebf5
movswl %si, %esi
shrl $0xf, %esi
andl $0xbfff, %esi           # imm = 0xBFFF
movzwl %dx, %eax
shlq $0x30, %rax
jmp 0xebf5
orl $0x3fff, %esi           # imm = 0x3FFF
xorl %eax, %eax
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
cmoveq %rcx, %rax
cmpq $0x3ffe, %r9            # imm = 0x3FFE
cmovel %esi, %edx
movl %edx, %esi
jmp 0xebf5
callq 0x1040