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


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   $0x800,-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    0xe63(%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    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x1,%ebx
movabs $0x646c726f57202c,%r15
movabs $0x57202c6f6c6c6548,%r12
2c 20 57
lea    0xeb5(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    $0x100000,%edi
call   1040 <malloc@plt>
test   %rax,%rax
je     119c <main+0x6c>
mov    %r15,0x5(%rax)
mov    %r12,(%rax)
mov    %r14,%rdi
mov    %rax,%rsi
mov    %ebx,%edx
call   1030 <printf@plt>
add    $0x1,%ebx
cmp    $0x801,%ebx
jne    1160 <main+0x30>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Hello, World\00"
@.str.1 = [33 x i8] c"%s - now allocated %d Megabytes\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = 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, 2048
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 ([13 x i8], [13 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_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello, World\00"
@.str.1 = [33 x i8] c"%s - now allocated %d Megabytes\0A\00"
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = 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(13) %4, i8* align 1 dereferenceable(13) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i64 13, 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, 2048
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_SUCCESS
%15 = tail call i32 @exit(i32 %14)
unreachable
}