#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int creat(char *, int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
scalar_t__ pipe(int *);
int /*<<< orphan*/ stderr;
int wait(int *);
int main(int argc, char **argv) {
  int st, pid, pid3;
  int fd[2], f;
  if (pipe(fd) < 0) {
    fprintf(stderr, "pipe failed\n");
    exit(0);
  }
  if ((pid = fork()) == 0) {
    dup2(fd[0], 0);
    close(fd[0]);
    close(fd[1]);
    f = creat(argv[6], 0666);
    if (f < 0) {
      fprintf(stderr, "permission denied\n");
      exit(0);
    }
    dup2(f, 1);
    close(f);
    execlp(argv[3], argv[3], argv[5], NULL);
    fprintf(stderr, "exec in pr3 failed\n");
    exit(0);
  } else if (pid == -1) {
    fprintf(stderr, "first fork failed\n");
    exit(0);
  }
  pid3 = pid;
  if ((pid = fork()) == 0) {
    dup2(fd[1], 1);
    close(fd[0]);
    close(fd[1]);
    execlp(argv[1], argv[1], NULL);
    fprintf(stderr, "exec in pr1 failed\n");
    exit(0);
  } else if (pid == -1) {
    fprintf(stderr, "second fork failed\n");
    exit(0);
  }
  pid = wait(&st);
  if (pid == pid3) {
    fprintf(stderr, "error in pr3\n");
    exit(0);
  }
  if ((pid = fork()) == 0) {
    dup2(fd[1], 1);
    close(fd[0]);
    close(fd[1]);
    f = open(argv[4], O_RDONLY);
    if (f < 0) {
      fprintf(stderr, "permission denied\n");
      exit(0);
    }
    dup2(f, 0);
    close(f);
    execlp(argv[2], argv[2], NULL);
    fprintf(stderr, "exec in pr2 failed\n");
    exit(0);
  } else if (pid == -1) {
    fprintf(stderr, "third fork failed\n");
    exit(0);
  }
  close(fd[0]);
  close(fd[1]);
  wait(&st);
  wait(&st);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x24(%rbp),%rdi
call   1050 <pipe@plt>
cmp    $0x0,%rax
jge    11e5 <main+0x45>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe27(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    12a1 <main+0x101>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x30(%rax),%rdi
mov    $0x1b6,%esi
call   1080 <creat@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    124d <main+0xad>
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x28(%rax),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   10a0 <execlp@plt>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    12c7 <main+0x127>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xd79(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    12cc <main+0x12c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1339 <main+0x199>
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   10a0 <execlp@plt>
mov    0x2cb4(%rip),%rax
mov    (%rax),%edi
lea    0xd1a(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    135f <main+0x1bf>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    0xd08(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    1364 <main+0x1c4>
lea    -0x14(%rbp),%rdi
call   10b0 <wait@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1398 <main+0x1f8>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
lea    0xce3(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jne    1450 <main+0x2b0>
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
mov    0x2c11(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0x0,-0x28(%rbp)
jge    1407 <main+0x267>
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
lea    0xc12(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0x28(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x28(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    $0x0,%al
call   10a0 <execlp@plt>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
lea    0xc39(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
cmpl   $0xffffffff,-0x18(%rbp)
jne    1476 <main+0x2d6>
mov    0x2b77(%rip),%rax
mov    (%rax),%edi
lea    0xc27(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>
jmp    147b <main+0x2db>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
lea    -0x14(%rbp),%rdi
call   10b0 <wait@plt>
lea    -0x14(%rbp),%rdi
call   10b0 <wait@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%rbx
lea    0xc(%rsp),%rdi
call   1050 <pipe@plt>
test   %rax,%rax
js     1248 <main+0xa8>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     125d <main+0xbd>
mov    %eax,%ebp
test   %eax,%eax
je     1272 <main+0xd2>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     12e3 <main+0x143>
test   %eax,%eax
je     12f8 <main+0x158>
lea    0x14(%rsp),%rdi
call   10b0 <wait@plt>
cmp    %ebp,%eax
je     133d <main+0x19d>
xor    %eax,%eax
call   10c0 <fork@plt>
cmp    $0xffffffff,%eax
je     1352 <main+0x1b2>
test   %eax,%eax
je     1364 <main+0x1c4>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
lea    0x14(%rsp),%rbx
mov    %rbx,%rdi
call   10b0 <wait@plt>
mov    %rbx,%rdi
call   10b0 <wait@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d89(%rip),%rax
mov    (%rax),%edi
lea    0xda8(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
lea    0xdc7(%rip),%rsi
jmp    13de <main+0x23e>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x30(%rbx),%rdi
mov    $0x1b6,%esi
call   1080 <creat@plt>
test   %eax,%eax
js     139a <main+0x1fa>
mov    %eax,%ebp
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x18(%rbx),%rdi
mov    0x28(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   10a0 <execlp@plt>
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
lea    0xd42(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd68(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x10(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   10a0 <execlp@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
lea    0xd0f(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
lea    0xd2f(%rip),%rsi
jmp    13de <main+0x23e>
mov    0x10(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x20(%rbx),%rdi
mov    0x2c59(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
jns    13ac <main+0x20c>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
lea    0xc63(%rip),%rsi
jmp    13de <main+0x23e>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x10(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   10a0 <execlp@plt>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
lea    0xc9f(%rip),%rsi
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [13 x i8] c"pipe failed\0A\00"
@.str.1 = [19 x i8] c"permission denied\0A\00"
@.str.2 = [20 x i8] c"exec in pr3 failed\0A\00"
@.str.3 = [19 x i8] c"first fork failed\0A\00"
@.str.4 = [20 x i8] c"exec in pr1 failed\0A\00"
@.str.5 = [20 x i8] c"second fork failed\0A\00"
@.str.6 = [14 x i8] c"error in pr3\0A\00"
@O_RDONLY = global i32 0
@.str.7 = [20 x i8] c"exec in pr2 failed\0A\00"
@.str.8 = [19 x i8] c"third fork failed\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [2 x i32]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%12 = call i64 @pipe(i32* %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 0)
unreachable
18: ; preds = %2
%19 = call i32 (...) @fork()
store i32 %19, i32* %7
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %59
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%23 = load i32, i32* %22
%24 = call i32 @dup2(i32 %23, i32 0)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 6
%33 = load i8*, i8** %32
%34 = call i32 @creat(i8* %33, i32 438)
store i32 %34, i32* %10
%35 = load i32, i32* %10
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %41
37: ; preds = %21
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 0)
unreachable
41: ; preds = %21
%42 = load i32, i32* %10
%43 = call i32 @dup2(i32 %42, i32 1)
%44 = load i32, i32* %10
%45 = call i32 @close(i32 %44)
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 3
%48 = load i8*, i8** %47
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 3
%51 = load i8*, i8** %50
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 5
%54 = load i8*, i8** %53
%55 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %48, i8* %51, i8* %54, i8* null)
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %18
%60 = load i32, i32* %7
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %66
62: ; preds = %59
%63 = load i32, i32* @stderr
%64 = call i32 @fprintf(i32 %63, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%65 = call i32 @exit(i32 0)
unreachable
66: ; preds = %59
br label %67
67: ; preds = %66
%68 = load i32, i32* %7
store i32 %68, i32* %8
%69 = call i32 (...) @fork()
store i32 %69, i32* %7
%70 = icmp eq i32 %69, 0
br i1 %70, label %71, label %91
71: ; preds = %67
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%73 = load i32, i32* %72
%74 = call i32 @dup2(i32 %73, i32 1)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i8**, i8*** %5
%82 = getelementptr inbounds i8*, i8** %81, i64 1
%83 = load i8*, i8** %82
%84 = load i8**, i8*** %5
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %83, i8* %86, i8* null)
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%90 = call i32 @exit(i32 0)
unreachable
91: ; preds = %67
%92 = load i32, i32* %7
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %98
94: ; preds = %91
%95 = load i32, i32* @stderr
%96 = call i32 @fprintf(i32 %95, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%97 = call i32 @exit(i32 0)
unreachable
98: ; preds = %91
br label %99
99: ; preds = %98
%100 = call i32 @wait(i32* %6)
store i32 %100, i32* %7
%101 = load i32, i32* %7
%102 = load i32, i32* %8
%103 = icmp eq i32 %101, %102
br i1 %103, label %104, label %108
104: ; preds = %99
%105 = load i32, i32* @stderr
%106 = call i32 @fprintf(i32 %105, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%107 = call i32 @exit(i32 0)
unreachable
108: ; preds = %99
%109 = call i32 (...) @fork()
store i32 %109, i32* %7
%110 = icmp eq i32 %109, 0
br i1 %110, label %111, label %147
111: ; preds = %108
%112 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%113 = load i32, i32* %112
%114 = call i32 @dup2(i32 %113, i32 1)
%115 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%116 = load i32, i32* %115
%117 = call i32 @close(i32 %116)
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%119 = load i32, i32* %118
%120 = call i32 @close(i32 %119)
%121 = load i8**, i8*** %5
%122 = getelementptr inbounds i8*, i8** %121, i64 4
%123 = load i8*, i8** %122
%124 = load i32, i32* @O_RDONLY
%125 = call i32 @open(i8* %123, i32 %124)
store i32 %125, i32* %10
%126 = load i32, i32* %10
%127 = icmp slt i32 %126, 0
br i1 %127, label %128, label %132
128: ; preds = %111
%129 = load i32, i32* @stderr
%130 = call i32 @fprintf(i32 %129, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%131 = call i32 @exit(i32 0)
unreachable
132: ; preds = %111
%133 = load i32, i32* %10
%134 = call i32 @dup2(i32 %133, i32 0)
%135 = load i32, i32* %10
%136 = call i32 @close(i32 %135)
%137 = load i8**, i8*** %5
%138 = getelementptr inbounds i8*, i8** %137, i64 2
%139 = load i8*, i8** %138
%140 = load i8**, i8*** %5
%141 = getelementptr inbounds i8*, i8** %140, i64 2
%142 = load i8*, i8** %141
%143 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %139, i8* %142, i8* null)
%144 = load i32, i32* @stderr
%145 = call i32 @fprintf(i32 %144, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%146 = call i32 @exit(i32 0)
unreachable
147: ; preds = %108
%148 = load i32, i32* %7
%149 = icmp eq i32 %148, -1
br i1 %149, label %150, label %154
150: ; preds = %147
%151 = load i32, i32* @stderr
%152 = call i32 @fprintf(i32 %151, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%153 = call i32 @exit(i32 0)
unreachable
154: ; preds = %147
br label %155
155: ; preds = %154
%156 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%157 = load i32, i32* %156
%158 = call i32 @close(i32 %157)
%159 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%160 = load i32, i32* %159
%161 = call i32 @close(i32 %160)
%162 = call i32 @wait(i32* %6)
%163 = call i32 @wait(i32* %6)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [13 x i8] c"pipe failed\0A\00"
@.str.1 = [19 x i8] c"permission denied\0A\00"
@.str.2 = [20 x i8] c"exec in pr3 failed\0A\00"
@.str.3 = [19 x i8] c"first fork failed\0A\00"
@.str.4 = [20 x i8] c"exec in pr1 failed\0A\00"
@.str.5 = [20 x i8] c"second fork failed\0A\00"
@.str.6 = [14 x i8] c"error in pr3\0A\00"
@O_RDONLY = global i32 0
@.str.7 = [20 x i8] c"exec in pr2 failed\0A\00"
@.str.8 = [19 x i8] c"third fork failed\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = bitcast i32* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%8 = call i64 @pipe(i32* %7)
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = call i32 (...) @fork()
switch i32 %15, label %47 [
i32 0, label %16
i32 -1, label %43
]
16: ; preds = %14
%17 = load i32, i32* %7
%18 = call i32 @dup2(i32 %17, i32 0)
%19 = load i32, i32* %7
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 6
%25 = load i8*, i8** %24
%26 = call i32 @creat(i8* %25, i32 438)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %32
28: ; preds = %16
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%31 = call i32 @exit(i32 0)
unreachable
32: ; preds = %16
%33 = call i32 @dup2(i32 %26, i32 1)
%34 = call i32 @close(i32 %26)
%35 = getelementptr inbounds i8*, i8** %1, i64 3
%36 = load i8*, i8** %35
%37 = getelementptr inbounds i8*, i8** %1, i64 5
%38 = load i8*, i8** %37
%39 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %36, i8* %36, i8* %38, i8* null)
%40 = load i32, i32* @stderr
%41 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %14
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%46 = call i32 @exit(i32 0)
unreachable
47: ; preds = %14
%48 = call i32 (...) @fork()
switch i32 %48, label %67 [
i32 0, label %49
i32 -1, label %63
]
49: ; preds = %47
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @dup2(i32 %51, i32 1)
%53 = load i32, i32* %7
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %50
%56 = call i32 @close(i32 %55)
%57 = getelementptr inbounds i8*, i8** %1, i64 1
%58 = load i8*, i8** %57
%59 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %58, i8* %58, i8* null)
%60 = load i32, i32* @stderr
%61 = call i32 @fprintf(i32 %60, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 0)
unreachable
63: ; preds = %47
%64 = load i32, i32* @stderr
%65 = call i32 @fprintf(i32 %64, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%66 = call i32 @exit(i32 0)
unreachable
67: ; preds = %47
%68 = call i32 @wait(i32* %3)
%69 = icmp eq i32 %68, %15
br i1 %69, label %70, label %74
70: ; preds = %67
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%73 = call i32 @exit(i32 0)
unreachable
74: ; preds = %67
%75 = call i32 (...) @fork()
switch i32 %75, label %106 [
i32 0, label %76
i32 -1, label %102
]
76: ; preds = %74
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%78 = load i32, i32* %77
%79 = call i32 @dup2(i32 %78, i32 1)
%80 = load i32, i32* %7
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %77
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds i8*, i8** %1, i64 4
%85 = load i8*, i8** %84
%86 = load i32, i32* @O_RDONLY
%87 = call i32 @open(i8* %85, i32 %86)
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %93
89: ; preds = %76
%90 = load i32, i32* @stderr
%91 = call i32 @fprintf(i32 %90, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%92 = call i32 @exit(i32 0)
unreachable
93: ; preds = %76
%94 = call i32 @dup2(i32 %87, i32 0)
%95 = call i32 @close(i32 %87)
%96 = getelementptr inbounds i8*, i8** %1, i64 2
%97 = load i8*, i8** %96
%98 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* %97, i8* %97, i8* null)
%99 = load i32, i32* @stderr
%100 = call i32 @fprintf(i32 %99, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%101 = call i32 @exit(i32 0)
unreachable
102: ; preds = %74
%103 = load i32, i32* @stderr
%104 = call i32 @fprintf(i32 %103, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%105 = call i32 @exit(i32 0)
unreachable
106: ; preds = %74
%107 = load i32, i32* %7
%108 = call i32 @close(i32 %107)
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%110 = load i32, i32* %109
%111 = call i32 @close(i32 %110)
%112 = call i32 @wait(i32* %3)
%113 = call i32 @wait(i32* %3)
ret i32 0
}