#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ perfPoll(int /*<<< orphan*/);
scalar_t__ rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
void main() {
  srand(0);
  int *array = (int *)malloc(sizeof(int) * 1024 * 1024);
  int i, o;
  perfPoll(0);
  for (o = 0; o < 5000; o++) {
    for (i = 0; i < 1024 * 1024; i++) {
      array[i] = (int)rand();
    }
  }
  perfPoll(0);
  for (;;) {
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
xor    %edi,%edi
call   1030 <srand@plt>
mov    $0x400000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
xor    %edi,%edi
call   1040 <perfPoll@plt>
movl   $0x0,-0x10(%rbp)
cmpl   $0x1388,-0x10(%rbp)
jge    11c1 <main+0x81>
movl   $0x0,-0xc(%rbp)
cmpl   $0x100000,-0xc(%rbp)
jge    11ae <main+0x6e>
mov    $0x0,%al
call   1060 <rand@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117f <main+0x3f>
jmp    11b3 <main+0x73>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <main+0x2b>
xor    %edi,%edi
call   1040 <perfPoll@plt>
jmp    11c8 <main+0x88>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %edi,%edi
call   1030 <srand@plt>
mov    $0x400000,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
call   1040 <perfPoll@plt>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %eax,%eax
call   1060 <rand@plt>
mov    %eax,(%rbx,%rbp,4)
add    $0x1,%rbp
cmp    $0x100000,%rbp
jne    1180 <main+0x40>
add    $0x1,%r14d
cmp    $0x1388,%r14d
jne    1170 <main+0x30>
xor    %edi,%edi
call   1040 <perfPoll@plt>
nopl   0x0(%rax,%rax,1)
jmp    11b0 <main+0x70>

LLVM IR (-O0):
define void @main() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32 @srand(i32 0)
%5 = call i64 @malloc(i32 4194304)
%6 = inttoptr i64 %5 to i32*
store i32* %6, i32** %1
%7 = call i32 @perfPoll(i32 0)
store i32 0, i32* %3
br label %8
8: ; preds = %26, %0
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 5000
br i1 %10, label %11, label %29
11: ; preds = %8
store i32 0, i32* %2
br label %12
12: ; preds = %22, %11
%13 = load i32, i32* %2
%14 = icmp slt i32 %13, 1048576
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = call i64 (...) @rand()
%17 = trunc i64 %16 to i32
%18 = load i32*, i32** %1
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %18, i64 %20
store i32 %17, i32* %21
br label %22
22: ; preds = %15
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %12
25: ; preds = %12
br label %26
26: ; preds = %25
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %8
29: ; preds = %8
%30 = call i32 @perfPoll(i32 0)
br label %31
31: ; preds = %31, %29
br label %31
}

LLVM IR (-O2):
define void @main() {
%1 = tail call i32 @srand(i32 0)
%2 = tail call i64 @malloc(i32 4194304)
%3 = inttoptr i64 %2 to i32*
%4 = tail call i32 @perfPoll(i32 0)
br label %5
5: ; preds = %0, %14
%6 = phi i32 [ 0, %0 ], [ %15, %14 ]
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %12, %7 ]
%9 = tail call i64 (...) @rand()
%10 = trunc i64 %9 to i32
%11 = getelementptr inbounds i32, i32* %3, i64 %8
store i32 %10, i32* %11
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, 1048576
br i1 %13, label %14, label %7
14: ; preds = %7
%15 = add nuw nsw i32 %6, 1
%16 = icmp eq i32 %15, 5000
br i1 %16, label %17, label %5
17: ; preds = %14
%18 = tail call i32 @perfPoll(i32 0)
br label %19
19: ; preds = %19, %17
br label %19
}