#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 rint(double x) {
  if (ceil(x + 0.5) == floor(x + 0.5)) {
    int a = (int)ceil(x);
    if (a % 2 == 0) {
      return ceil(x);
    } else {
      return floor(x);
    }
  } else
    return floor(x + 0.5);
}


x86 assembly (clang, -O0):
<rint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  0xecb(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  0xeb4(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jne    11bb <rint+0x9b>
jp     11bb <rint+0x9b>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
cvttsd2si %xmm0,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    11a7 <rint+0x87>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <rint+0xb2>
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x8(%rbp)
jmp    11d2 <rint+0xb2>
movsd  0xe3d(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rint>:
sub    $0x18,%rsp
movsd  0xed4(%rip),%xmm1
movsd  %xmm0,(%rsp)
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1040 <floor@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jne    117f <rint+0x5f>
jp     117f <rint+0x5f>
movsd  (%rsp),%xmm0
call   1030 <ceil@plt>
cvttsd2si %xmm0,%eax
test   $0x1,%al
je     117f <rint+0x5f>
movsd  (%rsp),%xmm0
call   1040 <floor@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rint(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
store double %0, double* %3
%5 = load double, double* %3
%6 = fadd double %5, 5.000000e-01
%7 = call double @llvm.ceil.f64(double %6)
%8 = load double, double* %3
%9 = fadd double %8, 5.000000e-01
%10 = call double @llvm.floor.f64(double %9)
%11 = fcmp oeq double %7, %10
br i1 %11, label %12, label %25
12: ; preds = %1
%13 = load double, double* %3
%14 = call double @llvm.ceil.f64(double %13)
%15 = fptosi double %14 to i32
store i32 %15, i32* %4
%16 = load i32, i32* %4
%17 = srem i32 %16, 2
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %12
%20 = load double, double* %3
%21 = call double @llvm.ceil.f64(double %20)
store double %21, double* %2
br label %29
22: ; preds = %12
%23 = load double, double* %3
%24 = call double @llvm.floor.f64(double %23)
store double %24, double* %2
br label %29
25: ; preds = %1
%26 = load double, double* %3
%27 = fadd double %26, 5.000000e-01
%28 = call double @llvm.floor.f64(double %27)
store double %28, double* %2
br label %29
29: ; preds = %25, %22, %19
%30 = load double, double* %2
ret double %30
}

LLVM IR (-O2):
define double @rint(double %0) {
%2 = fadd double %0, 5.000000e-01
%3 = tail call double @llvm.ceil.f64(double %2)
%4 = tail call double @llvm.floor.f64(double %2)
%5 = fcmp oeq double %3, %4
br i1 %5, label %6, label %13
6: ; preds = %1
%7 = tail call double @llvm.ceil.f64(double %0)
%8 = fptosi double %7 to i32
%9 = and i32 %8, 1
%10 = icmp eq i32 %9, 0
%11 = tail call double @llvm.floor.f64(double %0)
%12 = select i1 %10, double %7, double %11
br label %13
13: ; preds = %1, %6
%14 = phi double [ %12, %6 ], [ %4, %1 ]
ret double %14
}