#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 /*<<< orphan*/ assert(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int rand();
int main() {
  int *ar = (int *)malloc(sizeof(int) * (65 * 1024 * 1024 / sizeof(int)));
  int i;
  if (!ar) {
    perror("woo, failed");
    assert(0);
    return 0;
  }
  for (i = 1; i < (65 * 1024 * 1024 / sizeof(int)); i++)
    ar[i] = (rand() % 2) + ar[rand() % (65 * 1024 * 1024 / sizeof(int))] +
            ar[i - 1];
  printf("OK %d\n", ar[(65 * 1024 * 1024 / sizeof(int)) / 2]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x4100000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1197 <main+0x47>
lea    0xe81(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1040 <assert@plt>
movl   $0x0,-0x4(%rbp)
jmp    122e <main+0xde>
movl   $0x1,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    $0x1040000,%rax
jae    1211 <main+0xc1>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %edx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1070 <rand@plt>
cltq
mov    $0x1040000,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x20(%rbp),%rax
mov    %rdx,%rcx
mov    -0x18(%rbp),%edx
add    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
add    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    119e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    0x2080000(%rax),%esi
lea    0xdea(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0x4100000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     11eb <main+0x9b>
mov    %rax,%r14
mov    $0x1,%ebx
movabs $0xfc0fc0fc0fc0fc1,%r15
fc c0 0f
nopl   0x0(%rax)
xor    %eax,%eax
call   1070 <rand@plt>
mov    %eax,%ebp
shr    $0x1f,%eax
add    %ebp,%eax
and    $0xfffffffe,%eax
sub    %eax,%ebp
xor    %eax,%eax
call   1070 <rand@plt>
movslq %eax,%rcx
mov    %rcx,%rax
mul    %r15
shr    $0x14,%rdx
imul   $0x1040000,%rdx,%rax
sub    %rax,%rcx
add    (%r14,%rcx,4),%ebp
add    -0x4(%r14,%rbx,4),%ebp
mov    %ebp,(%r14,%rbx,4)
add    $0x1,%rbx
cmp    $0x1040000,%rbx
jne    1180 <main+0x30>
mov    0x2080000(%r14),%esi
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0e(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1040 <assert@plt>
jmp    11de <main+0x8e>

LLVM IR (-O0):
@.str = [12 x i8] c"woo, failed\00"
@.str.1 = [7 x i8] c"OK %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i64 @malloc(i32 68157440)
%5 = inttoptr i64 %4 to i32*
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @assert(i32 0)
store i32 0, i32* %1
br label %45
11: ; preds = %0
store i32 1, i32* %3
br label %12
12: ; preds = %37, %11
%13 = load i32, i32* %3
%14 = sext i32 %13 to i64
%15 = icmp ult i64 %14, 17039360
br i1 %15, label %16, label %40
16: ; preds = %12
%17 = call i32 (...) @rand()
%18 = srem i32 %17, 2
%19 = load i32*, i32** %2
%20 = call i32 (...) @rand()
%21 = sext i32 %20 to i64
%22 = urem i64 %21, 17039360
%23 = getelementptr inbounds i32, i32* %19, i64 %22
%24 = load i32, i32* %23
%25 = add nsw i32 %18, %24
%26 = load i32*, i32** %2
%27 = load i32, i32* %3
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
%31 = load i32, i32* %30
%32 = add nsw i32 %25, %31
%33 = load i32*, i32** %2
%34 = load i32, i32* %3
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i32, i32* %33, i64 %35
store i32 %32, i32* %36
br label %37
37: ; preds = %16
%38 = load i32, i32* %3
%39 = add nsw i32 %38, 1
store i32 %39, i32* %3
br label %12
40: ; preds = %12
%41 = load i32*, i32** %2
%42 = getelementptr inbounds i32, i32* %41, i64 8519680
%43 = load i32, i32* %42
%44 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %43)
store i32 0, i32* %1
br label %45
45: ; preds = %40, %8
%46 = load i32, i32* %1
ret i32 %46
}

LLVM IR (-O2):
@.str = [12 x i8] c"woo, failed\00"
@.str.1 = [7 x i8] c"OK %d\0A\00"
define i32 @main() {
%1 = tail call i64 @malloc(i32 68157440)
%2 = inttoptr i64 %1 to i32*
%3 = icmp eq i64 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @assert(i32 0)
br label %28
7: ; preds = %0, %7
%8 = phi i64 [ %22, %7 ], [ 1, %0 ]
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 2
%11 = tail call i32 (...) @rand()
%12 = sext i32 %11 to i64
%13 = urem i64 %12, 17039360
%14 = getelementptr inbounds i32, i32* %2, i64 %13
%15 = load i32, i32* %14
%16 = add nsw i32 %15, %10
%17 = add nsw i64 %8, -1
%18 = getelementptr inbounds i32, i32* %2, i64 %17
%19 = load i32, i32* %18
%20 = add nsw i32 %16, %19
%21 = getelementptr inbounds i32, i32* %2, i64 %8
store i32 %20, i32* %21
%22 = add nuw nsw i64 %8, 1
%23 = icmp eq i64 %22, 17039360
br i1 %23, label %24, label %7
24: ; preds = %7
%25 = getelementptr inbounds i32, i32* %2, i64 8519680
%26 = load i32, i32* %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %26)
br label %28
28: ; preds = %24, %4
ret i32 0
}