#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 lrintf(float);
void f2uc_clip_array(float *src, unsigned char *dest, int count,
                     int normalize) {
  float 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] = 0xFF;
      continue;
    };
    if (0 == 0 && scaled_value <= (-8.0 * 0x10000000)) {
      dest[count] = 0;
      continue;
    };
    dest[count] = (lrintf(scaled_value) >> 24) + 128;
  };
}


x86 assembly (clang, -O0):
<f2uc_clip_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 <f2uc_clip_array+0x46>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1209 <f2uc_clip_array+0xf9>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mulss  -0x1c(%rbp),%xmm0
movss  %xmm0,-0x20(%rbp)
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe72(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11b9 <f2uc_clip_array+0xa9>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
jmp    1164 <f2uc_clip_array+0x54>
movss  -0x20(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe4e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     11e5 <f2uc_clip_array+0xd5>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1164 <f2uc_clip_array+0x54>
movss  -0x20(%rbp),%xmm0
call   1030 <lrintf@plt>
sar    $0x18,%eax
add    $0x80,%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1164 <f2uc_clip_array+0x54>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2uc_clip_array>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
test   %ecx,%ecx
sete   %cl
test   %edx,%edx
jle    11b4 <f2uc_clip_array+0xa4>
mov    %rsi,%r14
mov    %rdi,%r15
mov    %cl,%al
lea    0xeca(%rip),%rcx
movss  (%rcx,%rax,4),%xmm2
mov    %edx,%ebx
add    $0x1,%rbx
movsd  0xebf(%rip),%xmm3
movss  0xebf(%rip),%xmm4
movss  %xmm2,0x4(%rsp)
jmp    118e <f2uc_clip_array+0x7e>
nopl   0x0(%rax)
call   1030 <lrintf@plt>
movss  0xea3(%rip),%xmm4
movsd  0xe93(%rip),%xmm3
movss  0x4(%rsp),%xmm2
shr    $0x18,%eax
xor    $0x80,%al
mov    %al,(%r14,%r12,1)
add    $0xffffffffffffffff,%rbx
cmp    $0x1,%rbx
jbe    11b4 <f2uc_clip_array+0xa4>
lea    -0x2(%rbx),%r12d
movss  (%r15,%r12,4),%xmm0
mulss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
mov    $0xff,%al
ucomisd %xmm3,%xmm1
jae    1180 <f2uc_clip_array+0x70>
ucomiss %xmm0,%xmm4
jb     1160 <f2uc_clip_array+0x50>
xor    %eax,%eax
jmp    1180 <f2uc_clip_array+0x70>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @f2uc_clip_array(float* nocapture %0, i8* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, float 0x4170000000000000, float 0x41E0000000000000
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %30
8: ; preds = %4
%9 = zext i32 %2 to i64
br label %10
10: ; preds = %8, %19
%11 = phi i64 [ %9, %8 ], [ %12, %19 ]
%12 = add nsw i64 %11, -1
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds float, float* %0, i64 %13
%15 = load float, float* %14
%16 = fmul float %6, %15
%17 = fpext float %16 to double
%18 = fcmp ult double %17, 0x41DFFFFFFFC00000
br i1 %18, label %23, label %19
19: ; preds = %10, %23, %25
%20 = phi i8 [ %29, %25 ], [ 0, %23 ], [ -1, %10 ]
%21 = getelementptr inbounds i8, i8* %1, i64 %13
store i8 %20, i8* %21
%22 = icmp ugt i64 %11, 1
br i1 %22, label %10, label %30
23: ; preds = %10
%24 = fcmp ugt float %16, 0xC1E0000000000000
br i1 %24, label %25, label %19
25: ; preds = %23
%26 = tail call i32 @lrintf(float %16)
%27 = lshr i32 %26, 24
%28 = trunc i32 %27 to i8
%29 = xor i8 %28, -128
br label %19
30: ; preds = %19, %4
ret void
}