#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);
scalar_t__ isinf(double);
scalar_t__ isnan(double);
double do_round(double x) {
  if (isnan(x))
    return x;
  if (isinf(x))
    return x;
  if (x == 0)
    return x;
  if (x > 0 && x < 0.5)
    return 0;
  if (x < 0 && x >= -0.5)
    return -0;
  return floor(x + 0.5);
}


x86 assembly (clang, -O0):
<do_round>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1160 <do_round+0x30>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <do_round+0xf5>
movsd  -0x10(%rbp),%xmm0
call   1050 <isinf@plt>
cmp    $0x0,%rax
je     1183 <do_round+0x53>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <do_round+0xf5>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11aa <do_round+0x7a>
jp     11aa <do_round+0x7a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <do_round+0xf5>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    11dc <do_round+0xac>
movsd  0xe3c(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11dc <do_round+0xac>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <do_round+0xf5>
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    120e <do_round+0xde>
movsd  -0x10(%rbp),%xmm0
movsd  0xe11(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     120e <do_round+0xde>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1225 <do_round+0xf5>
movsd  0xdea(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
call   1040 <floor@plt>
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_round>:
push   %rax
movsd  %xmm0,(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1147 <do_round+0x17>
movsd  (%rsp),%xmm0
pop    %rax
ret
movsd  (%rsp),%xmm0
call   1050 <isinf@plt>
xorpd  %xmm0,%xmm0
movsd  (%rsp),%xmm2
ucomisd %xmm0,%xmm2
jne    1162 <do_round+0x32>
jnp    1195 <do_round+0x65>
test   %rax,%rax
jne    1195 <do_round+0x65>
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
jbe    117f <do_round+0x4f>
movsd  0xe87(%rip),%xmm1
ucomisd %xmm2,%xmm1
ja     1193 <do_round+0x63>
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jbe    119b <do_round+0x6b>
ucomisd 0xe77(%rip),%xmm2
jb     119b <do_round+0x6b>
pop    %rax
ret
movapd %xmm2,%xmm0
pop    %rax
ret
addsd  0xe5d(%rip),%xmm2
movapd %xmm2,%xmm0
pop    %rax
jmp    1040 <floor@plt>

LLVM IR (-O0):
define double @do_round(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %3
%4 = load double, double* %3
%5 = call i64 @isnan(double %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = load double, double* %3
store double %8, double* %2
br label %38
9: ; preds = %1
%10 = load double, double* %3
%11 = call i64 @isinf(double %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = load double, double* %3
store double %14, double* %2
br label %38
15: ; preds = %9
%16 = load double, double* %3
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load double, double* %3
store double %19, double* %2
br label %38
20: ; preds = %15
%21 = load double, double* %3
%22 = fcmp ogt double %21, 0.000000e+00
br i1 %22, label %23, label %27
23: ; preds = %20
%24 = load double, double* %3
%25 = fcmp olt double %24, 5.000000e-01
br i1 %25, label %26, label %27
26: ; preds = %23
store double 0.000000e+00, double* %2
br label %38
27: ; preds = %23, %20
%28 = load double, double* %3
%29 = fcmp olt double %28, 0.000000e+00
br i1 %29, label %30, label %34
30: ; preds = %27
%31 = load double, double* %3
%32 = fcmp oge double %31, -5.000000e-01
br i1 %32, label %33, label %34
33: ; preds = %30
store double 0.000000e+00, double* %2
br label %38
34: ; preds = %30, %27
%35 = load double, double* %3
%36 = fadd double %35, 5.000000e-01
%37 = call double @llvm.floor.f64(double %36)
store double %37, double* %2
br label %38
38: ; preds = %34, %33, %26, %18, %13, %7
%39 = load double, double* %2
ret double %39
}

LLVM IR (-O2):
define double @do_round(double %0) {
%2 = tail call i64 @isnan(double %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %20
4: ; preds = %1
%5 = tail call i64 @isinf(double %0)
%6 = icmp ne i64 %5, 0
%7 = fcmp oeq double %0, 0.000000e+00
%8 = or i1 %7, %6
br i1 %8, label %20, label %9
9: ; preds = %4
%10 = fcmp ogt double %0, 0.000000e+00
%11 = fcmp olt double %0, 5.000000e-01
%12 = and i1 %10, %11
br i1 %12, label %20, label %13
13: ; preds = %9
%14 = fcmp olt double %0, 0.000000e+00
%15 = fcmp oge double %0, -5.000000e-01
%16 = and i1 %14, %15
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = fadd double %0, 5.000000e-01
%19 = tail call double @llvm.floor.f64(double %18)
br label %20
20: ; preds = %13, %9, %4, %1, %17
%21 = phi double [ %19, %17 ], [ %0, %1 ], [ %0, %4 ], [ 0.000000e+00, %9 ], [ 0.000000e+00, %13 ]
ret double %21
}