#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 */

/* Variables and functions */
long double LDBL_EPSILON;
long lrintl(long double x) {
  long double y;
  if (x < 0.0L) {
    y = -(1.0L / LDBL_EPSILON - x - 1.0 / LDBL_EPSILON);
    if (y < x)
      y = y + 1.0L;
  } else {
    y = 1.0L / LDBL_EPSILON + x - 1.0 / LDBL_EPSILON;
    if (y > x)
      y = y - 1.0L;
  }
  return (long)y;
}


x86 assembly (clang, -O0):
<lrintl>:
push   %rbp
mov    %rsp,%rbp
fldt   0x10(%rbp)
fstpt  -0x10(%rbp)
fldt   -0x10(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    115b <lrintl+0x5b>
jmp    111e <lrintl+0x1e>
mov    0x2eb3(%rip),%rax
fldt   (%rax)
fld1
fdivp  %st,%st(1)
fldt   -0x10(%rbp)
fsubr  %st(1),%st
fsubp  %st,%st(1)
fchs
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
fucomip %st(1),%st
fstp   %st(0)
jbe    1156 <lrintl+0x56>
jmp    114c <lrintl+0x4c>
fldt   -0x20(%rbp)
fld1
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
jmp    119a <lrintl+0x9a>
mov    0x2e76(%rip),%rax
fldt   (%rax)
fld1
fdivp  %st,%st(1)
fldt   -0x10(%rbp)
fadd   %st(1),%st
fsubp  %st,%st(1)
fstpt  -0x20(%rbp)
fldt   -0x20(%rbp)
fldt   -0x10(%rbp)
fxch   %st(1)
fucomip %st(1),%st
fstp   %st(0)
jbe    1195 <lrintl+0x95>
jmp    1189 <lrintl+0x89>
fldt   -0x20(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpt  -0x20(%rbp)
jmp    119a <lrintl+0x9a>
fldt   -0x20(%rbp)
fnstcw -0x2a(%rbp)
movzwl -0x2a(%rbp),%eax
or     $0xc00,%eax
mov    %ax,-0x2c(%rbp)
fldcw  -0x2c(%rbp)
fistpll -0x28(%rbp)
fldcw  -0x2a(%rbp)
mov    -0x28(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<lrintl>:
fldt   0x8(%rsp)
fldz
fucomip %st(1),%st
mov    0x2ec9(%rip),%rax
fldt   (%rax)
fld1
fdivp  %st,%st(1)
jbe    112f <lrintl+0x2f>
fld    %st(0)
fsub   %st(2),%st
fsubp  %st,%st(1)
fld    %st(0)
fchs
fxch   %st(2)
fucomip %st(2),%st
jbe    1143 <lrintl+0x43>
fstp   %st(1)
fld1
fsubp  %st,%st(1)
jmp    1141 <lrintl+0x41>
fld    %st(0)
fadd   %st(2),%st
fsubp  %st,%st(1)
fucomi %st(1),%st
fstp   %st(1)
jbe    1141 <lrintl+0x41>
fld1
fchs
faddp  %st,%st(1)
fldz
fstp   %st(0)
fnstcw -0xc(%rsp)
movzwl -0xc(%rsp),%eax
or     $0xc00,%eax
mov    %ax,-0xa(%rsp)
fldcw  -0xa(%rsp)
fistpll -0x8(%rsp)
fldcw  -0xc(%rsp)
mov    -0x8(%rsp),%rax
ret

LLVM IR (-O0):
@LDBL_EPSILON = global x86_fp80 0xK00000000000000000000
define i64 @lrintl(x86_fp80 %0) {
%2 = alloca x86_fp80
%3 = alloca x86_fp80
store x86_fp80 %0, x86_fp80* %2
%4 = load x86_fp80, x86_fp80* %2
%5 = fcmp olt x86_fp80 %4, 0xK00000000000000000000
br i1 %5, label %6, label %22
6: ; preds = %1
%7 = load x86_fp80, x86_fp80* @LDBL_EPSILON
%8 = fdiv x86_fp80 0xK3FFF8000000000000000, %7
%9 = load x86_fp80, x86_fp80* %2
%10 = fsub x86_fp80 %8, %9
%11 = load x86_fp80, x86_fp80* @LDBL_EPSILON
%12 = fdiv x86_fp80 0xK3FFF8000000000000000, %11
%13 = fsub x86_fp80 %10, %12
%14 = fneg x86_fp80 %13
store x86_fp80 %14, x86_fp80* %3
%15 = load x86_fp80, x86_fp80* %3
%16 = load x86_fp80, x86_fp80* %2
%17 = fcmp olt x86_fp80 %15, %16
br i1 %17, label %18, label %21
18: ; preds = %6
%19 = load x86_fp80, x86_fp80* %3
%20 = fadd x86_fp80 %19, 0xK3FFF8000000000000000
store x86_fp80 %20, x86_fp80* %3
br label %21
21: ; preds = %18, %6
br label %37
22: ; preds = %1
%23 = load x86_fp80, x86_fp80* @LDBL_EPSILON
%24 = fdiv x86_fp80 0xK3FFF8000000000000000, %23
%25 = load x86_fp80, x86_fp80* %2
%26 = fadd x86_fp80 %24, %25
%27 = load x86_fp80, x86_fp80* @LDBL_EPSILON
%28 = fdiv x86_fp80 0xK3FFF8000000000000000, %27
%29 = fsub x86_fp80 %26, %28
store x86_fp80 %29, x86_fp80* %3
%30 = load x86_fp80, x86_fp80* %3
%31 = load x86_fp80, x86_fp80* %2
%32 = fcmp ogt x86_fp80 %30, %31
br i1 %32, label %33, label %36
33: ; preds = %22
%34 = load x86_fp80, x86_fp80* %3
%35 = fsub x86_fp80 %34, 0xK3FFF8000000000000000
store x86_fp80 %35, x86_fp80* %3
br label %36
36: ; preds = %33, %22
br label %37
37: ; preds = %36, %21
%38 = load x86_fp80, x86_fp80* %3
%39 = fptosi x86_fp80 %38 to i64
ret i64 %39
}

LLVM IR (-O2):
@LDBL_EPSILON = global x86_fp80 0xK00000000000000000000
define i64 @lrintl(x86_fp80 %0) {
%2 = fcmp olt x86_fp80 %0, 0xK00000000000000000000
%3 = load x86_fp80, x86_fp80* @LDBL_EPSILON
%4 = fdiv x86_fp80 0xK3FFF8000000000000000, %3
br i1 %2, label %5, label %12
5: ; preds = %1
%6 = fsub x86_fp80 %4, %0
%7 = fsub x86_fp80 %6, %4
%8 = fneg x86_fp80 %7
%9 = fcmp olt x86_fp80 %8, %0
br i1 %9, label %10, label %18
10: ; preds = %5
%11 = fsub x86_fp80 0xK3FFF8000000000000000, %7
br label %18
12: ; preds = %1
%13 = fadd x86_fp80 %4, %0
%14 = fsub x86_fp80 %13, %4
%15 = fcmp ogt x86_fp80 %14, %0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = fadd x86_fp80 %14, 0xKBFFF8000000000000000
br label %18
18: ; preds = %12, %16, %5, %10
%19 = phi x86_fp80 [ %11, %10 ], [ %8, %5 ], [ %17, %16 ], [ %14, %12 ]
%20 = fptosi x86_fp80 %19 to i64
ret i64 %20
}