#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 d2uc_array(double *src, unsigned char *dest, int count, int normalize) {
  double normfact;
  normfact = normalize ? (1.0 * 0x7F) : 1.0;
  while (--count >= 0) {
    dest[count] = lrint(src[count] * normfact) + 128;
  };
}


x86 assembly (clang, -O0):
<d2uc_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movsd  0xecf(%rip),%xmm0
movsd  0xecf(%rip),%xmm1
movsd  %xmm1,-0x30(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x28(%rbp)
jne    1156 <d2uc_array+0x46>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     11a0 <d2uc_array+0x90>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <lrint@plt>
add    $0x80,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1160 <d2uc_array+0x50>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2uc_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %ecx,%ecx
sete   %cl
test   %edx,%edx
jle    1174 <d2uc_array+0x64>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %cl,%al
lea    0xece(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm0
movsd  %xmm0,(%rsp)
mov    %edx,%ebx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rbx),%r12d
movsd  (%r15,%r12,8),%xmm0
mulsd  (%rsp),%xmm0
call   1030 <lrint@plt>
xor    $0x80,%al
mov    %al,(%r14,%r12,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
ja     1150 <d2uc_array+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @d2uc_array(double* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
store double* %0, double** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = icmp ne i32 %10, 0
%12 = zext i1 %11 to i64
%13 = select i1 %11, double 1.270000e+02, double 1.000000e+00
store double %13, double* %9
br label %14
14: ; preds = %18, %4
%15 = load i32, i32* %7
%16 = add nsw i32 %15, -1
store i32 %16, i32* %7
%17 = icmp sge i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %14
%19 = load double*, double** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds double, double* %19, i64 %21
%23 = load double, double* %22
%24 = load double, double* %9
%25 = fmul double %23, %24
%26 = call i32 @lrint(double %25)
%27 = add nsw i32 %26, 128
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %6
%30 = load i32, i32* %7
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %29, i64 %31
store i8 %28, i8* %32
br label %14
33: ; preds = %14
ret void
}

LLVM IR (-O2):
define void @d2uc_array(double* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, double 1.000000e+00, double 1.270000e+02
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %22
8: ; preds = %4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ %9, %8 ], [ %12, %10 ]
%12 = add nsw i64 %11, -1
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds double, double* %0, i64 %13
%15 = load double, double* %14
%16 = fmul double %6, %15
%17 = tail call i32 @lrint(double %16)
%18 = trunc i32 %17 to i8
%19 = xor i8 %18, -128
%20 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %19, i8* %20
%21 = icmp ugt i64 %11, 1
br i1 %21, label %10, label %22
22: ; preds = %10, %4
ret void
}