#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 */
float fabs(double);
double modf(double, double *);
double round(double f) {
  double intpart, floatpart;
  floatpart = modf(f, &intpart);
  if (fabs(floatpart) >= 0.5f) {
    if (floatpart >= 0.5f)
      intpart += 1.0f;
    else if (floatpart <= 0.5f)
      intpart -= 1.0f;
  }
  return intpart;
}


x86 assembly (clang, -O0):
<round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
lea    -0x10(%rbp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1040 <fabs@plt>
movss  0xeae(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11bc <round+0x9c>
movsd  -0x18(%rbp),%xmm0
movsd  0xea0(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1189 <round+0x69>
movsd  0xe96(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b7 <round+0x97>
movsd  0xe77(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11b2 <round+0x92>
movsd  -0x10(%rbp),%xmm0
movsd  0xe67(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11b7 <round+0x97>
jmp    11bc <round+0x9c>
movsd  -0x10(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<round>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
call   1030 <modf@plt>
movsd  %xmm0,0x10(%rsp)
call   1040 <fabs@plt>
ucomiss 0xec0(%rip),%xmm0
jb     1184 <round+0x64>
movsd  0x10(%rsp),%xmm1
ucomisd 0xeb8(%rip),%xmm1
jae    1170 <round+0x50>
movsd  0xeae(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1184 <round+0x64>
movsd  0x8(%rsp),%xmm0
addsd  0xeaa(%rip),%xmm0
jmp    117e <round+0x5e>
movsd  0x8(%rsp),%xmm0
addsd  0xe92(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  0x8(%rsp),%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* %2
%5 = load double, double* %2
%6 = call double @modf(double %5, double* %3)
store double %6, double* %4
%7 = load double, double* %4
%8 = call float @fabs(double %7)
%9 = fcmp oge float %8, 5.000000e-01
br i1 %9, label %10, label %24
10: ; preds = %1
%11 = load double, double* %4
%12 = fcmp oge double %11, 5.000000e-01
br i1 %12, label %13, label %16
13: ; preds = %10
%14 = load double, double* %3
%15 = fadd double %14, 1.000000e+00
store double %15, double* %3
br label %23
16: ; preds = %10
%17 = load double, double* %4
%18 = fcmp ole double %17, 5.000000e-01
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load double, double* %3
%21 = fsub double %20, 1.000000e+00
store double %21, double* %3
br label %22
22: ; preds = %19, %16
br label %23
23: ; preds = %22, %13
br label %24
24: ; preds = %23, %1
%25 = load double, double* %3
ret double %25
}

LLVM IR (-O2):
define double @round(double %0) {
%2 = alloca double
%3 = bitcast double* %2 to i8*
%4 = call double @modf(double %0, double* %2)
%5 = tail call float @fabs(double %4)
%6 = fcmp ult float %5, 5.000000e-01
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = fcmp ult double %4, 5.000000e-01
br i1 %8, label %12, label %9
9: ; preds = %7
%10 = load double, double* %2
%11 = fadd double %10, 1.000000e+00
store double %11, double* %2
br label %17
12: ; preds = %7
%13 = fcmp ugt double %4, 5.000000e-01
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = load double, double* %2
%16 = fadd double %15, -1.000000e+00
store double %16, double* %2
br label %17
17: ; preds = %9, %14, %12, %1
%18 = load double, double* %2
ret double %18
}