#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 floorf(float);
int /*<<< orphan*/ isfinite(float);
float roundf(float x) {
  float t;
  if (!isfinite(x))
    return x;
  if (x >= 0.0) {
    t = floorf(x);
    if (t - x <= -0.5)
      t += 1.0;
    return t;
  } else {
    t = floorf(-x);
    if (t + x <= -0.5)
      t += 1.0;
    return -t;
  }
}


x86 assembly (clang, -O0):
<roundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <isfinite@plt>
cmp    $0x0,%eax
jne    114f <roundf+0x2f>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1232 <roundf+0x112>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11c1 <roundf+0xa1>
movss  -0x8(%rbp),%xmm0
call   1030 <floorf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe76(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11b2 <roundf+0x92>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1232 <roundf+0x112>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <floorf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe0d(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     121b <roundf+0xfb>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdfa(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundf>:
sub    $0x18,%rsp
movaps %xmm0,(%rsp)
call   1040 <isfinite@plt>
test   %eax,%eax
je     11a0 <roundf+0x80>
xorps  %xmm0,%xmm0
movaps (%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    11a9 <roundf+0x89>
movaps (%rsp),%xmm0
xorps  0xec8(%rip),%xmm0
call   1030 <floorf@plt>
movaps (%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,(%rsp)
movss  0xe9f(%rip),%xmm1
addss  %xmm0,%xmm1
movaps (%rsp),%xmm2
cmpnless 0xe92(%rip),%xmm2
movaps %xmm2,(%rsp)
andps  (%rsp),%xmm0
movaps (%rsp),%xmm2
andnps %xmm1,%xmm2
movaps %xmm2,(%rsp)
movaps (%rsp),%xmm1
orps   %xmm0,%xmm1
movaps %xmm1,(%rsp)
movaps (%rsp),%xmm0
xorps  0xe75(%rip),%xmm0
add    $0x18,%rsp
ret
movaps (%rsp),%xmm0
add    $0x18,%rsp
ret
movaps %xmm1,%xmm0
call   1030 <floorf@plt>
movaps %xmm0,%xmm1
subss  (%rsp),%xmm1
movss  0xe3f(%rip),%xmm2
cmpnless 0xe3a(%rip),%xmm1
addss  %xmm0,%xmm2
andps  %xmm1,%xmm0
andnps %xmm2,%xmm1
orps   %xmm0,%xmm1
movaps %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @roundf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %3
%5 = load float, float* %3
%6 = call i32 @isfinite(float %5)
%7 = icmp ne i32 %6, 0
br i1 %7, label %10, label %8
8: ; preds = %1
%9 = load float, float* %3
store float %9, float* %2
br label %46
10: ; preds = %1
%11 = load float, float* %3
%12 = fpext float %11 to double
%13 = fcmp oge double %12, 0.000000e+00
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load float, float* %3
%16 = call float @llvm.floor.f32(float %15)
store float %16, float* %4
%17 = load float, float* %4
%18 = load float, float* %3
%19 = fsub float %17, %18
%20 = fpext float %19 to double
%21 = fcmp ole double %20, -5.000000e-01
br i1 %21, label %22, label %27
22: ; preds = %14
%23 = load float, float* %4
%24 = fpext float %23 to double
%25 = fadd double %24, 1.000000e+00
%26 = fptrunc double %25 to float
store float %26, float* %4
br label %27
27: ; preds = %22, %14
%28 = load float, float* %4
store float %28, float* %2
br label %46
29: ; preds = %10
%30 = load float, float* %3
%31 = fneg float %30
%32 = call float @llvm.floor.f32(float %31)
store float %32, float* %4
%33 = load float, float* %4
%34 = load float, float* %3
%35 = fadd float %33, %34
%36 = fpext float %35 to double
%37 = fcmp ole double %36, -5.000000e-01
br i1 %37, label %38, label %43
38: ; preds = %29
%39 = load float, float* %4
%40 = fpext float %39 to double
%41 = fadd double %40, 1.000000e+00
%42 = fptrunc double %41 to float
store float %42, float* %4
br label %43
43: ; preds = %38, %29
%44 = load float, float* %4
%45 = fneg float %44
store float %45, float* %2
br label %46
46: ; preds = %43, %27, %8
%47 = load float, float* %2
ret float %47
}

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