#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 modff(float, float *);
float roundf(float x) {
  float f = modff(x, &x);
  if (x <= 0.0f && f <= -0.5f) {
    x -= 1.0f;
  }
  if (x >= 0.0f && f >= 0.5f) {
    x += 1.0f;
  }
  return x;
}


x86 assembly (clang, -O0):
<roundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
lea    -0x4(%rbp),%rdi
call   1030 <modff@plt>
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x4(%rbp),%xmm0
jb     1165 <roundf+0x55>
movss  0xebb(%rip),%xmm0
ucomiss -0x8(%rbp),%xmm0
jb     1165 <roundf+0x55>
movss  -0x4(%rbp),%xmm0
movss  0xea8(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     119e <roundf+0x8e>
movss  -0x8(%rbp),%xmm0
movss  0xe85(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     119e <roundf+0x8e>
movss  0xe70(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundf>:
push   %rax
movss  %xmm0,0x4(%rsp)
lea    0x4(%rsp),%rdi
call   1030 <modff@plt>
movaps %xmm0,%xmm1
movss  0x4(%rsp),%xmm2
movss  0xece(%rip),%xmm0
addss  %xmm2,%xmm0
movaps %xmm1,%xmm3
cmpless 0xec2(%rip),%xmm3
movaps %xmm3,%xmm4
andnps %xmm2,%xmm4
andps  %xmm0,%xmm3
orps   %xmm4,%xmm3
xorps  %xmm4,%xmm4
movaps %xmm2,%xmm0
cmpless %xmm4,%xmm0
andps  %xmm0,%xmm3
andnps %xmm2,%xmm0
orps   %xmm3,%xmm0
ucomiss %xmm4,%xmm0
jb     1182 <roundf+0x72>
ucomiss 0xe9a(%rip),%xmm1
jb     1182 <roundf+0x72>
movss  0xe94(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,0x4(%rsp)
pop    %rax
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 = call float @modff(float %4, float* %2)
store float %5, float* %3
%6 = load float, float* %2
%7 = fcmp ole float %6, 0.000000e+00
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load float, float* %3
%10 = fcmp ole float %9, -5.000000e-01
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load float, float* %2
%13 = fsub float %12, 1.000000e+00
store float %13, float* %2
br label %14
14: ; preds = %11, %8, %1
%15 = load float, float* %2
%16 = fcmp oge float %15, 0.000000e+00
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load float, float* %3
%19 = fcmp oge float %18, 5.000000e-01
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = load float, float* %2
%22 = fadd float %21, 1.000000e+00
store float %22, float* %2
br label %23
23: ; preds = %20, %17, %14
%24 = load float, float* %2
ret float %24
}

LLVM IR (-O2):
define float @roundf(float %0) {
%2 = alloca float
store float %0, float* %2
%3 = call float @modff(float %0, float* %2)
%4 = load float, float* %2
%5 = fcmp ole float %4, 0.000000e+00
%6 = fcmp ole float %3, -5.000000e-01
%7 = select i1 %5, i1 %6, i1 false
%8 = fadd float %4, -1.000000e+00
%9 = select i1 %7, float %8, float %4
%10 = fcmp oge float %9, 0.000000e+00
%11 = fcmp oge float %3, 5.000000e-01
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = fadd float %9, 1.000000e+00
store float %14, float* %2
br label %15
15: ; preds = %13, %1
%16 = phi float [ %14, %13 ], [ %9, %1 ]
ret float %16
}