#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 */
typedef scalar_t__ pid_t;

/* Variables and functions */
scalar_t__ EEXIST;
scalar_t__ ENOENT;
void *MAP_FAILED;
int /*<<< orphan*/ MAP_PRIVATE;
int O_CREAT;
int O_EXCL;
int O_RDWR;
int PROT_READ;
int PROT_WRITE;
int S_IRUSR;
int S_IRWXG;
int S_IRWXO;
int S_IRWXU;
int S_IWUSR;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
scalar_t__ close(int);
int /*<<< orphan*/ err(int, char *);
scalar_t__ errno;
scalar_t__ fork();
scalar_t__ ftruncate(int, int);
scalar_t__ mkdir(char *, int);
void *mmap(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/, int,
           int /*<<< orphan*/);
scalar_t__ mprotect(void *, int, int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ puts(char *);
scalar_t__ unlink(char *);
scalar_t__ wait(int *);
int main(void) {
  int fd;
  void *ptr;
  if (mkdir("/tmp", S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST) {
    err(1, "mkdir");
  }
  if (unlink("/tmp/test") < 0 && errno != ENOENT) {
    err(1, "unlink");
  }
  fd = open("/tmp/test", O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR);
  if (fd < 0) {
    err(1, "open");
  }
  if (ftruncate(fd, 0x10) < 0) {
    err(1, "ftruncate");
  }
  ptr = mmap(NULL, 0x1000, PROT_READ, MAP_PRIVATE, fd, 0);
  if (ptr == MAP_FAILED) {
    err(1, "mmap");
  }
  if (close(fd) < 0) {
    err(1, "close");
  }
  if (mprotect(ptr, 0x1000, PROT_READ | PROT_WRITE) < 0) {
    err(1, "mprotect");
  }
  *(int *)ptr = 0xff;
  pid_t p = fork();
  if (p < 0) {
    err(1, "fork");
  }
  if (p == 0) {
    if (*(int *)ptr != 0xff) {
      printf("EXPECTED: 0x%x\nGOT     : 0x%x\n", 0xff, *(int *)ptr);
      return 1;
    }
    return 0;
  }
  int st = 0;
  if (wait(&st) < 0) {
    err(1, "wait");
  }
  if (unlink("/tmp/test") < 0) {
    err(1, "unlink");
  }
  if (!WIFEXITED(st) || WEXITSTATUS(st) != 0) {
    printf("abnormal child termination: %d\n", st);
    return 1;
  }
  puts("Test successful!");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    0x2dc1(%rip),%rax
or     (%rax),%esi
mov    0x2dd8(%rip),%rax
or     (%rax),%esi
lea    0xdef(%rip),%rdi
call   1040 <mkdir@plt>
cmp    $0x0,%rax
jge    124b <main+0x6b>
mov    0x2d71(%rip),%rax
mov    (%rax),%rax
mov    0x2d77(%rip),%rcx
cmp    (%rcx),%rax
je     124b <main+0x6b>
mov    $0x1,%edi
lea    0xdbf(%rip),%rsi
call   10a0 <err@plt>
lea    0xdb9(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    128c <main+0xac>
mov    0x2d30(%rip),%rax
mov    (%rax),%rax
mov    0x2cf6(%rip),%rcx
cmp    (%rcx),%rax
je     128c <main+0xac>
mov    $0x1,%edi
lea    0xd8e(%rip),%rsi
call   10a0 <err@plt>
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
mov    0x2d04(%rip),%rax
or     (%rax),%esi
mov    0x2d23(%rip),%rax
or     (%rax),%esi
mov    0x2cda(%rip),%rax
mov    (%rax),%edx
mov    0x2d01(%rip),%rax
or     (%rax),%edx
lea    0xd4b(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    12e3 <main+0x103>
mov    $0x1,%edi
lea    0xd3e(%rip),%rsi
call   10a0 <err@plt>
mov    -0x8(%rbp),%edi
mov    $0x10,%esi
call   1080 <ftruncate@plt>
cmp    $0x0,%rax
jge    130b <main+0x12b>
mov    $0x1,%edi
lea    0xd1b(%rip),%rsi
call   10a0 <err@plt>
mov    0x2cde(%rip),%rax
mov    (%rax),%edx
mov    0x2c65(%rip),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1000,%esi
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c37(%rip),%rcx
cmp    (%rcx),%rax
jne    135b <main+0x17b>
mov    $0x1,%edi
lea    0xcd5(%rip),%rsi
call   10a0 <err@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
cmp    $0x0,%rax
jge    137e <main+0x19e>
mov    $0x1,%edi
lea    0xcb7(%rip),%rsi
call   10a0 <err@plt>
mov    -0x10(%rbp),%rdi
mov    0x2c67(%rip),%rax
mov    (%rax),%edx
mov    0x2bfe(%rip),%rax
or     (%rax),%edx
mov    $0x1000,%esi
call   10c0 <mprotect@plt>
cmp    $0x0,%rax
jge    13b9 <main+0x1d9>
mov    $0x1,%edi
lea    0xc82(%rip),%rsi
call   10a0 <err@plt>
mov    -0x10(%rbp),%rax
movl   $0xff,(%rax)
mov    $0x0,%al
call   1100 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    13ea <main+0x20a>
mov    $0x1,%edi
lea    0xc5a(%rip),%rsi
call   10a0 <err@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1436 <main+0x256>
mov    -0x10(%rbp),%rax
cmpl   $0xff,(%rax)
je     142a <main+0x24a>
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xc32(%rip),%rdi
mov    $0xff,%esi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14db <main+0x2fb>
movl   $0x0,-0x4(%rbp)
jmp    14db <main+0x2fb>
movl   $0x0,-0x1c(%rbp)
lea    -0x1c(%rbp),%rdi
call   10f0 <wait@plt>
cmp    $0x0,%rax
jge    1461 <main+0x281>
mov    $0x1,%edi
lea    0xc07(%rip),%rsi
call   10a0 <err@plt>
lea    0xba3(%rip),%rdi
call   1030 <unlink@plt>
cmp    $0x0,%rax
jge    1488 <main+0x2a8>
mov    $0x1,%edi
lea    0xb92(%rip),%rsi
call   10a0 <err@plt>
mov    -0x1c(%rbp),%edi
call   10e0 <WIFEXITED@plt>
cmp    $0x0,%eax
je     14ab <main+0x2cb>
mov    -0x1c(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     14c8 <main+0x2e8>
mov    -0x1c(%rbp),%esi
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14db <main+0x2fb>
lea    0xbb9(%rip),%rdi
call   1050 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2de1(%rip),%rax
mov    0x2dca(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ddf(%rip),%rax
or     (%rax),%esi
lea    0xdf6(%rip),%rdi
call   1040 <mkdir@plt>
test   %rax,%rax
jns    123b <main+0x5b>
mov    0x2d7d(%rip),%rax
mov    (%rax),%rax
mov    0x2d83(%rip),%rcx
cmp    (%rcx),%rax
je     123b <main+0x5b>
lea    0xdd4(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0xdc9(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    1273 <main+0x93>
mov    0x2d45(%rip),%rax
mov    (%rax),%rax
mov    0x2d0b(%rip),%rcx
cmp    (%rcx),%rax
je     1273 <main+0x93>
lea    0xdac(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2d7e(%rip),%rax
mov    0x2d1f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2d3c(%rip),%rax
or     (%rax),%esi
mov    0x2cf3(%rip),%rax
mov    0x2d1c(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
lea    0xd64(%rip),%rdi
call   10d0 <open@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    12c3 <main+0xe3>
lea    0xd63(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebp,%edi
mov    $0x10,%esi
call   1080 <ftruncate@plt>
test   %rax,%rax
jns    12e5 <main+0x105>
lea    0xd46(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2d04(%rip),%r14
mov    (%r14),%edx
mov    0x2c8a(%rip),%rax
mov    (%rax),%ecx
xor    %edi,%edi
mov    $0x1000,%esi
mov    %ebp,%r8d
xor    %r9d,%r9d
call   1060 <mmap@plt>
mov    %rax,%rbx
mov    0x2c64(%rip),%rax
cmp    (%rax),%rbx
jne    132a <main+0x14a>
lea    0xd0b(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    %ebp,%edi
call   1090 <close@plt>
test   %rax,%rax
jns    1347 <main+0x167>
lea    0xcf3(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0x2c42(%rip),%rax
mov    (%rax),%edx
or     (%r14),%edx
mov    %rbx,%rdi
mov    $0x1000,%esi
call   10c0 <mprotect@plt>
test   %rax,%rax
jns    1376 <main+0x196>
lea    0xcca(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
movl   $0xff,(%rbx)
xor    %eax,%eax
call   1100 <fork@plt>
test   %rax,%rax
js     13b7 <main+0x1d7>
jne    13c8 <main+0x1e8>
mov    (%rbx),%edx
xor    %eax,%eax
cmp    $0xff,%edx
je     1454 <main+0x274>
lea    0xca3(%rip),%rdi
mov    $0xff,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1454 <main+0x274>
lea    0xc81(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rdi
call   10f0 <wait@plt>
test   %rax,%rax
jns    13f0 <main+0x210>
lea    0xc7d(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
lea    0xc14(%rip),%rdi
call   1030 <unlink@plt>
test   %rax,%rax
jns    1412 <main+0x232>
lea    0xc0d(%rip),%rsi
mov    $0x1,%edi
call   10a0 <err@plt>
mov    0xc(%rsp),%edi
call   10e0 <WIFEXITED@plt>
test   %eax,%eax
je     142d <main+0x24d>
mov    0xc(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
test   %rax,%rax
je     1446 <main+0x266>
mov    0xc(%rsp),%esi
lea    0xc30(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
jmp    1454 <main+0x274>
lea    0xc3b(%rip),%rdi
call   1050 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"/tmp\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [10 x i8] c"/tmp/test\00"
@ENOENT = global i64 0
@.str.3 = [7 x i8] c"unlink\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [10 x i8] c"ftruncate\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.6 = [5 x i8] c"mmap\00"
@.str.7 = [6 x i8] c"close\00"
@PROT_WRITE = global i32 0
@.str.8 = [9 x i8] c"mprotect\00"
@.str.9 = [5 x i8] c"fork\00"
@.str.10 = [31 x i8] c"EXPECTED: 0x%x\0AGOT : 0x%x\0A\00"
@.str.11 = [5 x i8] c"wait\00"
@.str.12 = [32 x i8] c"abnormal child termination: %d\0A\00"
@.str.13 = [17 x i8] c"Test successful!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @S_IRWXU
%7 = load i32, i32* @S_IRWXG
%8 = or i32 %6, %7
%9 = load i32, i32* @S_IRWXO
%10 = or i32 %8, %9
%11 = call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %10)
%12 = icmp slt i64 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %0
%14 = load i64, i64* @errno
%15 = load i64, i64* @EEXIST
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %13, %0
%20 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %19
%23 = load i64, i64* @errno
%24 = load i64, i64* @ENOENT
%25 = icmp ne i64 %23, %24
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %26, %22, %19
%29 = load i32, i32* @O_CREAT
%30 = load i32, i32* @O_EXCL
%31 = or i32 %29, %30
%32 = load i32, i32* @O_RDWR
%33 = or i32 %31, %32
%34 = load i32, i32* @S_IRUSR
%35 = load i32, i32* @S_IWUSR
%36 = or i32 %34, %35
%37 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %33, i32 %36)
store i32 %37, i32* %2
%38 = load i32, i32* %2
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %28
%41 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %28
%43 = load i32, i32* %2
%44 = call i64 @ftruncate(i32 %43, i32 16)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %42
%47 = call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load i32, i32* @PROT_READ
%50 = load i32, i32* @MAP_PRIVATE
%51 = load i32, i32* %2
%52 = call i8* @mmap(i32* null, i32 4096, i32 %49, i32 %50, i32 %51, i32 0)
store i8* %52, i8** %3
%53 = load i8*, i8** %3
%54 = load i8*, i8** @MAP_FAILED
%55 = icmp eq i8* %53, %54
br i1 %55, label %56, label %58
56: ; preds = %48
%57 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %58
58: ; preds = %56, %48
%59 = load i32, i32* %2
%60 = call i64 @close(i32 %59)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %64
64: ; preds = %62, %58
%65 = load i8*, i8** %3
%66 = load i32, i32* @PROT_READ
%67 = load i32, i32* @PROT_WRITE
%68 = or i32 %66, %67
%69 = call i64 @mprotect(i8* %65, i32 4096, i32 %68)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %64
%72 = call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %73
73: ; preds = %71, %64
%74 = load i8*, i8** %3
%75 = bitcast i8* %74 to i32*
store i32 255, i32* %75
%76 = call i64 (...) @fork()
store i64 %76, i64* %4
%77 = load i64, i64* %4
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %73
%80 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %81
81: ; preds = %79, %73
%82 = load i64, i64* %4
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %95
84: ; preds = %81
%85 = load i8*, i8** %3
%86 = bitcast i8* %85 to i32*
%87 = load i32, i32* %86
%88 = icmp ne i32 %87, 255
br i1 %88, label %89, label %94
89: ; preds = %84
%90 = load i8*, i8** %3
%91 = bitcast i8* %90 to i32*
%92 = load i32, i32* %91
%93 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 255, i32 %92)
store i32 1, i32* %1
br label %118
94: ; preds = %84
store i32 0, i32* %1
br label %118
95: ; preds = %81
store i32 0, i32* %5
%96 = call i64 @wait(i32* %5)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %100
98: ; preds = %95
%99 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %100
100: ; preds = %98, %95
%101 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%102 = icmp slt i64 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %100
%104 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %105
105: ; preds = %103, %100
%106 = load i32, i32* %5
%107 = call i32 @WIFEXITED(i32 %106)
%108 = icmp ne i32 %107, 0
br i1 %108, label %109, label %113
109: ; preds = %105
%110 = load i32, i32* %5
%111 = call i64 @WEXITSTATUS(i32 %110)
%112 = icmp ne i64 %111, 0
br i1 %112, label %113, label %116
113: ; preds = %109, %105
%114 = load i32, i32* %5
%115 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i32 %114)
store i32 1, i32* %1
br label %118
116: ; preds = %109
%117 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0))
store i32 0, i32* %1
br label %118
118: ; preds = %116, %113, %94, %89
%119 = load i32, i32* %1
ret i32 %119
}

LLVM IR (-O2):
@.str = [5 x i8] c"/tmp\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IRWXO = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@.str.1 = [6 x i8] c"mkdir\00"
@.str.2 = [10 x i8] c"/tmp/test\00"
@ENOENT = global i64 0
@.str.3 = [7 x i8] c"unlink\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_RDWR = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.4 = [5 x i8] c"open\00"
@.str.5 = [10 x i8] c"ftruncate\00"
@PROT_READ = global i32 0
@MAP_PRIVATE = global i32 0
@MAP_FAILED = global i8* null
@.str.6 = [5 x i8] c"mmap\00"
@.str.7 = [6 x i8] c"close\00"
@PROT_WRITE = global i32 0
@.str.8 = [9 x i8] c"mprotect\00"
@.str.9 = [5 x i8] c"fork\00"
@.str.10 = [31 x i8] c"EXPECTED: 0x%x\0AGOT : 0x%x\0A\00"
@.str.11 = [5 x i8] c"wait\00"
@.str.12 = [32 x i8] c"abnormal child termination: %d\0A\00"
@.str.13 = [17 x i8] c"Test successful!\00"
define i32 @main() {
%1 = alloca i32
%2 = load i32, i32* @S_IRWXU
%3 = load i32, i32* @S_IRWXG
%4 = or i32 %3, %2
%5 = load i32, i32* @S_IRWXO
%6 = or i32 %4, %5
%7 = tail call i64 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i64, i64* @errno
%11 = load i64, i64* @EEXIST
%12 = icmp eq i64 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9, %0
%16 = tail call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %24
18: ; preds = %15
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %24, label %22
22: ; preds = %18
%23 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %24
24: ; preds = %22, %18, %15
%25 = load i32, i32* @O_CREAT
%26 = load i32, i32* @O_EXCL
%27 = or i32 %26, %25
%28 = load i32, i32* @O_RDWR
%29 = or i32 %27, %28
%30 = load i32, i32* @S_IRUSR
%31 = load i32, i32* @S_IWUSR
%32 = or i32 %31, %30
%33 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i32 %29, i32 %32)
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %24
%36 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %24
%38 = tail call i64 @ftruncate(i32 %33, i32 16)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %37
%41 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0))
br label %42
42: ; preds = %40, %37
%43 = load i32, i32* @PROT_READ
%44 = load i32, i32* @MAP_PRIVATE
%45 = tail call i8* @mmap(i32* null, i32 4096, i32 %43, i32 %44, i32 %33, i32 0)
%46 = load i8*, i8** @MAP_FAILED
%47 = icmp eq i8* %45, %46
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = tail call i64 @close(i32 %33)
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %55
53: ; preds = %50
%54 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.7, i64 0, i64 0))
br label %55
55: ; preds = %53, %50
%56 = load i32, i32* @PROT_READ
%57 = load i32, i32* @PROT_WRITE
%58 = or i32 %57, %56
%59 = tail call i64 @mprotect(i8* %45, i32 4096, i32 %58)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %55
%62 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0))
br label %63
63: ; preds = %61, %55
%64 = bitcast i8* %45 to i32*
store i32 255, i32* %64
%65 = tail call i64 (...) @fork()
%66 = icmp slt i64 %65, 0
br i1 %66, label %67, label %69
67: ; preds = %63
%68 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
br label %76
69: ; preds = %63
%70 = icmp eq i64 %65, 0
br i1 %70, label %71, label %76
71: ; preds = %69
%72 = load i32, i32* %64
%73 = icmp eq i32 %72, 255
br i1 %73, label %102, label %74
74: ; preds = %71
%75 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.10, i64 0, i64 0), i32 255, i32 %72)
br label %102
76: ; preds = %67, %69
%77 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%78 = call i64 @wait(i32* %1)
%79 = icmp slt i64 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %76
%81 = call i32 @err(i32 1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
br label %82
82: ; preds = %80, %76
%83 = call i64 @unlink(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%84 = icmp slt i64 %83, 0
br i1 %84, label %85, label %87
85: ; preds = %82
%86 = call i32 @err(i32 1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %87
87: ; preds = %85, %82
%88 = load i32, i32* %1
%89 = call i32 @WIFEXITED(i32 %88)
%90 = icmp eq i32 %89, 0
br i1 %90, label %95, label %91
91: ; preds = %87
%92 = load i32, i32* %1
%93 = call i64 @WEXITSTATUS(i32 %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %91, %87
%96 = load i32, i32* %1
%97 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.12, i64 0, i64 0), i32 %96)
br label %100
98: ; preds = %91
%99 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.13, i64 0, i64 0))
br label %100
100: ; preds = %98, %95
%101 = phi i32 [ 1, %95 ], [ 0, %98 ]
br label %102
102: ; preds = %71, %100, %74
%103 = phi i32 [ 1, %74 ], [ %101, %100 ], [ 0, %71 ]
ret i32 %103
}