#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 round(double x) {
  if (x > 0.0) {
    if ((ceil(x) - x) <= (x - floor(x)))
      return (ceil(x));
    else
      return (floor(x));
  } else if (x < 0.0) {
    if ((x - floor(x)) <= (ceil(x) - x))
      return (floor(x));
    else
      return (ceil(x));
  } else
    return (x);
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11aa <round+0x8a>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  -0x20(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x18(%rbp),%xmm0
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     1196 <round+0x76>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122d <round+0x10d>
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122d <round+0x10d>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1223 <round+0x103>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  -0x28(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     120f <round+0xef>
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122d <round+0x10d>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    122d <round+0x10d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
sub    $0x38,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    1184 <round+0x64>
movsd  %xmm0,0x8(%rsp)
call   1030 <ceil@plt>
movapd %xmm0,0x20(%rsp)
movapd %xmm0,%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
movapd %xmm1,0x10(%rsp)
call   1040 <floor@plt>
movsd  0x8(%rsp),%xmm2
subsd  %xmm0,%xmm2
movapd 0x10(%rsp),%xmm1
cmpnlesd %xmm2,%xmm1
andpd  %xmm1,%xmm0
andnpd 0x20(%rsp),%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x38,%rsp
ret
ucomisd %xmm0,%xmm1
jbe    11df <round+0xbf>
movsd  %xmm0,0x8(%rsp)
call   1040 <floor@plt>
movapd %xmm0,0x20(%rsp)
movsd  0x8(%rsp),%xmm1
movapd %xmm1,%xmm2
subsd  %xmm0,%xmm2
movapd %xmm2,0x10(%rsp)
movapd %xmm1,%xmm0
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movapd 0x10(%rsp),%xmm2
cmpnlesd %xmm1,%xmm2
andpd  %xmm2,%xmm0
andnpd 0x20(%rsp),%xmm2
orpd   %xmm0,%xmm2
movapd %xmm2,%xmm0
add    $0x38,%rsp
ret

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 ogt double %4, 0.000000e+00
br i1 %5, label %6, label %22
6: ; preds = %1
%7 = load double, double* %3
%8 = call double @llvm.ceil.f64(double %7)
%9 = load double, double* %3
%10 = fsub double %8, %9
%11 = load double, double* %3
%12 = load double, double* %3
%13 = call double @llvm.floor.f64(double %12)
%14 = fsub double %11, %13
%15 = fcmp ole double %10, %14
br i1 %15, label %16, label %19
16: ; preds = %6
%17 = load double, double* %3
%18 = call double @llvm.ceil.f64(double %17)
store double %18, double* %2
br label %43
19: ; preds = %6
%20 = load double, double* %3
%21 = call double @llvm.floor.f64(double %20)
store double %21, double* %2
br label %43
22: ; preds = %1
%23 = load double, double* %3
%24 = fcmp olt double %23, 0.000000e+00
br i1 %24, label %25, label %41
25: ; preds = %22
%26 = load double, double* %3
%27 = load double, double* %3
%28 = call double @llvm.floor.f64(double %27)
%29 = fsub double %26, %28
%30 = load double, double* %3
%31 = call double @llvm.ceil.f64(double %30)
%32 = load double, double* %3
%33 = fsub double %31, %32
%34 = fcmp ole double %29, %33
br i1 %34, label %35, label %38
35: ; preds = %25
%36 = load double, double* %3
%37 = call double @llvm.floor.f64(double %36)
store double %37, double* %2
br label %43
38: ; preds = %25
%39 = load double, double* %3
%40 = call double @llvm.ceil.f64(double %39)
store double %40, double* %2
br label %43
41: ; preds = %22
%42 = load double, double* %3
store double %42, double* %2
br label %43
43: ; preds = %41, %38, %35, %19, %16
%44 = load double, double* %2
ret double %44
}

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