// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x403e, %r9d           # imm = 0x403E
jb 0xfd8a
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0xfe9f
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
decq %rax
andq %rdi, %rax
je 0xfe9f
movq %rdi, %rdx
movl %esi, %ecx
callq 0xff00
movl %edx, %esi
jmp 0xfea2
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
ja 0xfe0d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq -0x1(%rcx), %r10
movq %rdi, %rax
andq %r10, %rax
orq %r9, %rax
je 0xfe9f
orb $0x20, 0x2(%r8)
movl %esi, %edx
andl $0x8000, %edx           # imm = 0x8000
movzbl 0x1(%r8), %r8d
xorl %eax, %eax
cmpq $0x4, %r8
ja 0xfef7
leaq 0x6a87(%rip), %r11      # 0x1685c
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 0xfef7
movb $0x3e, %cl
subb %r9b, %cl
movl $0x1, %edx
shlq %cl, %rdx
movzbl 0x1(%r8), %eax
cmpq $0x4, %rax
ja 0xfefb
leaq -0x1(%rdx), %rcx
leaq 0x6a14(%rip), %r9       # 0x16848
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 0xfe7f
movq %rdx, %rcx
notq %rcx
andq %rcx, %rax
jmp 0xfe7f
movq %rdx, %rax
shrq %rax
jmp 0xfe6b
xorl %eax, %eax
testw %si, %si
cmovsq %rcx, %rax
addq %rdi, %rax
jmp 0xfe7f
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 0xfea6
movq %rdi, %rax
movl %esi, %edx
popq %rcx
retq
orb $0x20, 0x2(%r8)
jmp 0xfea2
xorl %eax, %eax
testw %si, %si
movl $0x3fff, %edx           # imm = 0x3FFF
movl $0x8000, %esi           # imm = 0x8000
cmovnsl %edx, %esi
cmovnsq %rcx, %rax
jmp 0xfea2
movswl %si, %esi
shrl $0xf, %esi
andl $0xbfff, %esi           # imm = 0xBFFF
movzwl %dx, %eax
shlq $0x30, %rax
jmp 0xfea2
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 0xfea2
callq 0x1040