#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 */
typedef float int32_t;

/* Variables and functions */
float const copysignfk(float, float);
float fabsfk(float);
scalar_t__ xisinff(float);
__attribute__((visibility("default"))) const float xroundf(float d) {
  float x = d + 0.5f;
  float fr = x - (int32_t)x;
  if (fr == 0 && x <= 0)
    x--;
  fr = fr < 0 ? fr + 1.0f : fr;
  x = d == 0.4999999701976776123f ? 0 : x;
  return (xisinff(d) || fabsfk(d) >= (float)(1LL << 23))
             ? d
             : copysignfk(x - fr, d);
}


x86 assembly (clang, -O0):
<xroundf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xebb(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1194 <xroundf+0x64>
jp     1194 <xroundf+0x64>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jb     1194 <xroundf+0x64>
movss  0xe7a(%rip),%xmm0
addss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0xc(%rbp),%xmm0
jbe    11b8 <xroundf+0x88>
movss  0xe5f(%rip),%xmm0
addss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
jmp    11c2 <xroundf+0x92>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0xc(%rbp)
movss  -0x4(%rbp),%xmm0
movss  0xe33(%rip),%xmm1
ucomiss %xmm1,%xmm0
jne    11f5 <xroundf+0xc5>
jp     11f5 <xroundf+0xc5>
xorps  %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11ff <xroundf+0xcf>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <xisinff@plt>
cmp    $0x0,%rax
jne    1238 <xroundf+0x108>
movss  -0x4(%rbp),%xmm0
call   1050 <fabsfk@plt>
movss  0xde1(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     1247 <xroundf+0x117>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1260 <xroundf+0x130>
movss  -0x8(%rbp),%xmm0
subss  -0xc(%rbp),%xmm0
movss  -0x4(%rbp),%xmm1
call   1030 <copysignfk@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xroundf>:
push   %rax
movss  %xmm0,0x4(%rsp)
call   1040 <xisinff@plt>
test   %rax,%rax
jne    11de <xroundf+0xae>
movss  0x4(%rsp),%xmm0
call   1050 <fabsfk@plt>
ucomiss 0xeb9(%rip),%xmm0
jae    11de <xroundf+0xae>
movss  0xe9b(%rip),%xmm0
movss  0x4(%rsp),%xmm6
addss  %xmm6,%xmm0
movaps %xmm0,%xmm1
subss  %xmm0,%xmm1
movss  0xe86(%rip),%xmm2
addss  %xmm0,%xmm2
xorps  %xmm3,%xmm3
movss  0xe7b(%rip),%xmm4
addss  %xmm1,%xmm4
movaps %xmm1,%xmm5
cmpltss %xmm3,%xmm5
andps  %xmm5,%xmm4
andnps %xmm1,%xmm5
cmpeqss %xmm3,%xmm1
andps  %xmm1,%xmm2
andnps %xmm0,%xmm1
orps   %xmm2,%xmm1
movaps %xmm0,%xmm2
cmpless %xmm3,%xmm2
andps  %xmm2,%xmm1
andnps %xmm0,%xmm2
orps   %xmm1,%xmm2
orps   %xmm4,%xmm5
movss  0xe43(%rip),%xmm0
cmpeqss %xmm6,%xmm0
andnps %xmm2,%xmm0
subss  %xmm5,%xmm0
movaps %xmm6,%xmm1
pop    %rax
jmp    1030 <copysignfk@plt>
movss  0x4(%rsp),%xmm0
pop    %rax
ret

LLVM IR (-O0):
define float @xroundf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %2
%5 = load float, float* %2
%6 = fadd float %5, 5.000000e-01
store float %6, float* %3
%7 = load float, float* %3
%8 = load float, float* %3
%9 = fsub float %7, %8
store float %9, float* %4
%10 = load float, float* %4
%11 = fcmp oeq float %10, 0.000000e+00
br i1 %11, label %12, label %18
12: ; preds = %1
%13 = load float, float* %3
%14 = fcmp ole float %13, 0.000000e+00
br i1 %14, label %15, label %18
15: ; preds = %12
%16 = load float, float* %3
%17 = fadd float %16, -1.000000e+00
store float %17, float* %3
br label %18
18: ; preds = %15, %12, %1
%19 = load float, float* %4
%20 = fcmp olt float %19, 0.000000e+00
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load float, float* %4
%23 = fadd float %22, 1.000000e+00
br label %26
24: ; preds = %18
%25 = load float, float* %4
br label %26
26: ; preds = %24, %21
%27 = phi float [ %23, %21 ], [ %25, %24 ]
store float %27, float* %4
%28 = load float, float* %2
%29 = fcmp oeq float %28, 0x3FDFFFFFE0000000
br i1 %29, label %30, label %31
30: ; preds = %26
br label %33
31: ; preds = %26
%32 = load float, float* %3
br label %33
33: ; preds = %31, %30
%34 = phi float [ 0.000000e+00, %30 ], [ %32, %31 ]
store float %34, float* %3
%35 = load float, float* %2
%36 = call i64 @xisinff(float %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %33
%39 = load float, float* %2
%40 = call float @fabsfk(float %39)
%41 = fcmp oge float %40, 0x4160000000000000
br i1 %41, label %42, label %44
42: ; preds = %38, %33
%43 = load float, float* %2
br label %50
44: ; preds = %38
%45 = load float, float* %3
%46 = load float, float* %4
%47 = fsub float %45, %46
%48 = load float, float* %2
%49 = call float @copysignfk(float %47, float %48)
br label %50
50: ; preds = %44, %42
%51 = phi float [ %43, %42 ], [ %49, %44 ]
ret float %51
}

LLVM IR (-O2):
define float @xroundf(float %0) {
%2 = fadd float %0, 5.000000e-01
%3 = fsub float %2, %2
%4 = fcmp oeq float %3, 0.000000e+00
%5 = fcmp ole float %2, 0.000000e+00
%6 = and i1 %5, %4
%7 = fadd float %2, -1.000000e+00
%8 = select i1 %6, float %7, float %2
%9 = fcmp olt float %3, 0.000000e+00
%10 = fadd float %3, 1.000000e+00
%11 = select i1 %9, float %10, float %3
%12 = fcmp oeq float %0, 0x3FDFFFFFE0000000
%13 = select i1 %12, float 0.000000e+00, float %8
%14 = tail call i64 @xisinff(float %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %1
%17 = tail call float @fabsfk(float %0)
%18 = fcmp ult float %17, 0x4160000000000000
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = fsub float %13, %11
%21 = tail call float @copysignfk(float %20, float %0)
br label %22
22: ; preds = %1, %16, %19
%23 = phi float [ %21, %19 ], [ %0, %16 ], [ %0, %1 ]
ret float %23
}