#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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ malloc(unsigned long long);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, unsigned long long);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  unsigned long long BLOCK_SIZE = 1048576;
  char *ptr = NULL;
  unsigned long i = 0;
  while (1) {
    if ((ptr = (char *)malloc(BLOCK_SIZE)) != NULL) {
      fprintf(stderr, "%llu kB\n", (++i) * BLOCK_SIZE / 1024);
      memset(ptr, 0, BLOCK_SIZE);
    } else {
      fprintf(stderr, "failed to allocate memory\n");
    }
    fflush(stderr);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x100000,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11c5 <main+0x85>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
imul   -0x18(%rbp),%rdx
shr    $0xa,%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rdx
xor    %esi,%esi
call   1030 <memset@plt>
jmp    11dc <main+0x9c>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
jmp    116e <main+0x2e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e8e(%rip),%r12
lea    0xeb0(%rip),%r14
movabs $0x3ffffffffffc00,%r13
lea    0xe96(%rip),%r15
xor    %ebp,%ebp
jmp    1187 <main+0x47>
xchg   %ax,%ax
mov    (%r12),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    (%r12),%edi
call   1060 <fflush@plt>
mov    $0x100000,%edi
call   1050 <malloc@plt>
test   %rax,%rax
je     1170 <main+0x30>
mov    %rax,%rbx
mov    (%r12),%edi
add    $0x1,%rbp
mov    %rbp,%rdx
shl    $0xa,%rdx
and    %r13,%rdx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x100000,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <memset@plt>
jmp    117e <main+0x3e>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [9 x i8] c"%llu kB\0A\00"
@.str.1 = [27 x i8] c"failed to allocate 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*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1048576, i64* %6
store i8* null, i8** %7
store i64 0, i64* %8
br label %9
9: ; preds = %2, %28
%10 = load i64, i64* %6
%11 = call i64 @malloc(i64 %10)
%12 = inttoptr i64 %11 to i8*
store i8* %12, i8** %7
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %25
14: ; preds = %9
%15 = load i32, i32* @stderr
%16 = load i64, i64* %8
%17 = add i64 %16, 1
store i64 %17, i64* %8
%18 = load i64, i64* %6
%19 = mul i64 %17, %18
%20 = udiv i64 %19, 1024
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %20)
%22 = load i8*, i8** %7
%23 = load i64, i64* %6
%24 = call i32 @memset(i8* %22, i32 0, i64 %23)
br label %28
25: ; preds = %9
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %28
28: ; preds = %25, %14
%29 = load i32, i32* @stderr
%30 = call i32 @fflush(i32 %29)
br label %9
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [9 x i8] c"%llu kB\0A\00"
@.str.1 = [27 x i8] c"failed to allocate memory\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
br label %3
3: ; preds = %18, %2
%4 = phi i64 [ 0, %2 ], [ %19, %18 ]
%5 = tail call i64 @malloc(i64 1048576)
%6 = icmp eq i64 %5, 0
br i1 %6, label %15, label %7
7: ; preds = %3
%8 = inttoptr i64 %5 to i8*
%9 = load i32, i32* @stderr
%10 = add i64 %4, 1
%11 = shl i64 %10, 10
%12 = and i64 %11, 18014398509480960
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 %12)
%14 = tail call i32 @memset(i8* %8, i32 0, i64 1048576)
br label %18
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %15, %7
%19 = phi i64 [ %10, %7 ], [ %4, %15 ]
%20 = load i32, i32* @stderr
%21 = tail call i32 @fflush(i32 %20)
br label %3
}