#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 floorf(float);
double fmodf(float, int);
float roundf(float x) {
  if (x < 0.0f)
    return fmodf(x, -1) <= -0.5 ? floorf(x) : ceilf(x);
  else
    return fmodf(x, 1) < 0.5 ? floorf(x) : ceilf(x);
}


x86 assembly (clang, -O0):
<roundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    11a0 <roundf+0x70>
movss  -0x8(%rbp),%xmm0
mov    $0xffffffff,%edi
call   1030 <fmodf@plt>
movaps %xmm0,%xmm1
movsd  0xea4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     1182 <roundf+0x52>
movss  -0x8(%rbp),%xmm0
call   1040 <floorf@plt>
movss  %xmm0,-0xc(%rbp)
jmp    1191 <roundf+0x61>
movss  -0x8(%rbp),%xmm0
call   1050 <ceilf@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11f1 <roundf+0xc1>
movss  -0x8(%rbp),%xmm0
mov    $0x1,%edi
call   1030 <fmodf@plt>
movaps %xmm0,%xmm1
movsd  0xe46(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11d8 <roundf+0xa8>
movss  -0x8(%rbp),%xmm0
call   1040 <floorf@plt>
movss  %xmm0,-0x10(%rbp)
jmp    11e7 <roundf+0xb7>
movss  -0x8(%rbp),%xmm0
call   1050 <ceilf@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundf>:
push   %rax
xorps  %xmm1,%xmm1
ucomiss %xmm0,%xmm1
movss  %xmm0,0x4(%rsp)
jbe    1163 <roundf+0x33>
mov    $0xffffffff,%edi
call   1030 <fmodf@plt>
movsd  0xeb7(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    117b <roundf+0x4b>
movss  0x4(%rsp),%xmm0
pop    %rax
jmp    1050 <ceilf@plt>
mov    $0x1,%edi
call   1030 <fmodf@plt>
movsd  0xe8b(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1157 <roundf+0x27>
movss  0x4(%rsp),%xmm0
pop    %rax
jmp    1040 <floorf@plt>

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

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