#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_ANON;
int MAP_SHARED;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int *mmap(int /*<<< orphan*/ *, int, int, int, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
void main() {
  int x;
  int *ptr;
  ptr = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON,
             -1, 0);
  if (fork() == 0) {
    for (x = 1; x < 5; x++) {
      printf("child: %d\n", (*ptr)++);
      sleep(1);
    }
    exit(0);
  }
  for (x = 1; x < 5; x++) {
    printf("parent: %d\n", (*ptr)++);
    sleep(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edx
mov    0x2e68(%rip),%rax
or     (%rax),%edx
mov    0x2e77(%rip),%rax
mov    (%rax),%ecx
mov    0x2e4e(%rip),%rax
or     (%rax),%ecx
xor    %eax,%eax
mov    %eax,%edi
mov    $0x4,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    11f1 <main+0xa1>
movl   $0x1,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    11ea <main+0x9a>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    %esi,%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    0xe33(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <main+0x5f>
xor    %edi,%edi
call   1050 <exit@plt>
movl   $0x1,-0x4(%rbp)
cmpl   $0x5,-0x4(%rbp)
jge    1233 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    (%rax),%esi
mov    %esi,%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
lea    0xdf5(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11f8 <main+0xa8>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e9d(%rip),%rax
mov    0x2e6e(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x2e7b(%rip),%rax
mov    0x2e54(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x4,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1070 <fork@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%ecx
mov    %ecx,(%rbx)
test   %rax,%rax
je     120e <main+0xbe>
lea    0xe61(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <sleep@plt>
lea    0xdeb(%rip),%r14
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    (%rbx),%esi
lea    0x1(%rsi),%eax
mov    %eax,(%rbx)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANON = global i32 0
@.str = [11 x i8] c"child: %d\0A\00"
@.str.1 = [12 x i8] c"parent: %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = load i32, i32* @PROT_READ
%4 = load i32, i32* @PROT_WRITE
%5 = or i32 %3, %4
%6 = load i32, i32* @MAP_SHARED
%7 = load i32, i32* @MAP_ANON
%8 = or i32 %6, %7
%9 = call i32* @mmap(i32* null, i32 4, i32 %5, i32 %8, i32 -1, i32 0)
store i32* %9, i32** %2
%10 = call i64 (...) @fork()
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %0
store i32 1, i32* %1
br label %13
13: ; preds = %22, %12
%14 = load i32, i32* %1
%15 = icmp slt i32 %14, 5
br i1 %15, label %16, label %25
16: ; preds = %13
%17 = load i32*, i32** %2
%18 = load i32, i32* %17
%19 = add nsw i32 %18, 1
store i32 %19, i32* %17
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %18)
%21 = call i32 @sleep(i32 1)
br label %22
22: ; preds = %16
%23 = load i32, i32* %1
%24 = add nsw i32 %23, 1
store i32 %24, i32* %1
br label %13
25: ; preds = %13
%26 = call i32 @exit(i32 0)
unreachable
27: ; preds = %0
store i32 1, i32* %1
br label %28
28: ; preds = %37, %27
%29 = load i32, i32* %1
%30 = icmp slt i32 %29, 5
br i1 %30, label %31, label %40
31: ; preds = %28
%32 = load i32*, i32** %2
%33 = load i32, i32* %32
%34 = add nsw i32 %33, 1
store i32 %34, i32* %32
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %33)
%36 = call i32 @sleep(i32 1)
br label %37
37: ; preds = %31
%38 = load i32, i32* %1
%39 = add nsw i32 %38, 1
store i32 %39, i32* %1
br label %28
40: ; preds = %28
ret void
}

LLVM IR (-O2):
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANON = global i32 0
@.str = [11 x i8] c"child: %d\0A\00"
@.str.1 = [12 x i8] c"parent: %d\0A\00"
define void @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @PROT_WRITE
%3 = or i32 %2, %1
%4 = load i32, i32* @MAP_SHARED
%5 = load i32, i32* @MAP_ANON
%6 = or i32 %5, %4
%7 = tail call i32* @mmap(i32* null, i32 4, i32 %3, i32 %6, i32 -1, i32 0)
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
%10 = load i32, i32* %7
%11 = add nsw i32 %10, 1
store i32 %11, i32* %7
br i1 %9, label %27, label %12
12: ; preds = %0
%13 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%14 = tail call i32 @sleep(i32 1)
%15 = load i32, i32* %7
%16 = add nsw i32 %15, 1
store i32 %16, i32* %7
%17 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%18 = tail call i32 @sleep(i32 1)
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
%21 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %19)
%22 = tail call i32 @sleep(i32 1)
%23 = load i32, i32* %7
%24 = add nsw i32 %23, 1
store i32 %24, i32* %7
%25 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%26 = tail call i32 @sleep(i32 1)
ret void
27: ; preds = %0
%28 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %10)
%29 = tail call i32 @sleep(i32 1)
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %30)
%33 = tail call i32 @sleep(i32 1)
%34 = load i32, i32* %7
%35 = add nsw i32 %34, 1
store i32 %35, i32* %7
%36 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %34)
%37 = tail call i32 @sleep(i32 1)
%38 = load i32, i32* %7
%39 = add nsw i32 %38, 1
store i32 %39, i32* %7
%40 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %38)
%41 = tail call i32 @sleep(i32 1)
%42 = tail call i32 @exit(i32 0)
unreachable
}