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

/* Variables and functions */
double fabs(float);
float frexp(float, int *);
int32_t av_flt2int(float d) {
  int e;
  if (!d)
    return 0;
  else if (d - d)
    return 0x7F800000 + ((d < 0) << 31) + (d != d);
  d = frexp(d, &e);
  return (d < 0) << 31 | (e + 126) << 23 |
         (int64_t)((fabs(d) - 0.5) * (1 << 24));
}


x86 assembly (clang, -O0):
<av_flt2int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1150 <av_flt2int+0x30>
jp     1150 <av_flt2int+0x30>
movl   $0x0,-0x4(%rbp)
jmp    120f <av_flt2int+0xef>
movss  -0x8(%rbp),%xmm0
subss  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    1171 <av_flt2int+0x51>
jp     1171 <av_flt2int+0x51>
jmp    11a9 <av_flt2int+0x89>
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
shl    $0x1f,%eax
add    $0x7f800000,%eax
movss  -0x8(%rbp),%xmm0
ucomiss -0x8(%rbp),%xmm0
setne  %cl
setp   %dl
or     %dl,%cl
and    $0x1,%cl
movzbl %cl,%ecx
add    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    120f <av_flt2int+0xef>
jmp    11ae <av_flt2int+0x8e>
movss  -0x8(%rbp),%xmm0
lea    -0xc(%rbp),%rdi
call   1030 <frexp@plt>
movss  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
ucomiss -0x8(%rbp),%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%eax
shl    $0x1f,%eax
mov    -0xc(%rbp),%ecx
add    $0x7e,%ecx
shl    $0x17,%ecx
or     %ecx,%eax
mov    %eax,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
call   1040 <fabs@plt>
mov    -0x10(%rbp),%eax
movsd  0xe12(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  0xdfe(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%ecx
or     %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<av_flt2int>:
xorps  %xmm1,%xmm1
ucomiss %xmm1,%xmm0
jne    112a <av_flt2int+0xa>
jnp    1156 <av_flt2int+0x36>
movaps %xmm0,%xmm2
subss  %xmm0,%xmm2
ucomiss %xmm1,%xmm2
jne    1138 <av_flt2int+0x18>
jnp    1159 <av_flt2int+0x39>
xorps  %xmm1,%xmm1
xor    %eax,%eax
ucomiss %xmm0,%xmm1
setbe  %al
shl    $0x1f,%eax
xor    %ecx,%ecx
ucomiss %xmm0,%xmm0
setp   %cl
add    %ecx,%eax
add    $0xff800000,%eax
ret
xor    %eax,%eax
ret
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
call   1030 <frexp@plt>
xorps  %xmm1,%xmm1
xor    %eax,%eax
ucomiss %xmm0,%xmm1
seta   %al
shl    $0x1f,%eax
mov    0xc(%rsp),%ebx
shl    $0x17,%ebx
add    $0x3f000000,%ebx
or     %eax,%ebx
call   1040 <fabs@plt>
addsd  0xe6e(%rip),%xmm0
mulsd  0xe6e(%rip),%xmm0
cvttsd2si %xmm0,%eax
or     %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @av_flt2int(float %0) {
%2 = alloca i32
%3 = alloca float
%4 = alloca i32
store float %0, float* %3
%5 = load float, float* %3
%6 = fcmp une float %5, 0.000000e+00
br i1 %6, label %8, label %7
7: ; preds = %1
store i32 0, i32* %2
br label %42
8: ; preds = %1
%9 = load float, float* %3
%10 = load float, float* %3
%11 = fsub float %9, %10
%12 = fcmp une float %11, 0.000000e+00
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = load float, float* %3
%15 = fcmp olt float %14, 0.000000e+00
%16 = zext i1 %15 to i32
%17 = shl i32 %16, 31
%18 = add nsw i32 2139095040, %17
%19 = load float, float* %3
%20 = load float, float* %3
%21 = fcmp une float %19, %20
%22 = zext i1 %21 to i32
%23 = add nsw i32 %18, %22
store i32 %23, i32* %2
br label %42
24: ; preds = %8
br label %25
25: ; preds = %24
%26 = load float, float* %3
%27 = call float @frexp(float %26, i32* %4)
store float %27, float* %3
%28 = load float, float* %3
%29 = fcmp olt float %28, 0.000000e+00
%30 = zext i1 %29 to i32
%31 = shl i32 %30, 31
%32 = load i32, i32* %4
%33 = add nsw i32 %32, 126
%34 = shl i32 %33, 23
%35 = or i32 %31, %34
%36 = load float, float* %3
%37 = call double @fabs(float %36)
%38 = fsub double %37, 5.000000e-01
%39 = fmul double %38, 0x4170000000000000
%40 = fptosi double %39 to i32
%41 = or i32 %35, %40
store i32 %41, i32* %2
br label %42
42: ; preds = %25, %13, %7
%43 = load i32, i32* %2
ret i32 %43
}

LLVM IR (-O2):
define i32 @av_flt2int(float %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = fcmp une float %0, 0.000000e+00
br i1 %4, label %5, label %27
5: ; preds = %1
%6 = fsub float %0, %0
%7 = fcmp une float %6, 0.000000e+00
br i1 %7, label %8, label %14
8: ; preds = %5
%9 = fcmp olt float %0, 0.000000e+00
%10 = select i1 %9, i32 -8388608, i32 2139095040
%11 = fcmp uno float %0, 0.000000e+00
%12 = zext i1 %11 to i32
%13 = or i32 %10, %12
br label %27
14: ; preds = %5
%15 = call float @frexp(float %0, i32* %2)
%16 = fcmp olt float %15, 0.000000e+00
%17 = select i1 %16, i32 -2147483648, i32 0
%18 = load i32, i32* %2
%19 = shl i32 %18, 23
%20 = add i32 %19, 1056964608
%21 = or i32 %20, %17
%22 = tail call double @fabs(float %15)
%23 = fadd double %22, -5.000000e-01
%24 = fmul double %23, 0x4170000000000000
%25 = fptosi double %24 to i32
%26 = or i32 %21, %25
br label %27
27: ; preds = %1, %14, %8
%28 = phi i32 [ %13, %8 ], [ %26, %14 ], [ 0, %1 ]
ret i32 %28
}