#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int int64_t;

/* Variables and functions */
long double rintl(long double x) {
  int64_t llinteger;
  long double fremainder;
  long double ret;
  llinteger = (int64_t)x;
  fremainder = x - (long double)llinteger;
  if (x < 0.0) {
    if (fremainder == -0.5) {
      llinteger = ((llinteger + 1) & ~1);
    } else if (fremainder < -0.5) {
      llinteger--;
    }
  } else {
    if (fremainder == 0.5) {
      llinteger = ((llinteger + 1) & ~1);
    } else if (fremainder > 0.5) {
      llinteger++;
    }
  }
  ret = (long double)llinteger;
  return ret;
}


x86 assembly (clang, -O0):
<rintl>:
push   %rbp
mov    %rsp,%rbp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
fnstcw -0x4e(%rbp)
movzwl -0x4e(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x50(%rbp)
fldcw  -0x50(%rbp)
fistpl -0x48(%rbp)
fldcw  -0x4e(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x14(%rbp)
fldt   -0x10(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x44(%rbp)
fildl  -0x44(%rbp)
fsubrp %st,%st(1)
fstpt  -0x30(%rbp)
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    11ad <rintl+0xad>
jmp    1151 <rintl+0x51>
fldt   -0x30(%rbp)
flds   0xeaa(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1182 <rintl+0x82>
jp     1182 <rintl+0x82>
jmp    1171 <rintl+0x71>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0xfffffffe,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <rintl+0xa8>
fldt   -0x30(%rbp)
flds   0xe79(%rip)
fucomip %st(1),%st
fstp   %st(0)
jbe    11a3 <rintl+0xa3>
jmp    119a <rintl+0x9a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    11a8 <rintl+0xa8>
jmp    120b <rintl+0x10b>
fldt   -0x30(%rbp)
flds   0xe4a(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    11de <rintl+0xde>
jp     11de <rintl+0xde>
jmp    11cd <rintl+0xcd>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
and    $0xfffffffe,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <rintl+0x106>
fldt   -0x30(%rbp)
flds   0xe19(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1201 <rintl+0x101>
jmp    11f8 <rintl+0xf8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1206 <rintl+0x106>
jmp    120b <rintl+0x10b>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4c(%rbp)
fildl  -0x4c(%rbp)
fstpt  -0x40(%rbp)
fldt   -0x40(%rbp)
pop    %rbp
ret

x86 assembly (clang, -O2):
<rintl>:
fldt   0x8(%rsp)
fnstcw -0x10(%rsp)
movzwl -0x10(%rsp),%eax
or     $0xc00,%eax
mov    %ax,-0xe(%rsp)
fldcw  -0xe(%rsp)
fistl  -0x8(%rsp)
fldcw  -0x10(%rsp)
mov    -0x8(%rsp),%eax
mov    %eax,-0x4(%rsp)
fld    %st(0)
fisubl -0x4(%rsp)
fldz
fucomip %st(2),%st
fstp   %st(1)
jbe    114d <rintl+0x4d>
flds   0xec5(%rip)
fxch   %st(1)
fucomi %st(1),%st
jne    116c <rintl+0x6c>
jp     116c <rintl+0x6c>
fstp   %st(0)
fstp   %st(0)
jmp    115d <rintl+0x5d>
flds   0xead(%rip)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jne    1179 <rintl+0x79>
jp     1179 <rintl+0x79>
add    $0x1,%eax
and    $0xfffffffe,%eax
mov    %eax,-0xc(%rsp)
fildl  -0xc(%rsp)
ret
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1163 <rintl+0x63>
add    $0xffffffff,%eax
jmp    1163 <rintl+0x63>
jbe    1163 <rintl+0x63>
add    $0x1,%eax
jmp    1163 <rintl+0x63>

LLVM IR (-O0):
define x86_fp80 @rintl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca i32
%4 = alloca x86_fp80
%5 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %2
%6 = load x86_fp80, x86_fp80* %2
%7 = fptosi x86_fp80 %6 to i32
store i32 %7, i32* %3
%8 = load x86_fp80, x86_fp80* %2
%9 = load i32, i32* %3
%10 = sitofp i32 %9 to x86_fp80
%11 = fsub x86_fp80 %8, %10
store x86_fp80 %11, x86_fp80* %4
%12 = load x86_fp80, x86_fp80* %2
%13 = fcmp olt x86_fp80 %12, 0xK00000000000000000000
br i1 %13, label %14, label %29
14: ; preds = %1
%15 = load x86_fp80, x86_fp80* %4
%16 = fcmp oeq x86_fp80 %15, 0xKBFFE8000000000000000
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, 1
%20 = and i32 %19, -2
store i32 %20, i32* %3
br label %28
21: ; preds = %14
%22 = load x86_fp80, x86_fp80* %4
%23 = fcmp olt x86_fp80 %22, 0xKBFFE8000000000000000
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %3
%26 = add nsw i32 %25, -1
store i32 %26, i32* %3
br label %27
27: ; preds = %24, %21
br label %28
28: ; preds = %27, %17
br label %44
29: ; preds = %1
%30 = load x86_fp80, x86_fp80* %4
%31 = fcmp oeq x86_fp80 %30, 0xK3FFE8000000000000000
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i32, i32* %3
%34 = add nsw i32 %33, 1
%35 = and i32 %34, -2
store i32 %35, i32* %3
br label %43
36: ; preds = %29
%37 = load x86_fp80, x86_fp80* %4
%38 = fcmp ogt x86_fp80 %37, 0xK3FFE8000000000000000
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %3
%41 = add nsw i32 %40, 1
store i32 %41, i32* %3
br label %42
42: ; preds = %39, %36
br label %43
43: ; preds = %42, %32
br label %44
44: ; preds = %43, %28
%45 = load i32, i32* %3
%46 = sitofp i32 %45 to x86_fp80
store x86_fp80 %46, x86_fp80* %5
%47 = load x86_fp80, x86_fp80* %5
ret x86_fp80 %47
}

LLVM IR (-O2):
define x86_fp80 @rintl(x86_fp80 %0) {
%2 = fptosi x86_fp80 %0 to i32
%3 = sitofp i32 %2 to x86_fp80
%4 = fsub x86_fp80 %0, %3
%5 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = fcmp oeq x86_fp80 %4, 0xKBFFE8000000000000000
br i1 %7, label %8, label %11
8: ; preds = %6
%9 = add nsw i32 %2, 1
%10 = and i32 %9, -2
br label %24
11: ; preds = %6
%12 = fcmp olt x86_fp80 %4, 0xKBFFE8000000000000000
br i1 %12, label %13, label %24
13: ; preds = %11
%14 = add nsw i32 %2, -1
br label %24
15: ; preds = %1
%16 = fcmp oeq x86_fp80 %4, 0xK3FFE8000000000000000
br i1 %16, label %17, label %20
17: ; preds = %15
%18 = add nsw i32 %2, 1
%19 = and i32 %18, -2
br label %24
20: ; preds = %15
%21 = fcmp ogt x86_fp80 %4, 0xK3FFE8000000000000000
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = add nsw i32 %2, 1
br label %24
24: ; preds = %17, %22, %20, %8, %13, %11
%25 = phi i32 [ %10, %8 ], [ %14, %13 ], [ %2, %11 ], [ %19, %17 ], [ %23, %22 ], [ %2, %20 ]
%26 = sitofp i32 %25 to x86_fp80
ret x86_fp80 %26
}