#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) {
    double y = floor(x);
    if (x - y >= 0.5) {
      return y + 1.0;
    } else {
      return y;
    }
  } else {
    double y = ceil(x);
    if (y - x >= 0.5) {
      return y - 1.0;
    } else {
      return y;
    }
  }
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1190 <round+0x70>
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xea0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1181 <round+0x61>
movsd  0xe96(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <round+0xc0>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <round+0xc0>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe4f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11d6 <round+0xb6>
movsd  -0x20(%rbp),%xmm0
movsd  0xe40(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11e0 <round+0xc0>
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 %xmm1,%xmm0
movsd  %xmm0,(%rsp)
jae    1165 <round+0x45>
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  (%rsp),%xmm2
movsd  0xec6(%rip),%xmm3
addsd  %xmm0,%xmm3
movsd  0xeb2(%rip),%xmm0
cmpnlesd %xmm2,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm3,%xmm0
jmp    1198 <round+0x78>
call   1040 <floor@plt>
movapd %xmm0,%xmm1
movsd  (%rsp),%xmm3
subsd  %xmm0,%xmm3
movsd  0xe81(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xe7d(%rip),%xmm0
cmpnlesd %xmm3,%xmm0
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
pop    %rax
ret

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

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