#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);
float roundf(float x) {
  float res;
  if (x >= 0.0F) {
    res = ceilf(x);
    if (res - x > 0.5F)
      res -= 1.0F;
  } else {
    res = ceilf(-x);
    if (res + x > 0.5F)
      res -= 1.0F;
    res = -res;
  }
  return res;
}


x86 assembly (clang, -O0):
<roundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     1173 <roundf+0x63>
movss  -0x4(%rbp),%xmm0
call   1030 <ceilf@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0x4(%rbp),%xmm0
movss  0xeb1(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    116e <roundf+0x5e>
movss  -0x8(%rbp),%xmm0
movss  0xe9f(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
jmp    11d7 <roundf+0xc7>
movss  -0x4(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <ceilf@plt>
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
addss  -0x4(%rbp),%xmm0
movss  0xe5f(%rip),%xmm1
ucomiss %xmm1,%xmm0
jbe    11c0 <roundf+0xb0>
movss  -0x8(%rbp),%xmm0
movss  0xe4d(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundf>:
sub    $0x18,%rsp
movaps %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomiss %xmm0,%xmm1
movaps %xmm1,(%rsp)
movaps %xmm1,%xmm0
jae    116b <roundf+0x5b>
xorps  0xee3(%rip),%xmm0
call   1030 <ceilf@plt>
movaps %xmm0,%xmm1
movaps (%rsp),%xmm3
addss  %xmm0,%xmm3
movss  0xebf(%rip),%xmm2
addss  %xmm0,%xmm2
movss  0xeaf(%rip),%xmm0
cmpltss %xmm3,%xmm0
andps  %xmm0,%xmm2
andnps %xmm1,%xmm0
orps   %xmm2,%xmm0
xorps  0xeaa(%rip),%xmm0
add    $0x18,%rsp
ret
call   1030 <ceilf@plt>
movaps %xmm0,%xmm1
subss  (%rsp),%xmm1
ucomiss 0xe81(%rip),%xmm1
jbe    1166 <roundf+0x56>
addss  0xe7b(%rip),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define float @roundf(float %0) {
%2 = alloca float
%3 = alloca float
store float %0, float* %2
%4 = load float, float* %2
%5 = fcmp oge float %4, 0.000000e+00
br i1 %5, label %6, label %17
6: ; preds = %1
%7 = load float, float* %2
%8 = call float @llvm.ceil.f32(float %7)
store float %8, float* %3
%9 = load float, float* %3
%10 = load float, float* %2
%11 = fsub float %9, %10
%12 = fcmp ogt float %11, 5.000000e-01
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load float, float* %3
%15 = fsub float %14, 1.000000e+00
store float %15, float* %3
br label %16
16: ; preds = %13, %6
br label %31
17: ; preds = %1
%18 = load float, float* %2
%19 = fneg float %18
%20 = call float @llvm.ceil.f32(float %19)
store float %20, float* %3
%21 = load float, float* %3
%22 = load float, float* %2
%23 = fadd float %21, %22
%24 = fcmp ogt float %23, 5.000000e-01
br i1 %24, label %25, label %28
25: ; preds = %17
%26 = load float, float* %3
%27 = fsub float %26, 1.000000e+00
store float %27, float* %3
br label %28
28: ; preds = %25, %17
%29 = load float, float* %3
%30 = fneg float %29
store float %30, float* %3
br label %31
31: ; preds = %28, %16
%32 = load float, float* %3
ret float %32
}

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