#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  int cname, status, pid, i, j, max_count = 0;
  char app_name[20][100];
  int fd[20][2];
  while ((cname = getopt(argc, argv, ":p:")) != -1) {
    switch (cname) {
    case 'p':
      sprintf(app_name[max_count], "%s", optarg);
      max_count++;
    }
  }
  if (max_count > 20) {
    printf("max allowed parms is %d\n", 20);
    exit(2);
  }
  for (i = 0; i < max_count; i++) {
    if (pipe(fd[i]) == -1) {
      perror("pipe error");
      exit(1);
    }
  }
  for (i = 0; i < max_count; i++) {
    switch (pid = fork()) {
    case -1:
      perror("fork error");
      exit(1);
    case 0:
      if (i != 0) {
        if (dup2(fd[i - 1][0], STDIN_FILENO) == -1) {
          perror("dup2 error");
          exit(1);
        }
      }
      if (i != (max_count - 1)) {
        if (dup2(fd[i][1], STDOUT_FILENO) == -1) {
          perror("dup2 error");
          exit(1);
        }
      }
      for (j = 0; j < max_count; j++) {
        close(fd[j][0]);
        close(fd[j][1]);
      }
      execlp(app_name[i], app_name[i], NULL);
      perror("execlp error");
      exit(1);
    }
  }
  for (i = 0; i < max_count; i++) {
    close(fd[i][0]);
    close(fd[i][1]);
  }
  for (i = 0; i < max_count; i++) {
    wait(&status);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8b0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe22(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1236 <main+0x86>
mov    -0x14(%rbp),%eax
sub    $0x70,%eax
jne    1231 <main+0x81>
jmp    1200 <main+0x50>
movslq -0x28(%rbp),%rax
lea    -0x800(%rbp),%rdi
imul   $0x64,%rax,%rax
add    %rax,%rdi
mov    0x2ddf(%rip),%rax
mov    (%rax),%rdx
lea    0xde1(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    11d0 <main+0x20>
cmpl   $0x14,-0x28(%rbp)
jle    125b <main+0xab>
lea    0xdc0(%rip),%rdi
mov    $0x14,%esi
call   1040 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    12b7 <main+0x107>
movslq -0x20(%rbp),%rax
lea    -0x8a0(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    12a4 <main+0xf4>
lea    0xd8b(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    12a9 <main+0xf9>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1262 <main+0xb2>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1443 <main+0x293>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,-0x1c(%rbp)
mov    %eax,%ecx
mov    %ecx,-0x8a4(%rbp)
sub    $0xffffffff,%eax
je     12fd <main+0x14d>
jmp    12ea <main+0x13a>
mov    -0x8a4(%rbp),%eax
test   %eax,%eax
je     1313 <main+0x163>
jmp    1430 <main+0x280>
lea    0xd27(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     135e <main+0x1ae>
mov    -0x20(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x8a0(%rbp,%rax,8),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1359 <main+0x1a9>
lea    0xcec(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    135e <main+0x1ae>
mov    -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
je     13ac <main+0x1fc>
movslq -0x20(%rbp),%rax
mov    -0x89c(%rbp,%rax,8),%edi
mov    0x2c67(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
cmp    $0xffffffff,%eax
jne    13a7 <main+0x1f7>
lea    0xc9e(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    13ac <main+0x1fc>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    13ed <main+0x23d>
movslq -0x24(%rbp),%rax
mov    -0x8a0(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x24(%rbp),%rax
mov    -0x89c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    13b3 <main+0x203>
movslq -0x20(%rbp),%rax
lea    -0x800(%rbp),%rdi
imul   $0x64,%rax,%rax
add    %rax,%rdi
movslq -0x20(%rbp),%rax
lea    -0x800(%rbp),%rsi
imul   $0x64,%rax,%rax
add    %rax,%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <execlp@plt>
lea    0xc20(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
jmp    1435 <main+0x285>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    12be <main+0x10e>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1484 <main+0x2d4>
movslq -0x20(%rbp),%rax
mov    -0x8a0(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x20(%rbp),%rax
mov    -0x89c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    144a <main+0x29a>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    14ae <main+0x2fe>
lea    -0x18(%rbp),%rdi
call   10c0 <wait@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    148b <main+0x2db>
xor    %eax,%eax
add    $0x8b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x880,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %r15d,%r15d
lea    0xe32(%rip),%r14
mov    0x2e23(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     1218 <main+0x68>
cmp    $0x70,%eax
jne    11e0 <main+0x30>
mov    %r15d,%eax
imul   $0x64,%rax,%rax
lea    (%rsp,%rax,1),%rdi
add    $0xb0,%rdi
mov    (%r12),%rsi
call   1030 <strcpy@plt>
add    $0x1,%r15
jmp    11e0 <main+0x30>
cmp    $0x14,%r15d
ja     139e <main+0x1ee>
test   %r15d,%r15d
je     12ee <main+0x13e>
lea    0x10(%rsp),%rbx
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     1300 <main+0x150>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    1240 <main+0x90>
test   %r15d,%r15d
je     12ee <main+0x13e>
lea    0xb0(%rsp),%rbx
xor    %ebp,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     130c <main+0x15c>
cmp    $0xffffffff,%eax
je     134f <main+0x19f>
add    $0x64,%rbx
add    $0x1,%rbp
cmp    %ebp,%r15d
jne    1270 <main+0xc0>
test   %r15d,%r15d
je     12ee <main+0x13e>
lea    0x14(%rsp),%rbx
mov    %r15,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    -0x4(%rbx),%edi
call   1060 <close@plt>
mov    (%rbx),%edi
call   1060 <close@plt>
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
jne    12b0 <main+0x100>
test   %r15d,%r15d
je     12ee <main+0x13e>
lea    0xc(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   10c0 <wait@plt>
add    $0xffffffff,%r15d
jne    12e0 <main+0x130>
xor    %eax,%eax
add    $0x880,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd16(%rip),%rdi
jmp    138f <main+0x1df>
test   %ebp,%ebp
je     1327 <main+0x177>
mov    0x8(%rsp,%rbp,8),%edi
mov    0x2cb5(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
je     1346 <main+0x196>
lea    0x1(%rbp),%eax
cmp    %r15d,%eax
je     1358 <main+0x1a8>
mov    0x14(%rsp,%rbp,8),%edi
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
call   1040 <dup2@plt>
cmp    $0xffffffff,%eax
jne    1358 <main+0x1a8>
lea    0xce6(%rip),%rdi
jmp    138f <main+0x1df>
lea    0xcd2(%rip),%rdi
jmp    138f <main+0x1df>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbp,8),%edi
call   1060 <close@plt>
mov    0x14(%rsp,%rbp,8),%edi
call   1060 <close@plt>
add    $0x1,%rbp
cmp    %rbp,%r15
jne    1360 <main+0x1b0>
mov    %rbx,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
call   10b0 <execlp@plt>
lea    0xcaf(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xc5f(%rip),%rdi
mov    $0x14,%esi
call   1050 <printf@plt>
mov    $0x2,%edi
call   10a0 <exit@plt>

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

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