#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 ceilf(float);
int /*<<< orphan*/ isfinite(float);
float roundf(float x) {
  float t;
  if (!isfinite(x))
    return (x);
  if (x >= 0.0) {
    t = ceilf(x);
    if (t - x > 0.5)
      t -= 1.0;
    return (t);
  } else {
    t = ceilf(-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   1030 <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   1040 <ceilf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe76(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b2 <roundf+0x92>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe63(%rip),%xmm1
subsd  %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   1040 <ceilf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe0d(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    121b <roundf+0xfb>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdfa(%rip),%xmm1
subsd  %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   1030 <isfinite@plt>
test   %eax,%eax
je     1182 <roundf+0x62>
xorps  %xmm0,%xmm0
movaps (%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    1188 <roundf+0x68>
movaps %xmm1,%xmm0
xorps  0xec9(%rip),%xmm0
call   1040 <ceilf@plt>
movaps (%rsp),%xmm3
addss  %xmm0,%xmm3
movss  0xea4(%rip),%xmm1
addss  %xmm0,%xmm1
movss  0xe9c(%rip),%xmm2
cmpltss %xmm3,%xmm2
andps  %xmm2,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
xorps  0xe93(%rip),%xmm2
movaps %xmm2,%xmm3
jmp    11ba <roundf+0x9a>
movaps (%rsp),%xmm3
jmp    11ba <roundf+0x9a>
movaps %xmm1,%xmm0
call   1040 <ceilf@plt>
movaps %xmm0,%xmm1
subss  (%rsp),%xmm1
movss  0xe60(%rip),%xmm2
addss  %xmm0,%xmm2
movss  0xe58(%rip),%xmm3
cmpltss %xmm1,%xmm3
andps  %xmm3,%xmm2
andnps %xmm0,%xmm3
orps   %xmm2,%xmm3
movaps %xmm3,%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.ceil.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 ogt 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 = fsub 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.ceil.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 ogt 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 = fsub 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.ceil.f32(float %0)
%8 = fsub float %7, %0
%9 = fcmp ogt float %8, 5.000000e-01
%10 = fadd float %7, -1.000000e+00
%11 = select i1 %9, float %10, float %7
br label %20
12: ; preds = %4
%13 = fneg float %0
%14 = tail call float @llvm.ceil.f32(float %13)
%15 = fadd float %14, %0
%16 = fcmp ogt float %15, 5.000000e-01
%17 = fadd float %14, -1.000000e+00
%18 = select i1 %16, float %17, float %14
%19 = fneg float %18
br label %20
20: ; preds = %1, %12, %6
%21 = phi float [ %11, %6 ], [ %19, %12 ], [ %0, %1 ]
ret float %21
}