#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 lrint(double);
void src_float_to_int_array(const float *in, int *out, int len) {
  double scaled_value;
  while (len) {
    len--;
    scaled_value = in[len] * (8.0 * 0x10000000);
    if (0 == 0 && scaled_value >= (1.0 * 0x7FFFFFFF)) {
      out[len] = 0x7fffffff;
      continue;
    };
    if (0 == 0 && scaled_value <= (-8.0 * 0x10000000)) {
      out[len] = -1 - 0x7fffffff;
      continue;
    };
    out[len] = lrint(scaled_value);
  };
}


x86 assembly (clang, -O0):
<src_float_to_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11c6 <src_float_to_int_array+0xb6>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xeb9(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  0xe9b(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     1183 <src_float_to_int_array+0x73>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x7fffffff,(%rax,%rcx,4)
jmp    1123 <src_float_to_int_array+0x13>
movsd  0xe85(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     11aa <src_float_to_int_array+0x9a>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x80000000,(%rax,%rcx,4)
jmp    1123 <src_float_to_int_array+0x13>
movsd  -0x20(%rbp),%xmm0
call   1030 <lrint@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1123 <src_float_to_int_array+0x13>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<src_float_to_int_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
je     11b0 <src_float_to_int_array+0xa0>
mov    %edx,%r15d
movslq %edx,%rax
lea    (%rsi,%rax,4),%r14
add    $0xfffffffffffffffc,%r14
neg    %r15d
lea    (%rdi,%rax,4),%r12
add    $0xfffffffffffffffc,%r12
xor    %ebx,%ebx
movsd  0xebd(%rip),%xmm1
movsd  0xebd(%rip),%xmm2
movsd  0xebd(%rip),%xmm3
jmp    116d <src_float_to_int_array+0x5d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %eax,(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r15d
je     11b0 <src_float_to_int_array+0xa0>
movss  (%r12,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
mov    $0x7fffffff,%eax
ucomisd %xmm2,%xmm0
jae    1160 <src_float_to_int_array+0x50>
mov    $0x80000000,%eax
ucomisd %xmm0,%xmm3
jae    1160 <src_float_to_int_array+0x50>
call   1030 <lrint@plt>
movsd  0xe72(%rip),%xmm3
movsd  0xe62(%rip),%xmm2
movsd  0xe52(%rip),%xmm1
jmp    1160 <src_float_to_int_array+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @src_float_to_int_array(float* %0, i32* %1, i32 %2) {
%4 = alloca float*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca double
store float* %0, float** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %36, %31, %23, %3
%9 = load i32, i32* %6
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %43
11: ; preds = %8
%12 = load i32, i32* %6
%13 = add nsw i32 %12, -1
store i32 %13, i32* %6
%14 = load float*, float** %4
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds float, float* %14, i64 %16
%18 = load float, float* %17
%19 = fpext float %18 to double
%20 = fmul double %19, 0x41E0000000000000
store double %20, double* %7
%21 = load double, double* %7
%22 = fcmp oge double %21, 0x41DFFFFFFFC00000
br i1 %22, label %23, label %28
23: ; preds = %11
%24 = load i32*, i32** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 2147483647, i32* %27
br label %8
28: ; preds = %11
%29 = load double, double* %7
%30 = fcmp ole double %29, 0xC1E0000000000000
br i1 %30, label %31, label %36
31: ; preds = %28
%32 = load i32*, i32** %5
%33 = load i32, i32* %6
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
store i32 -2147483648, i32* %35
br label %8
36: ; preds = %28
%37 = load double, double* %7
%38 = call i32 @lrint(double %37)
%39 = load i32*, i32** %5
%40 = load i32, i32* %6
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
br label %8
43: ; preds = %8
ret void
}

LLVM IR (-O2):
define void @src_float_to_int_array(float* nocapture %0, i32* nocapture writeonly %1, i32 %2) {
%4 = icmp eq i32 %2, 0
br i1 %4, label %24, label %5
5: ; preds = %3
%6 = sext i32 %2 to i64
br label %7
7: ; preds = %5, %15
%8 = phi i64 [ %6, %5 ], [ %9, %15 ]
%9 = add nsw i64 %8, -1
%10 = getelementptr inbounds float, float* %0, i64 %9
%11 = load float, float* %10
%12 = fpext float %11 to double
%13 = fmul double %12, 0x41E0000000000000
%14 = fcmp ult double %13, 0x41DFFFFFFFC00000
br i1 %14, label %20, label %15
15: ; preds = %7, %20, %22
%16 = phi i32 [ %23, %22 ], [ -2147483648, %20 ], [ 2147483647, %7 ]
%17 = getelementptr inbounds i32, i32* %1, i64 %9
store i32 %16, i32* %17
%18 = trunc i64 %9 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %7
20: ; preds = %7
%21 = fcmp ugt double %13, 0xC1E0000000000000
br i1 %21, label %22, label %15
22: ; preds = %20
%23 = tail call i32 @lrint(double %13)
br label %15
24: ; preds = %15, %3
ret void
}