#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 */
unsigned int *malloc(int);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ usleep(int);
int main(int argc, char **argv) {
  int max = -1;
  int mb = 0;
  char *buffer;
  int i;
  unsigned int *p = malloc(1024 * 1024 * 2000);
  printf("malloc buffer: %p\n", p);
  for (i = 0; i < 1024 * 1024 * (2000 / sizeof(int)); i++) {
    p[i] = 123;
    if ((i & 0xFFFFF) == 0) {
      printf("%dMB written\n", i >> 18);
      usleep(100000);
    }
  }
  pause();
  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   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    $0x7d000000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rsi
lea    0xe83(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
movslq -0x24(%rbp),%rax
cmp    $0x1f400000,%rax
jae    11ec <main+0xac>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
movl   $0x7b,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
and    $0xfffff,%eax
cmp    $0x0,%eax
jne    11d9 <main+0x99>
mov    -0x24(%rbp),%esi
sar    $0x12,%esi
lea    0xe4b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
jmp    11de <main+0x9e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    118b <main+0x4b>
mov    $0x0,%al
call   1040 <pause@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x7d000000,%edi
call   1050 <malloc@plt>
mov    %rax,%r15
lea    0xea7(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xea9(%rip),%r14
xor    %ebx,%ebx
jmp    117d <main+0x3d>
xchg   %ax,%ax
add    $0x1,%rbx
cmp    $0x1f400000,%rbx
je     11a8 <main+0x68>
movl   $0x7b,(%r15,%rbx,4)
test   $0xfffff,%ebx
jne    1170 <main+0x30>
mov    %ebx,%esi
shr    $0x12,%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
jmp    1170 <main+0x30>
xor    %eax,%eax
call   1040 <pause@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [19 x i8] c"malloc buffer: %p\0A\00"
@.str.1 = [14 x i8] c"%dMB written\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32*
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 = call i32* @malloc(i32 2097152000)
store i32* %11, i32** %10
%12 = load i32*, i32** %10
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %12)
store i32 0, i32* %9
br label %14
14: ; preds = %32, %2
%15 = load i32, i32* %9
%16 = sext i32 %15 to i64
%17 = icmp ult i64 %16, 524288000
br i1 %17, label %18, label %35
18: ; preds = %14
%19 = load i32*, i32** %10
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
store i32 123, i32* %22
%23 = load i32, i32* %9
%24 = and i32 %23, 1048575
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %31
26: ; preds = %18
%27 = load i32, i32* %9
%28 = ashr i32 %27, 18
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 @usleep(i32 100000)
br label %31
31: ; preds = %26, %18
br label %32
32: ; preds = %31
%33 = load i32, i32* %9
%34 = add nsw i32 %33, 1
store i32 %34, i32* %9
br label %14
35: ; preds = %14
%36 = call i32 (...) @pause()
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"malloc buffer: %p\0A\00"
@.str.1 = [14 x i8] c"%dMB written\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32* @malloc(i32 2097152000)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %5
5: ; preds = %2, %15
%6 = phi i64 [ 0, %2 ], [ %16, %15 ]
%7 = getelementptr inbounds i32, i32* %3, i64 %6
store i32 123, i32* %7
%8 = trunc i64 %6 to i32
%9 = and i32 %8, 1048575
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %15
11: ; preds = %5
%12 = lshr i32 %8, 18
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %12)
%14 = tail call i32 @usleep(i32 100000)
br label %15
15: ; preds = %5, %11
%16 = add nuw nsw i64 %6, 1
%17 = icmp eq i64 %16, 524288000
br i1 %17, label %18, label %5
18: ; preds = %15
%19 = tail call i32 (...) @pause()
ret i32 0
}