#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 */
float const fabs(double);
double __rint(double x) {
  static const float TWO52 = 4503599627370496.0;
  if (fabs(x) < TWO52) {
    if (x > 0.0) {
      x += TWO52;
      x -= TWO52;
    } else if (x < 0.0) {
      x = TWO52 - x;
      x = -(x - TWO52);
    }
  }
  return x;
}


x86 assembly (clang, -O0):
<__rint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <fabs@plt>
movaps %xmm0,%xmm1
movss  0xece(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    11d1 <__rint+0xc1>
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    117a <__rint+0x6a>
movsd  0xeb3(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe9c(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cc <__rint+0xbc>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11c7 <__rint+0xb7>
movsd  0xe78(%rip),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe61(%rip),%xmm1
subsd  %xmm1,%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11cc <__rint+0xbc>
jmp    11d1 <__rint+0xc1>
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<__rint>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <fabs@plt>
movss  0xedd(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1148 <__rint+0x38>
xorps  %xmm1,%xmm1
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    114f <__rint+0x3f>
addsd  0xeca(%rip),%xmm0
addsd  0xeca(%rip),%xmm0
pop    %rax
ret
movsd  (%rsp),%xmm0
pop    %rax
ret
ucomisd %xmm0,%xmm1
jbe    1175 <__rint+0x65>
movsd  0xeab(%rip),%xmm1
subsd  %xmm0,%xmm1
addsd  0xea7(%rip),%xmm1
xorpd  0xeaf(%rip),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@__rint.TWO52 = internal constant float 0x4330000000000000
define double @__rint(double %0) {
%2 = alloca double
store double %0, double* %2
%3 = load double, double* %2
%4 = call float @fabs(double %3)
%5 = fcmp olt float %4, 0x4330000000000000
br i1 %5, label %6, label %25
6: ; preds = %1
%7 = load double, double* %2
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %9, label %14
9: ; preds = %6
%10 = load double, double* %2
%11 = fadd double %10, 0x4330000000000000
store double %11, double* %2
%12 = load double, double* %2
%13 = fsub double %12, 0x4330000000000000
store double %13, double* %2
br label %24
14: ; preds = %6
%15 = load double, double* %2
%16 = fcmp olt double %15, 0.000000e+00
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load double, double* %2
%19 = fsub double 0x4330000000000000, %18
store double %19, double* %2
%20 = load double, double* %2
%21 = fsub double %20, 0x4330000000000000
%22 = fneg double %21
store double %22, double* %2
br label %23
23: ; preds = %17, %14
br label %24
24: ; preds = %23, %9
br label %25
25: ; preds = %24, %1
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
define double @__rint(double %0) {
%2 = tail call float @fabs(double %0)
%3 = fcmp olt float %2, 0x4330000000000000
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = fcmp ogt double %0, 0.000000e+00
br i1 %5, label %6, label %9
6: ; preds = %4
%7 = fadd double %0, 0x4330000000000000
%8 = fadd double %7, 0xC330000000000000
br label %15
9: ; preds = %4
%10 = fcmp olt double %0, 0.000000e+00
br i1 %10, label %11, label %15
11: ; preds = %9
%12 = fsub double 0x4330000000000000, %0
%13 = fadd double %12, 0xC330000000000000
%14 = fneg double %13
br label %15
15: ; preds = %6, %11, %9, %1
%16 = phi double [ %8, %6 ], [ %14, %11 ], [ %0, %9 ], [ %0, %1 ]
ret double %16
}