#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);
int main(int argc, char *argv[]) {
  void *b = NULL;
  int c = 0;
  while (1) {
    b = (void *)malloc(10485760);
    if (!b) {
      break;
    }
    memset(b, 1, 10485760);
    printf("Allocating %d MB\n", (++c * 10));
  }
  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)
movl   $0x0,-0x1c(%rbp)
mov    $0xa00000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1183 <main+0x43>
jmp    11b3 <main+0x73>
mov    -0x18(%rbp),%rdi
mov    $0x1,%esi
mov    $0xa00000,%edx
call   1040 <memset@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
imul   $0xa,%eax,%esi
lea    0xe57(%rip),%rdi
call   1030 <printf@plt>
jmp    1165 <main+0x25>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0xa00000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     118e <main+0x4e>
mov    $0xa,%ebx
lea    0xea1(%rip),%r14
nop
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0xa00000,%edx
call   1040 <memset@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
mov    $0xa00000,%edi
call   1050 <malloc@plt>
add    $0xa,%ebx
test   %rax,%rax
jne    1160 <main+0x20>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [18 x i8] c"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 i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
store i32 0, i32* %7
br label %8
8: ; preds = %2, %14
%9 = call i64 @malloc(i32 10485760)
%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 %14, label %13
13: ; preds = %8
br label %21
14: ; preds = %8
%15 = load i8*, i8** %6
%16 = call i32 @memset(i8* %15, i32 1, i32 10485760)
%17 = load i32, i32* %7
%18 = add nsw i32 %17, 1
store i32 %18, i32* %7
%19 = mul nsw i32 %18, 10
%20 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %19)
br label %8
21: ; preds = %13
%22 = call i32 @exit(i32 0)
unreachable
}

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