#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 */
int float2int(float);
void float_to_i32(float *vv, int *i32) {
  float v = *vv;
  if (v < 0.0) {
    if (v < -1.0)
      *i32 = 0x80000000;
    else
      *i32 = float2int(v * 2147483648.0 - 0.5);
  } else {
    if (v >= (2147483646.5f / 2147483648.0f))
      *i32 = 0x7FFFFFFF;
    else
      *i32 = float2int(v * 2147483648.0 + 0.5);
  }
}


x86 assembly (clang, -O0):
<float_to_i32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movss  (%rax),%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
xorps  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jbe    11a4 <float_to_i32+0x94>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xec4(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    116d <float_to_i32+0x5d>
mov    -0x10(%rbp),%rax
movl   $0x80000000,(%rax)
jmp    119f <float_to_i32+0x8f>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe8a(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe96(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <float2int@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1200 <float_to_i32+0xf0>
movss  -0x14(%rbp),%xmm0
movss  0xe4f(%rip),%xmm1
ucomiss %xmm1,%xmm0
jb     11c9 <float_to_i32+0xb9>
mov    -0x10(%rbp),%rax
movl   $0x7fffffff,(%rax)
jmp    11fb <float_to_i32+0xeb>
movss  -0x14(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe2e(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe2a(%rip),%xmm1
addsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <float2int@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
jmp    1200 <float_to_i32+0xf0>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<float_to_i32>:
push   %rbx
mov    %rsi,%rbx
movss  (%rdi),%xmm1
cvtss2sd %xmm1,%xmm0
xorps  %xmm2,%xmm2
ucomiss %xmm1,%xmm2
jbe    1148 <float_to_i32+0x38>
mov    $0x80000000,%eax
movss  0xed3(%rip),%xmm2
ucomiss %xmm1,%xmm2
ja     116f <float_to_i32+0x5f>
mulsd  0xeca(%rip),%xmm0
addsd  0xed2(%rip),%xmm0
jmp    1166 <float_to_i32+0x56>
mov    $0x7fffffff,%eax
ucomiss 0xeac(%rip),%xmm1
jae    116f <float_to_i32+0x5f>
mulsd  0xeaa(%rip),%xmm0
addsd  0xeaa(%rip),%xmm0
cvtsd2ss %xmm0,%xmm0
call   1030 <float2int@plt>
mov    %eax,(%rbx)
pop    %rbx
ret

LLVM IR (-O0):
define void @float_to_i32(float* %0, i32* %1) {
%3 = alloca float*
%4 = alloca i32*
%5 = alloca float
store float* %0, float** %3
store i32* %1, i32** %4
%6 = load float*, float** %3
%7 = load float, float* %6
store float %7, float* %5
%8 = load float, float* %5
%9 = fpext float %8 to double
%10 = fcmp olt double %9, 0.000000e+00
br i1 %10, label %11, label %25
11: ; preds = %2
%12 = load float, float* %5
%13 = fpext float %12 to double
%14 = fcmp olt double %13, -1.000000e+00
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32*, i32** %4
store i32 -2147483648, i32* %16
br label %24
17: ; preds = %11
%18 = load float, float* %5
%19 = fpext float %18 to double
%20 = call double @llvm.fmuladd.f64(double %19, double 0x41E0000000000000, double -5.000000e-01)
%21 = fptrunc double %20 to float
%22 = call i32 @float2int(float %21)
%23 = load i32*, i32** %4
store i32 %22, i32* %23
br label %24
24: ; preds = %17, %15
br label %38
25: ; preds = %2
%26 = load float, float* %5
%27 = fcmp oge float %26, 1.000000e+00
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i32*, i32** %4
store i32 2147483647, i32* %29
br label %37
30: ; preds = %25
%31 = load float, float* %5
%32 = fpext float %31 to double
%33 = call double @llvm.fmuladd.f64(double %32, double 0x41E0000000000000, double 5.000000e-01)
%34 = fptrunc double %33 to float
%35 = call i32 @float2int(float %34)
%36 = load i32*, i32** %4
store i32 %35, i32* %36
br label %37
37: ; preds = %30, %28
br label %38
38: ; preds = %37, %24
ret void
}

LLVM IR (-O2):
define void @float_to_i32(float* nocapture %0, i32* nocapture writeonly %1) {
%3 = load float, float* %0
%4 = fpext float %3 to double
%5 = fcmp olt float %3, 0.000000e+00
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = fcmp olt float %3, -1.000000e+00
br i1 %7, label %18, label %8
8: ; preds = %6
%9 = tail call double @llvm.fmuladd.f64(double %4, double 0x41E0000000000000, double -5.000000e-01)
br label %14
10: ; preds = %2
%11 = fcmp ult float %3, 1.000000e+00
br i1 %11, label %12, label %18
12: ; preds = %10
%13 = tail call double @llvm.fmuladd.f64(double %4, double 0x41E0000000000000, double 5.000000e-01)
br label %14
14: ; preds = %8, %12
%15 = phi double [ %13, %12 ], [ %9, %8 ]
%16 = fptrunc double %15 to float
%17 = tail call i32 @float2int(float %16)
br label %18
18: ; preds = %14, %10, %6
%19 = phi i32 [ -2147483648, %6 ], [ 2147483647, %10 ], [ %17, %14 ]
store i32 %19, i32* %1
ret void
}