#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 */
scalar_t__ INT_MAX;
scalar_t__ INT_MIN;
scalar_t__ is_nan(float);
int /*<<< orphan*/ print_float_in_binary(float);
int /*<<< orphan*/ print_int_in_binary(int);
int /*<<< orphan*/ printf(char *, ...);
void test_signed_f2i_32(float a_i) {
  printf("0001_1_");
  print_float_in_binary(a_i);
  printf("\n");
  int z_lo;
  int invalid;
  if (is_nan(a_i)) {
    z_lo = 0;
    invalid = 1;
  } else if (a_i > (float)INT_MAX) {
    z_lo = 0x7fffffff;
    invalid = 1;
  } else if (a_i < (float)INT_MIN) {
    z_lo = 0x80000000;
    invalid = 1;
  } else {
    z_lo = (int)a_i;
    invalid = 0;
  }
  printf("0010_");
  printf("%d_", invalid);
  print_int_in_binary(z_lo);
  printf("\n");
}


x86 assembly (clang, -O0):
<test_signed_f2i_32>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x4(%rbp)
lea    0xeac(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x4(%rbp),%xmm0
call   1060 <print_float_in_binary@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movss  -0x4(%rbp),%xmm0
call   1050 <is_nan@plt>
cmp    $0x0,%rax
je     119a <test_signed_f2i_32+0x5a>
movl   $0x0,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    120d <test_signed_f2i_32+0xcd>
movss  -0x4(%rbp),%xmm0
mov    0x2e42(%rip),%rax
cvtsi2ssq (%rax),%xmm1
ucomiss %xmm1,%xmm0
jbe    11c7 <test_signed_f2i_32+0x87>
movl   $0x7fffffff,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    1208 <test_signed_f2i_32+0xc8>
movss  -0x4(%rbp),%xmm1
mov    0x2e0d(%rip),%rax
cvtsi2ssq (%rax),%xmm0
ucomiss %xmm1,%xmm0
jbe    11f4 <test_signed_f2i_32+0xb4>
movl   $0x80000000,-0x8(%rbp)
movl   $0x1,-0xc(%rbp)
jmp    1203 <test_signed_f2i_32+0xc3>
cvttss2si -0x4(%rbp),%eax
mov    %eax,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
jmp    1208 <test_signed_f2i_32+0xc8>
jmp    120d <test_signed_f2i_32+0xcd>
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1030 <print_int_in_binary@plt>
lea    0xdcd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_signed_f2i_32>:
push   %rbp
push   %rbx
push   %rax
movss  %xmm0,0x4(%rsp)
lea    0xea0(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <printf@plt>
movss  0x4(%rsp),%xmm0
call   1070 <print_float_in_binary@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
movss  0x4(%rsp),%xmm0
call   1060 <is_nan@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    11d1 <test_signed_f2i_32+0x81>
mov    0x2e4e(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2ssq (%rax),%xmm0
mov    $0x7fffffff,%ebx
movss  0x4(%rsp),%xmm1
ucomiss %xmm0,%xmm1
ja     11d1 <test_signed_f2i_32+0x81>
mov    0x2e27(%rip),%rax
xorps  %xmm0,%xmm0
cvtsi2ssq (%rax),%xmm0
mov    $0x80000000,%ebx
ucomiss %xmm1,%xmm0
ja     11d1 <test_signed_f2i_32+0x81>
cvttss2si %xmm1,%ebx
xor    %ebp,%ebp
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe28(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1040 <print_int_in_binary@plt>
mov    $0xa,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <putchar@plt>

LLVM IR (-O0):
@.str = [8 x i8] c"0001_1_\00"
@.str.1 = [2 x i8] c"\0A\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.2 = [6 x i8] c"0010_\00"
@.str.3 = [4 x i8] c"%d_\00"
define void @test_signed_f2i_32(float %0) {
%2 = alloca float
%3 = alloca i32
%4 = alloca i32
store float %0, float* %2
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%6 = load float, float* %2
%7 = call i32 @print_float_in_binary(float %6)
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = load float, float* %2
%10 = call i64 @is_nan(float %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %1
store i32 0, i32* %3
store i32 1, i32* %4
br label %30
13: ; preds = %1
%14 = load float, float* %2
%15 = load i64, i64* @INT_MAX
%16 = sitofp i64 %15 to float
%17 = fcmp ogt float %14, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 2147483647, i32* %3
store i32 1, i32* %4
br label %29
19: ; preds = %13
%20 = load float, float* %2
%21 = load i64, i64* @INT_MIN
%22 = sitofp i64 %21 to float
%23 = fcmp olt float %20, %22
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 -2147483648, i32* %3
store i32 1, i32* %4
br label %28
25: ; preds = %19
%26 = load float, float* %2
%27 = fptosi float %26 to i32
store i32 %27, i32* %3
store i32 0, i32* %4
br label %28
28: ; preds = %25, %24
br label %29
29: ; preds = %28, %18
br label %30
30: ; preds = %29, %12
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %4
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %32)
%34 = load i32, i32* %3
%35 = call i32 @print_int_in_binary(i32 %34)
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"0001_1_\00"
@INT_MAX = global i64 0
@INT_MIN = global i64 0
@.str.2 = [6 x i8] c"0010_\00"
@.str.3 = [4 x i8] c"%d_\00"
define void @test_signed_f2i_32(float %0) {
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 @print_float_in_binary(float %0)
%4 = tail call i32 @putchar(i32 10)
%5 = tail call i64 @is_nan(float %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %1
%8 = load i64, i64* @INT_MAX
%9 = sitofp i64 %8 to float
%10 = fcmp olt float %9, %0
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = load i64, i64* @INT_MIN
%13 = sitofp i64 %12 to float
%14 = fcmp ogt float %13, %0
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = fptosi float %0 to i32
br label %17
17: ; preds = %11, %7, %1, %15
%18 = phi i32 [ %16, %15 ], [ 0, %1 ], [ 2147483647, %7 ], [ -2147483648, %11 ]
%19 = phi i32 [ 0, %15 ], [ 1, %1 ], [ 1, %7 ], [ 1, %11 ]
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %19)
%22 = tail call i32 @print_int_in_binary(i32 %18)
%23 = tail call i32 @putchar(i32 10)
ret void
}