#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 f2lei_clip_array(float *src, int *dest, int count, int normalize) {
  unsigned char *ucptr;
  float normfact, scaled_value;
  int value;
  normfact = normalize ? (8.0 * 0x10000000) : 1.0;
  ucptr = ((unsigned char *)dest) + 4 * count;
  while (--count >= 0) {
    ucptr -= 4;
    scaled_value = src[count] * normfact;
    if (0 == 0 && scaled_value >= (1.0 * 0x7FFFFFFF)) {
      ucptr[0] = 0xFF;
      ucptr[1] = 0xFF;
      ucptr[2] = 0xFF;
      ucptr[3] = 0x7F;
      continue;
    };
    if (0 == 0 && scaled_value <= (-8.0 * 0x10000000)) {
      ucptr[0] = 0x00;
      ucptr[1] = 0x00;
      ucptr[2] = 0x00;
      ucptr[3] = 0x80;
      continue;
    };
    value = lrintf(scaled_value);
    ucptr[0] = value;
    ucptr[1] = value >> 8;
    ucptr[2] = value >> 16;
    ucptr[3] = value >> 24;
  };
}


x86 assembly (clang, -O0):
<f2lei_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,-0x40(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x38(%rbp)
jne    1156 <f2lei_clip_array+0x46>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1275 <f2lei_clip_array+0x165>
mov    -0x20(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
mulss  -0x24(%rbp),%xmm0
movss  %xmm0,-0x28(%rbp)
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
movsd  0xe52(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11ec <f2lei_clip_array+0xdc>
mov    -0x20(%rbp),%rax
movb   $0xff,(%rax)
mov    -0x20(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x7f,0x3(%rax)
jmp    1178 <f2lei_clip_array+0x68>
movss  -0x28(%rbp),%xmm0
cvtss2sd %xmm0,%xmm1
movsd  0xe1b(%rip),%xmm0
ucomisd %xmm1,%xmm0
jb     122b <f2lei_clip_array+0x11b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x80,0x3(%rax)
jmp    1178 <f2lei_clip_array+0x68>
movss  -0x28(%rbp),%xmm0
call   1030 <lrintf@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2c(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x2c(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x2c(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    1178 <f2lei_clip_array+0x68>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f2lei_clip_array>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
test   %ecx,%ecx
sete   %cl
test   %edx,%edx
jle    11df <f2lei_clip_array+0xcf>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %cl,%al
lea    0xeca(%rip),%rcx
movss  (%rcx,%rax,4),%xmm2
mov    %edx,%ebp
add    $0xffffffffffffffff,%rbp
movsd  0xebf(%rip),%xmm3
movss  0xebf(%rip),%xmm4
movss  %xmm2,0xc(%rsp)
jmp    1182 <f2lei_clip_array+0x72>
nopl   0x0(%rax)
movb   $0xff,(%rbx,%rbp,4)
movw   $0xffff,0x1(%rbx,%rbp,4)
mov    $0x7f,%al
mov    %al,0x3(%rbx,%rbp,4)
lea    -0x1(%rbp),%rax
add    $0x1,%rbp
cmp    $0x1,%rbp
mov    %rax,%rbp
jbe    11df <f2lei_clip_array+0xcf>
mov    %ebp,%eax
movss  (%r14,%rax,4),%xmm0
mulss  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtss2sd %xmm0,%xmm1
ucomisd %xmm3,%xmm1
jae    1160 <f2lei_clip_array+0x50>
ucomiss %xmm0,%xmm4
jae    11d0 <f2lei_clip_array+0xc0>
call   1030 <lrintf@plt>
movss  0xe63(%rip),%xmm4
movsd  0xe53(%rip),%xmm3
movss  0xc(%rsp),%xmm2
mov    %al,(%rbx,%rbp,4)
mov    %ah,0x1(%rbx,%rbp,4)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x2(%rbx,%rbp,4)
shr    $0x18,%eax
jmp    116d <f2lei_clip_array+0x5d>
movb   $0x0,(%rbx,%rbp,4)
movw   $0x0,0x1(%rbx,%rbp,4)
mov    $0x80,%al
jmp    116d <f2lei_clip_array+0x5d>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @f2lei_clip_array(float* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca float*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca float
%11 = alloca float
%12 = alloca i32
store float* %0, float** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%13 = load i32, i32* %8
%14 = icmp ne i32 %13, 0
%15 = zext i1 %14 to i64
%16 = select i1 %14, double 0x41E0000000000000, double 1.000000e+00
%17 = fptrunc double %16 to float
store float %17, float* %10
%18 = load i32*, i32** %6
%19 = bitcast i32* %18 to i8*
%20 = load i32, i32* %7
%21 = mul nsw i32 4, %20
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %19, i64 %22
store i8* %23, i8** %9
br label %24
24: ; preds = %63, %54, %41, %4
%25 = load i32, i32* %7
%26 = add nsw i32 %25, -1
store i32 %26, i32* %7
%27 = icmp sge i32 %26, 0
br i1 %27, label %28, label %85
28: ; preds = %24
%29 = load i8*, i8** %9
%30 = getelementptr inbounds i8, i8* %29, i64 -4
store i8* %30, i8** %9
%31 = load float*, float** %5
%32 = load i32, i32* %7
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds float, float* %31, i64 %33
%35 = load float, float* %34
%36 = load float, float* %10
%37 = fmul float %35, %36
store float %37, float* %11
%38 = load float, float* %11
%39 = fpext float %38 to double
%40 = fcmp oge double %39, 0x41DFFFFFFFC00000
br i1 %40, label %41, label %50
41: ; preds = %28
%42 = load i8*, i8** %9
%43 = getelementptr inbounds i8, i8* %42, i64 0
store i8 -1, i8* %43
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i64 1
store i8 -1, i8* %45
%46 = load i8*, i8** %9
%47 = getelementptr inbounds i8, i8* %46, i64 2
store i8 -1, i8* %47
%48 = load i8*, i8** %9
%49 = getelementptr inbounds i8, i8* %48, i64 3
store i8 127, i8* %49
br label %24
50: ; preds = %28
%51 = load float, float* %11
%52 = fpext float %51 to double
%53 = fcmp ole double %52, 0xC1E0000000000000
br i1 %53, label %54, label %63
54: ; preds = %50
%55 = load i8*, i8** %9
%56 = getelementptr inbounds i8, i8* %55, i64 0
store i8 0, i8* %56
%57 = load i8*, i8** %9
%58 = getelementptr inbounds i8, i8* %57, i64 1
store i8 0, i8* %58
%59 = load i8*, i8** %9
%60 = getelementptr inbounds i8, i8* %59, i64 2
store i8 0, i8* %60
%61 = load i8*, i8** %9
%62 = getelementptr inbounds i8, i8* %61, i64 3
store i8 -128, i8* %62
br label %24
63: ; preds = %50
%64 = load float, float* %11
%65 = call i32 @lrintf(float %64)
store i32 %65, i32* %12
%66 = load i32, i32* %12
%67 = trunc i32 %66 to i8
%68 = load i8*, i8** %9
%69 = getelementptr inbounds i8, i8* %68, i64 0
store i8 %67, i8* %69
%70 = load i32, i32* %12
%71 = ashr i32 %70, 8
%72 = trunc i32 %71 to i8
%73 = load i8*, i8** %9
%74 = getelementptr inbounds i8, i8* %73, i64 1
store i8 %72, i8* %74
%75 = load i32, i32* %12
%76 = ashr i32 %75, 16
%77 = trunc i32 %76 to i8
%78 = load i8*, i8** %9
%79 = getelementptr inbounds i8, i8* %78, i64 2
store i8 %77, i8* %79
%80 = load i32, i32* %12
%81 = ashr i32 %80, 24
%82 = trunc i32 %81 to i8
%83 = load i8*, i8** %9
%84 = getelementptr inbounds i8, i8* %83, i64 3
store i8 %82, i8* %84
br label %24
85: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @f2lei_clip_array(float* nocapture %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, float 1.000000e+00, float 0x41E0000000000000
%7 = icmp sgt i32 %2, 0
br i1 %7, label %8, label %47
8: ; preds = %4
%9 = zext i32 %2 to i64
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = bitcast i32* %10 to i8*
%12 = zext i32 %2 to i64
br label %13
13: ; preds = %8, %27
%14 = phi i64 [ %12, %8 ], [ %16, %27 ]
%15 = phi i8* [ %11, %8 ], [ %17, %27 ]
%16 = add nsw i64 %14, -1
%17 = getelementptr inbounds i8, i8* %15, i64 -4
%18 = and i64 %16, 4294967295
%19 = getelementptr inbounds float, float* %0, i64 %18
%20 = load float, float* %19
%21 = fmul float %6, %20
%22 = fpext float %21 to double
%23 = fcmp ult double %22, 0x41DFFFFFFFC00000
br i1 %23, label %31, label %24
24: ; preds = %13
store i8 -1, i8* %17
%25 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 -1, i8* %25
%26 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 -1, i8* %26
br label %27
27: ; preds = %24, %33, %36
%28 = phi i8 [ 127, %24 ], [ -128, %33 ], [ %46, %36 ]
%29 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 %28, i8* %29
%30 = icmp ugt i64 %14, 1
br i1 %30, label %13, label %47
31: ; preds = %13
%32 = fcmp ugt float %21, 0xC1E0000000000000
br i1 %32, label %36, label %33
33: ; preds = %31
store i8 0, i8* %17
%34 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 0, i8* %34
%35 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 0, i8* %35
br label %27
36: ; preds = %31
%37 = tail call i32 @lrintf(float %21)
%38 = trunc i32 %37 to i8
store i8 %38, i8* %17
%39 = lshr i32 %37, 8
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 %40, i8* %41
%42 = lshr i32 %37, 16
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 %43, i8* %44
%45 = lshr i32 %37, 24
%46 = trunc i32 %45 to i8
br label %27
47: ; preds = %27, %4
ret void
}