#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 uint;

/* Variables and functions */
int atoi(char *);
int *calloc(size_t, int);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ pause();
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  uint MB_to_allocate = 1;
  bool add_randomness = false;
  if (argc >= 2)
    MB_to_allocate = atoi(argv[1]);
  if (argc >= 3)
    add_randomness = atoi(argv[2]);
  if (argc >= 4)
    return 1;
  size_t array_size = MB_to_allocate * 1024 * 1024 / sizeof(int);
  int *array = calloc(array_size, sizeof(int));
  if (add_randomness) {
    srand(time(NULL));
    for (size_t i = 0; i < array_size / 2; i++) {
      array[i] = rand();
    }
  }
  pause();
  free(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     11ae <main+0x3e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11c8 <main+0x58>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x4,-0x8(%rbp)
jl     11de <main+0x6e>
movl   $0x1,-0x4(%rbp)
jmp    127b <main+0x10b>
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
cltq
shr    $0x2,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,-0x28(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1264 <main+0xf4>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x20(%rbp),%rcx
shr    $0x1,%rcx
cmp    %rcx,%rax
jae    125f <main+0xef>
mov    $0x0,%al
call   1090 <rand@plt>
mov    %eax,%edx
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1225 <main+0xb5>
jmp    1264 <main+0xf4>
mov    $0x0,%al
call   1070 <pause@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    $0x40000,%ebx
cmp    $0x2,%edi
jl     11a9 <main+0x39>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x8(%rsi),%rdi
call   1080 <atoi@plt>
mov    %eax,%r14d
shl    $0x14,%r14d
movslq %r14d,%r13
mov    %r13,%rbx
shr    $0x2,%rbx
cmp    $0x2,%ebp
jne    11dd <main+0x6d>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
xor    %r12d,%r12d
xor    %eax,%eax
call   1070 <pause@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%r12d
cmp    $0x3,%ebp
ja     11cb <main+0x5b>
mov    0x10(%r15),%rdi
call   1080 <atoi@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x4,%esi
call   1050 <calloc@plt>
mov    %rax,%rbx
test   %ebp,%ebp
je     11b9 <main+0x49>
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1040 <srand@plt>
test   %r14d,%r14d
je     11b9 <main+0x49>
shr    $0x3,%r13
cmp    $0x2,%r13
mov    $0x1,%r14d
cmovae %r13,%r14
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1090 <rand@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    %rbp,%r14
jne    1230 <main+0xc0>
jmp    11b9 <main+0x49>

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
%9 = alloca i32*
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
store i32 0, i32* %7
%11 = load i32, i32* %4
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %18
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @atoi(i8* %16)
store i32 %17, i32* %6
br label %18
18: ; preds = %13, %2
%19 = load i32, i32* %4
%20 = icmp sge i32 %19, 3
br i1 %20, label %21, label %26
21: ; preds = %18
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 2
%24 = load i8*, i8** %23
%25 = call i32 @atoi(i8* %24)
store i32 %25, i32* %7
br label %26
26: ; preds = %21, %18
%27 = load i32, i32* %4
%28 = icmp sge i32 %27, 4
br i1 %28, label %29, label %30
29: ; preds = %26
store i32 1, i32* %3
br label %61
30: ; preds = %26
%31 = load i32, i32* %6
%32 = mul nsw i32 %31, 1024
%33 = mul nsw i32 %32, 1024
%34 = sext i32 %33 to i64
%35 = udiv i64 %34, 4
store i64 %35, i64* %8
%36 = load i64, i64* %8
%37 = call i32* @calloc(i64 %36, i32 4)
store i32* %37, i32** %9
%38 = load i32, i32* %7
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %57
40: ; preds = %30
%41 = call i32 @time(i32* null)
%42 = call i32 @srand(i32 %41)
store i64 0, i64* %10
br label %43
43: ; preds = %53, %40
%44 = load i64, i64* %10
%45 = load i64, i64* %8
%46 = udiv i64 %45, 2
%47 = icmp ult i64 %44, %46
br i1 %47, label %48, label %56
48: ; preds = %43
%49 = call i32 (...) @rand()
%50 = load i32*, i32** %9
%51 = load i64, i64* %10
%52 = getelementptr inbounds i32, i32* %50, i64 %51
store i32 %49, i32* %52
br label %53
53: ; preds = %48
%54 = load i64, i64* %10
%55 = add i64 %54, 1
store i64 %55, i64* %10
br label %43
56: ; preds = %43
br label %57
57: ; preds = %56, %30
%58 = call i32 (...) @pause()
%59 = load i32*, i32** %9
%60 = call i32 @free(i32* %59)
store i32 0, i32* %3
br label %61
61: ; preds = %57, %29
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = shl i32 %7, 20
%9 = sext i32 %8 to i64
%10 = lshr exact i64 %9, 2
%11 = icmp eq i32 %0, 2
br i1 %11, label %12, label %15
12: ; preds = %2, %4
%13 = phi i64 [ %10, %4 ], [ 262144, %2 ]
%14 = tail call i32* @calloc(i64 %13, i32 4)
br label %36
15: ; preds = %4
%16 = icmp ugt i32 %0, 3
br i1 %16, label %40, label %17
17: ; preds = %15
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = tail call i32 @atoi(i8* %19)
%21 = tail call i32* @calloc(i64 %10, i32 4)
%22 = icmp eq i32 %20, 0
br i1 %22, label %36, label %23
23: ; preds = %17
%24 = tail call i32 @time(i32* null)
%25 = tail call i32 @srand(i32 %24)
%26 = icmp eq i32 %8, 0
br i1 %26, label %36, label %27
27: ; preds = %23
%28 = lshr exact i64 %9, 3
%29 = call i64 @llvm.umax.i64(i64 %28, i64 1)
br label %30
30: ; preds = %27, %30
%31 = phi i64 [ %34, %30 ], [ 0, %27 ]
%32 = tail call i32 (...) @rand()
%33 = getelementptr inbounds i32, i32* %21, i64 %31
store i32 %32, i32* %33
%34 = add nuw nsw i64 %31, 1
%35 = icmp eq i64 %34, %29
br i1 %35, label %36, label %30
36: ; preds = %30, %23, %12, %17
%37 = phi i32* [ %14, %12 ], [ %21, %17 ], [ %21, %23 ], [ %21, %30 ]
%38 = tail call i32 (...) @pause()
%39 = tail call i32 @free(i32* %37)
br label %40
40: ; preds = %15, %36
%41 = phi i32 [ 0, %36 ], [ 1, %15 ]
ret i32 %41
}