#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 */
short lrintf(float);
void f2s_array(float *src, int count, short *dest, float scale) {
  while (--count >= 0) {
    dest[count] = lrintf(scale * src[count]);
  };
}


x86 assembly (clang, -O0):
<f2s_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jl     1165 <f2s_array+0x55>
movss  -0x1c(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mulss  (%rax,%rcx,4),%xmm0
call   1030 <lrintf@plt>
mov    %ax,%dx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %dx,(%rax,%rcx,2)
jmp    1128 <f2s_array+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2s_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1168 <f2s_array+0x58>
movaps %xmm0,%xmm1
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%ebx
add    $0x1,%rbx
movss  %xmm0,0x4(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%r12d
movss  (%r15,%r12,4),%xmm0
mulss  %xmm1,%xmm0
call   1030 <lrintf@plt>
movss  0x4(%rsp),%xmm1
mov    %ax,(%r14,%r12,2)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <f2s_array+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @f2s_array(float* %0, i32 %1, i16* %2, float %3) {
%5 = alloca float*
%6 = alloca i32
%7 = alloca i16*
%8 = alloca float
store float* %0, float** %5
store i32 %1, i32* %6
store i16* %2, i16** %7
store float %3, float* %8
br label %9
9: ; preds = %13, %4
%10 = load i32, i32* %6
%11 = add nsw i32 %10, -1
store i32 %11, i32* %6
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %26
13: ; preds = %9
%14 = load float, float* %8
%15 = load float*, float** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds float, float* %15, i64 %17
%19 = load float, float* %18
%20 = fmul float %14, %19
%21 = call signext i16 @lrintf(float %20)
%22 = load i16*, i16** %7
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i16, i16* %22, i64 %24
store i16 %21, i16* %25
br label %9
26: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @f2s_array(float* nocapture %0, i32 %1, i16* nocapture writeonly %2, float %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %18
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %8
8: ; preds = %6, %8
%9 = phi i64 [ %7, %6 ], [ %10, %8 ]
%10 = add nsw i64 %9, -1
%11 = and i64 %10, 4294967295
%12 = getelementptr inbounds float, float* %0, i64 %11
%13 = load float, float* %12
%14 = fmul float %13, %3
%15 = tail call signext i16 @lrintf(float %14)
%16 = getelementptr inbounds i16, i16* %2, i64 %11
store i16 %15, i16* %16
%17 = icmp ugt i64 %9, 1
br i1 %17, label %8, label %18
18: ; preds = %8, %4
ret void
}