#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 ceil(double);
double fabs(double);
double floor(double);
double rt_roundd_snf(double u) {
  double y;
  if (fabs(u) < 4.503599627370496E+15) {
    if (u >= 0.5) {
      y = floor(u + 0.5);
    } else if (u > -0.5) {
      y = u * 0.0;
    } else {
      y = ceil(u - 0.5);
    }
  } else {
    y = u;
  }
  return y;
}


x86 assembly (clang, -O0):
<rt_roundd_snf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm1
movaps 0xee7(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  0xebb(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d0 <rt_roundd_snf+0xb0>
movsd  -0x8(%rbp),%xmm0
movsd  0xeac(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1182 <rt_roundd_snf+0x62>
movsd  0xe9a(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    11cb <rt_roundd_snf+0xab>
movsd  -0x8(%rbp),%xmm0
movsd  0xe81(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11ab <rt_roundd_snf+0x8b>
xorps  %xmm0,%xmm0
mulsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11c6 <rt_roundd_snf+0xa6>
movsd  -0x8(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    11cb <rt_roundd_snf+0xab>
jmp    11da <rt_roundd_snf+0xba>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rt_roundd_snf>:
movapd 0xed8(%rip),%xmm1
andpd  %xmm0,%xmm1
movsd  0xedc(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1156 <rt_roundd_snf+0x36>
ucomisd 0xed6(%rip),%xmm0
jae    1157 <rt_roundd_snf+0x37>
ucomisd 0xed4(%rip),%xmm0
jbe    1164 <rt_roundd_snf+0x44>
xorpd  %xmm1,%xmm1
mulsd  %xmm1,%xmm0
ret
addsd  0xeb9(%rip),%xmm0
jmp    1040 <floor@plt>
addsd  0xeb4(%rip),%xmm0
jmp    1030 <ceil@plt>

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

LLVM IR (-O2):
define double @rt_roundd_snf(double %0) {
%2 = tail call double @llvm.fabs.f64(double %0)
%3 = fcmp olt double %2, 0x4330000000000000
br i1 %3, label %4, label %16
4: ; preds = %1
%5 = fcmp ult double %0, 5.000000e-01
br i1 %5, label %9, label %6
6: ; preds = %4
%7 = fadd double %0, 5.000000e-01
%8 = tail call double @llvm.floor.f64(double %7)
br label %16
9: ; preds = %4
%10 = fcmp ogt double %0, -5.000000e-01
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = fmul double %0, 0.000000e+00
br label %16
13: ; preds = %9
%14 = fadd double %0, -5.000000e-01
%15 = tail call double @llvm.ceil.f64(double %14)
br label %16
16: ; preds = %1, %6, %13, %11
%17 = phi double [ %8, %6 ], [ %12, %11 ], [ %15, %13 ], [ %0, %1 ]
ret double %17
}