#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 lrint(double);
void d2s_array(const double *src, int count, short *dest, double scale) {
  while (--count >= 0) {
    dest[count] = lrint(scale * src[count]);
  };
}


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

x86 assembly (clang, -O2):
<d2s_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1167 <d2s_array+0x57>
movapd %xmm0,%xmm1
mov    %rdx,%r14
mov    %rdi,%r15
mov    %esi,%ebx
add    $0x1,%rbx
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rbx),%r12d
movsd  (%r15,%r12,8),%xmm0
mulsd  %xmm1,%xmm0
call   1030 <lrint@plt>
movsd  (%rsp),%xmm1
mov    %ax,(%r14,%r12,2)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <d2s_array+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @d2s_array(double* %0, i32 %1, i16* %2, double %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i16*
%8 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i16* %2, i16** %7
store double %3, double* %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 double, double* %8
%15 = load double*, double** %5
%16 = load i32, i32* %6
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds double, double* %15, i64 %17
%19 = load double, double* %18
%20 = fmul double %14, %19
%21 = call signext i16 @lrint(double %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 @d2s_array(double* nocapture %0, i32 %1, i16* nocapture writeonly %2, double %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 double, double* %0, i64 %11
%13 = load double, double* %12
%14 = fmul double %13, %3
%15 = tail call signext i16 @lrint(double %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
}