#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 abs(double);
long ceil(double);
long floor(double);
long l_round(double value) {
  long rounded = 0;
  if (abs(value - (long)value) >= 0.5)
    rounded = ceil(value);
  else if (abs(value - (long)value) < 0.5)
    rounded = floor(value);
  return rounded;
}


x86 assembly (clang, -O0):
<l_round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
cvttsd2si -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
call   1030 <abs@plt>
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1183 <l_round+0x53>
movsd  -0x8(%rbp),%xmm0
call   1040 <ceil@plt>
mov    %rax,-0x10(%rbp)
jmp    11c4 <l_round+0x94>
movsd  -0x8(%rbp),%xmm0
cvttsd2si -0x8(%rbp),%rax
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
call   1030 <abs@plt>
movaps %xmm0,%xmm1
movsd  0xe59(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11bf <l_round+0x8f>
movsd  -0x8(%rbp),%xmm0
call   1050 <floor@plt>
mov    %rax,-0x10(%rbp)
jmp    11c4 <l_round+0x94>
mov    -0x10(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<l_round>:
sub    $0x18,%rsp
cvttsd2si %xmm0,%rax
cvtsi2sd %rax,%xmm1
movsd  %xmm0,0x8(%rsp)
subsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
call   1030 <abs@plt>
ucomisd 0xea5(%rip),%xmm0
jae    1185 <l_round+0x55>
movsd  0x10(%rsp),%xmm0
call   1030 <abs@plt>
movsd  0xe90(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1194 <l_round+0x64>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
jmp    1050 <floor@plt>
movsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
jmp    1040 <ceil@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i64 @l_round(double %0) {
%2 = alloca double
%3 = alloca i64
store double %0, double* %2
store i64 0, i64* %3
%4 = load double, double* %2
%5 = load double, double* %2
%6 = fptosi double %5 to i64
%7 = sitofp i64 %6 to double
%8 = fsub double %4, %7
%9 = call double @abs(double %8)
%10 = fcmp oge double %9, 5.000000e-01
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load double, double* %2
%13 = call i64 @ceil(double %12)
store i64 %13, i64* %3
br label %26
14: ; preds = %1
%15 = load double, double* %2
%16 = load double, double* %2
%17 = fptosi double %16 to i64
%18 = sitofp i64 %17 to double
%19 = fsub double %15, %18
%20 = call double @abs(double %19)
%21 = fcmp olt double %20, 5.000000e-01
br i1 %21, label %22, label %25
22: ; preds = %14
%23 = load double, double* %2
%24 = call i64 @floor(double %23)
store i64 %24, i64* %3
br label %25
25: ; preds = %22, %14
br label %26
26: ; preds = %25, %11
%27 = load i64, i64* %3
ret i64 %27
}

LLVM IR (-O2):
define i64 @l_round(double %0) {
%2 = fptosi double %0 to i64
%3 = sitofp i64 %2 to double
%4 = fsub double %0, %3
%5 = tail call double @abs(double %4)
%6 = fcmp ult double %5, 5.000000e-01
br i1 %6, label %9, label %7
7: ; preds = %1
%8 = tail call i64 @ceil(double %0)
br label %14
9: ; preds = %1
%10 = tail call double @abs(double %4)
%11 = fcmp olt double %10, 5.000000e-01
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i64 @floor(double %0)
br label %14
14: ; preds = %9, %12, %7
%15 = phi i64 [ %8, %7 ], [ %13, %12 ], [ 0, %9 ]
ret i64 %15
}