#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;
size_t atol(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
void *malloc(size_t);
int /*<<< orphan*/ memset(void *, int, size_t);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  size_t len = 1 * 1024 * 1024 * 1024;
  if (argc == 2)
    len = atol(argv[1]);
  printf("Allocating %ld bytes ...", len);
  void *buff = malloc(len);
  if (buff == NULL) {
    printf("\nFailed to malloc.\n");
    exit(EXIT_FAILURE);
  }
  memset(buff, 1, len);
  printf("done\n");
  fflush(stdout);
  printf("Sleeping to hold memory...\n");
  sleep(2147483648);
}


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)
movq   $0x40000000,-0x18(%rbp)
40
cmpl   $0x2,-0x8(%rbp)
jne    11a9 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1070 <atol@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rsi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ef <main+0x7f>
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1,%esi
call   1040 <memset@plt>
lea    0xe25(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x80000000,%edi
call   1090 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    $0x40000000,%ebx
cmp    $0x2,%edi
jne    1197 <main+0x17>
mov    0x8(%rsi),%rdi
call   1080 <atol@plt>
mov    %rax,%rbx
lea    0xe62(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <malloc@plt>
test   %rax,%rax
je     11f9 <main+0x79>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   1050 <memset@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
lea    0xe38(%rip),%rdi
call   1030 <puts@plt>
mov    $0x80000000,%edi
call   10a0 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe39(%rip),%rdi
call   1030 <puts@plt>
mov    0x2dd4(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [25 x i8] c"Allocating %ld bytes ...\00"
@.str.1 = [20 x i8] c"\0AFailed to malloc.\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"done\0A\00"
@stdout = global i32 0
@.str.3 = [28 x i8] c"Sleeping to hold memory...\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1073741824, i64* %6
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @atol(i8* %13)
store i64 %14, i64* %6
br label %15
15: ; preds = %10, %2
%16 = load i64, i64* %6
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %16)
%18 = load i64, i64* %6
%19 = call i8* @malloc(i64 %18)
store i8* %19, i8** %7
%20 = load i8*, i8** %7
%21 = icmp eq i8* %20, null
br i1 %21, label %22, label %26
22: ; preds = %15
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %15
%27 = load i8*, i8** %7
%28 = load i64, i64* %6
%29 = call i32 @memset(i8* %27, i32 1, i64 %28)
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @stdout
%32 = call i32 @fflush(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @sleep(i32 -2147483648)
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@.str = [25 x i8] c"Allocating %ld bytes ...\00"
@EXIT_FAILURE = global i32 0
@stdout = global i32 0
@str = [5 x i8] c"done\00"
@str.4 = [27 x i8] c"Sleeping to hold memory...\00"
@str.5 = [19 x i8] c"\0AFailed to malloc.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @atol(i8* %6)
br label %8
8: ; preds = %4, %2
%9 = phi i64 [ %7, %4 ], [ 1073741824, %2 ]
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %9)
%11 = tail call i8* @malloc(i64 %9)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %17
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.5, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %8
%18 = tail call i32 @memset(i8* %11, i32 1, i64 %9)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @stdout
%21 = tail call i32 @fflush(i32 %20)
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.4, i64 0, i64 0))
%23 = tail call i32 @sleep(i32 -2147483648)
ret i32 0
}