#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 floor(double);
int /*<<< orphan*/ isfinite(double);
double round(double x) {
  double t;
  if (!isfinite(x))
    return x;
  if (x >= 0.0) {
    t = floor(x);
    if (t - x <= -0.5)
      t += 1.0;
    return t;
  } else {
    t = floor(-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
call   1030 <isfinite@plt>
cmp    $0x0,%eax
jne    114f <round+0x2f>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1222 <round+0x102>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11ad <round+0x8d>
movsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
subsd  -0x10(%rbp),%xmm1
movsd  0xe7e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     119e <round+0x7e>
movsd  0xe74(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1222 <round+0x102>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
addsd  -0x10(%rbp),%xmm1
movsd  0xe1b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1201 <round+0xe1>
movsd  0xe11(%rip),%xmm0
addsd  -0x18(%rbp),%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,(%rsp)
call   1030 <isfinite@plt>
test   %eax,%eax
je     11b1 <round+0x91>
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    11ba <round+0x9a>
movapd (%rsp),%xmm0
xorpd  0xec2(%rip),%xmm0
call   1040 <floor@plt>
movapd (%rsp),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movsd  0xe97(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd (%rsp),%xmm2
cmpnlesd 0xe8d(%rip),%xmm2
movapd %xmm2,(%rsp)
andpd  (%rsp),%xmm0
movapd (%rsp),%xmm2
andnpd %xmm1,%xmm2
movapd %xmm2,(%rsp)
movapd (%rsp),%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,(%rsp)
movaps (%rsp),%xmm0
xorps  0xe64(%rip),%xmm0
add    $0x18,%rsp
ret
movaps (%rsp),%xmm0
add    $0x18,%rsp
ret
movapd %xmm1,%xmm0
call   1040 <floor@plt>
movapd %xmm0,%xmm1
subsd  (%rsp),%xmm1
movsd  0xe2c(%rip),%xmm2
cmpnlesd 0xe2b(%rip),%xmm1
addsd  %xmm0,%xmm2
andpd  %xmm1,%xmm0
andnpd %xmm2,%xmm1
orpd   %xmm0,%xmm1
movapd %xmm1,%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 = call i32 @isfinite(double %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load double, double* %3
store double %9, double* %2
br label %39
10: ; preds = %1
%11 = load double, double* %3
%12 = fcmp oge double %11, 0.000000e+00
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = load double, double* %3
%15 = call double @llvm.floor.f64(double %14)
store double %15, double* %4
%16 = load double, double* %4
%17 = load double, double* %3
%18 = fsub double %16, %17
%19 = fcmp ole double %18, -5.000000e-01
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load double, double* %4
%22 = fadd double %21, 1.000000e+00
store double %22, double* %4
br label %23
23: ; preds = %20, %13
%24 = load double, double* %4
store double %24, double* %2
br label %39
25: ; preds = %10
%26 = load double, double* %3
%27 = fneg double %26
%28 = call double @llvm.floor.f64(double %27)
store double %28, double* %4
%29 = load double, double* %4
%30 = load double, double* %3
%31 = fadd double %29, %30
%32 = fcmp ole double %31, -5.000000e-01
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load double, double* %4
%35 = fadd double %34, 1.000000e+00
store double %35, double* %4
br label %36
36: ; preds = %33, %25
%37 = load double, double* %4
%38 = fneg double %37
store double %38, double* %2
br label %39
39: ; preds = %36, %23, %8
%40 = load double, double* %2
ret double %40
}

LLVM IR (-O2):
define double @round(double %0) {
%2 = tail call i32 @isfinite(double %0)
%3 = icmp eq i32 %2, 0
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = fcmp ult double %0, 0.000000e+00
br i1 %5, label %12, label %6
6: ; preds = %4
%7 = tail call double @llvm.floor.f64(double %0)
%8 = fsub double %7, %0
%9 = fcmp ugt double %8, -5.000000e-01
%10 = fadd double %7, 1.000000e+00
%11 = select i1 %9, double %7, double %10
br label %20
12: ; preds = %4
%13 = fneg double %0
%14 = tail call double @llvm.floor.f64(double %13)
%15 = fadd double %14, %0
%16 = fcmp ugt double %15, -5.000000e-01
%17 = fadd double %14, 1.000000e+00
%18 = select i1 %16, double %14, double %17
%19 = fneg double %18
br label %20
20: ; preds = %1, %12, %6
%21 = phi double [ %11, %6 ], [ %19, %12 ], [ %0, %1 ]
ret double %21
}