#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 MAP_SHARED;
int /*<<< orphan*/ PROT_READ;
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ mmap(int /*<<< orphan*/, int, int /*<<< orphan*/, int, int,
                        int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
scalar_t__ wait(int /*<<< orphan*/);
int main() {
  if (!mmap(0, 128, PROT_READ, MAP_SHARED | MAP_ANONYMOUS, -1, 0)) {
    perror("mmap 128");
    exit(1);
  }
  if (!mmap(0, 129, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)) {
    perror("mmap 129");
    exit(1);
  }
  int pid = fork();
  if (pid < 0) {
    perror("fork");
    exit(1);
  } else if (pid != 0) {
    while (wait(0) > 0)
      ;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%edx
mov    0x2e79(%rip),%rax
mov    (%rax),%ecx
mov    0x2e60(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x80,%esi
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
cmp    $0x0,%eax
jne    11af <main+0x5f>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
mov    0x2e09(%rip),%rax
mov    (%rax),%ecx
mov    0x2e10(%rip),%rax
or     (%rax),%ecx
xor    %r9d,%r9d
mov    $0x81,%esi
mov    $0xffffffff,%r8d
mov    %r9d,%edi
call   1030 <mmap@plt>
cmp    $0x0,%eax
jne    11ff <main+0xaf>
lea    0xe19(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    1229 <main+0xd9>
lea    0xdf8(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x8(%rbp)
je     1253 <main+0x103>
jmp    1238 <main+0xe8>
xor    %edi,%edi
call   1060 <wait@plt>
cmp    $0x0,%rax
jle    124e <main+0xfe>
jmp    1238 <main+0xe8>
jmp    1253 <main+0x103>
jmp    1258 <main+0x108>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2e9d(%rip),%r14
mov    (%r14),%edx
mov    0x2e83(%rip),%rax
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x80,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %eax,%eax
je     11d6 <main+0x86>
mov    (%r14),%edx
mov    0x2e35(%rip),%rax
mov    (%rbx),%ecx
or     (%rax),%ecx
xor    %edi,%edi
mov    $0x81,%esi
mov    $0xffffffff,%r8d
xor    %r9d,%r9d
call   1030 <mmap@plt>
test   %eax,%eax
je     11df <main+0x8f>
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
js     11e8 <main+0x98>
je     11cc <main+0x7c>
nopl   (%rax)
xor    %edi,%edi
call   1060 <wait@plt>
test   %rax,%rax
jg     11c0 <main+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe23(%rip),%rdi
jmp    11ef <main+0x9f>
lea    0xe23(%rip),%rdi
jmp    11ef <main+0x9f>
lea    0xe23(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@PROT_READ = global i32 0
@MAP_SHARED = global i32 0
@MAP_ANONYMOUS = global i32 0
@.str = [9 x i8] c"mmap 128\00"
@MAP_PRIVATE = global i32 0
@.str.1 = [9 x i8] c"mmap 129\00"
@.str.2 = [5 x i8] c"fork\00"
define i32 @main() {
%1 = load i32, i32* @PROT_READ
%2 = load i32, i32* @MAP_SHARED
%3 = load i32, i32* @MAP_ANONYMOUS
%4 = or i32 %3, %2
%5 = tail call i32 @mmap(i32 0, i32 128, i32 %1, i32 %4, i32 -1, i32 0)
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @PROT_READ
%12 = load i32, i32* @MAP_PRIVATE
%13 = load i32, i32* @MAP_ANONYMOUS
%14 = or i32 %13, %12
%15 = tail call i32 @mmap(i32 0, i32 129, i32 %11, i32 %14, i32 -1, i32 0)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = tail call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = tail call i32 (...) @fork()
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %20
%27 = icmp eq i32 %21, 0
br i1 %27, label %31, label %28
28: ; preds = %26, %28
%29 = tail call i64 @wait(i32 0)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %28, label %31
31: ; preds = %28, %26
ret i32 0
}