#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 /*<<< orphan*/ assert(int);
int rint32(double);
void src_float_to_int_array(float const *src, int *dest, int len) {
  double d, N = 32768. * 65536.;
  assert(src && dest);
  while (len--)
    d = src[len] * N, dest[len] = d >= N - 1 ? (int)(N - 1)
                                  : d < -N   ? (int)(-N)
                                             : rint32(d);
}


x86 assembly (clang, -O0):
<src_float_to_int_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movsd  0xec5(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x8(%rbp)
mov    %al,-0x29(%rbp)
je     115b <src_float_to_int_array+0x3b>
cmpq   $0x0,-0x10(%rbp)
setne  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
je     124d <src_float_to_int_array+0x12d>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
movsd  0xe5f(%rip),%xmm2
subsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jb     11d4 <src_float_to_int_array+0xb4>
movsd  -0x28(%rbp),%xmm0
movsd  0xe44(%rip),%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x30(%rbp)
jmp    123a <src_float_to_int_array+0x11a>
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
ucomisd %xmm1,%xmm0
jbe    1227 <src_float_to_int_array+0x107>
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
cvttsd2si %xmm0,%eax
mov    %eax,-0x34(%rbp)
jmp    1234 <src_float_to_int_array+0x114>
movsd  -0x20(%rbp),%xmm0
call   1040 <rint32@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1168 <src_float_to_int_array+0x48>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<src_float_to_int_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %rsi,%r14
mov    %rdi,%r15
test   %rdi,%rdi
setne  %al
test   %rsi,%rsi
setne  %cl
and    %al,%cl
movzbl %cl,%edi
call   1030 <assert@plt>
test   %r12d,%r12d
je     11e0 <src_float_to_int_array+0xc0>
movslq %r12d,%rax
lea    (%r15,%rax,4),%r15
add    $0xfffffffffffffffc,%r15
lea    (%r14,%rax,4),%r14
add    $0xfffffffffffffffc,%r14
neg    %r12d
xor    %ebx,%ebx
movsd  0xe90(%rip),%xmm1
movsd  0xe90(%rip),%xmm2
movsd  0xe90(%rip),%xmm3
jmp    119d <src_float_to_int_array+0x7d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %eax,(%r14,%rbx,4)
add    $0xffffffffffffffff,%rbx
cmp    %ebx,%r12d
je     11e0 <src_float_to_int_array+0xc0>
movss  (%r15,%rbx,4),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  %xmm1,%xmm0
mov    $0x7fffffff,%eax
ucomisd %xmm2,%xmm0
jae    1190 <src_float_to_int_array+0x70>
mov    $0x80000000,%eax
ucomisd %xmm0,%xmm3
ja     1190 <src_float_to_int_array+0x70>
call   1040 <rint32@plt>
movsd  0xe42(%rip),%xmm3
movsd  0xe32(%rip),%xmm2
movsd  0xe22(%rip),%xmm1
jmp    1190 <src_float_to_int_array+0x70>
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
%8 = alloca double
store float* %0, float** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
store double 0x41E0000000000000, double* %8
%9 = load float*, float** %4
%10 = icmp ne float* %9, null
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i32*, i32** %5
%13 = icmp ne i32* %12, null
br label %14
14: ; preds = %11, %3
%15 = phi i1 [ false, %3 ], [ %13, %11 ]
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
br label %18
18: ; preds = %53, %14
%19 = load i32, i32* %6
%20 = add nsw i32 %19, -1
store i32 %20, i32* %6
%21 = icmp ne i32 %19, 0
br i1 %21, label %22, label %59
22: ; preds = %18
%23 = load float*, float** %4
%24 = load i32, i32* %6
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds float, float* %23, i64 %25
%27 = load float, float* %26
%28 = fpext float %27 to double
%29 = load double, double* %8
%30 = fmul double %28, %29
store double %30, double* %7
%31 = load double, double* %7
%32 = load double, double* %8
%33 = fsub double %32, 1.000000e+00
%34 = fcmp oge double %31, %33
br i1 %34, label %35, label %39
35: ; preds = %22
%36 = load double, double* %8
%37 = fsub double %36, 1.000000e+00
%38 = fptosi double %37 to i32
br label %53
39: ; preds = %22
%40 = load double, double* %7
%41 = load double, double* %8
%42 = fneg double %41
%43 = fcmp olt double %40, %42
br i1 %43, label %44, label %48
44: ; preds = %39
%45 = load double, double* %8
%46 = fneg double %45
%47 = fptosi double %46 to i32
br label %51
48: ; preds = %39
%49 = load double, double* %7
%50 = call i32 @rint32(double %49)
br label %51
51: ; preds = %48, %44
%52 = phi i32 [ %47, %44 ], [ %50, %48 ]
br label %53
53: ; preds = %51, %35
%54 = phi i32 [ %38, %35 ], [ %52, %51 ]
%55 = load i32*, i32** %5
%56 = load i32, i32* %6
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i32, i32* %55, i64 %57
store i32 %54, i32* %58
br label %18
59: ; preds = %18
ret void
}

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