#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 const);
void d2uc_clip_array(const double *src, unsigned char *dest, int count,
                     int normalize) {
  double normfact, scaled_value;
  normfact = normalize ? (8.0 * 0x10000000) : (1.0 * 0x1000000);
  while (--count >= 0) {
    scaled_value = src[count] * normfact;
    if (0 == 0 && scaled_value >= (1.0 * 0x7FFFFFFF)) {
      dest[count] = 255;
      continue;
    };
    if (0 == 0 && scaled_value <= (-8.0 * 0x10000000)) {
      dest[count] = 0;
      continue;
    };
    dest[count] = (lrint(src[count] * normfact) >> 24) + 128;
  };
}


x86 assembly (clang, -O0):
<d2uc_clip_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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,-0x38(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x30(%rbp)
jne    1156 <d2uc_clip_array+0x46>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1206 <d2uc_clip_array+0xf6>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe7a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b1 <d2uc_clip_array+0xa1>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    1160 <d2uc_clip_array+0x50>
movsd  0xe5f(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     11d5 <d2uc_clip_array+0xc5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1160 <d2uc_clip_array+0x50>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1030 <lrint@plt>
sar    $0x18,%eax
add    $0x80,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1160 <d2uc_clip_array+0x50>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2uc_clip_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %ecx,%ecx
sete   %cl
test   %edx,%edx
jle    11ad <d2uc_clip_array+0x9d>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %cl,%al
lea    0xeca(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
mov    %edx,%ebx
add    $0x1,%rbx
movsd  0xec7(%rip),%xmm2
movsd  0xec7(%rip),%xmm3
movsd  %xmm1,(%rsp)
jmp    118d <d2uc_clip_array+0x7d>
nopl   0x0(%rax,%rax,1)
call   1030 <lrint@plt>
movsd  0xeab(%rip),%xmm3
movsd  0xe9b(%rip),%xmm2
movsd  (%rsp),%xmm1
shr    $0x18,%eax
xor    $0x80,%al
mov    %al,(%r14,%r12,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11ad <d2uc_clip_array+0x9d>
lea    -0x2(%rbx),%r12d
movsd  (%r15,%r12,8),%xmm0
mulsd  %xmm1,%xmm0
mov    $0xff,%al
ucomisd %xmm2,%xmm0
jae    117f <d2uc_clip_array+0x6f>
ucomisd %xmm0,%xmm3
jb     1160 <d2uc_clip_array+0x50>
xor    %eax,%eax
jmp    117f <d2uc_clip_array+0x6f>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @d2uc_clip_array(double* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca double*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca double
store double* %0, double** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = icmp ne i32 %11, 0
%13 = zext i1 %12 to i64
%14 = select i1 %12, double 0x41E0000000000000, double 0x4170000000000000
store double %14, double* %9
br label %15
15: ; preds = %42, %37, %29, %4
%16 = load i32, i32* %7
%17 = add nsw i32 %16, -1
store i32 %17, i32* %7
%18 = icmp sge i32 %17, 0
br i1 %18, label %19, label %58
19: ; preds = %15
%20 = load double*, double** %5
%21 = load i32, i32* %7
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds double, double* %20, i64 %22
%24 = load double, double* %23
%25 = load double, double* %9
%26 = fmul double %24, %25
store double %26, double* %10
%27 = load double, double* %10
%28 = fcmp oge double %27, 0x41DFFFFFFFC00000
br i1 %28, label %29, label %34
29: ; preds = %19
%30 = load i8*, i8** %6
%31 = load i32, i32* %7
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 -1, i8* %33
br label %15
34: ; preds = %19
%35 = load double, double* %10
%36 = fcmp ole double %35, 0xC1E0000000000000
br i1 %36, label %37, label %42
37: ; preds = %34
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
store i8 0, i8* %41
br label %15
42: ; preds = %34
%43 = load double*, double** %5
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds double, double* %43, i64 %45
%47 = load double, double* %46
%48 = load double, double* %9
%49 = fmul double %47, %48
%50 = call i32 @lrint(double %49)
%51 = ashr i32 %50, 24
%52 = add nsw i32 %51, 128
%53 = trunc i32 %52 to i8
%54 = load i8*, i8** %6
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8 %53, i8* %57
br label %15
58: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @d2uc_clip_array(double* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, double 0x4170000000000000, double 0x41E0000000000000
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %29
8: ; preds = %4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %18
%11 = phi i64 [ %9, %8 ], [ %12, %18 ]
%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 = fcmp ult double %16, 0x41DFFFFFFFC00000
br i1 %17, label %22, label %18
18: ; preds = %10, %22, %24
%19 = phi i8 [ %28, %24 ], [ 0, %22 ], [ -1, %10 ]
%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 %29
22: ; preds = %10
%23 = fcmp ugt double %16, 0xC1E0000000000000
br i1 %23, label %24, label %18
24: ; preds = %22
%25 = tail call i32 @lrint(double %16)
%26 = lshr i32 %25, 24
%27 = trunc i32 %26 to i8
%28 = xor i8 %27, -128
br label %18
29: ; preds = %18, %4
ret void
}