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

/* Variables and functions */
float INT32_MAX;
float INT32_MIN;
float lrint(float);
int32_t ftoi_native(float f) {
  if (f > (int64_t)INT32_MAX + 2)
    return INT32_MAX;
  if (f < (int64_t)INT32_MIN - 2)
    return INT32_MIN;
  int64_t l = lrint(f);
  if (l > INT32_MAX)
    return INT32_MAX;
  if (l < INT32_MIN)
    return INT32_MIN;
  return l;
}


x86 assembly (clang, -O0):
<ftoi_native>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
movss  0xed6(%rip),%xmm1
mov    0x2eaf(%rip),%rax
addss  (%rax),%xmm1
ucomiss %xmm1,%xmm0
jbe    1153 <ftoi_native+0x43>
mov    0x2e9b(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fe <ftoi_native+0xee>
movss  -0x8(%rbp),%xmm1
mov    0x2e79(%rip),%rax
movss  (%rax),%xmm0
movss  0xe95(%rip),%xmm2
subss  %xmm2,%xmm0
ucomiss %xmm1,%xmm0
jbe    118d <ftoi_native+0x7d>
mov    0x2e59(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fe <ftoi_native+0xee>
movss  -0x8(%rbp),%xmm0
call   1030 <lrint@plt>
movss  %xmm0,-0xc(%rbp)
movss  -0xc(%rbp),%xmm0
mov    0x2e38(%rip),%rax
ucomiss (%rax),%xmm0
jbe    11c6 <ftoi_native+0xb6>
mov    0x2e28(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fe <ftoi_native+0xee>
movss  -0xc(%rbp),%xmm1
mov    0x2e06(%rip),%rax
movss  (%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    11f4 <ftoi_native+0xe4>
mov    0x2df2(%rip),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11fe <ftoi_native+0xee>
movss  -0xc(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftoi_native>:
push   %r14
push   %rbx
push   %rax
movaps %xmm0,%xmm1
mov    0x2ec2(%rip),%rbx
movss  (%rbx),%xmm0
movss  0xed6(%rip),%xmm2
addss  %xmm0,%xmm2
ucomiss %xmm2,%xmm1
ja     117c <ftoi_native+0x6c>
mov    0x2e9e(%rip),%r14
movss  (%r14),%xmm0
movss  0xebd(%rip),%xmm2
addss  %xmm0,%xmm2
ucomiss %xmm1,%xmm2
ja     117c <ftoi_native+0x6c>
movaps %xmm1,%xmm0
call   1030 <lrint@plt>
movaps %xmm0,%xmm1
movss  (%rbx),%xmm2
movss  (%r14),%xmm3
maxss  %xmm0,%xmm3
movaps %xmm2,%xmm0
cmpltss %xmm1,%xmm0
movaps %xmm0,%xmm1
andnps %xmm3,%xmm1
andps  %xmm2,%xmm0
orps   %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@INT32_MAX = global float 0.000000e+00
@INT32_MIN = global float 0.000000e+00
define float @ftoi_native(float %0) {
%2 = alloca float
%3 = alloca float
%4 = alloca float
store float %0, float* %3
%5 = load float, float* %3
%6 = load float, float* @INT32_MAX
%7 = fadd float %6, 2.000000e+00
%8 = fcmp ogt float %5, %7
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = load float, float* @INT32_MAX
store float %10, float* %2
br label %34
11: ; preds = %1
%12 = load float, float* %3
%13 = load float, float* @INT32_MIN
%14 = fsub float %13, 2.000000e+00
%15 = fcmp olt float %12, %14
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = load float, float* @INT32_MIN
store float %17, float* %2
br label %34
18: ; preds = %11
%19 = load float, float* %3
%20 = call float @lrint(float %19)
store float %20, float* %4
%21 = load float, float* %4
%22 = load float, float* @INT32_MAX
%23 = fcmp ogt float %21, %22
br i1 %23, label %24, label %26
24: ; preds = %18
%25 = load float, float* @INT32_MAX
store float %25, float* %2
br label %34
26: ; preds = %18
%27 = load float, float* %4
%28 = load float, float* @INT32_MIN
%29 = fcmp olt float %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load float, float* @INT32_MIN
store float %31, float* %2
br label %34
32: ; preds = %26
%33 = load float, float* %4
store float %33, float* %2
br label %34
34: ; preds = %32, %30, %24, %16, %9
%35 = load float, float* %2
ret float %35
}

LLVM IR (-O2):
@INT32_MAX = global float 0.000000e+00
@INT32_MIN = global float 0.000000e+00
define float @ftoi_native(float %0) {
%2 = load float, float* @INT32_MAX
%3 = fadd float %2, 2.000000e+00
%4 = fcmp olt float %3, %0
br i1 %4, label %17, label %5
5: ; preds = %1
%6 = load float, float* @INT32_MIN
%7 = fadd float %6, -2.000000e+00
%8 = fcmp ogt float %7, %0
br i1 %8, label %17, label %9
9: ; preds = %5
%10 = tail call float @lrint(float %0)
%11 = load float, float* @INT32_MAX
%12 = fcmp ogt float %10, %11
%13 = load float, float* @INT32_MIN
%14 = fcmp olt float %10, %13
%15 = select i1 %14, float %13, float %10
%16 = select i1 %12, float %11, float %15
br label %17
17: ; preds = %5, %1, %9
%18 = phi float [ %16, %9 ], [ %2, %1 ], [ %6, %5 ]
ret float %18
}