#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*/ bzero(char *, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, unsigned long);
int rand();
int main(int argc, char *argv[]) {
  char *mem = (char *)malloc(1024 * 1024 * 1024);
  bzero(mem, 1024 * 1024 * 1024);
  char tinybyte;
  unsigned long addr = 0;
  printf("long: %lu\n", addr - 1);
  int i;
  for (i = 0; i < 1024 * 1024 * 1024; ++i) {
    addr = rand() % 1024 * 1024 * 1024;
    tinybyte = mem[i];
  }
  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)
mov    $0x40000000,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x40000000,%esi
call   1050 <bzero@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
sub    $0x1,%rsi
lea    0xe77(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x40000000,-0x2c(%rbp)
jge    11db <main+0x9b>
mov    $0x0,%al
call   1060 <rand@plt>
mov    $0x400,%ecx
cltd
idiv   %ecx
mov    %edx,%eax
shl    $0xa,%eax
shl    $0xa,%eax
cltq
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x19(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1195 <main+0x55>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x40000000,%ebx
mov    $0x40000000,%edi
call   1040 <malloc@plt>
mov    %rax,%rdi
mov    $0x40000000,%esi
call   1050 <bzero@plt>
lea    0xe9c(%rip),%rdi
mov    $0xffffffffffffffff,%rsi
call   1030 <printf@plt>
xor    %eax,%eax
call   1060 <rand@plt>
add    $0xffffffff,%ebx
jne    1170 <main+0x30>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"long: %lu\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8
%8 = alloca i64
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = call i64 @malloc(i32 1073741824)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @bzero(i8* %12, i32 1073741824)
store i64 0, i64* %8
%14 = load i64, i64* %8
%15 = sub i64 %14, 1
%16 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 %15)
store i32 0, i32* %9
br label %17
17: ; preds = %31, %2
%18 = load i32, i32* %9
%19 = icmp slt i32 %18, 1073741824
br i1 %19, label %20, label %34
20: ; preds = %17
%21 = call i32 (...) @rand()
%22 = srem i32 %21, 1024
%23 = mul nsw i32 %22, 1024
%24 = mul nsw i32 %23, 1024
%25 = sext i32 %24 to i64
store i64 %25, i64* %8
%26 = load i8*, i8** %6
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
store i8 %30, i8* %7
br label %31
31: ; preds = %20
%32 = load i32, i32* %9
%33 = add nsw i32 %32, 1
store i32 %33, i32* %9
br label %17
34: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"long: %lu\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 1073741824)
%4 = inttoptr i64 %3 to i8*
%5 = tail call i32 @bzero(i8* %4, i32 1073741824)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i64 -1)
br label %7
7: ; preds = %2, %7
%8 = phi i32 [ 0, %2 ], [ %10, %7 ]
%9 = tail call i32 (...) @rand()
%10 = add nuw nsw i32 %8, 1
%11 = icmp eq i32 %10, 1073741824
br i1 %11, label %12, label %7
12: ; preds = %7
ret i32 0
}