#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 NAN;
scalar_t__ isnan(float);
float modff(float, float *);
float roundf(float x) {
  float f;
  if (isnan(x)) {
    return NAN;
  }
  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,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <isnan@plt>
cmp    $0x0,%rax
je     1156 <roundf+0x36>
mov    0x2eb0(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e1 <roundf+0xc1>
movss  -0x8(%rbp),%xmm0
lea    -0x8(%rbp),%rdi
call   1030 <modff@plt>
movss  %xmm0,-0xc(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jb     119e <roundf+0x7e>
movss  0xe82(%rip),%xmm0
ucomiss -0xc(%rbp),%xmm0
jb     119e <roundf+0x7e>
movss  -0x8(%rbp),%xmm0
movss  0xe6f(%rip),%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11d7 <roundf+0xb7>
movss  -0xc(%rbp),%xmm0
movss  0xe4c(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11d7 <roundf+0xb7>
movss  0xe37(%rip),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%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,(%rsp)
movss  %xmm0,0x4(%rsp)
call   1040 <isnan@plt>
test   %rax,%rax
je     1143 <roundf+0x23>
mov    0x2ebb(%rip),%rax
movss  (%rax),%xmm0
pop    %rax
ret
mov    %rsp,%rdi
movss  0x4(%rsp),%xmm0
call   1030 <modff@plt>
movaps %xmm0,%xmm1
movss  (%rsp),%xmm2
movss  0xe9f(%rip),%xmm0
addss  %xmm2,%xmm0
movaps %xmm1,%xmm3
cmpless 0xe93(%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     11b0 <roundf+0x90>
ucomiss 0xe6b(%rip),%xmm1
jb     11b0 <roundf+0x90>
movss  0xe65(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,(%rsp)
pop    %rax
ret

LLVM IR (-O0):
@NAN = global float 0.000000e+00
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 @isnan(float %5)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = load float, float* @NAN
store float %9, float* %2
br label %32
10: ; preds = %1
%11 = load float, float* %3
%12 = call float @modff(float %11, float* %3)
store float %12, float* %4
%13 = load float, float* %3
%14 = fcmp ole float %13, 0.000000e+00
br i1 %14, label %15, label %21
15: ; preds = %10
%16 = load float, float* %4
%17 = fcmp ole float %16, -5.000000e-01
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load float, float* %3
%20 = fsub float %19, 1.000000e+00
store float %20, float* %3
br label %21
21: ; preds = %18, %15, %10
%22 = load float, float* %3
%23 = fcmp oge float %22, 0.000000e+00
br i1 %23, label %24, label %30
24: ; preds = %21
%25 = load float, float* %4
%26 = fcmp oge float %25, 5.000000e-01
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = load float, float* %3
%29 = fadd float %28, 1.000000e+00
store float %29, float* %3
br label %30
30: ; preds = %27, %24, %21
%31 = load float, float* %3
store float %31, float* %2
br label %32
32: ; preds = %30, %8
%33 = load float, float* %2
ret float %33
}

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