#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 atoi(char *);
int /*<<< orphan*/ getchar();
void *malloc(int);
int /*<<< orphan*/ memset(void *, int, int);
int main(int argc, char **argv) {
  if (argc < 2)
    return 1;
  int megs = atoi(argv[1]);
  if (megs <= 0)
    return 2;
  int i;
  for (i = 0; i < megs; i++) {
    void *data = malloc(1024 * 1024);
    memset(data, 1, 1024 * 1024);
  }
  getchar();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    116c <main+0x2c>
movl   $0x1,-0x4(%rbp)
jmp    11e2 <main+0xa2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1192 <main+0x52>
movl   $0x2,-0x4(%rbp)
jmp    11e2 <main+0xa2>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11d4 <main+0x94>
mov    $0x100000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
call   1030 <memset@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1199 <main+0x59>
mov    $0x0,%al
call   1040 <getchar@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x1,%ebx
cmp    $0x2,%edi
jl     1191 <main+0x51>
mov    0x8(%rsi),%rdi
call   1060 <atoi@plt>
test   %eax,%eax
jle    118c <main+0x4c>
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
mov    $0x100000,%edi
call   1050 <malloc@plt>
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x100000,%edx
call   1030 <memset@plt>
add    $0xffffffff,%ebx
jne    1160 <main+0x20>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
jmp    1191 <main+0x51>
mov    $0x2,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
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*
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 %12
11: ; preds = %2
store i32 1, i32* %3
br label %34
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @atoi(i8* %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp sle i32 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %12
store i32 2, i32* %3
br label %34
20: ; preds = %12
store i32 0, i32* %7
br label %21
21: ; preds = %29, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %6
%24 = icmp slt i32 %22, %23
br i1 %24, label %25, label %32
25: ; preds = %21
%26 = call i8* @malloc(i32 1048576)
store i8* %26, i8** %8
%27 = load i8*, i8** %8
%28 = call i32 @memset(i8* %27, i32 1, i32 1048576)
br label %29
29: ; preds = %25
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %21
32: ; preds = %21
%33 = call i32 (...) @getchar()
store i32 0, i32* %3
br label %34
34: ; preds = %32, %19, %11
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = icmp slt i32 %7, 1
br i1 %8, label %17, label %9
9: ; preds = %4, %9
%10 = phi i32 [ %13, %9 ], [ 0, %4 ]
%11 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%12 = tail call i32 @memset(i8* %11, i32 1, i32 1048576)
%13 = add nuw nsw i32 %10, 1
%14 = icmp eq i32 %13, %7
br i1 %14, label %15, label %9
15: ; preds = %9
%16 = tail call i32 (...) @getchar()
br label %17
17: ; preds = %15, %4, %2
%18 = phi i32 [ 1, %2 ], [ 0, %15 ], [ 2, %4 ]
ret i32 %18
}