#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 */
double INT_MAX;
double INT_MIN;
int /*<<< orphan*/ error(char *);
int roundfi(float x) {
  if ((x <= INT_MIN - 0.5) || (x >= INT_MAX + 0.5))
    error("roundfi() Float to int conversion out of range");
  if (x >= 0)
    return (int)(x + 0.5);
  return (int)(x - 0.5);
}


x86 assembly (clang, -O0):
<roundfi>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
mov    0x2eb3(%rip),%rax
movsd  (%rax),%xmm0
movsd  0xec7(%rip),%xmm2
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jae    116d <roundfi+0x5d>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xea8(%rip),%xmm1
mov    0x2e89(%rip),%rax
addsd  (%rax),%xmm1
ucomisd %xmm1,%xmm0
jb     1179 <roundfi+0x69>
lea    0xe94(%rip),%rdi
call   1030 <error@plt>
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jb     11ab <roundfi+0x9b>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe65(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
jmp    11c7 <roundfi+0xb7>
movss  -0x8(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe44(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<roundfi>:
sub    $0x18,%rsp
cvtss2sd %xmm0,%xmm1
mov    0x2ec1(%rip),%rax
movsd  (%rax),%xmm2
addsd  0xed5(%rip),%xmm2
ucomisd %xmm1,%xmm2
jae    114a <roundfi+0x3a>
mov    0x2eb0(%rip),%rax
movsd  (%rax),%xmm2
addsd  0xec4(%rip),%xmm2
ucomisd %xmm2,%xmm1
jb     116e <roundfi+0x5e>
lea    0xecf(%rip),%rdi
movsd  %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
call   1030 <error@plt>
movss  0xc(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
xorpd  %xmm2,%xmm2
xor    %eax,%eax
ucomiss %xmm2,%xmm0
setb   %al
lea    0xe8f(%rip),%rcx
addsd  (%rcx,%rax,8),%xmm1
cvttsd2si %xmm1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@INT_MIN = global double 0.000000e+00
@INT_MAX = global double 0.000000e+00
@.str = [47 x i8] c"roundfi() Float to int conversion out of range\00"
define i32 @roundfi(float %0) {
%2 = alloca i32
%3 = alloca float
store float %0, float* %3
%4 = load float, float* %3
%5 = fpext float %4 to double
%6 = load double, double* @INT_MIN
%7 = fsub double %6, 5.000000e-01
%8 = fcmp ole double %5, %7
br i1 %8, label %15, label %9
9: ; preds = %1
%10 = load float, float* %3
%11 = fpext float %10 to double
%12 = load double, double* @INT_MAX
%13 = fadd double %12, 5.000000e-01
%14 = fcmp oge double %11, %13
br i1 %14, label %15, label %17
15: ; preds = %9, %1
%16 = call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %9
%18 = load float, float* %3
%19 = fcmp oge float %18, 0.000000e+00
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load float, float* %3
%22 = fpext float %21 to double
%23 = fadd double %22, 5.000000e-01
%24 = fptosi double %23 to i32
store i32 %24, i32* %2
br label %30
25: ; preds = %17
%26 = load float, float* %3
%27 = fpext float %26 to double
%28 = fsub double %27, 5.000000e-01
%29 = fptosi double %28 to i32
store i32 %29, i32* %2
br label %30
30: ; preds = %25, %20
%31 = load i32, i32* %2
ret i32 %31
}

LLVM IR (-O2):
@INT_MIN = global double 0.000000e+00
@INT_MAX = global double 0.000000e+00
@.str = [47 x i8] c"roundfi() Float to int conversion out of range\00"
define i32 @roundfi(float %0) {
%2 = fpext float %0 to double
%3 = load double, double* @INT_MIN
%4 = fadd double %3, -5.000000e-01
%5 = fcmp ult double %4, %2
br i1 %5, label %6, label %10
6: ; preds = %1
%7 = load double, double* @INT_MAX
%8 = fadd double %7, 5.000000e-01
%9 = fcmp ugt double %8, %2
br i1 %9, label %12, label %10
10: ; preds = %6, %1
%11 = tail call i32 @error(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %6
%13 = fcmp ult float %0, 0.000000e+00
%14 = select i1 %13, double -5.000000e-01, double 5.000000e-01
%15 = fadd double %14, %2
%16 = fptosi double %15 to i32
ret i32 %16
}