#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);
int fabs(double);
double xround(double a) {
  double c;
  c = ceil(a);
  if ((fabs((double)(c - a) - (0.5)) < 1E-9)) {
    if (((long)c) % 2 == 0)
      return c;
    else
      return c - 1;
  } else if ((((double)(0.5) - (c)) >= 1E-9))
    return c;
  else
    return c - 1;
}


x86 assembly (clang, -O0):
<xround>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xeba(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe9d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b1 <xround+0x91>
cvttsd2si -0x18(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
cmp    $0x0,%rdx
jne    1196 <xround+0x76>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f5 <xround+0xd5>
movsd  -0x18(%rbp),%xmm0
movsd  0xe6d(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f5 <xround+0xd5>
movsd  0xe4f(%rip),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11df <xround+0xbf>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11f5 <xround+0xd5>
movsd  -0x18(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xround>:
sub    $0x18,%rsp
movsd  %xmm0,0x10(%rsp)
call   1030 <ceil@plt>
movsd  %xmm0,0x8(%rsp)
subsd  0x10(%rsp),%xmm0
addsd  0xebd(%rip),%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    1179 <xround+0x59>
movsd  0xeb4(%rip),%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm1,%xmm0
ucomisd 0xeaa(%rip),%xmm0
movapd %xmm1,%xmm0
jae    1174 <xround+0x54>
addsd  0xea4(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
cvttsd2si %xmm0,%rax
test   $0x1,%al
jne    116c <xround+0x4c>
jmp    1174 <xround+0x54>

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

LLVM IR (-O2):
define double @xround(double %0) {
%2 = tail call double @llvm.ceil.f64(double %0)
%3 = fsub double %2, %0
%4 = fadd double %3, -5.000000e-01
%5 = tail call i32 @fabs(double %4)
%6 = icmp slt i32 %5, 1
br i1 %6, label %7, label %13
7: ; preds = %1
%8 = fptosi double %2 to i64
%9 = and i64 %8, 1
%10 = icmp eq i64 %9, 0
%11 = fadd double %2, -1.000000e+00
%12 = select i1 %10, double %2, double %11
br label %18
13: ; preds = %1
%14 = fsub double 5.000000e-01, %2
%15 = fcmp ult double %14, 1.000000e-09
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = fadd double %2, -1.000000e+00
br label %18
18: ; preds = %7, %13, %16
%19 = phi double [ %17, %16 ], [ %2, %13 ], [ %12, %7 ]
ret double %19
}