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

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ dup(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
scalar_t__ getpid();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int wait(int *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int i;
  int iter = 0;
  int numiter;
  int links;
  int first = 1;
  int master = 1;
  int result;
  int pid;
  int debug = 0;
  int p1[2], p2[2];
  char pbuf[512] = {0};
  if (argc > 3 && strcmp(argv[1], "-d") == 0) {
    debug = 1;
    argc--;
    argv++;
  }
  if (argc != 3) {
    fprintf(stderr, "Usage: chain links iter\n");
    exit(1);
  }
  links = atoi(argv[1]);
  if (links < 1) {
    fprintf(stderr, "chain: bogus links (%s)\n", argv[1]);
    exit(1);
  }
  numiter = atoi(argv[2]);
  if (numiter < 1) {
    fprintf(stderr, "chain: bogus iter (%s)\n", argv[2]);
    exit(1);
  }
  if (pipe(p2)) {
    perror("chain: p2 pipe failed");
    exit(1);
  }
  close(0);
  if (dup(p2[0]) < 0) {
    perror("chain: p2 dup->0 failed");
    exit(1);
  }
  close(p2[0]);
  if (links == 1) {
    close(1);
    if (dup(p2[1]) < 0) {
      perror("chain: p2 dup->1 failed");
      exit(1);
    }
  } else {
    for (i = 1; i < links; i++) {
      if (pipe(p1)) {
        perror("chain: p1 pipe failed");
        exit(1);
      }
      master = fork();
      if (master == -1) {
        perror("chain: fork failed");
        exit(1);
      } else if (master) {
        close(1);
        if (dup(p1[1]) < 0) {
          perror("chain: p1 dup->1 failed");
          exit(1);
        }
      } else {
        iter++;
        close(0);
        if (dup(p1[0]) < 0) {
          perror("chain: p1 dup->0 failed");
          exit(1);
        }
        if (first) {
          close(1);
          if (dup(p2[1]) < 0) {
            perror("chain: p2 dup->1 failed");
            exit(1);
          }
          close(p2[1]);
        }
        close(p1[0]);
        close(p1[1]);
        close(p2[1]);
      }
      close(p1[0]);
      close(p1[1]);
      first = 0;
      if (!master)
        break;
    }
  }
  close(p2[1]);
  if (master) {
    if (debug)
      fprintf(stderr, "initial write, master pid %ld\n", (long)getpid());
    if (write(1, pbuf, sizeof(pbuf)) != sizeof(pbuf)) {
      perror("master write failed");
      exit(1);
    }
  }
  while (1) {
    result = read(0, pbuf, sizeof(pbuf));
    {
      int x;
      for (x = 0; x < 5000; x++)
        ;
    }
    if (result == 0)
      break;
    if (result != sizeof(pbuf)) {
      perror("read failed");
      exit(1);
    }
    if (debug)
      fprintf(stderr, "read seq %d pid %ld\n", iter, (long)getpid());
    if (iter >= numiter)
      break;
    iter += links;
    if (debug)
      fprintf(stderr, "write seq %d pid %ld\n", iter, (long)getpid());
    if (write(1, pbuf, sizeof(pbuf)) != sizeof(pbuf)) {
      perror("write failed");
      exit(1);
    }
  }
  close(1);
  while (master && (pid = wait(&result)) != -1) {
    if (debug)
      fprintf(stderr, "wait -> %d and 0x%x\n", pid, result);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
lea    -0x250(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1060 <memset@plt>
cmpl   $0x3,-0x8(%rbp)
jle    126c <main+0x8c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdbf(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    126c <main+0x8c>
movl   $0x1,-0x34(%rbp)
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     1297 <main+0xb7>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
lea    0xd7d(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x1,-0x20(%rbp)
jge    12da <main+0xfa>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xd53(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <atoi@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jge    131d <main+0x13d>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd29(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    -0x44(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
je     1346 <main+0x166>
lea    0xd16(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
xor    %edi,%edi
call   1070 <close@plt>
mov    -0x44(%rbp),%edi
call   1050 <dup@plt>
cmp    $0x0,%rax
jge    1375 <main+0x195>
lea    0xcfd(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x44(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x1,-0x20(%rbp)
jne    13be <main+0x1de>
mov    $0x1,%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%edi
call   1050 <dup@plt>
cmp    $0x0,%rax
jge    13b9 <main+0x1d9>
lea    0xcd1(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    153c <main+0x35c>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    1537 <main+0x357>
lea    -0x3c(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
je     13fa <main+0x21a>
lea    0xca8(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    1424 <main+0x244>
lea    0xc94(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x28(%rbp)
je     1465 <main+0x285>
mov    $0x1,%edi
call   1070 <close@plt>
mov    -0x38(%rbp),%edi
call   1050 <dup@plt>
cmp    $0x0,%rax
jge    1460 <main+0x280>
lea    0xc6b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    14f9 <main+0x319>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
xor    %edi,%edi
call   1070 <close@plt>
mov    -0x3c(%rbp),%edi
call   1050 <dup@plt>
cmp    $0x0,%rax
jge    149d <main+0x2bd>
lea    0xc46(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x24(%rbp)
je     14e1 <main+0x301>
mov    $0x1,%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%edi
call   1050 <dup@plt>
cmp    $0x0,%rax
jge    14d9 <main+0x2f9>
lea    0xbb1(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
jmp    14fe <main+0x31e>
mov    -0x3c(%rbp),%edi
call   1070 <close@plt>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x28(%rbp)
jne    1524 <main+0x344>
jmp    1537 <main+0x357>
jmp    1529 <main+0x349>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13c5 <main+0x1e5>
jmp    153c <main+0x35c>
mov    -0x40(%rbp),%edi
call   1070 <close@plt>
cmpl   $0x0,-0x28(%rbp)
je     15c4 <main+0x3e4>
cmpl   $0x0,-0x34(%rbp)
je     1585 <main+0x3a5>
mov    0x2a81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x258(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x258(%rbp),%edi
mov    %rax,%rdx
lea    0xb6e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x250(%rbp),%rsi
mov    $0x1,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cltq
cmp    $0x200,%rax
je     15bf <main+0x3df>
lea    0xb5b(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    15c4 <main+0x3e4>
jmp    15c9 <main+0x3e9>
lea    -0x250(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x254(%rbp)
cmpl   $0x1388,-0x254(%rbp)
jge    1612 <main+0x432>
jmp    15fe <main+0x41e>
mov    -0x254(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x254(%rbp)
jmp    15e9 <main+0x409>
cmpl   $0x0,-0x2c(%rbp)
jne    1621 <main+0x441>
jmp    172c <main+0x54c>
movslq -0x2c(%rbp),%rax
cmp    $0x200,%rax
je     1647 <main+0x467>
lea    0xae7(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
cmpl   $0x0,-0x34(%rbp)
je     168d <main+0x4ad>
mov    0x2988(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x260(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x25c(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x260(%rbp),%edi
mov    -0x25c(%rbp),%edx
mov    %rax,%rcx
lea    0xaa5(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jl     169e <main+0x4be>
jmp    172c <main+0x54c>
mov    -0x20(%rbp),%eax
add    -0x18(%rbp),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x34(%rbp)
je     16ed <main+0x50d>
mov    0x2928(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x268(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x264(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x268(%rbp),%edi
mov    -0x264(%rbp),%edx
mov    %rax,%rcx
lea    0xa5a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x250(%rbp),%rsi
mov    $0x1,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cltq
cmp    $0x200,%rax
je     1727 <main+0x547>
lea    0x9fa(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    15c9 <main+0x3e9>
mov    $0x1,%edi
call   1070 <close@plt>
xor    %eax,%eax
cmpl   $0x0,-0x28(%rbp)
mov    %al,-0x269(%rbp)
je     1760 <main+0x580>
lea    -0x2c(%rbp),%rdi
call   10f0 <wait@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
setne  %al
mov    %al,-0x269(%rbp)
mov    -0x269(%rbp),%al
test   $0x1,%al
jne    1773 <main+0x593>
jmp    179f <main+0x5bf>
cmpl   $0x0,-0x34(%rbp)
je     179a <main+0x5ba>
mov    0x285c(%rip),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0x9c3(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    1736 <main+0x556>
xor    %edi,%edi
call   10e0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0x30(%rsp),%rdi
mov    $0x200,%edx
xor    %esi,%esi
call   1060 <memset@plt>
cmp    $0x4,%ebp
jl     122a <main+0x4a>
mov    0x8(%rbx),%rdi
lea    0xde9(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    125d <main+0x7d>
add    $0x8,%rbx
lea    -0x1(%rbp),%eax
jmp    122c <main+0x4c>
mov    %ebp,%eax
cmp    $0x4,%ebp
setl   %r15b
cmp    $0x3,%eax
jne    125d <main+0x7d>
mov    0x8(%rbx),%r14
mov    %r14,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
jg     127e <main+0x9e>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
mov    %r14,%rdx
jmp    12a4 <main+0xc4>
mov    0x2d7c(%rip),%rax
mov    (%rax),%edi
lea    0xd96(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %eax,%r12d
mov    0x10(%rbx),%rbx
mov    %rbx,%rdi
call   10d0 <atoi@plt>
test   %eax,%eax
jg     12b5 <main+0xd5>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
lea    0xd94(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %eax,%r14d
lea    0x4(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
jne    12e5 <main+0x105>
xor    %edi,%edi
call   1070 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <dup@plt>
test   %rax,%rax
jns    12fb <main+0x11b>
lea    0xd80(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xd61(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    %r14d,0xc(%rsp)
mov    %rbp,0x28(%rsp)
mov    0x4(%rsp),%edi
call   1070 <close@plt>
cmp    $0x1,%r12d
mov    %r12,0x20(%rsp)
jne    1341 <main+0x161>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <dup@plt>
xor    %r12d,%r12d
test   %rax,%rax
jns    1428 <main+0x248>
lea    0xd3c(%rip),%rdi
jmp    12ec <main+0x10c>
lea    -0x1(%r12),%r14d
lea    0x14(%rsp),%r13
xor    %ebx,%ebx
xor    %r12d,%r12d
mov    %r13,%rdi
call   1080 <pipe@plt>
test   %rax,%rax
jne    149d <main+0x2bd>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     14a9 <main+0x2c9>
mov    %eax,%ebp
test   %eax,%eax
je     13a0 <main+0x1c0>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1050 <dup@plt>
test   %rax,%rax
jns    1402 <main+0x222>
jmp    15bf <main+0x3df>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1050 <dup@plt>
test   %rax,%rax
js     15cb <main+0x3eb>
test   $0x1,%bl
jne    13e3 <main+0x203>
mov    $0x1,%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <dup@plt>
test   %rax,%rax
js     1338 <main+0x158>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
add    $0x1,%r12d
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0x14(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rsp),%edi
call   1070 <close@plt>
test   %ebp,%ebp
je     14b5 <main+0x2d5>
mov    $0x1,%bl
add    $0xffffffff,%r14d
jne    1350 <main+0x170>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0x28(%rsp),%rbp
cmp    $0x4,%ebp
jl     145e <main+0x27e>
mov    0x2b9e(%rip),%rax
mov    (%rax),%ebx
xor    %eax,%eax
call   1040 <getpid@plt>
lea    0xc9a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0x30(%rsp),%rsi
mov    $0x1,%edi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
mov    0x20(%rsp),%r13
mov    0xc(%rsp),%ebx
jne    1491 <main+0x2b1>
mov    %r15b,0x3(%rsp)
movl   $0x0,0x1c(%rsp)
jmp    14d7 <main+0x2f7>
lea    0xc73(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xbef(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xbf9(%rip),%rdi
jmp    12ec <main+0x10c>
mov    %r15b,0x3(%rsp)
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    $0x1,%al
mov    %eax,0x1c(%rsp)
mov    0x28(%rsp),%rbp
mov    0x20(%rsp),%r13
mov    0xc(%rsp),%ebx
lea    0x30(%rsp),%r14
mov    0x2afd(%rip),%r15
jmp    150d <main+0x32d>
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x1,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
cmp    $0x200,%eax
jne    15b3 <main+0x3d3>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1090 <read@plt>
mov    %eax,0x10(%rsp)
cmp    $0x200,%eax
jne    159d <main+0x3bd>
cmp    $0x3,%ebp
jle    1590 <main+0x3b0>
mov    (%r15),%r13d
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %r13d,%edi
mov    0xc(%rsp),%ebx
lea    0xbe5(%rip),%rsi
mov    %r12d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
cmp    %ebx,%r12d
jge    15da <main+0x3fa>
mov    0x20(%rsp),%r13
add    %r13d,%r12d
mov    (%r15),%ebp
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %ebp,%edi
lea    0xbc9(%rip),%rsi
mov    %r12d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x28(%rsp),%rbp
jmp    14f0 <main+0x310>
xchg   %ax,%ax
cmp    %ebx,%r12d
jge    15d7 <main+0x3f7>
add    %r13d,%r12d
jmp    14f0 <main+0x310>
mov    0x3(%rsp),%cl
mov    %ecx,%ebp
test   %eax,%eax
je     15da <main+0x3fa>
lea    0xb71(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xb58(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xaf6(%rip),%rdi
jmp    12ec <main+0x10c>
lea    0xb02(%rip),%rdi
jmp    12ec <main+0x10c>
mov    $0x1,%bpl
mov    $0x1,%edi
call   1070 <close@plt>
cmpb   $0x0,0x1c(%rsp)
jne    15fa <main+0x41a>
lea    0x10(%rsp),%rdi
call   10f0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1601 <main+0x421>
xor    %edi,%edi
call   10e0 <exit@plt>
lea    0x10(%rsp),%rbx
lea    0xb49(%rip),%r14
jmp    161d <main+0x43d>
nop
mov    %rbx,%rdi
call   10f0 <wait@plt>
cmp    $0xffffffff,%eax
je     15fa <main+0x41a>
test   %bpl,%bpl
jne    1610 <main+0x430>
mov    (%r15),%edi
mov    0x10(%rsp),%ecx
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
jmp    1610 <main+0x430>

LLVM IR (-O0):
@.str = [3 x i8] c"-d\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Usage: chain links iter\0A\00"
@.str.2 = [25 x i8] c"chain: bogus links (%s)\0A\00"
@.str.3 = [24 x i8] c"chain: bogus iter (%s)\0A\00"
@.str.4 = [22 x i8] c"chain: p2 pipe failed\00"
@.str.5 = [24 x i8] c"chain: p2 dup->0 failed\00"
@.str.6 = [24 x i8] c"chain: p2 dup->1 failed\00"
@.str.7 = [22 x i8] c"chain: p1 pipe failed\00"
@.str.8 = [19 x i8] c"chain: fork failed\00"
@.str.9 = [24 x i8] c"chain: p1 dup->1 failed\00"
@.str.10 = [24 x i8] c"chain: p1 dup->0 failed\00"
@.str.11 = [31 x i8] c"initial write, master pid %ld\0A\00"
@.str.12 = [20 x i8] c"master write failed\00"
@.str.13 = [12 x i8] c"read failed\00"
@.str.14 = [21 x i8] c"read seq %d pid %ld\0A\00"
@.str.15 = [22 x i8] c"write seq %d pid %ld\0A\00"
@.str.16 = [13 x i8] c"write failed\00"
@.str.17 = [21 x i8] c"wait -> %d and 0x%x\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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca [2 x i32]
%16 = alloca [2 x i32]
%17 = alloca [512 x i8]
%18 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i32 1, i32* %10
store i32 1, i32* %11
store i32 0, i32* %14
%19 = bitcast [512 x i8]* %17 to i8*
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 3
br i1 %21, label %22, label %33
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %22
store i32 1, i32* %14
%29 = load i32, i32* %4
%30 = add nsw i32 %29, -1
store i32 %30, i32* %4
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i32 1
store i8** %32, i8*** %5
br label %33
33: ; preds = %28, %22, %2
%34 = load i32, i32* %4
%35 = icmp ne i32 %34, 3
br i1 %35, label %36, label %40
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %33
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 @atoi(i8* %43)
store i32 %44, i32* %9
%45 = load i32, i32* %9
%46 = icmp slt i32 %45, 1
br i1 %46, label %47, label %54
47: ; preds = %40
%48 = load i32, i32* @stderr
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %40
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
store i32 %58, i32* %8
%59 = load i32, i32* %8
%60 = icmp slt i32 %59, 1
br i1 %60, label %61, label %68
61: ; preds = %54
%62 = load i32, i32* @stderr
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = call i32 @exit(i32 1)
unreachable
68: ; preds = %54
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%70 = call i64 @pipe(i32* %69)
%71 = icmp ne i64 %70, 0
br i1 %71, label %72, label %75
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %68
%76 = call i32 @close(i32 0)
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%78 = load i32, i32* %77
%79 = call i64 @dup(i32 %78)
%80 = icmp slt i64 %79, 0
br i1 %80, label %81, label %84
81: ; preds = %75
%82 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %75
%85 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 0
%86 = load i32, i32* %85
%87 = call i32 @close(i32 %86)
%88 = load i32, i32* %9
%89 = icmp eq i32 %88, 1
br i1 %89, label %90, label %100
90: ; preds = %84
%91 = call i32 @close(i32 1)
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%93 = load i32, i32* %92
%94 = call i64 @dup(i32 %93)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %99
96: ; preds = %90
%97 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%98 = call i32 @exit(i32 1)
unreachable
99: ; preds = %90
br label %185
100: ; preds = %84
store i32 1, i32* %6
br label %101
101: ; preds = %181, %100
%102 = load i32, i32* %6
%103 = load i32, i32* %9
%104 = icmp slt i32 %102, %103
br i1 %104, label %105, label %184
105: ; preds = %101
%106 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%107 = call i64 @pipe(i32* %106)
%108 = icmp ne i64 %107, 0
br i1 %108, label %109, label %112
109: ; preds = %105
%110 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%111 = call i32 @exit(i32 1)
unreachable
112: ; preds = %105
%113 = call i32 (...) @fork()
store i32 %113, i32* %11
%114 = load i32, i32* %11
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %119
116: ; preds = %112
%117 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%118 = call i32 @exit(i32 1)
unreachable
119: ; preds = %112
%120 = load i32, i32* %11
%121 = icmp ne i32 %120, 0
br i1 %121, label %122, label %132
122: ; preds = %119
%123 = call i32 @close(i32 1)
%124 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%125 = load i32, i32* %124
%126 = call i64 @dup(i32 %125)
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %131
128: ; preds = %122
%129 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %122
br label %169
132: ; preds = %119
%133 = load i32, i32* %7
%134 = add nsw i32 %133, 1
store i32 %134, i32* %7
%135 = call i32 @close(i32 0)
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%137 = load i32, i32* %136
%138 = call i64 @dup(i32 %137)
%139 = icmp slt i64 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %132
%141 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %132
%144 = load i32, i32* %10
%145 = icmp ne i32 %144, 0
br i1 %145, label %146, label %159
146: ; preds = %143
%147 = call i32 @close(i32 1)
%148 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%149 = load i32, i32* %148
%150 = call i64 @dup(i32 %149)
%151 = icmp slt i64 %150, 0
br i1 %151, label %152, label %155
152: ; preds = %146
%153 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%154 = call i32 @exit(i32 1)
unreachable
155: ; preds = %146
%156 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%157 = load i32, i32* %156
%158 = call i32 @close(i32 %157)
br label %159
159: ; preds = %155, %143
%160 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%161 = load i32, i32* %160
%162 = call i32 @close(i32 %161)
%163 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%164 = load i32, i32* %163
%165 = call i32 @close(i32 %164)
%166 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%167 = load i32, i32* %166
%168 = call i32 @close(i32 %167)
br label %169
169: ; preds = %159, %131
br label %170
170: ; preds = %169
%171 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 0
%172 = load i32, i32* %171
%173 = call i32 @close(i32 %172)
%174 = getelementptr inbounds [2 x i32], [2 x i32]* %15, i64 0, i64 1
%175 = load i32, i32* %174
%176 = call i32 @close(i32 %175)
store i32 0, i32* %10
%177 = load i32, i32* %11
%178 = icmp ne i32 %177, 0
br i1 %178, label %180, label %179
179: ; preds = %170
br label %184
180: ; preds = %170
br label %181
181: ; preds = %180
%182 = load i32, i32* %6
%183 = add nsw i32 %182, 1
store i32 %183, i32* %6
br label %101
184: ; preds = %179, %101
br label %185
185: ; preds = %184, %99
%186 = getelementptr inbounds [2 x i32], [2 x i32]* %16, i64 0, i64 1
%187 = load i32, i32* %186
%188 = call i32 @close(i32 %187)
%189 = load i32, i32* %11
%190 = icmp ne i32 %189, 0
br i1 %190, label %191, label %207
191: ; preds = %185
%192 = load i32, i32* %14
%193 = icmp ne i32 %192, 0
br i1 %193, label %194, label %198
194: ; preds = %191
%195 = load i32, i32* @stderr
%196 = call i64 (...) @getpid()
%197 = call i32 (i32, i8*, ...) @fprintf(i32 %195, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i64 %196)
br label %198
198: ; preds = %194, %191
%199 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%200 = call i32 @write(i32 1, i8* %199, i32 512)
%201 = sext i32 %200 to i64
%202 = icmp ne i64 %201, 512
br i1 %202, label %203, label %206
203: ; preds = %198
%204 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
%205 = call i32 @exit(i32 1)
unreachable
206: ; preds = %198
br label %207
207: ; preds = %206, %185
br label %208
208: ; preds = %207, %261
%209 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%210 = call i32 @read(i32 0, i8* %209, i32 512)
store i32 %210, i32* %12
store i32 0, i32* %18
br label %211
211: ; preds = %215, %208
%212 = load i32, i32* %18
%213 = icmp slt i32 %212, 5000
br i1 %213, label %214, label %218
214: ; preds = %211
br label %215
215: ; preds = %214
%216 = load i32, i32* %18
%217 = add nsw i32 %216, 1
store i32 %217, i32* %18
br label %211
218: ; preds = %211
%219 = load i32, i32* %12
%220 = icmp eq i32 %219, 0
br i1 %220, label %221, label %222
221: ; preds = %218
br label %262
222: ; preds = %218
%223 = load i32, i32* %12
%224 = sext i32 %223 to i64
%225 = icmp ne i64 %224, 512
br i1 %225, label %226, label %229
226: ; preds = %222
%227 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%228 = call i32 @exit(i32 1)
unreachable
229: ; preds = %222
%230 = load i32, i32* %14
%231 = icmp ne i32 %230, 0
br i1 %231, label %232, label %237
232: ; preds = %229
%233 = load i32, i32* @stderr
%234 = load i32, i32* %7
%235 = call i64 (...) @getpid()
%236 = call i32 (i32, i8*, ...) @fprintf(i32 %233, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0), i32 %234, i64 %235)
br label %237
237: ; preds = %232, %229
%238 = load i32, i32* %7
%239 = load i32, i32* %8
%240 = icmp sge i32 %238, %239
br i1 %240, label %241, label %242
241: ; preds = %237
br label %262
242: ; preds = %237
%243 = load i32, i32* %9
%244 = load i32, i32* %7
%245 = add nsw i32 %244, %243
store i32 %245, i32* %7
%246 = load i32, i32* %14
%247 = icmp ne i32 %246, 0
br i1 %247, label %248, label %253
248: ; preds = %242
%249 = load i32, i32* @stderr
%250 = load i32, i32* %7
%251 = call i64 (...) @getpid()
%252 = call i32 (i32, i8*, ...) @fprintf(i32 %249, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i32 %250, i64 %251)
br label %253
253: ; preds = %248, %242
%254 = getelementptr inbounds [512 x i8], [512 x i8]* %17, i64 0, i64 0
%255 = call i32 @write(i32 1, i8* %254, i32 512)
%256 = sext i32 %255 to i64
%257 = icmp ne i64 %256, 512
br i1 %257, label %258, label %261
258: ; preds = %253
%259 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0))
%260 = call i32 @exit(i32 1)
unreachable
261: ; preds = %253
br label %208
262: ; preds = %241, %221
%263 = call i32 @close(i32 1)
br label %264
264: ; preds = %280, %262
%265 = load i32, i32* %11
%266 = icmp ne i32 %265, 0
br i1 %266, label %267, label %270
267: ; preds = %264
%268 = call i32 @wait(i32* %12)
store i32 %268, i32* %13
%269 = icmp ne i32 %268, -1
br label %270
270: ; preds = %267, %264
%271 = phi i1 [ false, %264 ], [ %269, %267 ]
br i1 %271, label %272, label %281
272: ; preds = %270
%273 = load i32, i32* %14
%274 = icmp ne i32 %273, 0
br i1 %274, label %275, label %280
275: ; preds = %272
%276 = load i32, i32* @stderr
%277 = load i32, i32* %13
%278 = load i32, i32* %12
%279 = call i32 (i32, i8*, ...) @fprintf(i32 %276, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.17, i64 0, i64 0), i32 %277, i32 %278)
br label %280
280: ; preds = %275, %272
br label %264
281: ; preds = %270
%282 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [3 x i8] c"-d\00"
@stderr = global i32 0
@.str.1 = [25 x i8] c"Usage: chain links iter\0A\00"
@.str.2 = [25 x i8] c"chain: bogus links (%s)\0A\00"
@.str.3 = [24 x i8] c"chain: bogus iter (%s)\0A\00"
@.str.4 = [22 x i8] c"chain: p2 pipe failed\00"
@.str.5 = [24 x i8] c"chain: p2 dup->0 failed\00"
@.str.6 = [24 x i8] c"chain: p2 dup->1 failed\00"
@.str.7 = [22 x i8] c"chain: p1 pipe failed\00"
@.str.8 = [19 x i8] c"chain: fork failed\00"
@.str.9 = [24 x i8] c"chain: p1 dup->1 failed\00"
@.str.10 = [24 x i8] c"chain: p1 dup->0 failed\00"
@.str.11 = [31 x i8] c"initial write, master pid %ld\0A\00"
@.str.12 = [20 x i8] c"master write failed\00"
@.str.13 = [12 x i8] c"read failed\00"
@.str.14 = [21 x i8] c"read seq %d pid %ld\0A\00"
@.str.15 = [22 x i8] c"write seq %d pid %ld\0A\00"
@.str.16 = [13 x i8] c"write failed\00"
@.str.17 = [21 x i8] c"wait -> %d and 0x%x\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca [2 x i32]
%5 = alloca [2 x i32]
%6 = alloca [512 x i8]
%7 = bitcast i32* %3 to i8*
%8 = bitcast [2 x i32]* %4 to i8*
%9 = bitcast [2 x i32]* %5 to i8*
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = icmp sgt i32 %0, 3
br i1 %11, label %12, label %19
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %24
17: ; preds = %12
%18 = add nsw i32 %0, -1
br label %19
19: ; preds = %17, %2
%20 = phi i8** [ %13, %17 ], [ %1, %2 ]
%21 = phi i32 [ %18, %17 ], [ %0, %2 ]
%22 = xor i1 %11, true
%23 = icmp eq i32 %21, 3
br i1 %23, label %28, label %24
24: ; preds = %12, %19
%25 = load i32, i32* @stderr
%26 = tail call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%27 = tail call i32 @exit(i32 1)
unreachable
28: ; preds = %19
%29 = getelementptr inbounds i8*, i8** %20, i64 1
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%36 = tail call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = getelementptr inbounds i8*, i8** %20, i64 2
%39 = load i8*, i8** %38
%40 = tail call i32 @atoi(i8* %39)
%41 = icmp slt i32 %40, 1
br i1 %41, label %42, label %46
42: ; preds = %37
%43 = load i32, i32* @stderr
%44 = tail call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%45 = tail call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%48 = call i64 @pipe(i32* %47)
%49 = icmp eq i64 %48, 0
br i1 %49, label %53, label %50
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0))
%52 = call i32 @exit(i32 1)
unreachable
53: ; preds = %46
%54 = call i32 @close(i32 0)
%55 = load i32, i32* %47
%56 = call i64 @dup(i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %61
58: ; preds = %53
%59 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %53
%62 = load i32, i32* %47
%63 = call i32 @close(i32 %62)
%64 = icmp eq i32 %31, 1
br i1 %64, label %69, label %65
65: ; preds = %61
%66 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
br label %80
69: ; preds = %61
%70 = call i32 @close(i32 1)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i64 @dup(i32 %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %143
75: ; preds = %69
%76 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %133
%79 = icmp eq i32 %139, %31
br i1 %79, label %143, label %80
80: ; preds = %65, %78
%81 = phi i1 [ false, %65 ], [ true, %78 ]
%82 = phi i32 [ 1, %65 ], [ %139, %78 ]
%83 = phi i32 [ 0, %65 ], [ %134, %78 ]
%84 = call i64 @pipe(i32* %66)
%85 = icmp eq i64 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %80
%87 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0))
%88 = call i32 @exit(i32 1)
unreachable
89: ; preds = %80
%90 = call i32 (...) @fork()
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %89
%93 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.8, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %89
%96 = icmp eq i32 %90, 0
br i1 %96, label %105, label %97
97: ; preds = %95
%98 = call i32 @close(i32 1)
%99 = load i32, i32* %67
%100 = call i64 @dup(i32 %99)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %133
102: ; preds = %97
%103 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%104 = call i32 @exit(i32 1)
unreachable
105: ; preds = %95
%106 = add nsw i32 %83, 1
%107 = call i32 @close(i32 0)
%108 = load i32, i32* %66
%109 = call i64 @dup(i32 %108)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %105
%112 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %105
br i1 %81, label %126, label %115
115: ; preds = %114
%116 = call i32 @close(i32 1)
%117 = load i32, i32* %68
%118 = call i64 @dup(i32 %117)
%119 = icmp slt i64 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %115
%121 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%122 = call i32 @exit(i32 1)
unreachable
123: ; preds = %115
%124 = load i32, i32* %68
%125 = call i32 @close(i32 %124)
br label %126
126: ; preds = %123, %114
%127 = load i32, i32* %66
%128 = call i32 @close(i32 %127)
%129 = load i32, i32* %67
%130 = call i32 @close(i32 %129)
%131 = load i32, i32* %68
%132 = call i32 @close(i32 %131)
br label %133
133: ; preds = %126, %97
%134 = phi i32 [ %83, %97 ], [ %106, %126 ]
%135 = load i32, i32* %66
%136 = call i32 @close(i32 %135)
%137 = load i32, i32* %67
%138 = call i32 @close(i32 %137)
%139 = add nuw nsw i32 %82, 1
br i1 %96, label %140, label %78
140: ; preds = %133
%141 = load i32, i32* %68
%142 = call i32 @close(i32 %141)
br label %158
143: ; preds = %78, %69
%144 = phi i32 [ 0, %69 ], [ %134, %78 ]
%145 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%146 = load i32, i32* %145
%147 = call i32 @close(i32 %146)
br i1 %11, label %148, label %152
148: ; preds = %143
%149 = load i32, i32* @stderr
%150 = call i64 (...) @getpid()
%151 = call i32 (i32, i8*, ...) @fprintf(i32 %149, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.11, i64 0, i64 0), i64 %150)
br label %152
152: ; preds = %148, %143
%153 = call i32 @write(i32 1, i8* %10, i32 512)
%154 = icmp eq i32 %153, 512
br i1 %154, label %158, label %155
155: ; preds = %152
%156 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0))
%157 = call i32 @exit(i32 1)
unreachable
158: ; preds = %140, %152
%159 = phi i1 [ false, %152 ], [ true, %140 ]
%160 = phi i32 [ %144, %152 ], [ %134, %140 ]
br label %161
161: ; preds = %182, %158
%162 = phi i32 [ %160, %158 ], [ %183, %182 ]
%163 = call i32 @read(i32 0, i8* %10, i32 512)
store i32 %163, i32* %3
switch i32 %163, label %164 [
i32 0, label %189
i32 512, label %167
]
164: ; preds = %161
%165 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0))
%166 = call i32 @exit(i32 1)
unreachable
167: ; preds = %161
br i1 %11, label %170, label %168
168: ; preds = %167
%169 = icmp slt i32 %162, %40
br i1 %169, label %175, label %189
170: ; preds = %167
%171 = load i32, i32* @stderr
%172 = call i64 (...) @getpid()
%173 = call i32 (i32, i8*, ...) @fprintf(i32 %171, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.14, i64 0, i64 0), i32 %162, i64 %172)
%174 = icmp slt i32 %162, %40
br i1 %174, label %177, label %189
175: ; preds = %168
%176 = add nsw i32 %162, %31
br label %182
177: ; preds = %170
%178 = add nsw i32 %162, %31
%179 = load i32, i32* @stderr
%180 = call i64 (...) @getpid()
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %179, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.15, i64 0, i64 0), i32 %178, i64 %180)
br label %182
182: ; preds = %175, %177
%183 = phi i32 [ %178, %177 ], [ %176, %175 ]
%184 = call i32 @write(i32 1, i8* %10, i32 512)
%185 = icmp eq i32 %184, 512
br i1 %185, label %161, label %186
186: ; preds = %182
%187 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.16, i64 0, i64 0))
%188 = call i32 @exit(i32 1)
unreachable
189: ; preds = %170, %161, %168
%190 = phi i1 [ %22, %161 ], [ true, %168 ], [ false, %170 ]
%191 = call i32 @close(i32 1)
br i1 %159, label %204, label %192
192: ; preds = %189
%193 = call i32 @wait(i32* %3)
%194 = icmp eq i32 %193, -1
br i1 %194, label %204, label %195
195: ; preds = %192, %201
%196 = phi i32 [ %202, %201 ], [ %193, %192 ]
br i1 %190, label %201, label %197
197: ; preds = %195
%198 = load i32, i32* @stderr
%199 = load i32, i32* %3
%200 = call i32 (i32, i8*, ...) @fprintf(i32 %198, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.17, i64 0, i64 0), i32 %196, i32 %199)
br label %201
201: ; preds = %197, %195
%202 = call i32 @wait(i32* %3)
%203 = icmp eq i32 %202, -1
br i1 %203, label %204, label %195
204: ; preds = %201, %192, %189
%205 = call i32 @exit(i32 0)
unreachable
}