#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_PRIVATE;
int PROT_READ;
int PROT_WRITE;
char *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main() {
  char *p;
  char *q;
  int i;
  p = mmap(NULL, 1024 * 1024 * 128, PROT_READ | PROT_WRITE,
           MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  for (i = 0; i < 1024 * 1024 * 128; i++) {
    p[i] = 'c';
  }
  printf("p finished\n");
  sleep(10);
  q = mmap(NULL, 1024 * 1024 * 128, PROT_READ | PROT_WRITE,
           MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
  for (i = 0; i < 1024 * 1024 * 128; i++) {
    q[i] = 'c';
  }
  printf("q finished\n");
  sleep(10000);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%edx
mov    0x2e81(%rip),%rax
or     (%rax),%edx
mov    0x2e88(%rip),%rax
mov    (%rax),%ecx
mov    0x2e67(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000000,-0x1c(%rbp)
jge    11ac <main+0x7c>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x63,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1185 <main+0x55>
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
mov    $0xa,%edi
call   1050 <sleep@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edx
mov    0x2dfe(%rip),%rax
or     (%rax),%edx
mov    0x2e05(%rip),%rax
mov    (%rax),%ecx
mov    0x2de4(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x8000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x8000000,-0x1c(%rbp)
jge    122f <main+0xff>
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x63,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1208 <main+0xd8>
lea    0xdd6(%rip),%rdi
call   1040 <printf@plt>
mov    $0x2710,%edi
call   1050 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    0x2ea9(%rip),%r14
mov    0x2e7a(%rip),%r12
mov    (%r12),%edx
or     (%r14),%edx
mov    0x2e7c(%rip),%r15
mov    0x2e5d(%rip),%rbx
mov    (%rbx),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x8000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    $0x8000000,%edx
mov    %rax,%rdi
mov    $0x63,%esi
call   1050 <memset@plt>
lea    0xe62(%rip),%rdi
call   1030 <puts@plt>
mov    $0xa,%edi
call   1060 <sleep@plt>
mov    (%r12),%edx
or     (%r14),%edx
mov    (%rbx),%ecx
or     (%r15),%ecx
xor    %edi,%edi
mov    $0x8000000,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1040 <mmap@plt>
mov    $0x8000000,%edx
mov    %rax,%rdi
mov    $0x63,%esi
call   1050 <memset@plt>
lea    0xe24(%rip),%rdi
call   1030 <puts@plt>
mov    $0x2710,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@.str = [12 x i8] c"p finished\0A\00"
@.str.1 = [12 x i8] c"q finished\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i32 0, i32* %1
%5 = load i32, i32* @PROT_READ
%6 = load i32, i32* @PROT_WRITE
%7 = or i32 %5, %6
%8 = load i32, i32* @MAP_ANONYMOUS
%9 = load i32, i32* @MAP_PRIVATE
%10 = or i32 %8, %9
%11 = call i8* @mmap(i32* null, i32 134217728, i32 %7, i32 %10, i32 -1, i32 0)
store i8* %11, i8** %2
store i32 0, i32* %4
br label %12
12: ; preds = %20, %0
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 134217728
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i8*, i8** %2
%17 = load i32, i32* %4
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
store i8 99, i8* %19
br label %20
20: ; preds = %15
%21 = load i32, i32* %4
%22 = add nsw i32 %21, 1
store i32 %22, i32* %4
br label %12
23: ; preds = %12
%24 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @sleep(i32 10)
%26 = load i32, i32* @PROT_READ
%27 = load i32, i32* @PROT_WRITE
%28 = or i32 %26, %27
%29 = load i32, i32* @MAP_ANONYMOUS
%30 = load i32, i32* @MAP_PRIVATE
%31 = or i32 %29, %30
%32 = call i8* @mmap(i32* null, i32 134217728, i32 %28, i32 %31, i32 -1, i32 0)
store i8* %32, i8** %3
store i32 0, i32* %4
br label %33
33: ; preds = %41, %23
%34 = load i32, i32* %4
%35 = icmp slt i32 %34, 134217728
br i1 %35, label %36, label %44
36: ; preds = %33
%37 = load i8*, i8** %3
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 99, i8* %40
br label %41
41: ; preds = %36
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %33
44: ; preds = %33
%45 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
%46 = call i32 @sleep(i32 10000)
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_ANONYMOUS = global i32 0
@MAP_PRIVATE = global i32 0
@str = [11 x i8] c"p finished\00"
@str.2 = [11 x i8] c"q finished\00"
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_PRIVATE
%6 = or i32 %5, %4
%7 = tail call i8* @mmap(i32* null, i32 134217728, i32 %3, i32 %6, i32 -1, i32 0)
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%9 = tail call i32 @sleep(i32 10)
%10 = load i32, i32* @PROT_READ
%11 = load i32, i32* @PROT_WRITE
%12 = or i32 %11, %10
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = load i32, i32* @MAP_PRIVATE
%15 = or i32 %14, %13
%16 = tail call i8* @mmap(i32* null, i32 134217728, i32 %12, i32 %15, i32 -1, i32 0)
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.2, i64 0, i64 0))
%18 = tail call i32 @sleep(i32 10000)
ret i32 0
}