#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 d2bei_clip_array(const double *src, int *dest, int count, int normalize) {
  unsigned char *ucptr;
  int value;
  double normfact, scaled_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[3] = 0xFF;
      ucptr[2] = 0xFF;
      ucptr[1] = 0xFF;
      ucptr[0] = 0x7F;
      continue;
    };
    if (0 == 0 && scaled_value <= (-8.0 * 0x10000000)) {
      ucptr[3] = 0x00;
      ucptr[2] = 0x00;
      ucptr[1] = 0x00;
      ucptr[0] = 0x80;
      continue;
    };
    value = lrint(scaled_value);
    ucptr[0] = value >> 24;
    ucptr[1] = value >> 16;
    ucptr[2] = value >> 8;
    ucptr[3] = value;
  };
}


x86 assembly (clang, -O0):
<d2bei_clip_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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,-0x48(%rbp)
cmp    $0x0,%eax
movsd  %xmm0,-0x40(%rbp)
jne    1156 <d2bei_clip_array+0x46>
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%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     1265 <d2bei_clip_array+0x155>
mov    -0x20(%rbp),%rax
add    $0xfffffffffffffffc,%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsd  (%rax,%rcx,8),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     11e4 <d2bei_clip_array+0xd4>
mov    -0x20(%rbp),%rax
movb   $0xff,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0xff,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0xff,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x7f,(%rax)
jmp    1174 <d2bei_clip_array+0x64>
movsd  0xe2c(%rip),%xmm0
ucomisd -0x38(%rbp),%xmm0
jb     121b <d2bei_clip_array+0x10b>
mov    -0x20(%rbp),%rax
movb   $0x0,0x3(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x2(%rax)
mov    -0x20(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x20(%rbp),%rax
movb   $0x80,(%rax)
jmp    1174 <d2bei_clip_array+0x64>
movsd  -0x38(%rbp),%xmm0
call   1030 <lrint@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x18,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
sar    $0x10,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x1(%rax)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x2(%rax)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %cl,0x3(%rax)
jmp    1174 <d2bei_clip_array+0x64>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d2bei_clip_array>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
test   %ecx,%ecx
sete   %cl
test   %edx,%edx
jle    11e2 <d2bei_clip_array+0xd2>
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %cl,%al
lea    0xeca(%rip),%rcx
movsd  (%rcx,%rax,8),%xmm1
mov    %edx,%ebp
add    $0xffffffffffffffff,%rbp
movsd  0xec7(%rip),%xmm2
movsd  0xec7(%rip),%xmm3
movsd  %xmm1,0x8(%rsp)
jmp    1181 <d2bei_clip_array+0x71>
nopl   0x0(%rax)
movb   $0xff,0x3(%rbx,%rbp,4)
movw   $0xffff,0x1(%rbx,%rbp,4)
movb   $0x7f,(%rbx,%rbp,4)
lea    -0x1(%rbp),%rax
add    $0x1,%rbp
cmp    $0x1,%rbp
mov    %rax,%rbp
jbe    11e2 <d2bei_clip_array+0xd2>
mov    %ebp,%eax
movsd  (%r14,%rax,8),%xmm0
mulsd  %xmm1,%xmm0
ucomisd %xmm2,%xmm0
jae    1160 <d2bei_clip_array+0x50>
ucomisd %xmm0,%xmm3
jae    11d0 <d2bei_clip_array+0xc0>
call   1030 <lrint@plt>
movsd  0xe72(%rip),%xmm3
movsd  0xe62(%rip),%xmm2
movsd  0x8(%rsp),%xmm1
mov    %eax,%ecx
shr    $0x18,%ecx
mov    %cl,(%rbx,%rbp,4)
mov    %eax,%ecx
shr    $0x10,%ecx
mov    %cl,0x1(%rbx,%rbp,4)
mov    %ah,0x2(%rbx,%rbp,4)
mov    %al,0x3(%rbx,%rbp,4)
jmp    1170 <d2bei_clip_array+0x60>
nop
movb   $0x0,0x3(%rbx,%rbp,4)
movw   $0x0,0x1(%rbx,%rbp,4)
movb   $0x80,(%rbx,%rbp,4)
jmp    1170 <d2bei_clip_array+0x60>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @d2bei_clip_array(double* nocapture %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = icmp eq i32 %3, 0
%6 = select i1 %5, double 1.000000e+00, double 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 double, double* %0, i64 %18
%20 = load double, double* %19
%21 = fmul double %6, %20
%22 = fcmp ult double %21, 0x41DFFFFFFFC00000
br i1 %22, label %29, label %23
23: ; preds = %13
%24 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 -1, i8* %24
%25 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 -1, i8* %25
%26 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 -1, i8* %26
store i8 127, i8* %17
br label %27
27: ; preds = %23, %31, %35
%28 = icmp ugt i64 %14, 1
br i1 %28, label %13, label %47
29: ; preds = %13
%30 = fcmp ugt double %21, 0xC1E0000000000000
br i1 %30, label %35, label %31
31: ; preds = %29
%32 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 0, i8* %32
%33 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 0, i8* %33
%34 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 0, i8* %34
store i8 -128, i8* %17
br label %27
35: ; preds = %29
%36 = tail call i32 @lrint(double %21)
%37 = lshr i32 %36, 24
%38 = trunc i32 %37 to i8
store i8 %38, i8* %17
%39 = lshr i32 %36, 16
%40 = trunc i32 %39 to i8
%41 = getelementptr inbounds i8, i8* %15, i64 -3
store i8 %40, i8* %41
%42 = lshr i32 %36, 8
%43 = trunc i32 %42 to i8
%44 = getelementptr inbounds i8, i8* %15, i64 -2
store i8 %43, i8* %44
%45 = trunc i32 %36 to i8
%46 = getelementptr inbounds i8, i8* %15, i64 -1
store i8 %45, i8* %46
br label %27
47: ; preds = %27, %4
ret void
}