#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(int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ sprintf(char *, char *);
int main() {
  char *some_memory;
  size_t size_to_allocate = (1024 * 1024);
  int megs_obtained = 0;
  while (megs_obtained < (1024 * 100 * 2)) {
    some_memory = (char *)malloc(size_to_allocate);
    if (some_memory != NULL) {
      megs_obtained++;
      sprintf(some_memory, "Hello World");
      printf("%s - now allocated %d Megabytes\n", some_memory, megs_obtained);
    } else {
      exit(EXIT_FAILURE);
    }
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x100000,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x32000,-0x1c(%rbp)
jge    11c7 <main+0x87>
mov    -0x18(%rbp),%rdi
call   1040 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b4 <main+0x74>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe69(%rip),%rsi
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe62(%rip),%rdi
call   1030 <printf@plt>
jmp    11c2 <main+0x82>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    115e <main+0x1e>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x1,%ebx
movabs $0x6f57206f6c6c6548,%r15
20 57 6f
lea    0xec1(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    $0x100000,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     1181 <main+0x51>
mov    %r15,(%rax)
movl   $0x646c72,0x8(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x32001,%ebx
jne    1150 <main+0x20>
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"Hello World\00"
@.str.1 = [33 x i8] c"%s - now allocated %d Megabytes\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i32
store i32 0, i32* %1
store i64 1048576, i64* %3
store i32 0, i32* %4
br label %5
5: ; preds = %25, %0
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 204800
br i1 %7, label %8, label %26
8: ; preds = %5
%9 = load i64, i64* %3
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
%17 = load i8*, i8** %2
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %2
%20 = load i32, i32* %4
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %20)
br label %25
22: ; preds = %8
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %14
br label %5
26: ; preds = %5
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"Hello World\00"
@.str.1 = [33 x i8] c"%s - now allocated %d Megabytes\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @main() {
br label %1
1: ; preds = %0, %6
%2 = phi i32 [ 0, %0 ], [ %7, %6 ]
%3 = tail call i64 @malloc(i64 1048576)
%4 = inttoptr i64 %3 to i8*
%5 = icmp eq i64 %3, 0
br i1 %5, label %10, label %6
6: ; preds = %1
%7 = add nuw nsw i32 %2, 1
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(12) %4, i8* align 1 dereferenceable(12) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i64 12, i1 false)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %4, i32 %7)
%9 = icmp eq i32 %7, 204800
br i1 %9, label %13, label %1
10: ; preds = %1
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %6
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
}