#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);
scalar_t__ isinff(float);
scalar_t__ isnanf(float);
float roundf(float x) {
  float t;
  if (isinff(x) || isnanf(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   1050 <isinff@plt>
cmp    $0x0,%rax
jne    1165 <roundf+0x35>
movss  -0x8(%rbp),%xmm0
call   1040 <isnanf@plt>
cmp    $0x0,%rax
je     1174 <roundf+0x44>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1257 <roundf+0x127>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     11e6 <roundf+0xb6>
movss  -0x8(%rbp),%xmm0
call   1030 <floorf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe51(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11d7 <roundf+0xa7>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3e(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1257 <roundf+0x127>
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  0xde8(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1240 <roundf+0x110>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xdd5(%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   1050 <isinff@plt>
test   %rax,%rax
jne    1150 <roundf+0x20>
movaps (%rsp),%xmm0
call   1040 <isnanf@plt>
test   %rax,%rax
je     1159 <roundf+0x29>
movaps (%rsp),%xmm0
add    $0x18,%rsp
ret
xorps  %xmm0,%xmm0
movaps (%rsp),%xmm1
ucomiss %xmm0,%xmm1
jae    11c8 <roundf+0x98>
movaps (%rsp),%xmm0
xorps  0xea0(%rip),%xmm0
call   1030 <floorf@plt>
movaps (%rsp),%xmm1
addss  %xmm0,%xmm1
movaps %xmm1,(%rsp)
movss  0xe77(%rip),%xmm1
addss  %xmm0,%xmm1
movaps (%rsp),%xmm2
cmpnless 0xe6a(%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  0xe4d(%rip),%xmm0
add    $0x18,%rsp
ret
movaps %xmm1,%xmm0
call   1030 <floorf@plt>
movaps %xmm0,%xmm1
subss  (%rsp),%xmm1
movss  0xe20(%rip),%xmm2
cmpnless 0xe1b(%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 i64 @isinff(float %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %1
%9 = load float, float* %3
%10 = call i64 @isnanf(float %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %8, %1
%13 = load float, float* %3
store float %13, float* %2
br label %50
14: ; preds = %8
%15 = load float, float* %3
%16 = fpext float %15 to double
%17 = fcmp oge double %16, 0.000000e+00
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load float, float* %3
%20 = call float @llvm.floor.f32(float %19)
store float %20, float* %4
%21 = load float, float* %4
%22 = load float, float* %3
%23 = fsub float %21, %22
%24 = fpext float %23 to double
%25 = fcmp ole double %24, -5.000000e-01
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load float, float* %4
%28 = fpext float %27 to double
%29 = fadd double %28, 1.000000e+00
%30 = fptrunc double %29 to float
store float %30, float* %4
br label %31
31: ; preds = %26, %18
%32 = load float, float* %4
store float %32, float* %2
br label %50
33: ; preds = %14
%34 = load float, float* %3
%35 = fneg float %34
%36 = call float @llvm.floor.f32(float %35)
store float %36, float* %4
%37 = load float, float* %4
%38 = load float, float* %3
%39 = fadd float %37, %38
%40 = fpext float %39 to double
%41 = fcmp ole double %40, -5.000000e-01
br i1 %41, label %42, label %47
42: ; preds = %33
%43 = load float, float* %4
%44 = fpext float %43 to double
%45 = fadd double %44, 1.000000e+00
%46 = fptrunc double %45 to float
store float %46, float* %4
br label %47
47: ; preds = %42, %33
%48 = load float, float* %4
%49 = fneg float %48
store float %49, float* %2
br label %50
50: ; preds = %47, %31, %12
%51 = load float, float* %2
ret float %51
}

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