#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 /*<<< orphan*/ isfinite(double);
double round(double x) {
  double t;
  if (!isfinite(x))
    return (x);
  if (x >= 0.0) {
    t = ceil(x);
    if (t - x > 0.5)
      t -= 1.0;
    return (t);
  } else {
    t = ceil(-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   1040 <isfinite@plt>
cmp    $0x0,%eax
jne    114f <round+0x2f>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <round+0x10a>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11b1 <round+0x91>
movsd  -0x10(%rbp),%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  0xe7e(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11a2 <round+0x82>
movsd  -0x18(%rbp),%xmm0
movsd  0xe6f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    122a <round+0x10a>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <ceil@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  0xe17(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1209 <round+0xe9>
movsd  -0x18(%rbp),%xmm0
movsd  0xe08(%rip),%xmm1
subsd  %xmm1,%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   1040 <isfinite@plt>
test   %eax,%eax
je     118e <round+0x6e>
xorpd  %xmm0,%xmm0
movapd (%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    1195 <round+0x75>
movapd %xmm1,%xmm0
xorpd  0xec3(%rip),%xmm0
call   1030 <ceil@plt>
movapd (%rsp),%xmm3
addsd  %xmm0,%xmm3
movsd  0xe9d(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  0xe99(%rip),%xmm2
cmpltsd %xmm3,%xmm2
andpd  %xmm2,%xmm1
andnpd %xmm0,%xmm2
orpd   %xmm1,%xmm2
xorpd  0xe88(%rip),%xmm2
movapd %xmm2,%xmm3
jmp    11cc <round+0xac>
movapd (%rsp),%xmm3
jmp    11cc <round+0xac>
movapd %xmm1,%xmm0
call   1030 <ceil@plt>
movapd %xmm0,%xmm1
subsd  (%rsp),%xmm1
movsd  0xe51(%rip),%xmm2
addsd  %xmm0,%xmm2
movsd  0xe4d(%rip),%xmm3
cmpltsd %xmm1,%xmm3
andpd  %xmm3,%xmm2
andnpd %xmm0,%xmm3
orpd   %xmm2,%xmm3
movapd %xmm3,%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.ceil.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 ogt double %18, 5.000000e-01
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load double, double* %4
%22 = fsub 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.ceil.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 ogt double %31, 5.000000e-01
br i1 %32, label %33, label %36
33: ; preds = %25
%34 = load double, double* %4
%35 = fsub 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.ceil.f64(double %0)
%8 = fsub double %7, %0
%9 = fcmp ogt double %8, 5.000000e-01
%10 = fadd double %7, -1.000000e+00
%11 = select i1 %9, double %10, double %7
br label %20
12: ; preds = %4
%13 = fneg double %0
%14 = tail call double @llvm.ceil.f64(double %13)
%15 = fadd double %14, %0
%16 = fcmp ogt double %15, 5.000000e-01
%17 = fadd double %14, -1.000000e+00
%18 = select i1 %16, double %17, double %14
%19 = fneg double %18
br label %20
20: ; preds = %1, %12, %6
%21 = phi double [ %11, %6 ], [ %19, %12 ], [ %0, %1 ]
ret double %21
}