#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int j;
  char *c;
  if (argc < 2) {
    fprintf(stderr, "You must give the memory in MB to waste, aborting\n");
    exit(EXIT_FAILURE);
  }
  int m = atoi(argv[1]);
  for (j = 0; j < m; j++) {
    c = malloc((1024 * 1024));
    memset(c, j, (1024 * 1024));
    printf("%5d", j);
    fflush(stdout);
  }
  printf("All memory allocated, pausing 5 seconds\n");
  sleep(5);
  printf("Quitting and releasing memory\n");
  exit(EXIT_SUCCESS);
}


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)
cmpl   $0x2,-0x8(%rbp)
jge    11c3 <main+0x43>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1232 <main+0xb2>
mov    $0x100000,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    $0x100000,%edx
call   1040 <memset@plt>
mov    -0x14(%rbp),%esi
lea    0xe24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11da <main+0x5a>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x5,%edi
call   10a0 <sleep@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     11bf <main+0x2f>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x8(%rsi),%rdi
call   1090 <atoi@plt>
test   %eax,%eax
jle    1214 <main+0x84>
mov    %eax,%ebx
lea    0xe5e(%rip),%r14
mov    0x2df4(%rip),%r15
xor    %ebp,%ebp
xchg   %ax,%ax
mov    $0x100000,%edi
call   1070 <malloc@plt>
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x100000,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    (%r15),%edi
call   1080 <fflush@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    11e0 <main+0x50>
lea    0xe1c(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   10b0 <sleep@plt>
lea    0xe2e(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [51 x i8] c"You must give the memory in MB to waste, aborting\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%5d\00"
@stdout = global i32 0
@.str.2 = [41 x i8] c"All memory allocated, pausing 5 seconds\0A\00"
@.str.3 = [31 x i8] c"Quitting and releasing memory\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %8
store i32 0, i32* %6
br label %21
21: ; preds = %34, %16
%22 = load i32, i32* %6
%23 = load i32, i32* %8
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %37
25: ; preds = %21
%26 = call i8* @malloc(i32 1048576)
store i8* %26, i8** %7
%27 = load i8*, i8** %7
%28 = load i32, i32* %6
%29 = call i32 @memset(i8* %27, i32 %28, i32 1048576)
%30 = load i32, i32* %6
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = load i32, i32* @stdout
%33 = call i32 @fflush(i32 %32)
br label %34
34: ; preds = %25
%35 = load i32, i32* %6
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
br label %21
37: ; preds = %21
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @sleep(i32 5)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%41 = load i32, i32* @EXIT_SUCCESS
%42 = call i32 @exit(i32 %41)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [51 x i8] c"You must give the memory in MB to waste, aborting\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [4 x i8] c"%5d\00"
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [40 x i8] c"All memory allocated, pausing 5 seconds\00"
@str.4 = [30 x i8] c"Quitting and releasing memory\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call i32 @atoi(i8* %11)
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %9, %14
%15 = phi i32 [ %21, %14 ], [ 0, %9 ]
%16 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%17 = tail call i32 @memset(i8* %16, i32 %15, i32 1048576)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%19 = load i32, i32* @stdout
%20 = tail call i32 @fflush(i32 %19)
%21 = add nuw nsw i32 %15, 1
%22 = icmp eq i32 %21, %12
br i1 %22, label %23, label %14
23: ; preds = %14, %9
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
%25 = tail call i32 @sleep(i32 5)
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.4, i64 0, i64 0))
%27 = load i32, i32* @EXIT_SUCCESS
%28 = tail call i32 @exit(i32 %27)
unreachable
}