#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);
int fegetround();
float floorf(float);
float fmodf(float, int);
float rintf(float x) {
  const int rounding = fegetround();
  if (rounding == 0) {
    return fmodf(x, 1) < 0.5f ? floorf(x) : ceilf(x);
  }
  if (rounding == 1024) {
    return floorf(x);
  }
  if (rounding == 2048) {
    return ceilf(x);
  }
  return fmodf(x, 1) == 0.0f ? x : (x < 0.0f ? ceilf(x) : floorf(x));
}


x86 assembly (clang, -O0):
<rintf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movss  %xmm0,-0x8(%rbp)
mov    $0x0,%al
call   1040 <fegetround@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    11b6 <rintf+0x76>
movss  -0x8(%rbp),%xmm0
mov    $0x1,%edi
call   1030 <fmodf@plt>
movaps %xmm0,%xmm1
movss  0xe85(%rip),%xmm0
ucomiss %xmm1,%xmm0
jbe    1198 <rintf+0x58>
movss  -0x8(%rbp),%xmm0
call   1050 <floorf@plt>
movss  %xmm0,-0x10(%rbp)
jmp    11a7 <rintf+0x67>
movss  -0x8(%rbp),%xmm0
call   1060 <ceilf@plt>
movss  %xmm0,-0x10(%rbp)
movss  -0x10(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    126c <rintf+0x12c>
cmpl   $0x400,-0xc(%rbp)
jne    11d7 <rintf+0x97>
movss  -0x8(%rbp),%xmm0
call   1050 <floorf@plt>
movss  %xmm0,-0x4(%rbp)
jmp    126c <rintf+0x12c>
cmpl   $0x800,-0xc(%rbp)
jne    11f8 <rintf+0xb8>
movss  -0x8(%rbp),%xmm0
call   1060 <ceilf@plt>
movss  %xmm0,-0x4(%rbp)
jmp    126c <rintf+0x12c>
movss  -0x8(%rbp),%xmm0
mov    $0x1,%edi
call   1030 <fmodf@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1228 <rintf+0xe8>
jp     1228 <rintf+0xe8>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
jmp    1262 <rintf+0x122>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
jbe    1249 <rintf+0x109>
movss  -0x8(%rbp),%xmm0
call   1060 <ceilf@plt>
movss  %xmm0,-0x18(%rbp)
jmp    1258 <rintf+0x118>
movss  -0x8(%rbp),%xmm0
call   1050 <floorf@plt>
movss  %xmm0,-0x18(%rbp)
movss  -0x18(%rbp),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rintf>:
push   %rax
movss  %xmm0,0x4(%rsp)
xor    %eax,%eax
call   1040 <fegetround@plt>
cmp    $0x800,%eax
je     1189 <rintf+0x49>
cmp    $0x400,%eax
je     117d <rintf+0x3d>
test   %eax,%eax
jne    1195 <rintf+0x55>
movss  0x4(%rsp),%xmm0
mov    $0x1,%edi
call   1030 <fmodf@plt>
movss  0xe88(%rip),%xmm1
ucomiss %xmm0,%xmm1
jbe    1189 <rintf+0x49>
movss  0x4(%rsp),%xmm0
pop    %rax
jmp    1050 <floorf@plt>
movss  0x4(%rsp),%xmm0
pop    %rax
jmp    1060 <ceilf@plt>
movss  0x4(%rsp),%xmm0
mov    $0x1,%edi
call   1030 <fmodf@plt>
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    11b7 <rintf+0x77>
jp     11b7 <rintf+0x77>
movss  0x4(%rsp),%xmm0
pop    %rax
ret
movss  0x4(%rsp),%xmm0
ucomiss %xmm0,%xmm1
jbe    11c8 <rintf+0x88>
pop    %rax
jmp    1060 <ceilf@plt>
pop    %rax
jmp    1050 <floorf@plt>

LLVM IR (-O0):
define float @rintf(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca i32
store float %0, float* %3
%5 = call i32 (...) @fegetround()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %1
%9 = load float, float* %3
%10 = call float @fmodf(float %9, i32 1)
%11 = fcmp olt float %10, 5.000000e-01
br i1 %11, label %12, label %15
12: ; preds = %8
%13 = load float, float* %3
%14 = call float @llvm.floor.f32(float %13)
br label %18
15: ; preds = %8
%16 = load float, float* %3
%17 = call float @llvm.ceil.f32(float %16)
br label %18
18: ; preds = %15, %12
%19 = phi float [ %14, %12 ], [ %17, %15 ]
store float %19, float* %2
br label %51
20: ; preds = %1
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 1024
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load float, float* %3
%25 = call float @llvm.floor.f32(float %24)
store float %25, float* %2
br label %51
26: ; preds = %20
%27 = load i32, i32* %4
%28 = icmp eq i32 %27, 2048
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load float, float* %3
%31 = call float @llvm.ceil.f32(float %30)
store float %31, float* %2
br label %51
32: ; preds = %26
%33 = load float, float* %3
%34 = call float @fmodf(float %33, i32 1)
%35 = fcmp oeq float %34, 0.000000e+00
br i1 %35, label %36, label %38
36: ; preds = %32
%37 = load float, float* %3
br label %49
38: ; preds = %32
%39 = load float, float* %3
%40 = fcmp olt float %39, 0.000000e+00
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = load float, float* %3
%43 = call float @llvm.ceil.f32(float %42)
br label %47
44: ; preds = %38
%45 = load float, float* %3
%46 = call float @llvm.floor.f32(float %45)
br label %47
47: ; preds = %44, %41
%48 = phi float [ %43, %41 ], [ %46, %44 ]
br label %49
49: ; preds = %47, %36
%50 = phi float [ %37, %36 ], [ %48, %47 ]
store float %50, float* %2
br label %51
51: ; preds = %49, %29, %23, %18
%52 = load float, float* %2
ret float %52
}

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