#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 */
double ft_modf(double, double *);
double ft_rint(double x) {
  double f;
  double n;
  n = 0.0;
  f = ft_modf(x, &n);
  if (x > 0.0) {
    if (f > 0.5)
      n += 1.0;
  } else if (x < 0.0) {
    if (f < -0.5)
      n -= 1.0;
  }
  return (n);
}


x86 assembly (clang, -O0):
<ft_rint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1030 <ft_modf@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1178 <ft_rint+0x68>
movsd  -0x10(%rbp),%xmm0
movsd  0xeb9(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1173 <ft_rint+0x63>
movsd  0xe9f(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11b9 <ft_rint+0xa9>
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11b4 <ft_rint+0xa4>
movsd  0xe72(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11af <ft_rint+0x9f>
movsd  -0x18(%rbp),%xmm0
movsd  0xe62(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11b4 <ft_rint+0xa4>
jmp    11b9 <ft_rint+0xa9>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ft_rint>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
call   1030 <ft_modf@plt>
movsd  0x10(%rsp),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jbe    1157 <ft_rint+0x47>
ucomisd 0xecb(%rip),%xmm0
jbe    117f <ft_rint+0x6f>
movsd  0x8(%rsp),%xmm0
addsd  0xec3(%rip),%xmm0
jmp    1179 <ft_rint+0x69>
ucomisd %xmm2,%xmm1
jbe    117f <ft_rint+0x6f>
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    117f <ft_rint+0x6f>
movsd  0x8(%rsp),%xmm0
addsd  0xe8f(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @ft_rint(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %4
%5 = load double, double* %2
%6 = call double @ft_modf(double %5, double* %4)
store double %6, double* %3
%7 = load double, double* %2
%8 = fcmp ogt double %7, 0.000000e+00
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp ogt double %10, 5.000000e-01
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %4
%14 = fadd double %13, 1.000000e+00
store double %14, double* %4
br label %15
15: ; preds = %12, %9
br label %27
16: ; preds = %1
%17 = load double, double* %2
%18 = fcmp olt double %17, 0.000000e+00
br i1 %18, label %19, label %26
19: ; preds = %16
%20 = load double, double* %3
%21 = fcmp olt double %20, -5.000000e-01
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = load double, double* %4
%24 = fsub double %23, 1.000000e+00
store double %24, double* %4
br label %25
25: ; preds = %22, %19
br label %26
26: ; preds = %25, %16
br label %27
27: ; preds = %26, %15
%28 = load double, double* %4
ret double %28
}

LLVM IR (-O2):
define double @ft_rint(double %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
store double 0.000000e+00, double* %2
%4 = call double @ft_modf(double %0, double* %2)
%5 = fcmp ogt double %0, 0.000000e+00
br i1 %5, label %6, label %11
6: ; preds = %1
%7 = fcmp ogt double %4, 5.000000e-01
br i1 %7, label %8, label %18
8: ; preds = %6
%9 = load double, double* %2
%10 = fadd double %9, 1.000000e+00
store double %10, double* %2
br label %18
11: ; preds = %1
%12 = fcmp olt double %0, 0.000000e+00
%13 = fcmp olt double %4, -5.000000e-01
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load double, double* %2
%17 = fadd double %16, -1.000000e+00
store double %17, double* %2
br label %18
18: ; preds = %11, %15, %6, %8
%19 = load double, double* %2
ret double %19
}