#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 rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/);
long alloc_intarr(int *arr, long sz, int mod) {
  int i = 0;
  srand(time(0));
  for (i = 0; i < sz; i++) {
    if (mod)
      arr[i] = rand() % mod;
    else
      arr[i] = rand();
  }
  return sz;
}


x86 assembly (clang, -O0):
<alloc_intarr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
movl   $0x0,-0x18(%rbp)
movslq -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    11b9 <alloc_intarr+0x89>
cmpl   $0x0,-0x14(%rbp)
je     1192 <alloc_intarr+0x62>
mov    $0x0,%al
call   1050 <rand@plt>
cltd
idivl  -0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11a6 <alloc_intarr+0x76>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11ab <alloc_intarr+0x7b>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <alloc_intarr+0x2f>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alloc_intarr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%r14
xor    %edi,%edi
call   1040 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
test   %r15,%r15
jle    117f <alloc_intarr+0x4f>
xor    %ebx,%ebx
jmp    116d <alloc_intarr+0x3d>
cs nopw 0x0(%rax,%rax,1)
mov    %eax,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r15
je     117f <alloc_intarr+0x4f>
xor    %eax,%eax
call   1050 <rand@plt>
test   %ebp,%ebp
je     1160 <alloc_intarr+0x30>
cltd
idiv   %ebp
mov    %edx,%eax
jmp    1160 <alloc_intarr+0x30>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i64 @alloc_intarr(i32* nocapture writeonly %0, i64 returned %1, i32 %2) {
%4 = tail call i32 @time(i32 0)
%5 = tail call i32 @srand(i32 %4)
%6 = icmp sgt i64 %1, 0
br i1 %6, label %7, label %19
7: ; preds = %3
%8 = icmp eq i32 %2, 0
br label %9
9: ; preds = %7, %14
%10 = phi i64 [ 0, %7 ], [ %17, %14 ]
%11 = tail call i32 (...) @rand()
br i1 %8, label %14, label %12
12: ; preds = %9
%13 = srem i32 %11, %2
br label %14
14: ; preds = %9, %12
%15 = phi i32 [ %13, %12 ], [ %11, %9 ]
%16 = getelementptr inbounds i32, i32* %0, i64 %10
store i32 %15, i32* %16
%17 = add nuw nsw i64 %10, 1
%18 = icmp eq i64 %17, %1
br i1 %18, label %19, label %9
19: ; preds = %14, %3
ret i64 %1
}