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


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     117f <round+0x6f>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xeb0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1170 <round+0x60>
movsd  -0x18(%rbp),%xmm0
movsd  0xea1(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f8 <round+0xe8>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe49(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d7 <round+0xc7>
movsd  -0x18(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
sub    $0x18,%rsp
movapd %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
jae    1177 <round+0x67>
xorpd  0xedd(%rip),%xmm0
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
movapd (%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0xeb3(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xeaf(%rip),%xmm0
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
xorpd  0xe9e(%rip),%xmm0
add    $0x18,%rsp
ret
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  (%rsp),%xmm2
movsd  0xe6f(%rip),%xmm3
addsd  %xmm0,%xmm3
movsd  0xe6b(%rip),%xmm0
cmpltsd %xmm2,%xmm0
andpd  %xmm0,%xmm3
andnpd %xmm1,%xmm0
orpd   %xmm3,%xmm0
add    $0x18,%rsp
ret

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

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.ceil.f64(double %0)
%5 = fsub double %4, %0
%6 = fcmp ogt double %5, 5.000000e-01
%7 = fadd double %4, -1.000000e+00
%8 = select i1 %6, double %7, double %4
br label %17
9: ; preds = %1
%10 = fneg double %0
%11 = tail call double @llvm.ceil.f64(double %10)
%12 = fadd double %11, %0
%13 = fcmp ogt double %12, 5.000000e-01
%14 = fadd double %11, -1.000000e+00
%15 = select i1 %13, double %14, double %11
%16 = fneg double %15
br label %17
17: ; preds = %9, %3
%18 = phi double [ %8, %3 ], [ %16, %9 ]
ret double %18
}