#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 */
typedef int int32_t;

/* Variables and functions */
int lrand48();
void fill_i32_array(int32_t *array, int max_range) {
  for (int i = 0; i < 1024; i++) {
    int32_t tmp;
    if (max_range > 0xFFFF) {
      tmp = lrand48();
    } else {
      tmp = lrand48() % 0x10000;
    }
    if (tmp == 0)
      tmp++;
    array[i] = tmp;
  }
}


x86 assembly (clang, -O0):
<fill_i32_array>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
cmpl   $0x400,-0x10(%rbp)
jge    1190 <fill_i32_array+0x80>
cmpl   $0xffff,-0xc(%rbp)
jle    114f <fill_i32_array+0x3f>
mov    $0x0,%al
call   1030 <lrand48@plt>
mov    %eax,-0x14(%rbp)
jmp    1161 <fill_i32_array+0x51>
mov    $0x0,%al
call   1030 <lrand48@plt>
mov    $0x10000,%ecx
cltd
idiv   %ecx
mov    %edx,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1174 <fill_i32_array+0x64>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <fill_i32_array+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_i32_array>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%rbx
mov    $0x1,%r14d
xor    %ebp,%ebp
jmp    1146 <fill_i32_array+0x36>
nopw   0x0(%rax,%rax,1)
test   %eax,%eax
cmove  %r14d,%eax
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x400,%rbp
je     116b <fill_i32_array+0x5b>
xor    %eax,%eax
call   1030 <lrand48@plt>
cmp    $0xffff,%r15d
jg     1130 <fill_i32_array+0x20>
lea    0xffff(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xffff0000,%ecx
sub    %ecx,%eax
jmp    1130 <fill_i32_array+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @fill_i32_array(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %30, %2
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1024
br i1 %9, label %10, label %33
10: ; preds = %7
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 65535
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = call i32 (...) @lrand48()
store i32 %14, i32* %6
br label %18
15: ; preds = %10
%16 = call i32 (...) @lrand48()
%17 = srem i32 %16, 65536
store i32 %17, i32* %6
br label %18
18: ; preds = %15, %13
%19 = load i32, i32* %6
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i32, i32* %6
%23 = add nsw i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %21, %18
%25 = load i32, i32* %6
%26 = load i32*, i32** %3
%27 = load i32, i32* %5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %24
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %7
33: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @fill_i32_array(i32* nocapture writeonly %0, i32 %1) {
%3 = icmp sgt i32 %1, 65535
br label %5
4: ; preds = %5
ret void
5: ; preds = %2, %5
%6 = phi i64 [ 0, %2 ], [ %13, %5 ]
%7 = tail call i32 (...) @lrand48()
%8 = srem i32 %7, 65536
%9 = select i1 %3, i32 %7, i32 %8
%10 = icmp eq i32 %9, 0
%11 = select i1 %10, i32 1, i32 %9
%12 = getelementptr inbounds i32, i32* %0, i64 %6
store i32 %11, i32* %12
%13 = add nuw nsw i64 %6, 1
%14 = icmp eq i64 %13, 1024
br i1 %14, label %4, label %5
}