#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*/ escape(int *);
int /*<<< orphan*/ fgetc(int /*<<< orphan*/);
int getpid();
int *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ report_memory(char *);
int /*<<< orphan*/ stdin;
int main(int argc, char **argv) {
  printf("PID = %d\n", getpid());
  report_memory("started");
  int N = 100 * 1024 * 1024;
  int *m = malloc(N * sizeof(int));
  escape(m);
  report_memory("after malloc");
  for (int i = 0; i < N; ++i) {
    m[i] = i;
  }
  report_memory("after touch");
  printf("press ENTER\n");
  (void)fgetc(stdin);
  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)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe76(%rip),%rdi
call   1070 <report_memory@plt>
movl   $0x6400000,-0x14(%rbp)
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <escape@plt>
lea    0xe4f(%rip),%rdi
call   1070 <report_memory@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11f7 <main+0x97>
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11cf <main+0x6f>
lea    0xe21(%rip),%rdi
call   1070 <report_memory@plt>
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1050 <fgetc@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xf31(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xf2b(%rip),%rdi
call   1080 <report_memory@plt>
mov    $0x19000000,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <escape@plt>
lea    0xf12(%rip),%rdi
call   1080 <report_memory@plt>
movdqa 0xe43(%rip),%xmm0
mov    $0x24,%eax
movdqa 0xe45(%rip),%xmm8
movdqa 0xe4c(%rip),%xmm9
movdqa 0xe53(%rip),%xmm10
movdqa 0xe5a(%rip),%xmm11
movdqa 0xe61(%rip),%xmm12
movdqa 0xe69(%rip),%xmm6
movdqa 0xe71(%rip),%xmm7
movdqa 0xe79(%rip),%xmm1
movdqa 0xe81(%rip),%xmm2
movdqa 0xe89(%rip),%xmm3
nopw   0x0(%rax,%rax,1)
movdqa %xmm0,%xmm4
paddd  %xmm8,%xmm4
movdqu %xmm0,-0x90(%rbx,%rax,4)
ff ff
movdqu %xmm4,-0x80(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm9,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm10,%xmm5
movdqu %xmm4,-0x70(%rbx,%rax,4)
movdqu %xmm5,-0x60(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm11,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm12,%xmm5
movdqu %xmm4,-0x50(%rbx,%rax,4)
movdqu %xmm5,-0x40(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm6,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm7,%xmm5
movdqu %xmm4,-0x30(%rbx,%rax,4)
movdqu %xmm5,-0x20(%rbx,%rax,4)
movdqa %xmm0,%xmm4
paddd  %xmm1,%xmm4
movdqa %xmm0,%xmm5
paddd  %xmm2,%xmm5
movdqu %xmm4,-0x10(%rbx,%rax,4)
movdqu %xmm5,(%rbx,%rax,4)
paddd  %xmm3,%xmm0
add    $0x28,%rax
cmp    $0x6400024,%rax
jne    1220 <main+0xb0>
lea    0xe09(%rip),%rdi
call   1080 <report_memory@plt>
lea    0xe09(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1060 <fgetc@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [10 x i8] c"PID = %d\0A\00"
@.str.1 = [8 x i8] c"started\00"
@.str.2 = [13 x i8] c"after malloc\00"
@.str.3 = [12 x i8] c"after touch\00"
@.str.4 = [13 x i8] c"press ENTER\0A\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @getpid()
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @report_memory(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
store i32 104857600, i32* %6
%12 = load i32, i32* %6
%13 = sext i32 %12 to i64
%14 = mul i64 %13, 4
%15 = trunc i64 %14 to i32
%16 = call i32* @malloc(i32 %15)
store i32* %16, i32** %7
%17 = load i32*, i32** %7
%18 = call i32 @escape(i32* %17)
%19 = call i32 @report_memory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %8
br label %20
20: ; preds = %30, %2
%21 = load i32, i32* %8
%22 = load i32, i32* %6
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %8
%26 = load i32*, i32** %7
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
store i32 %25, i32* %29
br label %30
30: ; preds = %24
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
br label %20
33: ; preds = %20
%34 = call i32 @report_memory(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.4, i64 0, i64 0))
%36 = load i32, i32* @stdin
%37 = call i32 @fgetc(i32 %36)
ret i32 0
}

LLVM IR (-O2):
@.str = [10 x i8] c"PID = %d\0A\00"
@.str.1 = [8 x i8] c"started\00"
@.str.2 = [13 x i8] c"after malloc\00"
@.str.3 = [12 x i8] c"after touch\00"
@stdin = global i32 0
@str = [12 x i8] c"press ENTER\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i32 (...) @getpid()
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i32 @report_memory(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32* @malloc(i32 419430400)
%7 = tail call i32 @escape(i32* %6)
%8 = tail call i32 @report_memory(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %9
9: ; preds = %9, %2
%10 = phi i64 [ 0, %2 ], [ %45, %9 ]
%11 = phi <4 x i32> [ <i32 0, i32 1, i32 2, i32 3>, %2 ], [ %46, %9 ]
%12 = add <4 x i32> %11, <i32 4, i32 4, i32 4, i32 4>
%13 = getelementptr inbounds i32, i32* %6, i64 %10
%14 = bitcast i32* %13 to <4 x i32>*
store <4 x i32> %11, <4 x i32>* %14
%15 = getelementptr inbounds i32, i32* %13, i64 4
%16 = bitcast i32* %15 to <4 x i32>*
store <4 x i32> %12, <4 x i32>* %16
%17 = add nuw nsw i64 %10, 8
%18 = add <4 x i32> %11, <i32 8, i32 8, i32 8, i32 8>
%19 = add <4 x i32> %11, <i32 12, i32 12, i32 12, i32 12>
%20 = getelementptr inbounds i32, i32* %6, i64 %17
%21 = bitcast i32* %20 to <4 x i32>*
store <4 x i32> %18, <4 x i32>* %21
%22 = getelementptr inbounds i32, i32* %20, i64 4
%23 = bitcast i32* %22 to <4 x i32>*
store <4 x i32> %19, <4 x i32>* %23
%24 = add nuw nsw i64 %10, 16
%25 = add <4 x i32> %11, <i32 16, i32 16, i32 16, i32 16>
%26 = add <4 x i32> %11, <i32 20, i32 20, i32 20, i32 20>
%27 = getelementptr inbounds i32, i32* %6, i64 %24
%28 = bitcast i32* %27 to <4 x i32>*
store <4 x i32> %25, <4 x i32>* %28
%29 = getelementptr inbounds i32, i32* %27, i64 4
%30 = bitcast i32* %29 to <4 x i32>*
store <4 x i32> %26, <4 x i32>* %30
%31 = add nuw nsw i64 %10, 24
%32 = add <4 x i32> %11, <i32 24, i32 24, i32 24, i32 24>
%33 = add <4 x i32> %11, <i32 28, i32 28, i32 28, i32 28>
%34 = getelementptr inbounds i32, i32* %6, i64 %31
%35 = bitcast i32* %34 to <4 x i32>*
store <4 x i32> %32, <4 x i32>* %35
%36 = getelementptr inbounds i32, i32* %34, i64 4
%37 = bitcast i32* %36 to <4 x i32>*
store <4 x i32> %33, <4 x i32>* %37
%38 = add nuw nsw i64 %10, 32
%39 = add <4 x i32> %11, <i32 32, i32 32, i32 32, i32 32>
%40 = add <4 x i32> %11, <i32 36, i32 36, i32 36, i32 36>
%41 = getelementptr inbounds i32, i32* %6, i64 %38
%42 = bitcast i32* %41 to <4 x i32>*
store <4 x i32> %39, <4 x i32>* %42
%43 = getelementptr inbounds i32, i32* %41, i64 4
%44 = bitcast i32* %43 to <4 x i32>*
store <4 x i32> %40, <4 x i32>* %44
%45 = add nuw nsw i64 %10, 40
%46 = add <4 x i32> %11, <i32 40, i32 40, i32 40, i32 40>
%47 = icmp eq i64 %45, 104857600
br i1 %47, label %48, label %9
48: ; preds = %9
%49 = tail call i32 @report_memory(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%50 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%51 = load i32, i32* @stdin
%52 = tail call i32 @fgetc(i32 %51)
ret i32 0
}