#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__ ECHILD;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ usleep(int);
scalar_t__ waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int write(int, char *, int);
int main(void) {
  pid_t childPid;
  int retval = -1;
  int i = 0;
  int fdArray[4][2];
  char chr;
  for (i = 0; i < 4; i++) {
    if (pipe(fdArray[i]) == -1) {
      perror("pipe creation");
      exit(EXIT_FAILURE);
    }
  }
  for (i = 0; i < 5; i++) {
    childPid = fork();
    if (childPid < 0) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (childPid == 0) {
      if (i == 4) {
        for (i = 0; i < 3; i++) {
          close(fdArray[i][0]);
          close(fdArray[i][1]);
        }
        close(fdArray[3][0]);
        if (write(fdArray[3][1], "A", 1) == -1) {
          perror("write");
          exit(EXIT_FAILURE);
        }
        close(fdArray[3][1]);
        exit(EXIT_SUCCESS);
      } else if (i == 3) {
        for (i = 0; i < 2; i++) {
          close(fdArray[i][0]);
          close(fdArray[i][1]);
        }
        close(fdArray[2][0]);
        close(fdArray[3][1]);
        while ((retval = read(fdArray[3][0], &chr, 1)) != 0) {
          if (retval == -1) {
            perror("read");
            exit(EXIT_FAILURE);
          }
          chr = chr + 1;
          write(fdArray[2][1], &chr, 1);
        }
        close(fdArray[3][0]);
        close(fdArray[2][1]);
        exit(EXIT_SUCCESS);
      } else if (i == 2) {
        close(fdArray[0][0]);
        close(fdArray[0][1]);
        close(fdArray[1][0]);
        close(fdArray[2][1]);
        close(fdArray[3][0]);
        close(fdArray[3][1]);
        while ((retval = read(fdArray[2][0], &chr, 1)) != 0) {
          if (retval == -1) {
            perror("read");
            exit(EXIT_FAILURE);
          }
          chr = chr + 1;
          write(fdArray[1][1], &chr, 1);
        }
        close(fdArray[1][1]);
        close(fdArray[2][0]);
        exit(EXIT_SUCCESS);
      } else if (i == 1) {
        for (i = 2; i < 4; i++) {
          close(fdArray[i][0]);
          close(fdArray[i][1]);
        }
        close(fdArray[0][0]);
        close(fdArray[1][1]);
        while ((retval = read(fdArray[1][0], &chr, 1)) != 0) {
          if (retval == -1) {
            perror("read");
            exit(EXIT_FAILURE);
          }
          chr = chr + 1;
          write(fdArray[0][1], &chr, 1);
        }
        close(fdArray[0][1]);
        close(fdArray[1][0]);
        exit(EXIT_SUCCESS);
      } else {
        for (i = 1; i < 4; i++) {
          close(fdArray[i][0]);
          close(fdArray[i][1]);
        }
        close(fdArray[0][1]);
        while ((retval = read(fdArray[0][0], &chr, 1)) != 0) {
          if (retval == -1) {
            perror("read");
            exit(EXIT_FAILURE);
          }
          printf("The 1st child is displaying character to stdout from the "
                 "pipeline\n");
          write(STDOUT_FILENO, &chr, 1);
          printf("\n");
        }
        close(fdArray[0][0]);
        exit(EXIT_SUCCESS);
      }
    }
    printf("Child created. pid = %d\n", childPid);
    usleep(500000);
  }
  for (i = 0; i < 4; i++) {
    close(fdArray[i][0]);
    close(fdArray[i][1]);
  }
  while ((childPid = waitpid(-1, NULL, 0))) {
    if (errno == ECHILD) {
      break;
    }
  }
  printf("All child processes have terminated\n");
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1218 <main+0x78>
movslq -0x18(%rbp),%rax
lea    -0x40(%rbp),%rdi
shl    $0x3,%rax
add    %rax,%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1205 <main+0x65>
lea    0xe0e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    120a <main+0x6a>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11c4 <main+0x24>
movl   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x18(%rbp)
jge    1653 <main+0x4b3>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    1259 <main+0xb9>
lea    0xdc8(%rip),%rdi
call   1090 <perror@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    1629 <main+0x489>
cmpl   $0x4,-0x18(%rbp)
jne    12fc <main+0x15c>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3,-0x18(%rbp)
jge    12a7 <main+0x107>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x18(%rbp),%rax
mov    -0x3c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1275 <main+0xd5>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
lea    0xd5a(%rip),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0xffffffff,%eax
jne    12e6 <main+0x146>
lea    0xd42(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x3,-0x18(%rbp)
jne    13ce <main+0x22e>
movl   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x18(%rbp)
jge    133f <main+0x19f>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x18(%rbp),%rax
mov    -0x3c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    130d <main+0x16d>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     13b0 <main+0x210>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1390 <main+0x1f0>
lea    0xc9e(%rip),%rdi
call   1090 <perror@plt>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movsbl -0x41(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x41(%rbp)
mov    -0x2c(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    134f <main+0x1af>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    0x2bf9(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x2,-0x18(%rbp)
jne    1487 <main+0x2e7>
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    -0x2c(%rbp),%edi
call   1050 <close@plt>
mov    -0x28(%rbp),%edi
call   1050 <close@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1469 <main+0x2c9>
cmpl   $0xffffffff,-0x14(%rbp)
jne    1449 <main+0x2a9>
lea    0xbe5(%rip),%rdi
call   1090 <perror@plt>
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movsbl -0x41(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x41(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    1408 <main+0x268>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x30(%rbp),%edi
call   1050 <close@plt>
mov    0x2b40(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x1,-0x18(%rbp)
jne    1559 <main+0x3b9>
movl   $0x2,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    14ca <main+0x32a>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x18(%rbp),%rax
mov    -0x3c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1498 <main+0x2f8>
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
mov    -0x34(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     153b <main+0x39b>
cmpl   $0xffffffff,-0x14(%rbp)
jne    151b <main+0x37b>
lea    0xb13(%rip),%rdi
call   1090 <perror@plt>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movsbl -0x41(%rbp),%eax
add    $0x1,%eax
mov    %al,-0x41(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
jmp    14da <main+0x33a>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    -0x38(%rbp),%edi
call   1050 <close@plt>
mov    0x2a6e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
movl   $0x1,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    1592 <main+0x3f2>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x18(%rbp),%rax
mov    -0x3c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1560 <main+0x3c0>
mov    -0x3c(%rbp),%edi
call   1050 <close@plt>
mov    -0x40(%rbp),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1070 <read@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     1613 <main+0x473>
cmpl   $0xffffffff,-0x14(%rbp)
jne    15db <main+0x43b>
lea    0xa53(%rip),%rdi
call   1090 <perror@plt>
mov    0x29fc(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    0xa3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2a00(%rip),%rax
mov    (%rax),%edi
lea    -0x41(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
lea    0xa73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    159a <main+0x3fa>
mov    -0x40(%rbp),%edi
call   1050 <close@plt>
mov    0x299e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rsi
lea    0xa2f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x7a120,%edi
call   10c0 <usleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    121f <main+0x7f>
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0x18(%rbp)
jge    168c <main+0x4ec>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
call   1050 <close@plt>
movslq -0x18(%rbp),%rax
mov    -0x3c(%rbp,%rax,8),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    165a <main+0x4ba>
jmp    1691 <main+0x4f1>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1080 <waitpid@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     16d3 <main+0x533>
mov    0x2922(%rip),%rax
mov    (%rax),%rax
mov    0x2908(%rip),%rcx
cmp    (%rcx),%rax
jne    16ce <main+0x52e>
jmp    16d3 <main+0x533>
jmp    1691 <main+0x4f1>
lea    0x9a2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x28d8(%rip),%rax
mov    (%rax),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
lea    0x10(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
je     13a6 <main+0x1e6>
lea    0x18(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
je     13a6 <main+0x1e6>
lea    0x20(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
je     13a6 <main+0x1e6>
lea    0x28(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
je     13a6 <main+0x1e6>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     139a <main+0x1da>
je     13b2 <main+0x1f2>
lea    0xdee(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10e0 <usleep@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     139a <main+0x1da>
je     1456 <main+0x296>
lea    0xdbd(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10e0 <usleep@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     139a <main+0x1da>
je     14da <main+0x31a>
lea    0xd8c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10e0 <usleep@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     139a <main+0x1da>
je     155a <main+0x39a>
lea    0xd5b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10e0 <usleep@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %rax,%rax
js     139a <main+0x1da>
je     15df <main+0x41f>
lea    0xd2a(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x7a120,%edi
call   10e0 <usleep@plt>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
mov    0x2c7f(%rip),%r14
mov    0x2c68(%rip),%rbx
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10a0 <waitpid@plt>
test   %rax,%rax
je     137b <main+0x1bb>
mov    (%r14),%rax
cmp    (%rbx),%rax
jne    1360 <main+0x1a0>
lea    0xcb7(%rip),%rdi
call   1040 <puts@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xc6d(%rip),%rdi
jmp    163f <main+0x47f>
lea    0xc53(%rip),%rdi
jmp    163f <main+0x47f>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
lea    0xf(%rsp),%rbx
lea    0xc60(%rip),%r14
mov    0x2bec(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x10(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1652 <main+0x492>
cmp    $0xffffffff,%eax
je     15d6 <main+0x416>
mov    %r14,%rdi
call   1040 <puts@plt>
mov    (%r15),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    1410 <main+0x250>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1658 <main+0x498>
cmp    $0xffffffff,%eax
je     15d6 <main+0x416>
addb   $0x1,0xf(%rsp)
mov    0x14(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    14a0 <main+0x2e0>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x20(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1667 <main+0x4a7>
cmp    $0xffffffff,%eax
je     15d6 <main+0x416>
addb   $0x1,0xf(%rsp)
mov    0x1c(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    1520 <main+0x360>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
lea    0xf(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x28(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1676 <main+0x4b6>
cmp    $0xffffffff,%eax
je     15d6 <main+0x416>
addb   $0x1,0xf(%rsp)
mov    0x24(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <write@plt>
jmp    15a0 <main+0x3e0>
lea    0xa3e(%rip),%rdi
jmp    163f <main+0x47f>
mov    0x10(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
mov    0x20(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x2c(%rsp),%edi
lea    0x9ea(%rip),%rsi
mov    $0x1,%edx
call   1050 <write@plt>
cmp    $0xffffffff,%eax
jne    1685 <main+0x4c5>
lea    0x9d6(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2985(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x10(%rsp),%edi
jmp    1689 <main+0x4c9>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
jmp    1689 <main+0x4c9>
mov    0x1c(%rsp),%edi
call   1070 <close@plt>
mov    0x20(%rsp),%edi
jmp    1689 <main+0x4c9>
mov    0x28(%rsp),%edi
call   1070 <close@plt>
mov    0x24(%rsp),%edi
jmp    1689 <main+0x4c9>
mov    0x2c(%rsp),%edi
call   1070 <close@plt>
mov    0x292b(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"pipe creation\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [2 x i8] c"A\00"
@.str.3 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [5 x i8] c"read\00"
@.str.5 = [67 x i8] c"The 1st child is displaying character to stdout from the pipeline\0A\00"
@STDOUT_FILENO = global i32 0
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [25 x i8] c"Child created. pid = %d\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@.str.8 = [37 x i8] c"All child processes have terminated\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32
%4 = alloca i32
%5 = alloca [4 x [2 x i32]]
%6 = alloca i8
store i32 0, i32* %1
store i32 -1, i32* %3
store i32 0, i32* %4
store i32 0, i32* %4
br label %7
7: ; preds = %22, %0
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 4
br i1 %9, label %10, label %25
10: ; preds = %7
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %12
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %13, i64 0, i64 0
%15 = call i32 @pipe(i32* %14)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %21
17: ; preds = %10
%18 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %10
br label %22
22: ; preds = %21
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %7
25: ; preds = %7
store i32 0, i32* %4
br label %26
26: ; preds = %329, %25
%27 = load i32, i32* %4
%28 = icmp slt i32 %27, 5
br i1 %28, label %29, label %332
29: ; preds = %26
%30 = call i64 (...) @fork()
store i64 %30, i64* %2
%31 = load i64, i64* %2
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %29
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %29
%38 = load i64, i64* %2
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %325
40: ; preds = %37
%41 = load i32, i32* %4
%42 = icmp eq i32 %41, 4
br i1 %42, label %43, label %84
43: ; preds = %40
store i32 0, i32* %4
br label %44
44: ; preds = %60, %43
%45 = load i32, i32* %4
%46 = icmp slt i32 %45, 3
br i1 %46, label %47, label %63
47: ; preds = %44
%48 = load i32, i32* %4
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %49
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %50, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = load i32, i32* %4
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %55
%57 = getelementptr inbounds [2 x i32], [2 x i32]* %56, i64 0, i64 1
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
br label %60
60: ; preds = %47
%61 = load i32, i32* %4
%62 = add nsw i32 %61, 1
store i32 %62, i32* %4
br label %44
63: ; preds = %44
%64 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %64, i64 0, i64 0
%66 = load i32, i32* %65
%67 = call i32 @close(i32 %66)
%68 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %68, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @write(i32 %70, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %77
73: ; preds = %63
%74 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%75 = load i32, i32* @EXIT_FAILURE
%76 = call i32 @exit(i32 %75)
unreachable
77: ; preds = %63
%78 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%79 = getelementptr inbounds [2 x i32], [2 x i32]* %78, i64 0, i64 1
%80 = load i32, i32* %79
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %40
%85 = load i32, i32* %4
%86 = icmp eq i32 %85, 3
br i1 %86, label %87, label %149
87: ; preds = %84
store i32 0, i32* %4
br label %88
88: ; preds = %104, %87
%89 = load i32, i32* %4
%90 = icmp slt i32 %89, 2
br i1 %90, label %91, label %107
91: ; preds = %88
%92 = load i32, i32* %4
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %93
%95 = getelementptr inbounds [2 x i32], [2 x i32]* %94, i64 0, i64 0
%96 = load i32, i32* %95
%97 = call i32 @close(i32 %96)
%98 = load i32, i32* %4
%99 = sext i32 %98 to i64
%100 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %99
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %100, i64 0, i64 1
%102 = load i32, i32* %101
%103 = call i32 @close(i32 %102)
br label %104
104: ; preds = %91
%105 = load i32, i32* %4
%106 = add nsw i32 %105, 1
store i32 %106, i32* %4
br label %88
107: ; preds = %88
%108 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%109 = getelementptr inbounds [2 x i32], [2 x i32]* %108, i64 0, i64 0
%110 = load i32, i32* %109
%111 = call i32 @close(i32 %110)
%112 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%113 = getelementptr inbounds [2 x i32], [2 x i32]* %112, i64 0, i64 1
%114 = load i32, i32* %113
%115 = call i32 @close(i32 %114)
br label %116
116: ; preds = %129, %107
%117 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%118 = getelementptr inbounds [2 x i32], [2 x i32]* %117, i64 0, i64 0
%119 = load i32, i32* %118
%120 = call i32 @read(i32 %119, i8* %6, i32 1)
store i32 %120, i32* %3
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %138
122: ; preds = %116
%123 = load i32, i32* %3
%124 = icmp eq i32 %123, -1
br i1 %124, label %125, label %129
125: ; preds = %122
%126 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%127 = load i32, i32* @EXIT_FAILURE
%128 = call i32 @exit(i32 %127)
unreachable
129: ; preds = %122
%130 = load i8, i8* %6
%131 = sext i8 %130 to i32
%132 = add nsw i32 %131, 1
%133 = trunc i32 %132 to i8
store i8 %133, i8* %6
%134 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%135 = getelementptr inbounds [2 x i32], [2 x i32]* %134, i64 0, i64 1
%136 = load i32, i32* %135
%137 = call i32 @write(i32 %136, i8* %6, i32 1)
br label %116
138: ; preds = %116
%139 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%140 = getelementptr inbounds [2 x i32], [2 x i32]* %139, i64 0, i64 0
%141 = load i32, i32* %140
%142 = call i32 @close(i32 %141)
%143 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%144 = getelementptr inbounds [2 x i32], [2 x i32]* %143, i64 0, i64 1
%145 = load i32, i32* %144
%146 = call i32 @close(i32 %145)
%147 = load i32, i32* @EXIT_SUCCESS
%148 = call i32 @exit(i32 %147)
unreachable
149: ; preds = %84
%150 = load i32, i32* %4
%151 = icmp eq i32 %150, 2
br i1 %151, label %152, label %210
152: ; preds = %149
%153 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%154 = getelementptr inbounds [2 x i32], [2 x i32]* %153, i64 0, i64 0
%155 = load i32, i32* %154
%156 = call i32 @close(i32 %155)
%157 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%158 = getelementptr inbounds [2 x i32], [2 x i32]* %157, i64 0, i64 1
%159 = load i32, i32* %158
%160 = call i32 @close(i32 %159)
%161 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%162 = getelementptr inbounds [2 x i32], [2 x i32]* %161, i64 0, i64 0
%163 = load i32, i32* %162
%164 = call i32 @close(i32 %163)
%165 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%166 = getelementptr inbounds [2 x i32], [2 x i32]* %165, i64 0, i64 1
%167 = load i32, i32* %166
%168 = call i32 @close(i32 %167)
%169 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%170 = getelementptr inbounds [2 x i32], [2 x i32]* %169, i64 0, i64 0
%171 = load i32, i32* %170
%172 = call i32 @close(i32 %171)
%173 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 3
%174 = getelementptr inbounds [2 x i32], [2 x i32]* %173, i64 0, i64 1
%175 = load i32, i32* %174
%176 = call i32 @close(i32 %175)
br label %177
177: ; preds = %190, %152
%178 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%179 = getelementptr inbounds [2 x i32], [2 x i32]* %178, i64 0, i64 0
%180 = load i32, i32* %179
%181 = call i32 @read(i32 %180, i8* %6, i32 1)
store i32 %181, i32* %3
%182 = icmp ne i32 %181, 0
br i1 %182, label %183, label %199
183: ; preds = %177
%184 = load i32, i32* %3
%185 = icmp eq i32 %184, -1
br i1 %185, label %186, label %190
186: ; preds = %183
%187 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%188 = load i32, i32* @EXIT_FAILURE
%189 = call i32 @exit(i32 %188)
unreachable
190: ; preds = %183
%191 = load i8, i8* %6
%192 = sext i8 %191 to i32
%193 = add nsw i32 %192, 1
%194 = trunc i32 %193 to i8
store i8 %194, i8* %6
%195 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%196 = getelementptr inbounds [2 x i32], [2 x i32]* %195, i64 0, i64 1
%197 = load i32, i32* %196
%198 = call i32 @write(i32 %197, i8* %6, i32 1)
br label %177
199: ; preds = %177
%200 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%201 = getelementptr inbounds [2 x i32], [2 x i32]* %200, i64 0, i64 1
%202 = load i32, i32* %201
%203 = call i32 @close(i32 %202)
%204 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 2
%205 = getelementptr inbounds [2 x i32], [2 x i32]* %204, i64 0, i64 0
%206 = load i32, i32* %205
%207 = call i32 @close(i32 %206)
%208 = load i32, i32* @EXIT_SUCCESS
%209 = call i32 @exit(i32 %208)
unreachable
210: ; preds = %149
%211 = load i32, i32* %4
%212 = icmp eq i32 %211, 1
br i1 %212, label %213, label %275
213: ; preds = %210
store i32 2, i32* %4
br label %214
214: ; preds = %230, %213
%215 = load i32, i32* %4
%216 = icmp slt i32 %215, 4
br i1 %216, label %217, label %233
217: ; preds = %214
%218 = load i32, i32* %4
%219 = sext i32 %218 to i64
%220 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %219
%221 = getelementptr inbounds [2 x i32], [2 x i32]* %220, i64 0, i64 0
%222 = load i32, i32* %221
%223 = call i32 @close(i32 %222)
%224 = load i32, i32* %4
%225 = sext i32 %224 to i64
%226 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %225
%227 = getelementptr inbounds [2 x i32], [2 x i32]* %226, i64 0, i64 1
%228 = load i32, i32* %227
%229 = call i32 @close(i32 %228)
br label %230
230: ; preds = %217
%231 = load i32, i32* %4
%232 = add nsw i32 %231, 1
store i32 %232, i32* %4
br label %214
233: ; preds = %214
%234 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%235 = getelementptr inbounds [2 x i32], [2 x i32]* %234, i64 0, i64 0
%236 = load i32, i32* %235
%237 = call i32 @close(i32 %236)
%238 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%239 = getelementptr inbounds [2 x i32], [2 x i32]* %238, i64 0, i64 1
%240 = load i32, i32* %239
%241 = call i32 @close(i32 %240)
br label %242
242: ; preds = %255, %233
%243 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%244 = getelementptr inbounds [2 x i32], [2 x i32]* %243, i64 0, i64 0
%245 = load i32, i32* %244
%246 = call i32 @read(i32 %245, i8* %6, i32 1)
store i32 %246, i32* %3
%247 = icmp ne i32 %246, 0
br i1 %247, label %248, label %264
248: ; preds = %242
%249 = load i32, i32* %3
%250 = icmp eq i32 %249, -1
br i1 %250, label %251, label %255
251: ; preds = %248
%252 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%253 = load i32, i32* @EXIT_FAILURE
%254 = call i32 @exit(i32 %253)
unreachable
255: ; preds = %248
%256 = load i8, i8* %6
%257 = sext i8 %256 to i32
%258 = add nsw i32 %257, 1
%259 = trunc i32 %258 to i8
store i8 %259, i8* %6
%260 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%261 = getelementptr inbounds [2 x i32], [2 x i32]* %260, i64 0, i64 1
%262 = load i32, i32* %261
%263 = call i32 @write(i32 %262, i8* %6, i32 1)
br label %242
264: ; preds = %242
%265 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%266 = getelementptr inbounds [2 x i32], [2 x i32]* %265, i64 0, i64 1
%267 = load i32, i32* %266
%268 = call i32 @close(i32 %267)
%269 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 1
%270 = getelementptr inbounds [2 x i32], [2 x i32]* %269, i64 0, i64 0
%271 = load i32, i32* %270
%272 = call i32 @close(i32 %271)
%273 = load i32, i32* @EXIT_SUCCESS
%274 = call i32 @exit(i32 %273)
unreachable
275: ; preds = %210
store i32 1, i32* %4
br label %276
276: ; preds = %292, %275
%277 = load i32, i32* %4
%278 = icmp slt i32 %277, 4
br i1 %278, label %279, label %295
279: ; preds = %276
%280 = load i32, i32* %4
%281 = sext i32 %280 to i64
%282 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %281
%283 = getelementptr inbounds [2 x i32], [2 x i32]* %282, i64 0, i64 0
%284 = load i32, i32* %283
%285 = call i32 @close(i32 %284)
%286 = load i32, i32* %4
%287 = sext i32 %286 to i64
%288 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %287
%289 = getelementptr inbounds [2 x i32], [2 x i32]* %288, i64 0, i64 1
%290 = load i32, i32* %289
%291 = call i32 @close(i32 %290)
br label %292
292: ; preds = %279
%293 = load i32, i32* %4
%294 = add nsw i32 %293, 1
store i32 %294, i32* %4
br label %276
295: ; preds = %276
%296 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%297 = getelementptr inbounds [2 x i32], [2 x i32]* %296, i64 0, i64 1
%298 = load i32, i32* %297
%299 = call i32 @close(i32 %298)
br label %300
300: ; preds = %313, %295
%301 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%302 = getelementptr inbounds [2 x i32], [2 x i32]* %301, i64 0, i64 0
%303 = load i32, i32* %302
%304 = call i32 @read(i32 %303, i8* %6, i32 1)
store i32 %304, i32* %3
%305 = icmp ne i32 %304, 0
br i1 %305, label %306, label %318
306: ; preds = %300
%307 = load i32, i32* %3
%308 = icmp eq i32 %307, -1
br i1 %308, label %309, label %313
309: ; preds = %306
%310 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%311 = load i32, i32* @EXIT_FAILURE
%312 = call i32 @exit(i32 %311)
unreachable
313: ; preds = %306
%314 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.5, i64 0, i64 0))
%315 = load i32, i32* @STDOUT_FILENO
%316 = call i32 @write(i32 %315, i8* %6, i32 1)
%317 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
br label %300
318: ; preds = %300
%319 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 0
%320 = getelementptr inbounds [2 x i32], [2 x i32]* %319, i64 0, i64 0
%321 = load i32, i32* %320
%322 = call i32 @close(i32 %321)
%323 = load i32, i32* @EXIT_SUCCESS
%324 = call i32 @exit(i32 %323)
unreachable
325: ; preds = %37
%326 = load i64, i64* %2
%327 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %326)
%328 = call i32 @usleep(i32 500000)
br label %329
329: ; preds = %325
%330 = load i32, i32* %4
%331 = add nsw i32 %330, 1
store i32 %331, i32* %4
br label %26
332: ; preds = %26
store i32 0, i32* %4
br label %333
333: ; preds = %349, %332
%334 = load i32, i32* %4
%335 = icmp slt i32 %334, 4
br i1 %335, label %336, label %352
336: ; preds = %333
%337 = load i32, i32* %4
%338 = sext i32 %337 to i64
%339 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %338
%340 = getelementptr inbounds [2 x i32], [2 x i32]* %339, i64 0, i64 0
%341 = load i32, i32* %340
%342 = call i32 @close(i32 %341)
%343 = load i32, i32* %4
%344 = sext i32 %343 to i64
%345 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %5, i64 0, i64 %344
%346 = getelementptr inbounds [2 x i32], [2 x i32]* %345, i64 0, i64 1
%347 = load i32, i32* %346
%348 = call i32 @close(i32 %347)
br label %349
349: ; preds = %336
%350 = load i32, i32* %4
%351 = add nsw i32 %350, 1
store i32 %351, i32* %4
br label %333
352: ; preds = %333
br label %353
353: ; preds = %361, %352
%354 = call i64 @waitpid(i32 -1, i32* null, i32 0)
store i64 %354, i64* %2
%355 = icmp ne i64 %354, 0
br i1 %355, label %356, label %362
356: ; preds = %353
%357 = load i64, i64* @errno
%358 = load i64, i64* @ECHILD
%359 = icmp eq i64 %357, %358
br i1 %359, label %360, label %361
360: ; preds = %356
br label %362
361: ; preds = %356
br label %353
362: ; preds = %360, %353
%363 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.8, i64 0, i64 0))
%364 = load i32, i32* @EXIT_SUCCESS
ret i32 %364
}

LLVM IR (-O2):
@.str = [14 x i8] c"pipe creation\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@.str.2 = [2 x i8] c"A\00"
@.str.3 = [6 x i8] c"write\00"
@EXIT_SUCCESS = global i32 0
@.str.4 = [5 x i8] c"read\00"
@STDOUT_FILENO = global i32 0
@.str.7 = [25 x i8] c"Child created. pid = %d\0A\00"
@errno = global i64 0
@ECHILD = global i64 0
@str = [36 x i8] c"All child processes have terminated\00"
@str.9 = [66 x i8] c"The 1st child is displaying character to stdout from the pipeline\00"
define i32 @main() {
%1 = alloca [4 x [2 x i32]]
%2 = alloca i8
%3 = bitcast [4 x [2 x i32]]* %1 to i8*
%4 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = icmp eq i32 %5, -1
br i1 %6, label %22, label %7
7: ; preds = %0
%8 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 0
%9 = call i32 @pipe(i32* %8)
%10 = icmp eq i32 %9, -1
br i1 %10, label %22, label %11
11: ; preds = %7
%12 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 0
%13 = call i32 @pipe(i32* %12)
%14 = icmp eq i32 %13, -1
br i1 %14, label %22, label %15
15: ; preds = %11
%16 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = icmp eq i32 %17, -1
br i1 %18, label %22, label %19
19: ; preds = %15
%20 = call i64 (...) @fork()
%21 = icmp slt i64 %20, 0
br i1 %21, label %26, label %30
22: ; preds = %15, %11, %7, %0
%23 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %228, %221, %214, %207, %19
%27 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = call i32 @exit(i32 %28)
unreachable
30: ; preds = %19
%31 = icmp eq i64 %20, 0
br i1 %31, label %88, label %207
32: ; preds = %212
%33 = load i32, i32* %12
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %16
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%41 = load i32, i32* %40
%42 = call i32 @close(i32 %41)
%43 = load i32, i32* %4
%44 = call i32 @close(i32 %43)
%45 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
%48 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
br label %171
49: ; preds = %226
%50 = load i32, i32* %4
%51 = call i32 @close(i32 %50)
%52 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = load i32, i32* %8
%56 = call i32 @close(i32 %55)
%57 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
%58 = load i32, i32* %57
%59 = call i32 @close(i32 %58)
%60 = load i32, i32* %12
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
br label %116
66: ; preds = %233
%67 = load i32, i32* %4
%68 = call i32 @close(i32 %67)
%69 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
%70 = load i32, i32* %69
%71 = call i32 @close(i32 %70)
%72 = load i32, i32* %8
%73 = call i32 @close(i32 %72)
%74 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
%75 = load i32, i32* %74
%76 = call i32 @close(i32 %75)
%77 = load i32, i32* %12
%78 = call i32 @close(i32 %77)
%79 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
%80 = load i32, i32* %79
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %16
%83 = call i32 @close(i32 %82)
%84 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%85 = load i32, i32* %84
%86 = call i32 @write(i32 %85, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 1)
%87 = icmp eq i32 %86, -1
br i1 %87, label %107, label %111
88: ; preds = %30
%89 = load i32, i32* %8
%90 = call i32 @close(i32 %89)
%91 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
%92 = load i32, i32* %91
%93 = call i32 @close(i32 %92)
%94 = load i32, i32* %12
%95 = call i32 @close(i32 %94)
%96 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
%97 = load i32, i32* %96
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %16
%100 = call i32 @close(i32 %99)
%101 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%102 = load i32, i32* %101
%103 = call i32 @close(i32 %102)
%104 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
%105 = load i32, i32* %104
%106 = call i32 @close(i32 %105)
br label %190
107: ; preds = %66
%108 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%109 = load i32, i32* @EXIT_FAILURE
%110 = call i32 @exit(i32 %109)
unreachable
111: ; preds = %66
%112 = load i32, i32* %84
%113 = call i32 @close(i32 %112)
%114 = load i32, i32* @EXIT_SUCCESS
%115 = call i32 @exit(i32 %114)
unreachable
116: ; preds = %123, %49
%117 = load i32, i32* %16
%118 = call i32 @read(i32 %117, i8* %2, i32 1)
switch i32 %118, label %123 [
i32 0, label %128
i32 -1, label %119
]
119: ; preds = %116
%120 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%121 = load i32, i32* @EXIT_FAILURE
%122 = call i32 @exit(i32 %121)
unreachable
123: ; preds = %116
%124 = load i8, i8* %2
%125 = add i8 %124, 1
store i8 %125, i8* %2
%126 = load i32, i32* %65
%127 = call i32 @write(i32 %126, i8* %2, i32 1)
br label %116
128: ; preds = %116
%129 = load i32, i32* %16
%130 = call i32 @close(i32 %129)
%131 = load i32, i32* %65
%132 = call i32 @close(i32 %131)
%133 = load i32, i32* @EXIT_SUCCESS
%134 = call i32 @exit(i32 %133)
unreachable
135: ; preds = %219
%136 = load i32, i32* %4
%137 = call i32 @close(i32 %136)
%138 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
%139 = load i32, i32* %138
%140 = call i32 @close(i32 %139)
%141 = load i32, i32* %8
%142 = call i32 @close(i32 %141)
%143 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
%144 = load i32, i32* %143
%145 = call i32 @close(i32 %144)
%146 = load i32, i32* %16
%147 = call i32 @close(i32 %146)
%148 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%149 = load i32, i32* %148
%150 = call i32 @close(i32 %149)
%151 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
br label %152
152: ; preds = %159, %135
%153 = load i32, i32* %12
%154 = call i32 @read(i32 %153, i8* %2, i32 1)
switch i32 %154, label %159 [
i32 0, label %164
i32 -1, label %155
]
155: ; preds = %152
%156 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%157 = load i32, i32* @EXIT_FAILURE
%158 = call i32 @exit(i32 %157)
unreachable
159: ; preds = %152
%160 = load i8, i8* %2
%161 = add i8 %160, 1
store i8 %161, i8* %2
%162 = load i32, i32* %151
%163 = call i32 @write(i32 %162, i8* %2, i32 1)
br label %152
164: ; preds = %152
%165 = load i32, i32* %151
%166 = call i32 @close(i32 %165)
%167 = load i32, i32* %12
%168 = call i32 @close(i32 %167)
%169 = load i32, i32* @EXIT_SUCCESS
%170 = call i32 @exit(i32 %169)
unreachable
171: ; preds = %178, %32
%172 = load i32, i32* %8
%173 = call i32 @read(i32 %172, i8* %2, i32 1)
switch i32 %173, label %178 [
i32 0, label %183
i32 -1, label %174
]
174: ; preds = %171
%175 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%176 = load i32, i32* @EXIT_FAILURE
%177 = call i32 @exit(i32 %176)
unreachable
178: ; preds = %171
%179 = load i8, i8* %2
%180 = add i8 %179, 1
store i8 %180, i8* %2
%181 = load i32, i32* %48
%182 = call i32 @write(i32 %181, i8* %2, i32 1)
br label %171
183: ; preds = %171
%184 = load i32, i32* %48
%185 = call i32 @close(i32 %184)
%186 = load i32, i32* %8
%187 = call i32 @close(i32 %186)
%188 = load i32, i32* @EXIT_SUCCESS
%189 = call i32 @exit(i32 %188)
unreachable
190: ; preds = %197, %88
%191 = load i32, i32* %4
%192 = call i32 @read(i32 %191, i8* %2, i32 1)
switch i32 %192, label %197 [
i32 0, label %202
i32 -1, label %193
]
193: ; preds = %190
%194 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%195 = load i32, i32* @EXIT_FAILURE
%196 = call i32 @exit(i32 %195)
unreachable
197: ; preds = %190
%198 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @str.9, i64 0, i64 0))
%199 = load i32, i32* @STDOUT_FILENO
%200 = call i32 @write(i32 %199, i8* %2, i32 1)
%201 = call i32 @putchar(i32 10)
br label %190
202: ; preds = %190
%203 = load i32, i32* %4
%204 = call i32 @close(i32 %203)
%205 = load i32, i32* @EXIT_SUCCESS
%206 = call i32 @exit(i32 %205)
unreachable
207: ; preds = %30
%208 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %20)
%209 = call i32 @usleep(i32 500000)
%210 = call i64 (...) @fork()
%211 = icmp slt i64 %210, 0
br i1 %211, label %26, label %212
212: ; preds = %207
%213 = icmp eq i64 %210, 0
br i1 %213, label %32, label %214
214: ; preds = %212
%215 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %210)
%216 = call i32 @usleep(i32 500000)
%217 = call i64 (...) @fork()
%218 = icmp slt i64 %217, 0
br i1 %218, label %26, label %219
219: ; preds = %214
%220 = icmp eq i64 %217, 0
br i1 %220, label %135, label %221
221: ; preds = %219
%222 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %217)
%223 = call i32 @usleep(i32 500000)
%224 = call i64 (...) @fork()
%225 = icmp slt i64 %224, 0
br i1 %225, label %26, label %226
226: ; preds = %221
%227 = icmp eq i64 %224, 0
br i1 %227, label %49, label %228
228: ; preds = %226
%229 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %224)
%230 = call i32 @usleep(i32 500000)
%231 = call i64 (...) @fork()
%232 = icmp slt i64 %231, 0
br i1 %232, label %26, label %233
233: ; preds = %228
%234 = icmp eq i64 %231, 0
br i1 %234, label %66, label %235
235: ; preds = %233
%236 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i64 %231)
%237 = call i32 @usleep(i32 500000)
%238 = load i32, i32* %4
%239 = call i32 @close(i32 %238)
%240 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 0, i64 1
%241 = load i32, i32* %240
%242 = call i32 @close(i32 %241)
%243 = load i32, i32* %8
%244 = call i32 @close(i32 %243)
%245 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 1, i64 1
%246 = load i32, i32* %245
%247 = call i32 @close(i32 %246)
%248 = load i32, i32* %12
%249 = call i32 @close(i32 %248)
%250 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 2, i64 1
%251 = load i32, i32* %250
%252 = call i32 @close(i32 %251)
%253 = load i32, i32* %16
%254 = call i32 @close(i32 %253)
%255 = getelementptr inbounds [4 x [2 x i32]], [4 x [2 x i32]]* %1, i64 0, i64 3, i64 1
%256 = load i32, i32* %255
%257 = call i32 @close(i32 %256)
br label %258
258: ; preds = %235, %261
%259 = call i64 @waitpid(i32 -1, i32* null, i32 0)
%260 = icmp eq i64 %259, 0
br i1 %260, label %265, label %261
261: ; preds = %258
%262 = load i64, i64* @errno
%263 = load i64, i64* @ECHILD
%264 = icmp eq i64 %262, %263
br i1 %264, label %265, label %258
265: ; preds = %261, %258
%266 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%267 = load i32, i32* @EXIT_SUCCESS
ret i32 %267
}