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


x86 assembly (clang, -O0):
<d2i_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     1163 <d2i_array+0x53>
movsd  -0x20(%rbp),%xmm0
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mulsd  (%rax,%rcx,8),%xmm0
call   1030 <lrint@plt>
mov    %eax,%edx
mov    -0x18(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    1128 <d2i_array+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2i_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1166 <d2i_array+0x56>
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    %eax,(%r14,%r12,4)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1140 <d2i_array+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @d2i_array(double* %0, i32 %1, i32* %2, double %3) {
%5 = alloca double*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca double
store double* %0, double** %5
store i32 %1, i32* %6
store i32* %2, i32** %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 i32 @lrint(double %20)
%22 = load i32*, i32** %7
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i32, i32* %22, i64 %24
store i32 %21, i32* %25
br label %9
26: ; preds = %9
ret void
}

LLVM IR (-O2):
define void @d2i_array(double* nocapture %0, i32 %1, i32* 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 i32 @lrint(double %14)
%16 = getelementptr inbounds i32, i32* %2, i64 %11
store i32 %15, i32* %16
%17 = icmp ugt i64 %9, 1
br i1 %17, label %8, label %18
18: ; preds = %8, %4
ret void
}