#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(int /*<<< orphan*/);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(void *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  void *myblock = NULL;
  long long count = 0;
  while (1) {
    myblock = (void *)malloc(100 * 1024 * 1024);
    if (!myblock) {
      printf("malloc failed\n");
      break;
    }
    memset(myblock, 1, 100 * 1024 * 1024);
    printf("Currently allocating %d MB\n", ++count * 100);
  }
  exit(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)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    $0x6400000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1192 <main+0x52>
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11c8 <main+0x88>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0x6400000,%edx
call   1040 <memset@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
imul   $0x64,%rax,%rsi
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1166 <main+0x26>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x6400000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11a2 <main+0x52>
mov    $0x64,%ebx
lea    0xe91(%rip),%r14
nop
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x6400000,%edx
call   1050 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x6400000,%edi
call   1060 <malloc@plt>
add    $0x64,%rbx
test   %rax,%rax
jne    1170 <main+0x20>
lea    0xe73(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [15 x i8] c"malloc failed\0A\00"
@.str.1 = [28 x i8] c"Currently allocating %d MB\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i64 0, i64* %7
br label %8
8: ; preds = %2, %15
%9 = call i64 @malloc(i32 104857600)
%10 = inttoptr i64 %9 to i8*
store i8* %10, i8** %6
%11 = load i8*, i8** %6
%12 = icmp ne i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %8
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %22
15: ; preds = %8
%16 = load i8*, i8** %6
%17 = call i32 @memset(i8* %16, i32 1, i32 104857600)
%18 = load i64, i64* %7
%19 = add nsw i64 %18, 1
store i64 %19, i64* %7
%20 = mul nsw i64 %19, 100
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %20)
br label %8
22: ; preds = %13
%23 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.1 = [28 x i8] c"Currently allocating %d MB\0A\00"
@str = [14 x i8] c"malloc failed\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 @malloc(i32 104857600)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %8, %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 0)
unreachable
8: ; preds = %2, %8
%9 = phi i64 [ %16, %8 ], [ %3, %2 ]
%10 = phi i64 [ %13, %8 ], [ 0, %2 ]
%11 = inttoptr i64 %9 to i8*
%12 = tail call i32 @memset(i8* %11, i32 1, i32 104857600)
%13 = add nuw nsw i64 %10, 1
%14 = mul nsw i64 %13, 100
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i64 %14)
%16 = tail call i64 @malloc(i32 104857600)
%17 = icmp eq i64 %16, 0
br i1 %17, label %5, label %8
}