#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 floor(double);
double fmod(double, int);
double round(double x) {
  if (x < 0.0)
    return fmod(x, -1) <= -0.5 ? floor(x) : ceil(x);
  else
    return fmod(x, 1) < 0.5 ? floor(x) : ceil(x);
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11a1 <round+0x71>
movsd  -0x10(%rbp),%xmm0
mov    $0xffffffff,%edi
call   1040 <fmod@plt>
movaps %xmm0,%xmm1
movsd  0xea3(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1183 <round+0x53>
movsd  -0x10(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1192 <round+0x62>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f2 <round+0xc2>
movsd  -0x10(%rbp),%xmm0
mov    $0x1,%edi
call   1040 <fmod@plt>
movaps %xmm0,%xmm1
movsd  0xe45(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d9 <round+0xa9>
movsd  -0x10(%rbp),%xmm0
call   1050 <floor@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    11e8 <round+0xb8>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
jbe    1163 <round+0x33>
mov    $0xffffffff,%edi
call   1040 <fmod@plt>
movsd  0xeb6(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    117b <round+0x4b>
movsd  (%rsp),%xmm0
pop    %rax
jmp    1030 <ceil@plt>
mov    $0x1,%edi
call   1040 <fmod@plt>
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1158 <round+0x28>
movsd  (%rsp),%xmm0
pop    %rax
jmp    1050 <floor@plt>

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

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