// File: /workspace/github_c_makefile_star2_O1/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 0xfd47
cmpl $0x7fff, %r9d           # imm = 0x7FFF
jne 0xfd69
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
decq %rax
andq %rdi, %rax
je 0xfd69
movq %rdi, %rdx
movl %esi, %ecx
callq 0xfecb
movl %edx, %esi
jmp 0xfec2
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
ja 0xfd71
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
leaq -0x1(%rcx), %r10
movq %rdi, %rax
andq %r10, %rax
orq %r9, %rax
jne 0xfdc5
movq %rdi, %rax
jmp 0xfec2
movb $0x3e, %cl
subb %r9b, %cl
movl $0x1, %edx
shlq %cl, %rdx
movzbl 0x1(%r8), %eax
cmpq $0x4, %rax
ja 0xfec6
leaq -0x1(%rdx), %rcx
leaq 0x6ab0(%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 0xfe47
movq %rdx, %rcx
notq %rcx
andq %rcx, %rax
jmp 0xfe47
orb $0x20, 0x2(%r8)
movl %esi, %edx
andl $0x8000, %edx           # imm = 0x8000
movzbl 0x1(%r8), %r8d
xorl %eax, %eax
cmpq $0x4, %r8
ja 0xfec0
leaq 0x6a72(%rip), %r11      # 0x1685c
movslq (%r11,%r8,4), %r8
addq %r11, %r8
jmpq *%r8
cmpl $0x3ffe, %r9d           # imm = 0x3FFE
setne %al
testq %r10, %rdi
sete %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 0xfec0
movq %rdx, %rax
shrq %rax
jmp 0xfe33
xorl %eax, %eax
testw %si, %si
cmovsq %rcx, %rax
addq %rdi, %rax
jmp 0xfe47
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
je 0xfec2
orb $0x20, 0x2(%r8)
jmp 0xfec2
xorl %eax, %eax
testw %si, %si
movl $0x3fff, %edx           # imm = 0x3FFF
movl $0x8000, %esi           # imm = 0x8000
cmovnsl %edx, %esi
cmovnsq %rcx, %rax
jmp 0xfec2
movswl %si, %ecx
shrl $0xf, %ecx
andl $0xbfff, %ecx           # imm = 0xBFFF
andl $0x8000, %esi           # imm = 0x8000
shlq $0x30, %rsi
movq %rsi, %rax
movl %ecx, %esi
jmp 0xfec2
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
movl %esi, %edx
popq %rcx
retq
callq 0x1040