#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;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ TELL_CHILD(scalar_t__);
int /*<<< orphan*/ TELL_PARENT(scalar_t__);
int /*<<< orphan*/ TELL_WAIT();
int /*<<< orphan*/ WAIT_CHILD();
int /*<<< orphan*/ WAIT_PARENT();
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ fork();
scalar_t__ fprintf(int /*<<< orphan*/ *, char *, int);
scalar_t__ getpid();
scalar_t__ getppid();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int main() {
  FILE *fp = NULL;
  const char *file_name = "myFile.txt";
  char str_buff[10];
  int counter = 0;
  int fd1[2], fd2[2];
  pid_t pid;
  TELL_WAIT();
  if ((fp = fopen(file_name, "w+")) == NULL)
    err("Couldn't Open");
  else
    printf("File Created\n");
  if (fprintf(fp, "%d\n", counter) < 0)
    err("Couldn't Write Data to File");
  else
    printf("Initial Write to File Successful\n\n");
  pipe(fd1);
  pipe(fd2);
  if ((pid = fork()) < 0) {
    err("Fork() Error");
  } else if (pid == 0) {
    close(fd1[1]);
    close(fd2[0]);
    if ((fp = fopen(file_name, "r+")) == NULL)
      err("Couldn't Open File");
    while (fgets(str_buff, 10, fp) != NULL) {
      sscanf(str_buff, "%d", &counter);
    }
    while (counter <= 5) {
      WAIT_PARENT();
      fprintf(fp, "%d\n", counter);
      printf("Child PID = %ld Writing to File\n", (long)getpid());
      printf("%d\n", counter);
      counter++;
      TELL_PARENT(getppid());
    }
  } else {
    close(fd1[0]);
    close(fd2[1]);
    if ((fp = fopen(file_name, "r+")) == NULL)
      err("Couldn't open file");
    while (fgets(str_buff, 10, fp) != NULL) {
      sscanf(str_buff, "%d", &counter);
    }
    while (counter <= 5) {
      fprintf(fp, "%d\n", counter);
      printf("Parent PID = %ld Writing to File\n", (long)getppid());
      printf("%d\n", counter);
      counter++;
      TELL_CHILD(pid);
      WAIT_CHILD();
    }
  }
  fclose(fp);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xdc2(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1090 <TELL_WAIT@plt>
mov    -0x18(%rbp),%rdi
lea    0xdb0(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    127f <main+0x5f>
lea    0xd99(%rip),%rdi
call   10e0 <err@plt>
jmp    128d <main+0x6d>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xd8f(%rip),%rsi
call   10d0 <fprintf@plt>
cmp    $0x0,%rax
jge    12bb <main+0x9b>
lea    0xd7d(%rip),%rdi
call   10e0 <err@plt>
jmp    12c9 <main+0xa9>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x30(%rbp),%rdi
call   10b0 <pipe@plt>
lea    -0x38(%rbp),%rdi
call   10b0 <pipe@plt>
mov    $0x0,%al
call   1140 <fork@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jge    1301 <main+0xe1>
lea    0xd76(%rip),%rdi
call   10e0 <err@plt>
jmp    14db <main+0x2bb>
cmpq   $0x0,-0x40(%rbp)
jne    13f4 <main+0x1d4>
mov    -0x2c(%rbp),%edi
call   10a0 <close@plt>
mov    -0x38(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1346 <main+0x126>
lea    0xd3c(%rip),%rdi
call   10e0 <err@plt>
jmp    134b <main+0x12b>
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1380 <main+0x160>
lea    -0x22(%rbp),%rdi
lea    0xd1e(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   10f0 <sscanf@plt>
jmp    134b <main+0x12b>
jmp    1385 <main+0x165>
cmpl   $0x5,-0x28(%rbp)
jg     13ef <main+0x1cf>
mov    $0x0,%al
call   1130 <WAIT_PARENT@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xc86(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x0,%al
call   1050 <getpid@plt>
mov    %rax,%rsi
lea    0xcd9(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xc5f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    $0x0,%al
call   1110 <getppid@plt>
mov    %rax,%rdi
call   1070 <TELL_PARENT@plt>
jmp    1385 <main+0x165>
jmp    14d6 <main+0x2b6>
mov    -0x30(%rbp),%edi
call   10a0 <close@plt>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
lea    0xc6b(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    142e <main+0x20e>
lea    0xc8b(%rip),%rdi
call   10e0 <err@plt>
jmp    1433 <main+0x213>
lea    -0x22(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0xa,%esi
call   10c0 <fgets@plt>
cmp    $0x0,%rax
je     1468 <main+0x248>
lea    -0x22(%rbp),%rdi
lea    0xc36(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   10f0 <sscanf@plt>
jmp    1433 <main+0x213>
jmp    146d <main+0x24d>
cmpl   $0x5,-0x28(%rbp)
jg     14d1 <main+0x2b1>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%edx
lea    0xba5(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x0,%al
call   1110 <getppid@plt>
mov    %rax,%rsi
lea    0xc2c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%esi
lea    0xb7e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x40(%rbp),%rdi
call   1040 <TELL_CHILD@plt>
mov    $0x0,%al
call   1030 <WAIT_CHILD@plt>
jmp    146d <main+0x24d>
jmp    14d6 <main+0x2b6>
jmp    14db <main+0x2bb>
mov    -0x10(%rbp),%rdi
call   1060 <fclose@plt>
xor    %edi,%edi
call   1120 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
movl   $0x0,(%rsp)
xor    %eax,%eax
call   10a0 <TELL_WAIT@plt>
lea    0xdae(%rip),%rdi
lea    0xdb2(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1274 <main+0x44>
lea    0xda1(%rip),%rdi
call   10f0 <err@plt>
jmp    1280 <main+0x50>
lea    0xe3d(%rip),%rdi
call   1040 <puts@plt>
lea    0xd95(%rip),%rsi
mov    %r15,%rdi
xor    %edx,%edx
call   10e0 <fprintf@plt>
test   %rax,%rax
jns    12a4 <main+0x74>
lea    0xd83(%rip),%rdi
call   10f0 <err@plt>
jmp    12b0 <main+0x80>
lea    0xe1a(%rip),%rdi
call   1040 <puts@plt>
lea    0x18(%rsp),%rdi
call   10c0 <pipe@plt>
lea    0x10(%rsp),%rdi
call   10c0 <pipe@plt>
xor    %eax,%eax
call   1150 <fork@plt>
test   %rax,%rax
jns    12e1 <main+0xb1>
lea    0xd65(%rip),%rdi
call   10f0 <err@plt>
jmp    14d7 <main+0x2a7>
jne    13df <main+0x1af>
mov    0x1c(%rsp),%edi
call   10b0 <close@plt>
mov    0x10(%rsp),%edi
call   10b0 <close@plt>
lea    0xd00(%rip),%rdi
lea    0xd42(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1320 <main+0xf0>
lea    0xd31(%rip),%rdi
call   10f0 <err@plt>
lea    0x6(%rsp),%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
je     1380 <main+0x150>
lea    0xd21(%rip),%r14
lea    0x6(%rsp),%rbx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1100 <sscanf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
jne    1350 <main+0x120>
cmpl   $0x5,(%rsp)
jg     14d7 <main+0x2a7>
nopl   (%rax)
xor    %eax,%eax
call   1140 <WAIT_PARENT@plt>
mov    (%rsp),%edx
lea    0xc8b(%rip),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   10e0 <fprintf@plt>
xor    %eax,%eax
call   1060 <getpid@plt>
lea    0xcb8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
addl   $0x1,(%rsp)
xor    %eax,%eax
call   1120 <getppid@plt>
mov    %rax,%rdi
call   1080 <TELL_PARENT@plt>
cmpl   $0x6,(%rsp)
jl     1380 <main+0x150>
jmp    14d7 <main+0x2a7>
mov    %rax,%r14
mov    0x18(%rsp),%edi
call   10b0 <close@plt>
mov    0x14(%rsp),%edi
call   10b0 <close@plt>
lea    0xc05(%rip),%rdi
lea    0xc47(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    141b <main+0x1eb>
lea    0xc6d(%rip),%rdi
call   10f0 <err@plt>
lea    0x6(%rsp),%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
xor    %edx,%edx
test   %rax,%rax
je     147b <main+0x24b>
lea    0xc24(%rip),%r12
lea    0x6(%rsp),%rbx
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1100 <sscanf@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    %r15,%rdx
call   10d0 <fgets@plt>
test   %rax,%rax
jne    1450 <main+0x220>
mov    (%rsp),%edx
cmp    $0x5,%edx
jg     14d7 <main+0x2a7>
lea    0xb9a(%rip),%rbx
lea    0xc0d(%rip),%r12
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   10e0 <fprintf@plt>
xor    %eax,%eax
call   1120 <getppid@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1090 <printf@plt>
addl   $0x1,(%rsp)
mov    %r14,%rdi
call   1050 <TELL_CHILD@plt>
xor    %eax,%eax
call   1030 <WAIT_CHILD@plt>
mov    (%rsp),%edx
cmp    $0x6,%edx
jl     1490 <main+0x260>
mov    %r15,%rdi
call   1070 <fclose@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"myFile.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"Couldn't Open\00"
@.str.3 = [14 x i8] c"File Created\0A\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [28 x i8] c"Couldn't Write Data to File\00"
@.str.6 = [35 x i8] c"Initial Write to File Successful\0A\0A\00"
@.str.7 = [13 x i8] c"Fork() Error\00"
@.str.8 = [3 x i8] c"r+\00"
@.str.9 = [19 x i8] c"Couldn't Open File\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [33 x i8] c"Child PID = %ld Writing to File\0A\00"
@.str.12 = [19 x i8] c"Couldn't open file\00"
@.str.13 = [34 x i8] c"Parent PID = %ld Writing to File\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca [10 x i8]
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i64
store i32 0, i32* %1
store i32* null, i32** %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
store i32 0, i32* %5
%9 = call i32 (...) @TELL_WAIT()
%10 = load i8*, i8** %3
%11 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %11, i32** %2
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %17
15: ; preds = %0
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
%18 = load i32*, i32** %2
%19 = load i32, i32* %5
%20 = call i64 @fprintf(i32* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %17
%23 = call i32 @err(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %26
24: ; preds = %17
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0))
br label %26
26: ; preds = %24, %22
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%28 = call i32 @pipe(i32* %27)
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = call i32 @pipe(i32* %29)
%31 = call i64 (...) @fork()
store i64 %31, i64* %8
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %26
%34 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %117
35: ; preds = %26
%36 = load i64, i64* %8
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %77
38: ; preds = %35
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
%45 = load i8*, i8** %3
%46 = call i32* @fopen(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %46, i32** %2
%47 = icmp eq i32* %46, null
br i1 %47, label %48, label %50
48: ; preds = %38
%49 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %50
50: ; preds = %48, %38
br label %51
51: ; preds = %56, %50
%52 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%53 = load i32*, i32** %2
%54 = call i32* @fgets(i8* %52, i32 10, i32* %53)
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %59
56: ; preds = %51
%57 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%58 = call i32 @sscanf(i8* %57, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %5)
br label %51
59: ; preds = %51
br label %60
60: ; preds = %63, %59
%61 = load i32, i32* %5
%62 = icmp sle i32 %61, 5
br i1 %62, label %63, label %76
63: ; preds = %60
%64 = call i32 (...) @WAIT_PARENT()
%65 = load i32*, i32** %2
%66 = load i32, i32* %5
%67 = call i64 @fprintf(i32* %65, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %66)
%68 = call i64 (...) @getpid()
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i64 %68)
%70 = load i32, i32* %5
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %70)
%72 = load i32, i32* %5
%73 = add nsw i32 %72, 1
store i32 %73, i32* %5
%74 = call i64 (...) @getppid()
%75 = call i32 @TELL_PARENT(i64 %74)
br label %60
76: ; preds = %60
br label %116
77: ; preds = %35
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%82 = load i32, i32* %81
%83 = call i32 @close(i32 %82)
%84 = load i8*, i8** %3
%85 = call i32* @fopen(i8* %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
store i32* %85, i32** %2
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %89
87: ; preds = %77
%88 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %89
89: ; preds = %87, %77
br label %90
90: ; preds = %95, %89
%91 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%92 = load i32*, i32** %2
%93 = call i32* @fgets(i8* %91, i32 10, i32* %92)
%94 = icmp ne i32* %93, null
br i1 %94, label %95, label %98
95: ; preds = %90
%96 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%97 = call i32 @sscanf(i8* %96, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %5)
br label %90
98: ; preds = %90
br label %99
99: ; preds = %102, %98
%100 = load i32, i32* %5
%101 = icmp sle i32 %100, 5
br i1 %101, label %102, label %115
102: ; preds = %99
%103 = load i32*, i32** %2
%104 = load i32, i32* %5
%105 = call i64 @fprintf(i32* %103, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %104)
%106 = call i64 (...) @getppid()
%107 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0), i64 %106)
%108 = load i32, i32* %5
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %108)
%110 = load i32, i32* %5
%111 = add nsw i32 %110, 1
store i32 %111, i32* %5
%112 = load i64, i64* %8
%113 = call i32 @TELL_CHILD(i64 %112)
%114 = call i32 (...) @WAIT_CHILD()
br label %99
115: ; preds = %99
br label %116
116: ; preds = %115, %76
br label %117
117: ; preds = %116, %33
%118 = load i32*, i32** %2
%119 = call i32 @fclose(i32* %118)
%120 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [11 x i8] c"myFile.txt\00"
@.str.1 = [3 x i8] c"w+\00"
@.str.2 = [14 x i8] c"Couldn't Open\00"
@.str.4 = [4 x i8] c"%d\0A\00"
@.str.5 = [28 x i8] c"Couldn't Write Data to File\00"
@.str.7 = [13 x i8] c"Fork() Error\00"
@.str.8 = [3 x i8] c"r+\00"
@.str.9 = [19 x i8] c"Couldn't Open File\00"
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [33 x i8] c"Child PID = %ld Writing to File\0A\00"
@.str.12 = [19 x i8] c"Couldn't open file\00"
@.str.13 = [34 x i8] c"Parent PID = %ld Writing to File\0A\00"
@str = [13 x i8] c"File Created\00"
@str.14 = [34 x i8] c"Initial Write to File Successful\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca i32
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%6 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%7 = bitcast [2 x i32]* %3 to i8*
%8 = bitcast [2 x i32]* %4 to i8*
%9 = tail call i32 (...) @TELL_WAIT()
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %0
%13 = tail call i32 @err(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %16
14: ; preds = %0
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = tail call i64 @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 0)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = tail call i32 @err(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %23
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.14, i64 0, i64 0))
br label %23
23: ; preds = %21, %19
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%25 = call i32 @pipe(i32* %24)
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%27 = call i32 @pipe(i32* %26)
%28 = call i64 (...) @fork()
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %32
30: ; preds = %23
%31 = call i32 @err(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %104
32: ; preds = %23
%33 = icmp eq i64 %28, 0
br i1 %33, label %34, label %69
34: ; preds = %32
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %26
%39 = call i32 @close(i32 %38)
%40 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%41 = icmp eq i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
br label %44
44: ; preds = %42, %34
%45 = call i32* @fgets(i8* %5, i32 10, i32* %40)
%46 = icmp eq i32* %45, null
br i1 %46, label %50, label %51
47: ; preds = %51
%48 = load i32, i32* %2
%49 = icmp slt i32 %48, 6
br i1 %49, label %50, label %104
50: ; preds = %44, %47
br label %55
51: ; preds = %44, %51
%52 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %2)
%53 = call i32* @fgets(i8* %5, i32 10, i32* %40)
%54 = icmp eq i32* %53, null
br i1 %54, label %47, label %51
55: ; preds = %50, %55
%56 = call i32 (...) @WAIT_PARENT()
%57 = load i32, i32* %2
%58 = call i64 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %57)
%59 = call i64 (...) @getpid()
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.11, i64 0, i64 0), i64 %59)
%61 = load i32, i32* %2
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load i32, i32* %2
%64 = add nsw i32 %63, 1
store i32 %64, i32* %2
%65 = call i64 (...) @getppid()
%66 = call i32 @TELL_PARENT(i64 %65)
%67 = load i32, i32* %2
%68 = icmp slt i32 %67, 6
br i1 %68, label %55, label %104
69: ; preds = %32
%70 = load i32, i32* %24
%71 = call i32 @close(i32 %70)
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%73 = load i32, i32* %72
%74 = call i32 @close(i32 %73)
%75 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0))
%76 = icmp eq i32* %75, null
br i1 %76, label %77, label %79
77: ; preds = %69
%78 = call i32 @err(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.12, i64 0, i64 0))
br label %79
79: ; preds = %77, %69
%80 = call i32* @fgets(i8* %5, i32 10, i32* %75)
%81 = icmp eq i32* %80, null
br i1 %81, label %85, label %87
82: ; preds = %87
%83 = load i32, i32* %2
%84 = icmp slt i32 %83, 6
br i1 %84, label %85, label %104
85: ; preds = %79, %82
%86 = phi i32 [ 0, %79 ], [ %83, %82 ]
br label %91
87: ; preds = %79, %87
%88 = call i32 @sscanf(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32* %2)
%89 = call i32* @fgets(i8* %5, i32 10, i32* %75)
%90 = icmp eq i32* %89, null
br i1 %90, label %82, label %87
91: ; preds = %85, %91
%92 = phi i32 [ %102, %91 ], [ %86, %85 ]
%93 = call i64 @fprintf(i32* %75, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %92)
%94 = call i64 (...) @getppid()
%95 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.13, i64 0, i64 0), i64 %94)
%96 = load i32, i32* %2
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %96)
%98 = load i32, i32* %2
%99 = add nsw i32 %98, 1
store i32 %99, i32* %2
%100 = call i32 @TELL_CHILD(i64 %28)
%101 = call i32 (...) @WAIT_CHILD()
%102 = load i32, i32* %2
%103 = icmp slt i32 %102, 6
br i1 %103, label %91, label %104
104: ; preds = %91, %55, %82, %47, %30
%105 = phi i32* [ %10, %30 ], [ %40, %47 ], [ %75, %82 ], [ %40, %55 ], [ %75, %91 ]
%106 = call i32 @fclose(i32* %105)
%107 = call i32 @exit(i32 0)
unreachable
}