#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 *malloc(int);
int rand();
int *arrGen(int size) {
  if (size <= 0) {
    return NULL;
  }
  int *arr = malloc(sizeof(int) * size);
  if (arr == NULL) {
    return NULL;
  }
  int ind;
  for (ind = 0; ind < size; ind++) {
    arr[ind] = rand() % 10000;
  }
  return arr;
}


x86 assembly (clang, -O0):
<arrGen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jg     1142 <arrGen+0x22>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <arrGen+0x90>
movslq -0xc(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    116d <arrGen+0x4d>
movq   $0x0,-0x8(%rbp)
jmp    11b0 <arrGen+0x90>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a8 <arrGen+0x88>
mov    $0x0,%al
call   1040 <rand@plt>
mov    $0x2710,%ecx
cltd
idiv   %ecx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1174 <arrGen+0x54>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<arrGen>:
push   %r15
push   %r14
push   %rbx
test   %edi,%edi
jle    1184 <arrGen+0x64>
mov    %edi,%r14d
lea    0x0(,%r14,4),%edi
call   1030 <malloc@plt>
test   %rax,%rax
je     1184 <arrGen+0x64>
mov    %rax,%r15
mov    %r14d,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <rand@plt>
cltq
imul   $0x68db8bad,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2710,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%r15,%rbx,4)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1150 <arrGen+0x30>
jmp    1187 <arrGen+0x67>
xor    %r15d,%r15d
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32* @arrGen(i32 %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32
store i32 %0, i32* %3
%6 = load i32, i32* %3
%7 = icmp sle i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
store i32* null, i32** %2
br label %35
9: ; preds = %1
%10 = load i32, i32* %3
%11 = sext i32 %10 to i64
%12 = mul i64 4, %11
%13 = trunc i64 %12 to i32
%14 = call i32* @malloc(i32 %13)
store i32* %14, i32** %4
%15 = load i32*, i32** %4
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %18
17: ; preds = %9
store i32* null, i32** %2
br label %35
18: ; preds = %9
store i32 0, i32* %5
br label %19
19: ; preds = %30, %18
%20 = load i32, i32* %5
%21 = load i32, i32* %3
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = call i32 (...) @rand()
%25 = srem i32 %24, 10000
%26 = load i32*, i32** %4
%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 = %23
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %19
33: ; preds = %19
%34 = load i32*, i32** %4
store i32* %34, i32** %2
br label %35
35: ; preds = %33, %17, %8
%36 = load i32*, i32** %2
ret i32* %36
}

LLVM IR (-O2):
define noalias i32* @arrGen(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %16, label %3
3: ; preds = %1
%4 = shl i32 %0, 2
%5 = tail call i32* @malloc(i32 %4)
%6 = icmp eq i32* %5, null
br i1 %6, label %16, label %7
7: ; preds = %3
%8 = zext i32 %0 to i64
br label %9
9: ; preds = %7, %9
%10 = phi i64 [ 0, %7 ], [ %14, %9 ]
%11 = tail call i32 (...) @rand()
%12 = srem i32 %11, 10000
%13 = getelementptr inbounds i32, i32* %5, i64 %10
store i32 %12, i32* %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, %8
br i1 %15, label %16, label %9
16: ; preds = %9, %3, %1
%17 = phi i32* [ null, %1 ], [ null, %3 ], [ %5, %9 ]
ret i32* %17
}