#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 MAP_ANONYMOUS;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int main() {
  char *p = mmap(NULL, 50 << 20, PROT_READ | PROT_WRITE,
                 MAP_ANONYMOUS | MAP_SHARED, -1, 0);
  int i = 0;
  for (i = 0; i < (50 << 20) / 4096; i++)
    p[i * 4096] = i;
  sleep(1000000);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ec2(%rip),%rax
mov    (%rax),%edx
mov    0x2e89(%rip),%rax
or     (%rax),%edx
mov    0x2e90(%rip),%rax
mov    (%rax),%ecx
mov    0x2e97(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x3200000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x3200,-0x14(%rbp)
jge    11ac <main+0x8c>
mov    -0x14(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
shl    $0xc,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117c <main+0x5c>
mov    $0xf4240,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2ed0(%rip),%rax
mov    0x2e99(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e9e(%rip),%rax
mov    0x2ea7(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %ebx,%ebx
xor    %edi,%edi
mov    $0x3200000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
add    $0x4000,%rax
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %bl,-0x4000(%rax)
lea    0x1(%rbx),%ecx
mov    %cl,-0x3000(%rax)
lea    0x2(%rbx),%ecx
mov    %cl,-0x2000(%rax)
lea    0x3(%rbx),%ecx
mov    %cl,-0x1000(%rax)
lea    0x4(%rbx),%ecx
mov    %cl,(%rax)
add    $0x5,%rbx
add    $0x5000,%rax
cmp    $0x3200,%rbx
jne    1170 <main+0x50>
mov    $0xf4240,%edi
call   1040 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @PROT_READ
%5 = load i32, i32* @PROT_WRITE
%6 = or i32 %4, %5
%7 = load i32, i32* @MAP_ANONYMOUS
%8 = load i32, i32* @MAP_SHARED
%9 = or i32 %7, %8
%10 = call i8* @mmap(i32* null, i32 52428800, i32 %6, i32 %9, i32 -1, i32 0)
store i8* %10, i8** %2
store i32 0, i32* %3
store i32 0, i32* %3
br label %11
11: ; preds = %22, %0
%12 = load i32, i32* %3
%13 = icmp slt i32 %12, 12800
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = load i32, i32* %3
%16 = trunc i32 %15 to i8
%17 = load i8*, i8** %2
%18 = load i32, i32* %3
%19 = mul nsw i32 %18, 4096
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %17, i64 %20
store i8 %16, i8* %21
br label %22
22: ; preds = %14
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %11
25: ; preds = %11
%26 = call i32 @sleep(i32 1000000)
ret i32 0
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_SHARED = global i32 0
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_ANONYMOUS
%5 = load i32, i32* @MAP_SHARED
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i32* null, i32 52428800, i32 %3, i32 %6, i32 -1, i32 0)
br label %8
8: ; preds = %8, %0
%9 = phi i64 [ 0, %0 ], [ %29, %8 ]
%10 = trunc i64 %9 to i8
%11 = shl nuw nsw i64 %9, 12
%12 = getelementptr inbounds i8, i8* %7, i64 %11
store i8 %10, i8* %12
%13 = add nuw nsw i64 %9, 1
%14 = trunc i64 %13 to i8
%15 = shl nuw nsw i64 %13, 12
%16 = getelementptr inbounds i8, i8* %7, i64 %15
store i8 %14, i8* %16
%17 = add nuw nsw i64 %9, 2
%18 = trunc i64 %17 to i8
%19 = shl nuw nsw i64 %17, 12
%20 = getelementptr inbounds i8, i8* %7, i64 %19
store i8 %18, i8* %20
%21 = add nuw nsw i64 %9, 3
%22 = trunc i64 %21 to i8
%23 = shl nuw nsw i64 %21, 12
%24 = getelementptr inbounds i8, i8* %7, i64 %23
store i8 %22, i8* %24
%25 = add nuw nsw i64 %9, 4
%26 = trunc i64 %25 to i8
%27 = shl nuw nsw i64 %25, 12
%28 = getelementptr inbounds i8, i8* %7, i64 %27
store i8 %26, i8* %28
%29 = add nuw nsw i64 %9, 5
%30 = icmp eq i64 %29, 12800
br i1 %30, label %31, label %8
31: ; preds = %8
%32 = tail call i32 @sleep(i32 1000000)
ret i32 0
}