#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 DBL_EPSILON;
long lrint(double x) {
  double y;
  if (x < 0.0L) {
    y = -(1.0L / DBL_EPSILON - x - 1.0 / DBL_EPSILON);
    if (y < x)
      y = y + 1.0L;
  } else {
    y = 1.0L / DBL_EPSILON + x - 1.0 / DBL_EPSILON;
    if (y > x)
      y = y - 1.0L;
  }
  return (long)y;
}


x86 assembly (clang, -O0):
<lrint>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x8(%rbp)
fldl   -0x8(%rbp)
fldz
fucomip %st(1),%st
fstp   %st(0)
jbe    116d <lrint+0x6d>
jmp    111d <lrint+0x1d>
mov    0x2ec4(%rip),%rax
fldt   (%rax)
fld1
fdivp  %st,%st(1)
fldl   -0x8(%rbp)
fsubr  %st(1),%st
fsubp  %st,%st(1)
fchs
fstpl  -0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1168 <lrint+0x68>
fldl   -0x10(%rbp)
fld1
faddp  %st,%st(1)
fstpl  -0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b9 <lrint+0xb9>
mov    0x2e74(%rip),%rax
fldt   (%rax)
fld1
fdivp  %st,%st(1)
fldl   -0x8(%rbp)
fadd   %st(1),%st
fsubp  %st,%st(1)
fstpl  -0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11b4 <lrint+0xb4>
fldl   -0x10(%rbp)
fld1
fchs
faddp  %st,%st(1)
fstpl  -0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b9 <lrint+0xb9>
cvttsd2si -0x10(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<lrint>:
movsd  %xmm0,-0x8(%rsp)
fldl   -0x8(%rsp)
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
mov    0x2ecf(%rip),%rax
fldt   (%rax)
fld1
fdiv   %st,%st(1)
jbe    1159 <lrint+0x59>
fxch   %st(2)
fsubr  %st(1),%st
fsubp  %st,%st(1)
fstpl  -0x28(%rsp)
movsd  -0x28(%rsp),%xmm1
xorpd  0xec7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118b <lrint+0x8b>
movsd  %xmm1,-0x30(%rsp)
faddl  -0x30(%rsp)
fstpl  -0x38(%rsp)
movsd  -0x38(%rsp),%xmm1
cvttsd2si %xmm1,%rax
ret
fxch   %st(2)
fadd   %st(1),%st
fsubp  %st,%st(1)
fstpl  -0x10(%rsp)
movsd  -0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jbe    118b <lrint+0x8b>
movsd  %xmm1,-0x18(%rsp)
fchs
faddl  -0x18(%rsp)
fstpl  -0x20(%rsp)
movsd  -0x20(%rsp),%xmm1
cvttsd2si %xmm1,%rax
ret
fstp   %st(0)
cvttsd2si %xmm1,%rax
ret

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

LLVM IR (-O2):
@DBL_EPSILON = global x86_fp80 0xK00000000000000000000
define i64 @lrint(double %0) {
%2 = fpext double %0 to x86_fp80
%3 = fcmp olt double %0, 0.000000e+00
%4 = load x86_fp80, x86_fp80* @DBL_EPSILON
%5 = fdiv x86_fp80 0xK3FFF8000000000000000, %4
br i1 %3, label %6, label %16
6: ; preds = %1
%7 = fsub x86_fp80 %5, %2
%8 = fsub x86_fp80 %7, %5
%9 = fptrunc x86_fp80 %8 to double
%10 = fneg double %9
%11 = fcmp olt double %10, %0
br i1 %11, label %12, label %25
12: ; preds = %6
%13 = fpext double %10 to x86_fp80
%14 = fadd x86_fp80 %13, 0xK3FFF8000000000000000
%15 = fptrunc x86_fp80 %14 to double
br label %25
16: ; preds = %1
%17 = fadd x86_fp80 %5, %2
%18 = fsub x86_fp80 %17, %5
%19 = fptrunc x86_fp80 %18 to double
%20 = fcmp ogt double %19, %0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = fpext double %19 to x86_fp80
%23 = fadd x86_fp80 %22, 0xKBFFF8000000000000000
%24 = fptrunc x86_fp80 %23 to double
br label %25
25: ; preds = %16, %21, %6, %12
%26 = phi double [ %15, %12 ], [ %10, %6 ], [ %24, %21 ], [ %19, %16 ]
%27 = fptosi double %26 to i64
ret i64 %27
}