#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 t;
  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
cvtss2sd %xmm0,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     118f <roundf+0x7f>
movss  -0x8(%rbp),%xmm0
call   1030 <ceilf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea8(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1180 <roundf+0x70>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe95(%rip),%xmm1
subsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    1200 <roundf+0xf0>
movss  -0x8(%rbp),%xmm0
movd   %xmm0,%eax
xor    $0x80000000,%eax
movd   %eax,%xmm0
call   1030 <ceilf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
addss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe3f(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11e9 <roundf+0xd9>
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2c(%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,%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  0xebb(%rip),%xmm2
addss  %xmm0,%xmm2
movss  0xeb3(%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
movaps %xmm0,%xmm2
subss  (%rsp),%xmm2
movss  0xe7d(%rip),%xmm3
addss  %xmm0,%xmm3
movss  0xe75(%rip),%xmm0
cmpltss %xmm2,%xmm0
andps  %xmm0,%xmm3
andnps %xmm1,%xmm0
orps   %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 = fpext float %5 to double
%7 = fcmp oge double %6, 0.000000e+00
br i1 %7, label %8, label %23
8: ; preds = %1
%9 = load float, float* %3
%10 = call float @llvm.ceil.f32(float %9)
store float %10, float* %4
%11 = load float, float* %4
%12 = load float, float* %3
%13 = fsub float %11, %12
%14 = fpext float %13 to double
%15 = fcmp ogt double %14, 5.000000e-01
br i1 %15, label %16, label %21
16: ; preds = %8
%17 = load float, float* %4
%18 = fpext float %17 to double
%19 = fsub double %18, 1.000000e+00
%20 = fptrunc double %19 to float
store float %20, float* %4
br label %21
21: ; preds = %16, %8
%22 = load float, float* %4
store float %22, float* %2
br label %40
23: ; preds = %1
%24 = load float, float* %3
%25 = fneg float %24
%26 = call float @llvm.ceil.f32(float %25)
store float %26, float* %4
%27 = load float, float* %4
%28 = load float, float* %3
%29 = fadd float %27, %28
%30 = fpext float %29 to double
%31 = fcmp ogt double %30, 5.000000e-01
br i1 %31, label %32, label %37
32: ; preds = %23
%33 = load float, float* %4
%34 = fpext float %33 to double
%35 = fsub double %34, 1.000000e+00
%36 = fptrunc double %35 to float
store float %36, float* %4
br label %37
37: ; preds = %32, %23
%38 = load float, float* %4
%39 = fneg float %38
store float %39, float* %2
br label %40
40: ; preds = %37, %21
%41 = load float, float* %2
ret float %41
}

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
%7 = fadd float %4, -1.000000e+00
%8 = select i1 %6, float %7, float %4
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 = %9, %3
%18 = phi float [ %8, %3 ], [ %16, %9 ]
ret float %18
}