#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 */
unsigned char volatile *MAP_FAILED;
int /*<<< orphan*/ MAP_SHARED;
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int PROT_READ;
int PROT_WRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ exit(int);
int fork();
int getpagesize();
unsigned char *malloc(int);
int /*<<< orphan*/ memset(unsigned char *, int, int);
unsigned char *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
                    int /*<<< orphan*/);
int open(char const *, int, int);
scalar_t__ pipe(int *);
int /*<<< orphan*/ pwrite(int, char *, int, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ unlink(char const *);
int write(int, ...);
int main(int argc, char *argv[]) {
  int tochild[2], toparent[2];
  int fd;
  volatile unsigned char *map;
  unsigned char *page;
  const char *fname = argv[1];
  char c = 0;
  if (pipe(tochild) != 0 || pipe(toparent) != 0)
    err(2, "Creating pipe");
  if (!fname)
    fname = "coherent.mmap";
  fd = open(fname, O_RDWR | O_CREAT | O_TRUNC, 0600);
  if (fd < 0)
    err(2, "opening %s", fname);
  unlink(fname);
  switch (fork()) {
  case -1:
    err(2, "Fork");
  case 0:
    close(tochild[1]);
    close(toparent[0]);
    if (read(tochild[0], &c, 1) != 1)
      err(2, "reading from parent");
    pwrite(fd, &c, 1, 0);
    if (write(toparent[1], &c, 1) != 1)
      err(2, "writing to parent");
    exit(0);
  default:
    close(tochild[0]);
    close(toparent[1]);
    page = malloc(getpagesize());
    memset(page, 0x42, getpagesize());
    if (write(fd, page, getpagesize()) != getpagesize())
      err(2, "writing first page");
    map = mmap(NULL, getpagesize(), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (map == MAP_FAILED)
      err(2, "mapping file");
    if (*map != 0x42)
      errx(2, "first byte isn't 0x42!");
    if (write(tochild[1], &c, 1) != 1)
      err(2, "writing to child");
    if (read(toparent[0], &c, 1) != 1)
      err(2, "reading from child");
    if (*map)
      errx(0, "mmap incoherent: first byte isn't 0.");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
movb   $0x0,-0x41(%rbp)
lea    -0x18(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
jne    123c <main+0x4c>
lea    -0x20(%rbp),%rdi
call   1090 <pipe@plt>
cmp    $0x0,%rax
je     124f <main+0x5f>
mov    $0x2,%edi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
cmpq   $0x0,-0x40(%rbp)
jne    1265 <main+0x75>
lea    0xdad(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    0x2d58(%rip),%rax
mov    (%rax),%esi
mov    0x2d7f(%rip),%rax
or     (%rax),%esi
mov    0x2d6e(%rip),%rax
or     (%rax),%esi
mov    $0x180,%edx
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    12b2 <main+0xc2>
mov    -0x40(%rbp),%rdx
mov    $0x2,%edi
lea    0xd71(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x40(%rbp),%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
call   1110 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x48(%rbp)
sub    $0xffffffff,%eax
je     12e5 <main+0xf5>
jmp    12d5 <main+0xe5>
mov    -0x48(%rbp),%eax
test   %eax,%eax
je     12f8 <main+0x108>
jmp    137e <main+0x18e>
mov    $0x2,%edi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    -0x20(%rbp),%edi
call   1080 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
je     1335 <main+0x145>
mov    $0x2,%edi
lea    0xcfe(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x24(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10d0 <pwrite@plt>
mov    -0x1c(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x1,%eax
je     1377 <main+0x187>
mov    $0x2,%edi
lea    0xcd0(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x18(%rbp),%edi
call   1080 <close@plt>
mov    -0x1c(%rbp),%edi
call   1080 <close@plt>
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    -0x68(%rbp),%rdi
mov    %eax,%edx
mov    $0x42,%esi
call   1070 <memset@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
mov    $0x0,%al
call   1040 <write@plt>
mov    %eax,-0x4c(%rbp)
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%ecx
mov    -0x4c(%rbp),%eax
cmp    %ecx,%eax
je     140e <main+0x21e>
mov    $0x2,%edi
lea    0xc4b(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    $0x0,%al
call   10f0 <getpagesize@plt>
mov    %eax,%esi
mov    0x2bca(%rip),%rax
mov    (%rax),%edx
mov    0x2b91(%rip),%rax
or     (%rax),%edx
mov    0x2ba8(%rip),%rax
mov    (%rax),%ecx
mov    -0x24(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x2b5f(%rip),%rcx
cmp    (%rcx),%rax
jne    146d <main+0x27d>
mov    $0x2,%edi
lea    0xbff(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
movzbl %al,%eax
cmp    $0x42,%eax
je     1490 <main+0x2a0>
mov    $0x2,%edi
lea    0xbe7(%rip),%rsi
call   1060 <errx@plt>
mov    -0x14(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
mov    $0x0,%al
call   1040 <write@plt>
cmp    $0x1,%eax
je     14bf <main+0x2cf>
mov    $0x2,%edi
lea    0xbd1(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x20(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
je     14ec <main+0x2fc>
mov    $0x2,%edi
lea    0xbb5(%rip),%rsi
mov    $0x0,%al
call   10b0 <err@plt>
mov    -0x30(%rbp),%rax
mov    (%rax),%al
cmp    $0x0,%al
je     1508 <main+0x318>
xor    %edi,%edi
lea    0xbaa(%rip),%rsi
call   1060 <errx@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    0x8(%rsi),%rbp
movb   $0x0,0x7(%rsp)
lea    0x10(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
jne    121d <main+0x2d>
lea    0x8(%rsp),%rdi
call   1090 <pipe@plt>
test   %rax,%rax
je     1230 <main+0x40>
lea    0xddc(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
test   %rbp,%rbp
lea    0xdd4(%rip),%rbx
cmovne %rbp,%rbx
mov    0x2d83(%rip),%rax
mov    0x2dac(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d99(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x180,%edx
call   10e0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    1282 <main+0x92>
lea    0xda9(%rip),%rsi
mov    $0x2,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <err@plt>
mov    %rbx,%rdi
call   1030 <unlink@plt>
xor    %eax,%eax
call   1110 <fork@plt>
test   %eax,%eax
je     12b1 <main+0xc1>
cmp    $0xffffffff,%eax
jne    1336 <main+0x146>
lea    0xd82(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
mov    0x14(%rsp),%edi
call   1080 <close@plt>
mov    0x8(%rsp),%edi
call   1080 <close@plt>
mov    0x10(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
je     12ee <main+0xfe>
lea    0xd4a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
lea    0x7(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   10d0 <pwrite@plt>
mov    0xc(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    $0x1,%eax
je     132f <main+0x13f>
lea    0xd1d(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    0x10(%rsp),%edi
call   1080 <close@plt>
mov    0xc(%rsp),%edi
call   1080 <close@plt>
xor    %eax,%eax
call   10f0 <getpagesize@plt>
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   10f0 <getpagesize@plt>
mov    %rbx,%rdi
mov    $0x42,%esi
mov    %eax,%edx
call   1070 <memset@plt>
xor    %eax,%eax
call   10f0 <getpagesize@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <write@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   10f0 <getpagesize@plt>
cmp    %eax,%ebx
je     13a4 <main+0x1b4>
lea    0xcba(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
xor    %eax,%eax
call   10f0 <getpagesize@plt>
mov    0x2c36(%rip),%rcx
mov    0x2bff(%rip),%rdx
mov    (%rdx),%edx
or     (%rcx),%edx
mov    0x2c14(%rip),%rcx
mov    (%rcx),%ecx
xor    %edi,%edi
mov    %eax,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1050 <mmap@plt>
mov    %rax,%rbx
mov    0x2bd1(%rip),%rax
cmp    (%rax),%rbx
jne    13f7 <main+0x207>
lea    0xc7a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
mov    (%rbx),%al
cmp    $0x42,%al
je     140e <main+0x21e>
lea    0xc6e(%rip),%rsi
mov    $0x2,%edi
call   1060 <errx@plt>
mov    0x14(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1040 <write@plt>
cmp    $0x1,%eax
je     143b <main+0x24b>
lea    0xc5a(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   10a0 <read@plt>
cmp    $0x1,%eax
jne    1462 <main+0x272>
cmpb   $0x0,(%rbx)
jne    147a <main+0x28a>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xc31(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   10b0 <err@plt>
cmpb   $0x0,(%rbx)
je     1458 <main+0x268>
lea    0xc2c(%rip),%rsi
xor    %edi,%edi
call   1060 <errx@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Creating pipe\00"
@.str.1 = [14 x i8] c"coherent.mmap\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [11 x i8] c"opening %s\00"
@.str.3 = [5 x i8] c"Fork\00"
@.str.4 = [20 x i8] c"reading from parent\00"
@.str.5 = [18 x i8] c"writing to parent\00"
@.str.6 = [19 x i8] c"writing first page\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [13 x i8] c"mapping file\00"
@.str.8 = [23 x i8] c"first byte isn't 0x42!\00"
@.str.9 = [17 x i8] c"writing to child\00"
@.str.10 = [19 x i8] c"reading from child\00"
@.str.11 = [37 x i8] c"mmap incoherent: first byte isn't 0.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
store i8* %15, i8** %11
store i8 0, i8* %12
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i64 @pipe(i32* %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%21 = call i64 @pipe(i32* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19, %2
%24 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %25
25: ; preds = %23, %19
%26 = load i8*, i8** %11
%27 = icmp ne i8* %26, null
br i1 %27, label %29, label %28
28: ; preds = %25
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8** %11
br label %29
29: ; preds = %28, %25
%30 = load i8*, i8** %11
%31 = load i32, i32* @O_RDWR
%32 = load i32, i32* @O_CREAT
%33 = or i32 %31, %32
%34 = load i32, i32* @O_TRUNC
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %30, i32 %35, i32 384)
store i32 %36, i32* %8
%37 = load i32, i32* %8
%38 = icmp slt i32 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %29
%40 = load i8*, i8** %11
%41 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %40)
br label %42
42: ; preds = %39, %29
%43 = load i8*, i8** %11
%44 = call i32 @unlink(i8* %43)
%45 = call i32 (...) @fork()
switch i32 %45, label %72 [
i32 -1, label %46
i32 0, label %48
]
46: ; preds = %42
%47 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %42, %46
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%56 = load i32, i32* %55
%57 = call i32 @read(i32 %56, i8* %12, i32 1)
%58 = icmp ne i32 %57, 1
br i1 %58, label %59, label %61
59: ; preds = %48
%60 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %48
%62 = load i32, i32* %8
%63 = call i32 @pwrite(i32 %62, i8* %12, i32 1, i32 0)
%64 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%65 = load i32, i32* %64
%66 = call i32 (i32, ...) @write(i32 %65, i8* %12, i32 1)
%67 = icmp ne i32 %66, 1
br i1 %67, label %68, label %70
68: ; preds = %61
%69 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %70
70: ; preds = %68, %61
%71 = call i32 @exit(i32 0)
unreachable
72: ; preds = %42
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%74 = load i32, i32* %73
%75 = call i32 @close(i32 %74)
%76 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%77 = load i32, i32* %76
%78 = call i32 @close(i32 %77)
%79 = call i32 (...) @getpagesize()
%80 = call i8* @malloc(i32 %79)
store i8* %80, i8** %10
%81 = load i8*, i8** %10
%82 = call i32 (...) @getpagesize()
%83 = call i32 @memset(i8* %81, i32 66, i32 %82)
%84 = load i32, i32* %8
%85 = load i8*, i8** %10
%86 = call i32 (...) @getpagesize()
%87 = call i32 (i32, ...) @write(i32 %84, i8* %85, i32 %86)
%88 = call i32 (...) @getpagesize()
%89 = icmp ne i32 %87, %88
br i1 %89, label %90, label %92
90: ; preds = %72
%91 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %92
92: ; preds = %90, %72
%93 = call i32 (...) @getpagesize()
%94 = load i32, i32* @PROT_READ
%95 = load i32, i32* @PROT_WRITE
%96 = or i32 %94, %95
%97 = load i32, i32* @MAP_SHARED
%98 = load i32, i32* %8
%99 = call i8* @mmap(i32* null, i32 %93, i32 %96, i32 %97, i32 %98, i32 0)
store i8* %99, i8** %9
%100 = load i8*, i8** %9
%101 = load i8*, i8** @MAP_FAILED
%102 = icmp eq i8* %100, %101
br i1 %102, label %103, label %105
103: ; preds = %92
%104 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %105
105: ; preds = %103, %92
%106 = load i8*, i8** %9
%107 = load volatile i8, i8* %106
%108 = zext i8 %107 to i32
%109 = icmp ne i32 %108, 66
br i1 %109, label %110, label %112
110: ; preds = %105
%111 = call i32 @errx(i32 2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %112
112: ; preds = %110, %105
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%114 = load i32, i32* %113
%115 = call i32 (i32, ...) @write(i32 %114, i8* %12, i32 1)
%116 = icmp ne i32 %115, 1
br i1 %116, label %117, label %119
117: ; preds = %112
%118 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %119
119: ; preds = %117, %112
%120 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%121 = load i32, i32* %120
%122 = call i32 @read(i32 %121, i8* %12, i32 1)
%123 = icmp ne i32 %122, 1
br i1 %123, label %124, label %126
124: ; preds = %119
%125 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %126
126: ; preds = %124, %119
%127 = load i8*, i8** %9
%128 = load volatile i8, i8* %127
%129 = icmp ne i8 %128, 0
br i1 %129, label %130, label %132
130: ; preds = %126
%131 = call i32 @errx(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
br label %132
132: ; preds = %130, %126
%133 = call i32 @exit(i32 1)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"Creating pipe\00"
@.str.1 = [14 x i8] c"coherent.mmap\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@.str.2 = [11 x i8] c"opening %s\00"
@.str.3 = [5 x i8] c"Fork\00"
@.str.4 = [20 x i8] c"reading from parent\00"
@.str.5 = [18 x i8] c"writing to parent\00"
@.str.6 = [19 x i8] c"writing first page\00"
@PROT_READ = global i32 0
@PROT_WRITE = global i32 0
@MAP_SHARED = global i32 0
@MAP_FAILED = global i8* null
@.str.7 = [13 x i8] c"mapping file\00"
@.str.8 = [23 x i8] c"first byte isn't 0x42!\00"
@.str.9 = [17 x i8] c"writing to child\00"
@.str.10 = [19 x i8] c"reading from child\00"
@.str.11 = [37 x i8] c"mmap incoherent: first byte isn't 0.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca i8
%6 = bitcast [2 x i32]* %3 to i8*
%7 = bitcast [2 x i32]* %4 to i8*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
store i8 0, i8* %5
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i64 @pipe(i32* %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13, %2
%18 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
%20 = icmp eq i8* %9, null
%21 = select i1 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %9
%22 = load i32, i32* @O_RDWR
%23 = load i32, i32* @O_CREAT
%24 = or i32 %23, %22
%25 = load i32, i32* @O_TRUNC
%26 = or i32 %24, %25
%27 = call i32 @open(i8* %21, i32 %26, i32 384)
%28 = icmp slt i32 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %19
%30 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %21)
br label %31
31: ; preds = %29, %19
%32 = call i32 @unlink(i8* %21)
%33 = call i32 (...) @fork()
switch i32 %33, label %58 [
i32 -1, label %34
i32 0, label %36
]
34: ; preds = %31
%35 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %31, %34
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %10
%44 = call i32 @read(i32 %43, i8* %5, i32 1)
%45 = icmp eq i32 %44, 1
br i1 %45, label %48, label %46
46: ; preds = %36
%47 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
br label %48
48: ; preds = %46, %36
%49 = call i32 @pwrite(i32 %27, i8* %5, i32 1, i32 0)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 (i32, ...) @write(i32 %51, i8* %5, i32 1)
%53 = icmp eq i32 %52, 1
br i1 %53, label %56, label %54
54: ; preds = %48
%55 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = call i32 @exit(i32 0)
unreachable
58: ; preds = %31
%59 = load i32, i32* %10
%60 = call i32 @close(i32 %59)
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%62 = load i32, i32* %61
%63 = call i32 @close(i32 %62)
%64 = call i32 (...) @getpagesize()
%65 = call i8* @malloc(i32 %64)
%66 = call i32 (...) @getpagesize()
%67 = call i32 @memset(i8* %65, i32 66, i32 %66)
%68 = call i32 (...) @getpagesize()
%69 = call i32 (i32, ...) @write(i32 %27, i8* %65, i32 %68)
%70 = call i32 (...) @getpagesize()
%71 = icmp eq i32 %69, %70
br i1 %71, label %74, label %72
72: ; preds = %58
%73 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
br label %74
74: ; preds = %72, %58
%75 = call i32 (...) @getpagesize()
%76 = load i32, i32* @PROT_READ
%77 = load i32, i32* @PROT_WRITE
%78 = or i32 %77, %76
%79 = load i32, i32* @MAP_SHARED
%80 = call i8* @mmap(i32* null, i32 %75, i32 %78, i32 %79, i32 %27, i32 0)
%81 = load i8*, i8** @MAP_FAILED
%82 = icmp eq i8* %80, %81
br i1 %82, label %83, label %85
83: ; preds = %74
%84 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %85
85: ; preds = %83, %74
%86 = load volatile i8, i8* %80
%87 = icmp eq i8 %86, 66
br i1 %87, label %90, label %88
88: ; preds = %85
%89 = call i32 @errx(i32 2, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
br label %90
90: ; preds = %88, %85
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%92 = load i32, i32* %91
%93 = call i32 (i32, ...) @write(i32 %92, i8* %5, i32 1)
%94 = icmp eq i32 %93, 1
br i1 %94, label %97, label %95
95: ; preds = %90
%96 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.9, i64 0, i64 0))
br label %97
97: ; preds = %95, %90
%98 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%99 = load i32, i32* %98
%100 = call i32 @read(i32 %99, i8* %5, i32 1)
%101 = icmp eq i32 %100, 1
br i1 %101, label %104, label %102
102: ; preds = %97
%103 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
br label %104
104: ; preds = %102, %97
%105 = load volatile i8, i8* %80
%106 = icmp eq i8 %105, 0
br i1 %106, label %109, label %107
107: ; preds = %104
%108 = call i32 @errx(i32 0, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0))
br label %109
109: ; preds = %107, %104
%110 = call i32 @exit(i32 1)
unreachable
}