#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 int int32_t;

/* Variables and functions */
float const copysignfk(float, float);
float fabsfk(float);
__attribute__((always_)) const float rintfk2(float d) {
  float x = d + 0.5f;
  int32_t isodd = (1 & (int32_t)x) != 0;
  float fr = x - (int32_t)x;
  fr = (fr < 0 || (fr == 0 && isodd)) ? fr + 1.0f : fr;
  return (fabsfk(d) >= (float)(1LL << 23)) ? d : copysignfk(x - fr, d);
}


x86 assembly (clang, -O0):
<rintfk2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x4(%rbp)
movss  0xecb(%rip),%xmm0
addss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x8(%rbp)
cvttss2si -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xc(%rbp)
movss  -0x8(%rbp),%xmm0
cvttss2si -0x8(%rbp),%eax
cvtsi2ss %eax,%xmm1
subss  %xmm1,%xmm0
movss  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x10(%rbp),%xmm0
ja     119a <rintfk2+0x7a>
movss  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b1 <rintfk2+0x91>
jp     11b1 <rintfk2+0x91>
cmpl   $0x0,-0xc(%rbp)
je     11b1 <rintfk2+0x91>
movss  0xe62(%rip),%xmm0
addss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    11bb <rintfk2+0x9b>
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x10(%rbp)
movss  -0x4(%rbp),%xmm0
call   1040 <fabsfk@plt>
movss  0xe31(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11ef <rintfk2+0xcf>
movss  -0x4(%rbp),%xmm0
movss  %xmm0,-0x18(%rbp)
jmp    1208 <rintfk2+0xe8>
movss  -0x8(%rbp),%xmm0
subss  -0x10(%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):
<rintfk2>:
sub    $0x38,%rsp
movss  0xed4(%rip),%xmm2
addss  %xmm0,%xmm2
cvttps2dq %xmm2,%xmm1
cvtdq2ps %xmm1,%xmm1
movaps %xmm2,%xmm3
subss  %xmm1,%xmm3
xorps  %xmm1,%xmm1
ucomiss %xmm3,%xmm1
movaps %xmm2,0x20(%rsp)
ja     115b <rintfk2+0x3b>
ucomiss %xmm1,%xmm3
jne    1163 <rintfk2+0x43>
jp     1163 <rintfk2+0x43>
cvttss2si %xmm2,%eax
and    $0x1,%eax
je     1163 <rintfk2+0x43>
addss  0xea1(%rip),%xmm3
movaps %xmm3,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
call   1040 <fabsfk@plt>
ucomiss 0xe8e(%rip),%xmm0
jae    1196 <rintfk2+0x76>
movaps 0x20(%rsp),%xmm0
subss  0x10(%rsp),%xmm0
movss  0xc(%rsp),%xmm1
add    $0x38,%rsp
jmp    1030 <copysignfk@plt>
movss  0xc(%rsp),%xmm0
add    $0x38,%rsp
ret

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

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