#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*/ getchar();
void *malloc(long);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  void *m;
  int i;
  printf("Allocation VIRT memory\n");
  printf("top shows a questionmark for VIRT when it is larger than 8TB\n");
  for (i = 0; i < 200; i++) {
    m = malloc(1L * 50 * 1024 * 1024 * 1024);
    printf("malloc returned %p\n", m);
    if (i > 161) {
      printf("press return to for next allocation\n");
      getchar();
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xec4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xc8,-0x14(%rbp)
jge    11c9 <main+0x99>
movabs $0xc80000000,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xa1,-0x14(%rbp)
jle    11b6 <main+0x86>
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
jmp    11bb <main+0x8b>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1162 <main+0x32>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
call   1030 <puts@plt>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
movabs $0xc80000000,%r14
lea    0xe90(%rip),%rbx
lea    0xef1(%rip),%r15
xor    %ebp,%ebp
jmp    118b <main+0x4b>
nopl   0x0(%rax,%rax,1)
add    $0x1,%ebp
cmp    $0xc8,%ebp
je     11b9 <main+0x79>
mov    %r14,%rdi
call   1060 <malloc@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0xa2,%ebp
jb     1180 <main+0x40>
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
jmp    1180 <main+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [24 x i8] c"Allocation VIRT memory\0A\00"
@.str.1 = [62 x i8] c"top shows a questionmark for VIRT when it is larger than 8TB\0A\00"
@.str.2 = [20 x i8] c"malloc returned %p\0A\00"
@.str.3 = [37 x i8] c"press return to for next allocation\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %6
6: ; preds = %19, %0
%7 = load i32, i32* %3
%8 = icmp slt i32 %7, 200
br i1 %8, label %9, label %22
9: ; preds = %6
%10 = call i8* @malloc(i64 53687091200)
store i8* %10, i8** %2
%11 = load i8*, i8** %2
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* %3
%14 = icmp sgt i32 %13, 161
br i1 %14, label %15, label %18
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (...) @getchar()
br label %18
18: ; preds = %15, %9
br label %19
19: ; preds = %18
%20 = load i32, i32* %3
%21 = add nsw i32 %20, 1
store i32 %21, i32* %3
br label %6
22: ; preds = %6
%23 = load i32, i32* %1
ret i32 %23
}

LLVM IR (-O2):
@.str.2 = [20 x i8] c"malloc returned %p\0A\00"
@str = [23 x i8] c"Allocation VIRT memory\00"
@str.4 = [61 x i8] c"top shows a questionmark for VIRT when it is larger than 8TB\00"
@str.5 = [36 x i8] c"press return to for next allocation\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str.4, i64 0, i64 0))
br label %3
3: ; preds = %0, %11
%4 = phi i32 [ 0, %0 ], [ %12, %11 ]
%5 = tail call dereferenceable_or_null(53687091200) i8* @malloc(i64 53687091200)
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%7 = icmp ugt i32 %4, 161
br i1 %7, label %8, label %11
8: ; preds = %3
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.5, i64 0, i64 0))
%10 = tail call i32 (...) @getchar()
br label %11
11: ; preds = %3, %8
%12 = add nuw nsw i32 %4, 1
%13 = icmp eq i32 %12, 200
br i1 %13, label %14, label %3
14: ; preds = %11
ret i32 0
}