#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 */
struct pollfd {
  int member_0;
  int member_1;
  int revents;
  int /*<<< orphan*/ member_2;
};
typedef int /*<<< orphan*/ sockoptval;
typedef int /*<<< orphan*/ argv;

/* Variables and functions */
int /*<<< orphan*/ AF_LOCAL;
scalar_t__ EINTR;
int /*<<< orphan*/ FD_CLOEXEC;
int /*<<< orphan*/ F_SETFD;
int /*<<< orphan*/ F_SETFL;
int /*<<< orphan*/ O_NONBLOCK;
int POLLHUP;
int POLLIN;
int /*<<< orphan*/ SIGTERM;
int /*<<< orphan*/ SOCK_SEQPACKET;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_TIMESTAMP;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int WEXITSTATUS(int);
char **calloc(int, int);
int /*<<< orphan*/ choose_color(int /*<<< orphan*/, char const **);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
scalar_t__ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ dye_pipe(int, char const *);
scalar_t__ errno;
int /*<<< orphan*/ execvp(char *, char **);
int fcntl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char **);
char getopt(int, char **, char *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ print_help(char *);
int /*<<< orphan*/ print_usage(char *, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
scalar_t__ socketpair(int /*<<< orphan*/, int /*<<< orphan*/,
                      int /*<<< orphan*/, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
scalar_t__ wait(int *);
int main(int argc, char **argv) {
  if (argc < 2) {
    print_usage(argv[0], true);
    return 128;
  }
  char const *out_color = "\033[39m";
  char const *err_color = "\033[31m";
  char c;
  while ((c = getopt(argc, argv, "o:e:h")) != -1) {
    switch (c) {
    case 'o':
      if (choose_color(optarg, &out_color)) {
        fprintf(stderr, "Invalid color for stdout.\n");
        print_usage(argv[0], true);
        return 128;
      }
      break;
    case 'e':
      if (choose_color(optarg, &err_color)) {
        fprintf(stderr, "Invalid color for stderr.\n");
        print_usage(argv[0], true);
        return 128;
      }
      break;
    case 'h':
      print_help(argv[0]);
      return 0;
      break;
    case '?':
      print_usage(argv[0], true);
      return 128;
      break;
    }
  }
  int outsock_fds[2];
  int errsock_fds[2];
  if (socketpair(AF_LOCAL, SOCK_SEQPACKET, 0, outsock_fds) ||
      socketpair(AF_LOCAL, SOCK_SEQPACKET, 0, errsock_fds)) {
    perror("socketpair");
    return 128;
  }
  if (fcntl(outsock_fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
      fcntl(outsock_fds[1], F_SETFD, FD_CLOEXEC) == -1 ||
      fcntl(errsock_fds[0], F_SETFD, FD_CLOEXEC) == -1 ||
      fcntl(errsock_fds[1], F_SETFD, FD_CLOEXEC) == -1 ||
      fcntl(outsock_fds[0], F_SETFL, O_NONBLOCK) == -1 ||
      fcntl(errsock_fds[0], F_SETFL, O_NONBLOCK) == -1) {
    perror("fcntl");
    return 128;
  }
  int sockoptval = 1;
  if (setsockopt(outsock_fds[0], SOL_SOCKET, SO_TIMESTAMP, &sockoptval,
                 sizeof(sockoptval)) < 0 ||
      setsockopt(errsock_fds[0], SOL_SOCKET, SO_TIMESTAMP, &sockoptval,
                 sizeof(sockoptval)) < 0) {
    perror("setsockopt");
    return 128;
  }
  char **exec_args = calloc(sizeof(argv[0]), argc - optind + 1);
  if (!exec_args) {
    perror("calloc");
    return 128;
  }
  for (int i = optind; i < argc; i++)
    exec_args[i - optind] = argv[i];
  int pid = fork();
  if (pid == -1) {
    perror("fork");
    free(exec_args);
    return 128;
  }
  if (pid == 0) {
    while (dup2(outsock_fds[1], STDOUT_FILENO) < 0 ||
           dup2(errsock_fds[1], STDERR_FILENO) < 0) {
      if (errno != EINTR) {
        free(exec_args);
        perror("dup2");
        return 128;
      }
    }
    execvp(exec_args[0], exec_args);
    perror("exec");
    free(exec_args);
    return 128;
  }
  free(exec_args);
  close(outsock_fds[1]);
  close(errsock_fds[1]);
  struct pollfd pollfds[] = {{outsock_fds[0], POLLIN, 0},
                             {errsock_fds[0], POLLIN, 0}};
  bool running = true;
  while (running) {
    int pollres = poll(pollfds, 2, -1);
    if (pollres > 0) {
      running = !(pollfds[0].revents & POLLHUP && pollfds[1].revents & POLLHUP);
      if (pollfds[0].revents & POLLIN && !dye_pipe(outsock_fds[0], out_color))
        goto error;
      if (pollfds[1].revents & POLLIN && !dye_pipe(errsock_fds[0], err_color))
        goto error;
      continue;
    } else if (pollres < 0) {
      if (errno == EINTR)
        continue;
      perror("poll");
    }
  error:
    kill(pid, SIGTERM);
    break;
  }
  char reset_colorcode[] = "\033[39m";
  do_write(STDOUT_FILENO, reset_colorcode, strlen(reset_colorcode));
  int status;
  if (wait(&status) < 0) {
    perror("wait");
    return 128;
  }
  return WEXITSTATUS(status);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    12a0 <main+0x40>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1160 <print_usage@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
lea    0xd59(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xd54(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xd48(%rip),%rdx
call   1130 <getopt@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0xffffffff,%eax
je     140a <main+0x1aa>
movsbl -0x21(%rbp),%eax
mov    %eax,-0x88(%rbp)
sub    $0x3f,%eax
je     13e8 <main+0x188>
jmp    12f0 <main+0x90>
mov    -0x88(%rbp),%eax
sub    $0x65,%eax
je     137e <main+0x11e>
jmp    1304 <main+0xa4>
mov    -0x88(%rbp),%eax
sub    $0x68,%eax
je     13d0 <main+0x170>
jmp    1318 <main+0xb8>
mov    -0x88(%rbp),%eax
sub    $0x6f,%eax
jne    1405 <main+0x1a5>
jmp    132c <main+0xcc>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1090 <choose_color@plt>
cmp    $0x0,%eax
je     1379 <main+0x119>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
lea    0xcbb(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1160 <print_usage@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
jmp    1405 <main+0x1a5>
mov    0x2c73(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1090 <choose_color@plt>
cmp    $0x0,%eax
je     13cb <main+0x16b>
mov    0x2bf0(%rip),%rax
mov    (%rax),%edi
lea    0xc84(%rip),%rsi
call   10c0 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1160 <print_usage@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
jmp    1405 <main+0x1a5>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1150 <print_help@plt>
movl   $0x0,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0x1,%esi
call   1160 <print_usage@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
jmp    12b6 <main+0x56>
mov    0x2b9f(%rip),%rax
mov    (%rax),%edi
mov    0x2b3e(%rip),%rax
mov    (%rax),%esi
lea    -0x2c(%rbp),%rcx
xor    %edx,%edx
call   10d0 <socketpair@plt>
cmp    $0x0,%rax
jne    1458 <main+0x1f8>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
mov    0x2b17(%rip),%rax
mov    (%rax),%esi
lea    -0x34(%rbp),%rcx
xor    %edx,%edx
call   10d0 <socketpair@plt>
cmp    $0x0,%rax
je     1470 <main+0x210>
lea    0xbe9(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    -0x2c(%rbp),%edi
mov    0x2b0e(%rip),%rax
mov    (%rax),%esi
mov    0x2af5(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2e2>
mov    -0x28(%rbp),%edi
mov    0x2aeb(%rip),%rax
mov    (%rax),%esi
mov    0x2ad2(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2e2>
mov    -0x34(%rbp),%edi
mov    0x2ac8(%rip),%rax
mov    (%rax),%esi
mov    0x2aaf(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2e2>
mov    -0x30(%rbp),%edi
mov    0x2aa5(%rip),%rax
mov    (%rax),%esi
mov    0x2a8c(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2e2>
mov    -0x2c(%rbp),%edi
mov    0x2a7a(%rip),%rax
mov    (%rax),%esi
mov    0x2ab1(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1542 <main+0x2e2>
mov    -0x34(%rbp),%edi
mov    0x2a57(%rip),%rax
mov    (%rax),%esi
mov    0x2a8e(%rip),%rax
mov    (%rax),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
jne    155a <main+0x2fa>
lea    0xb0a(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
movl   $0x1,-0x38(%rbp)
mov    -0x2c(%rbp),%edi
mov    0x2a6d(%rip),%rax
mov    (%rax),%esi
mov    0x2a5c(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jl     15bd <main+0x35d>
mov    -0x34(%rbp),%edi
mov    0x2a3f(%rip),%rax
mov    (%rax),%esi
mov    0x2a2e(%rip),%rax
mov    (%rax),%edx
lea    -0x38(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    15d5 <main+0x375>
lea    0xa95(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    -0x8(%rbp),%esi
mov    0x29c9(%rip),%rax
sub    (%rax),%esi
add    $0x1,%esi
mov    $0x8,%edi
call   10b0 <calloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1615 <main+0x3b5>
lea    0xa60(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    0x298c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    165e <main+0x3fe>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x40(%rbp),%rax
mov    -0x44(%rbp),%ecx
mov    0x2961(%rip),%rsi
sub    (%rsi),%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1621 <main+0x3c1>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1693 <main+0x433>
lea    0x9f2(%rip),%rdi
call   1120 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
cmpl   $0x0,-0x48(%rbp)
jne    176a <main+0x50a>
jmp    16a2 <main+0x442>
mov    -0x28(%rbp),%edi
mov    0x293c(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0x89(%rbp)
jl     16e6 <main+0x486>
mov    -0x30(%rbp),%edi
mov    0x2896(%rip),%rax
mov    (%rax),%esi
call   1080 <dup2@plt>
cmp    $0x0,%rax
setl   %al
mov    %al,-0x89(%rbp)
mov    -0x89(%rbp),%al
test   $0x1,%al
jne    16f9 <main+0x499>
jmp    1739 <main+0x4d9>
mov    0x2870(%rip),%rax
mov    (%rax),%rax
mov    0x2856(%rip),%rcx
cmp    (%rcx),%rax
je     1734 <main+0x4d4>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
lea    0x94d(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
jmp    16a2 <main+0x442>
mov    -0x40(%rbp),%rax
mov    (%rax),%rdi
mov    -0x40(%rbp),%rsi
call   1140 <execvp@plt>
lea    0x925(%rip),%rdi
call   1120 <perror@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%edi
call   10a0 <close@plt>
mov    -0x30(%rbp),%edi
call   10a0 <close@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2810(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
movl   $0x0,-0x68(%rbp)
movl   $0x0,-0x64(%rbp)
mov    -0x34(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    0x27f0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
movl   $0x0,-0x58(%rbp)
movl   $0x0,-0x54(%rbp)
movl   $0x1,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     18ec <main+0x68c>
lea    -0x70(%rbp),%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1100 <poll@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0x0,-0x78(%rbp)
jle    189c <main+0x63c>
mov    -0x68(%rbp),%ecx
mov    0x27ca(%rip),%rax
and    (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x8a(%rbp)
je     1829 <main+0x5c9>
mov    -0x58(%rbp),%eax
mov    0x27ad(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
mov    %al,-0x8a(%rbp)
mov    -0x8a(%rbp),%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x74(%rbp)
mov    -0x68(%rbp),%eax
mov    0x275d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1868 <main+0x608>
mov    -0x2c(%rbp),%edi
mov    -0x18(%rbp),%rsi
call   10f0 <dye_pipe@plt>
cmp    $0x0,%eax
jne    1868 <main+0x608>
jmp    18db <main+0x67b>
mov    -0x58(%rbp),%eax
mov    0x272e(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1897 <main+0x637>
mov    -0x34(%rbp),%edi
mov    -0x20(%rbp),%rsi
call   10f0 <dye_pipe@plt>
cmp    $0x0,%eax
jne    1897 <main+0x637>
jmp    18db <main+0x67b>
jmp    17ca <main+0x56a>
cmpl   $0x0,-0x78(%rbp)
jge    18d1 <main+0x671>
mov    0x26c3(%rip),%rax
mov    (%rax),%rax
mov    0x26a9(%rip),%rcx
cmp    (%rcx),%rax
jne    18c5 <main+0x665>
jmp    17ca <main+0x56a>
lea    0x7ae(%rip),%rdi
call   1120 <perror@plt>
jmp    18d6 <main+0x676>
jmp    18db <main+0x67b>
mov    -0x48(%rbp),%edi
mov    0x26d3(%rip),%rax
mov    (%rax),%esi
call   10e0 <kill@plt>
mov    0x70e(%rip),%eax
mov    %eax,-0x7e(%rbp)
mov    0x708(%rip),%ax
mov    %ax,-0x7a(%rbp)
mov    0x26e1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
lea    -0x7e(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    -0x7e(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x9c(%rbp),%edi
mov    -0x98(%rbp),%rsi
mov    %eax,%edx
call   1040 <do_write@plt>
lea    -0x84(%rbp),%rdi
call   1170 <wait@plt>
cmp    $0x0,%rax
jge    1965 <main+0x705>
lea    0x72b(%rip),%rdi
call   1120 <perror@plt>
movl   $0x80,-0x4(%rbp)
jmp    1973 <main+0x713>
mov    -0x84(%rbp),%edi
call   1110 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r15
cmp    $0x1,%edi
jg     1298 <main+0x28>
mov    (%r15),%rdi
mov    $0x1,%esi
call   1170 <print_usage@plt>
jmp    174a <main+0x4da>
mov    %edi,%ebp
lea    0xdd8(%rip),%rax
mov    %rax,0x38(%rsp)
lea    0xd53(%rip),%rax
mov    %rax,0x30(%rsp)
lea    0xd4d(%rip),%rdx
mov    %r15,%rsi
call   1140 <getopt@plt>
cmp    $0xff,%al
je     135a <main+0xea>
mov    0x2d28(%rip),%r13
lea    0x30(%rsp),%r14
lea    0xd2a(%rip),%rbx
lea    0x38(%rsp),%r12
jmp    131a <main+0xaa>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0x65,%eax
jne    133c <main+0xcc>
mov    0x0(%r13),%edi
mov    %r14,%rsi
call   1090 <choose_color@plt>
test   %eax,%eax
jne    165e <main+0x3ee>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1140 <getopt@plt>
cmp    $0xff,%al
je     135a <main+0xea>
movsbl %al,%eax
cmp    $0x67,%eax
jle    12f0 <main+0x80>
cmp    $0x6f,%eax
jne    1346 <main+0xd6>
mov    0x0(%r13),%edi
mov    %r12,%rsi
call   1090 <choose_color@plt>
test   %eax,%eax
je     1309 <main+0x99>
jmp    1678 <main+0x408>
cmp    $0x3f,%eax
jne    1309 <main+0x99>
jmp    1286 <main+0x16>
cmp    $0x68,%eax
jne    1309 <main+0x99>
mov    (%r15),%rdi
call   1160 <print_help@plt>
xor    %eax,%eax
jmp    174f <main+0x4df>
mov    0x2c4f(%rip),%r14
mov    (%r14),%edi
mov    0x2bed(%rip),%rbx
mov    (%rbx),%esi
lea    0x14(%rsp),%rcx
xor    %edx,%edx
call   10e0 <socketpair@plt>
test   %rax,%rax
jne    1692 <main+0x422>
mov    (%r14),%edi
mov    (%rbx),%esi
lea    0xc(%rsp),%rcx
xor    %edx,%edx
call   10e0 <socketpair@plt>
test   %rax,%rax
jne    1692 <main+0x422>
mov    0x14(%rsp),%edi
mov    0x2be1(%rip),%r14
mov    (%r14),%esi
mov    0x2bc7(%rip),%rbx
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
mov    0x18(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
mov    0xc(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
mov    0x10(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
mov    0x14(%rsp),%edi
mov    0x2b6f(%rip),%r14
mov    (%r14),%esi
mov    0x2ba5(%rip),%rbx
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
mov    0xc(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
call   1060 <fcntl@plt>
cmp    $0xffffffff,%eax
je     1652 <main+0x3e2>
movl   $0x1,0x1c(%rsp)
mov    0x14(%rsp),%edi
mov    0x2b83(%rip),%r14
mov    (%r14),%esi
mov    0x2b71(%rip),%rbx
mov    (%rbx),%edx
lea    0x1c(%rsp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     169e <main+0x42e>
mov    0xc(%rsp),%edi
mov    (%r14),%esi
mov    (%rbx),%edx
lea    0x1c(%rsp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     169e <main+0x42e>
mov    0x2b05(%rip),%rax
movslq (%rax),%rbx
mov    %ebp,%esi
sub    %ebx,%esi
add    $0x1,%esi
mov    $0x8,%edi
call   10b0 <calloc@plt>
test   %rax,%rax
je     16aa <main+0x43a>
mov    %rax,%r14
cmp    %ebp,%ebx
jge    14df <main+0x26f>
lea    (%r15,%rbx,8),%rsi
not    %ebx
add    %ebp,%ebx
lea    0x8(,%rbx,8),%rdx
mov    %r14,%rdi
call   10d0 <memcpy@plt>
xor    %eax,%eax
call   1190 <fork@plt>
cmp    $0xffffffff,%eax
je     16b6 <main+0x446>
test   %eax,%eax
je     16bf <main+0x44f>
mov    %eax,0x20(%rsp)
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%edi
call   10a0 <close@plt>
mov    0x10(%rsp),%edi
call   10a0 <close@plt>
mov    0x14(%rsp),%eax
mov    %eax,0x40(%rsp)
mov    0x2a7c(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x44(%rsp)
movq   $0x0,0x48(%rsp)
mov    0xc(%rsp),%ecx
mov    %ecx,0x50(%rsp)
mov    %eax,0x54(%rsp)
movq   $0x0,0x58(%rsp)
lea    0x40(%rsp),%rbp
mov    0x2a74(%rip),%r14
mov    0x2a05(%rip),%r13
jmp    1569 <main+0x2f9>
nopl   (%rax)
or     %r12b,%r15b
je     1600 <main+0x390>
mov    %rbp,%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1110 <poll@plt>
test   %eax,%eax
jle    15d0 <main+0x360>
mov    (%r14),%ecx
mov    0x48(%rsp),%edx
mov    0x58(%rsp),%eax
test   %edx,%ecx
sete   %r15b
test   %ecx,%eax
sete   %r12b
mov    (%rbx),%ecx
test   %edx,%ecx
je     15b4 <main+0x344>
mov    0x14(%rsp),%edi
mov    0x38(%rsp),%rsi
call   1100 <dye_pipe@plt>
test   %eax,%eax
je     15ee <main+0x37e>
mov    0x58(%rsp),%eax
mov    (%rbx),%ecx
test   %eax,%ecx
je     1560 <main+0x2f0>
mov    0xc(%rsp),%edi
mov    0x30(%rsp),%rsi
call   1100 <dye_pipe@plt>
test   %eax,%eax
jne    1560 <main+0x2f0>
jmp    15ee <main+0x37e>
nopl   0x0(%rax)
jns    15ee <main+0x37e>
mov    0x2997(%rip),%rax
mov    (%rax),%rax
cmp    0x0(%r13),%rax
je     1569 <main+0x2f9>
lea    0xa8b(%rip),%rdi
call   1130 <perror@plt>
mov    0x29c3(%rip),%rax
mov    (%rax),%esi
mov    0x20(%rsp),%edi
call   10f0 <kill@plt>
movw   $0x6d,0x2c(%rsp)
movl   $0x39335b1b,0x28(%rsp)
39
mov    0x29d2(%rip),%rax
mov    (%rax),%ebx
lea    0x28(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <do_write@plt>
lea    0x24(%rsp),%rdi
call   1180 <wait@plt>
test   %rax,%rax
js     172d <main+0x4bd>
mov    0x24(%rsp),%edi
call   1120 <WEXITSTATUS@plt>
jmp    174f <main+0x4df>
lea    0x9f4(%rip),%rdi
jmp    1745 <main+0x4d5>
mov    0x292b(%rip),%rax
mov    (%rax),%edi
lea    0x9b9(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1286 <main+0x16>
mov    0x2911(%rip),%rax
mov    (%rax),%edi
lea    0x984(%rip),%rsi
call   10c0 <fprintf@plt>
jmp    1286 <main+0x16>
lea    0x9a9(%rip),%rdi
jmp    1745 <main+0x4d5>
lea    0x9ae(%rip),%rdi
jmp    1745 <main+0x4d5>
lea    0x9ad(%rip),%rdi
jmp    1745 <main+0x4d5>
lea    0x9a8(%rip),%rdi
jmp    171e <main+0x4ae>
mov    0x2922(%rip),%r15
mov    0x28a3(%rip),%rbp
mov    0x288c(%rip),%rbx
mov    0x288d(%rip),%r12
jmp    16e9 <main+0x479>
nopl   (%rax)
mov    0x0(%rbp),%rax
cmp    (%rbx),%rax
jne    1736 <main+0x4c6>
mov    0x18(%rsp),%edi
mov    (%r15),%esi
call   1080 <dup2@plt>
test   %rax,%rax
js     16e0 <main+0x470>
mov    0x10(%rsp),%edi
mov    (%r12),%esi
call   1080 <dup2@plt>
test   %rax,%rax
js     16e0 <main+0x470>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1150 <execvp@plt>
lea    0x951(%rip),%rdi
call   1130 <perror@plt>
mov    %r14,%rdi
call   1030 <free@plt>
jmp    174a <main+0x4da>
lea    0x94b(%rip),%rdi
jmp    1745 <main+0x4d5>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0x925(%rip),%rdi
call   1130 <perror@plt>
mov    $0x80,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32, i32 }
@.str = [6 x i8] c"\1B[39m\00"
@.str.1 = [6 x i8] c"\1B[31m\00"
@.str.2 = [6 x i8] c"o:e:h\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Invalid color for stdout.\0A\00"
@.str.4 = [27 x i8] c"Invalid color for stderr.\0A\00"
@AF_LOCAL = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str.5 = [11 x i8] c"socketpair\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.6 = [6 x i8] c"fcntl\00"
@SOL_SOCKET = global i32 0
@SO_TIMESTAMP = global i32 0
@.str.7 = [11 x i8] c"setsockopt\00"
@optind = global i32 0
@.str.8 = [7 x i8] c"calloc\00"
@.str.9 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.10 = [5 x i8] c"dup2\00"
@.str.11 = [5 x i8] c"exec\00"
@POLLIN = global i32 0
@POLLHUP = global i32 0
@.str.12 = [5 x i8] c"poll\00"
@SIGTERM = global i32 0
@__const.main.reset_colorcode = [6 x i8] c"\1B[39m\00"
@.str.13 = [5 x i8] c"wait\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8
%9 = alloca [2 x i32]
%10 = alloca [2 x i32]
%11 = alloca i32
%12 = alloca i8**
%13 = alloca i32
%14 = alloca i32
%15 = alloca [2 x %struct.pollfd]
%16 = alloca i32
%17 = alloca i32
%18 = alloca [6 x i8]
%19 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 2
br i1 %21, label %22, label %27
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 @print_usage(i8* %25, i32 1)
store i32 128, i32* %3
br label %330
27: ; preds = %2
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
br label %28
28: ; preds = %71, %27
%29 = load i32, i32* %4
%30 = load i8**, i8*** %5
%31 = call signext i8 @getopt(i32 %29, i8** %30, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
store i8 %31, i8* %8
%32 = sext i8 %31 to i32
%33 = icmp ne i32 %32, -1
br i1 %33, label %34, label %72
34: ; preds = %28
%35 = load i8, i8* %8
%36 = sext i8 %35 to i32
switch i32 %36, label %71 [
i32 111, label %37
i32 101, label %49
i32 104, label %61
i32 63, label %66
]
37: ; preds = %34
%38 = load i32, i32* @optarg
%39 = call i32 @choose_color(i32 %38, i8** %6)
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %48
41: ; preds = %37
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%44 = load i8**, i8*** %5
%45 = getelementptr inbounds i8*, i8** %44, i64 0
%46 = load i8*, i8** %45
%47 = call i32 @print_usage(i8* %46, i32 1)
store i32 128, i32* %3
br label %330
48: ; preds = %37
br label %71
49: ; preds = %34
%50 = load i32, i32* @optarg
%51 = call i32 @choose_color(i32 %50, i8** %7)
%52 = icmp ne i32 %51, 0
br i1 %52, label %53, label %60
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 0
%58 = load i8*, i8** %57
%59 = call i32 @print_usage(i8* %58, i32 1)
store i32 128, i32* %3
br label %330
60: ; preds = %49
br label %71
61: ; preds = %34
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 @print_help(i8* %64)
store i32 0, i32* %3
br label %330
66: ; preds = %34
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 0
%69 = load i8*, i8** %68
%70 = call i32 @print_usage(i8* %69, i32 1)
store i32 128, i32* %3
br label %330
71: ; preds = %34, %60, %48
br label %28
72: ; preds = %28
%73 = load i32, i32* @AF_LOCAL
%74 = load i32, i32* @SOCK_SEQPACKET
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%76 = call i64 @socketpair(i32 %73, i32 %74, i32 0, i32* %75)
%77 = icmp ne i64 %76, 0
br i1 %77, label %84, label %78
78: ; preds = %72
%79 = load i32, i32* @AF_LOCAL
%80 = load i32, i32* @SOCK_SEQPACKET
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%82 = call i64 @socketpair(i32 %79, i32 %80, i32 0, i32* %81)
%83 = icmp ne i64 %82, 0
br i1 %83, label %84, label %86
84: ; preds = %78, %72
%85 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
store i32 128, i32* %3
br label %330
86: ; preds = %78
%87 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%88 = load i32, i32* %87
%89 = load i32, i32* @F_SETFD
%90 = load i32, i32* @FD_CLOEXEC
%91 = call i32 @fcntl(i32 %88, i32 %89, i32 %90)
%92 = icmp eq i32 %91, -1
br i1 %92, label %128, label %93
93: ; preds = %86
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%95 = load i32, i32* %94
%96 = load i32, i32* @F_SETFD
%97 = load i32, i32* @FD_CLOEXEC
%98 = call i32 @fcntl(i32 %95, i32 %96, i32 %97)
%99 = icmp eq i32 %98, -1
br i1 %99, label %128, label %100
100: ; preds = %93
%101 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%102 = load i32, i32* %101
%103 = load i32, i32* @F_SETFD
%104 = load i32, i32* @FD_CLOEXEC
%105 = call i32 @fcntl(i32 %102, i32 %103, i32 %104)
%106 = icmp eq i32 %105, -1
br i1 %106, label %128, label %107
107: ; preds = %100
%108 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%109 = load i32, i32* %108
%110 = load i32, i32* @F_SETFD
%111 = load i32, i32* @FD_CLOEXEC
%112 = call i32 @fcntl(i32 %109, i32 %110, i32 %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %128, label %114
114: ; preds = %107
%115 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%116 = load i32, i32* %115
%117 = load i32, i32* @F_SETFL
%118 = load i32, i32* @O_NONBLOCK
%119 = call i32 @fcntl(i32 %116, i32 %117, i32 %118)
%120 = icmp eq i32 %119, -1
br i1 %120, label %128, label %121
121: ; preds = %114
%122 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%123 = load i32, i32* %122
%124 = load i32, i32* @F_SETFL
%125 = load i32, i32* @O_NONBLOCK
%126 = call i32 @fcntl(i32 %123, i32 %124, i32 %125)
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %130
128: ; preds = %121, %114, %107, %100, %93, %86
%129 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
store i32 128, i32* %3
br label %330
130: ; preds = %121
store i32 1, i32* %11
%131 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%132 = load i32, i32* %131
%133 = load i32, i32* @SOL_SOCKET
%134 = load i32, i32* @SO_TIMESTAMP
%135 = call i64 @setsockopt(i32 %132, i32 %133, i32 %134, i32* %11, i32 4)
%136 = icmp slt i64 %135, 0
br i1 %136, label %144, label %137
137: ; preds = %130
%138 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%139 = load i32, i32* %138
%140 = load i32, i32* @SOL_SOCKET
%141 = load i32, i32* @SO_TIMESTAMP
%142 = call i64 @setsockopt(i32 %139, i32 %140, i32 %141, i32* %11, i32 4)
%143 = icmp slt i64 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %137, %130
%145 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
store i32 128, i32* %3
br label %330
146: ; preds = %137
%147 = load i32, i32* %4
%148 = load i32, i32* @optind
%149 = sub nsw i32 %147, %148
%150 = add nsw i32 %149, 1
%151 = call i8** @calloc(i32 8, i32 %150)
store i8** %151, i8*** %12
%152 = load i8**, i8*** %12
%153 = icmp ne i8** %152, null
br i1 %153, label %156, label %154
154: ; preds = %146
%155 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
store i32 128, i32* %3
br label %330
156: ; preds = %146
%157 = load i32, i32* @optind
store i32 %157, i32* %13
br label %158
158: ; preds = %174, %156
%159 = load i32, i32* %13
%160 = load i32, i32* %4
%161 = icmp slt i32 %159, %160
br i1 %161, label %162, label %177
162: ; preds = %158
%163 = load i8**, i8*** %5
%164 = load i32, i32* %13
%165 = sext i32 %164 to i64
%166 = getelementptr inbounds i8*, i8** %163, i64 %165
%167 = load i8*, i8** %166
%168 = load i8**, i8*** %12
%169 = load i32, i32* %13
%170 = load i32, i32* @optind
%171 = sub nsw i32 %169, %170
%172 = sext i32 %171 to i64
%173 = getelementptr inbounds i8*, i8** %168, i64 %172
store i8* %167, i8** %173
br label %174
174: ; preds = %162
%175 = load i32, i32* %13
%176 = add nsw i32 %175, 1
store i32 %176, i32* %13
br label %158
177: ; preds = %158
%178 = call i32 (...) @fork()
store i32 %178, i32* %14
%179 = load i32, i32* %14
%180 = icmp eq i32 %179, -1
br i1 %180, label %181, label %185
181: ; preds = %177
%182 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%183 = load i8**, i8*** %12
%184 = call i32 @free(i8** %183)
store i32 128, i32* %3
br label %330
185: ; preds = %177
%186 = load i32, i32* %14
%187 = icmp eq i32 %186, 0
br i1 %187, label %188, label %221
188: ; preds = %185
br label %189
189: ; preds = %211, %188
%190 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%191 = load i32, i32* %190
%192 = load i32, i32* @STDOUT_FILENO
%193 = call i64 @dup2(i32 %191, i32 %192)
%194 = icmp slt i64 %193, 0
br i1 %194, label %201, label %195
195: ; preds = %189
%196 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%197 = load i32, i32* %196
%198 = load i32, i32* @STDERR_FILENO
%199 = call i64 @dup2(i32 %197, i32 %198)
%200 = icmp slt i64 %199, 0
br label %201
201: ; preds = %195, %189
%202 = phi i1 [ true, %189 ], [ %200, %195 ]
br i1 %202, label %203, label %212
203: ; preds = %201
%204 = load i64, i64* @errno
%205 = load i64, i64* @EINTR
%206 = icmp ne i64 %204, %205
br i1 %206, label %207, label %211
207: ; preds = %203
%208 = load i8**, i8*** %12
%209 = call i32 @free(i8** %208)
%210 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
store i32 128, i32* %3
br label %330
211: ; preds = %203
br label %189
212: ; preds = %201
%213 = load i8**, i8*** %12
%214 = getelementptr inbounds i8*, i8** %213, i64 0
%215 = load i8*, i8** %214
%216 = load i8**, i8*** %12
%217 = call i32 @execvp(i8* %215, i8** %216)
%218 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%219 = load i8**, i8*** %12
%220 = call i32 @free(i8** %219)
store i32 128, i32* %3
br label %330
221: ; preds = %185
%222 = load i8**, i8*** %12
%223 = call i32 @free(i8** %222)
%224 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%225 = load i32, i32* %224
%226 = call i32 @close(i32 %225)
%227 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 1
%228 = load i32, i32* %227
%229 = call i32 @close(i32 %228)
%230 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 0
%231 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %230, i32 0, i32 0
%232 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%233 = load i32, i32* %232
store i32 %233, i32* %231
%234 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %230, i32 0, i32 1
%235 = load i32, i32* @POLLIN
store i32 %235, i32* %234
%236 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %230, i32 0, i32 2
store i32 0, i32* %236
%237 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %230, i32 0, i32 3
store i32 0, i32* %237
%238 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %230, i64 1
%239 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %238, i32 0, i32 0
%240 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%241 = load i32, i32* %240
store i32 %241, i32* %239
%242 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %238, i32 0, i32 1
%243 = load i32, i32* @POLLIN
store i32 %243, i32* %242
%244 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %238, i32 0, i32 2
store i32 0, i32* %244
%245 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %238, i32 0, i32 3
store i32 0, i32* %245
store i32 1, i32* %16
br label %246
246: ; preds = %307, %299, %221
%247 = load i32, i32* %16
%248 = icmp ne i32 %247, 0
br i1 %248, label %249, label %316
249: ; preds = %246
%250 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 0
%251 = call i32 @poll(%struct.pollfd* %250, i32 2, i32 -1)
store i32 %251, i32* %17
%252 = load i32, i32* %17
%253 = icmp sgt i32 %252, 0
br i1 %253, label %254, label %300
254: ; preds = %249
%255 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 0
%256 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %255, i32 0, i32 2
%257 = load i32, i32* %256
%258 = load i32, i32* @POLLHUP
%259 = and i32 %257, %258
%260 = icmp ne i32 %259, 0
br i1 %260, label %261, label %268
261: ; preds = %254
%262 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 1
%263 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %262, i32 0, i32 2
%264 = load i32, i32* %263
%265 = load i32, i32* @POLLHUP
%266 = and i32 %264, %265
%267 = icmp ne i32 %266, 0
br label %268
268: ; preds = %261, %254
%269 = phi i1 [ false, %254 ], [ %267, %261 ]
%270 = xor i1 %269, true
%271 = zext i1 %270 to i32
store i32 %271, i32* %16
%272 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 0
%273 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %272, i32 0, i32 2
%274 = load i32, i32* %273
%275 = load i32, i32* @POLLIN
%276 = and i32 %274, %275
%277 = icmp ne i32 %276, 0
br i1 %277, label %278, label %285
278: ; preds = %268
%279 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%280 = load i32, i32* %279
%281 = load i8*, i8** %6
%282 = call i32 @dye_pipe(i32 %280, i8* %281)
%283 = icmp ne i32 %282, 0
br i1 %283, label %285, label %284
284: ; preds = %278
br label %312
285: ; preds = %278, %268
%286 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %15, i64 0, i64 1
%287 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %286, i32 0, i32 2
%288 = load i32, i32* %287
%289 = load i32, i32* @POLLIN
%290 = and i32 %288, %289
%291 = icmp ne i32 %290, 0
br i1 %291, label %292, label %299
292: ; preds = %285
%293 = getelementptr inbounds [2 x i32], [2 x i32]* %10, i64 0, i64 0
%294 = load i32, i32* %293
%295 = load i8*, i8** %7
%296 = call i32 @dye_pipe(i32 %294, i8* %295)
%297 = icmp ne i32 %296, 0
br i1 %297, label %299, label %298
298: ; preds = %292
br label %312
299: ; preds = %292, %285
br label %246
300: ; preds = %249
%301 = load i32, i32* %17
%302 = icmp slt i32 %301, 0
br i1 %302, label %303, label %310
303: ; preds = %300
%304 = load i64, i64* @errno
%305 = load i64, i64* @EINTR
%306 = icmp eq i64 %304, %305
br i1 %306, label %307, label %308
307: ; preds = %303
br label %246
308: ; preds = %303
%309 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %310
310: ; preds = %308, %300
br label %311
311: ; preds = %310
br label %312
312: ; preds = %311, %298, %284
%313 = load i32, i32* %14
%314 = load i32, i32* @SIGTERM
%315 = call i32 @kill(i32 %313, i32 %314)
br label %316
316: ; preds = %312, %246
%317 = bitcast [6 x i8]* %18 to i8*
%318 = load i32, i32* @STDOUT_FILENO
%319 = getelementptr inbounds [6 x i8], [6 x i8]* %18, i64 0, i64 0
%320 = getelementptr inbounds [6 x i8], [6 x i8]* %18, i64 0, i64 0
%321 = call i32 @strlen(i8* %320)
%322 = call i32 @do_write(i32 %318, i8* %319, i32 %321)
%323 = call i64 @wait(i32* %19)
%324 = icmp slt i64 %323, 0
br i1 %324, label %325, label %327
325: ; preds = %316
%326 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
store i32 128, i32* %3
br label %330
327: ; preds = %316
%328 = load i32, i32* %19
%329 = call i32 @WEXITSTATUS(i32 %328)
store i32 %329, i32* %3
br label %330
330: ; preds = %327, %325, %212, %207, %181, %154, %144, %128, %84, %66, %61, %53, %41, %22
%331 = load i32, i32* %3
ret i32 %331
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32, i32 }
@.str.1 = [6 x i8] c"\1B[31m\00"
@.str.2 = [6 x i8] c"o:e:h\00"
@optarg = global i32 0
@stderr = global i32 0
@.str.3 = [27 x i8] c"Invalid color for stdout.\0A\00"
@.str.4 = [27 x i8] c"Invalid color for stderr.\0A\00"
@AF_LOCAL = global i32 0
@SOCK_SEQPACKET = global i32 0
@.str.5 = [11 x i8] c"socketpair\00"
@F_SETFD = global i32 0
@FD_CLOEXEC = global i32 0
@F_SETFL = global i32 0
@O_NONBLOCK = global i32 0
@.str.6 = [6 x i8] c"fcntl\00"
@SOL_SOCKET = global i32 0
@SO_TIMESTAMP = global i32 0
@.str.7 = [11 x i8] c"setsockopt\00"
@optind = global i32 0
@.str.8 = [7 x i8] c"calloc\00"
@.str.9 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@errno = global i64 0
@EINTR = global i64 0
@.str.10 = [5 x i8] c"dup2\00"
@.str.11 = [5 x i8] c"exec\00"
@POLLIN = global i32 0
@POLLHUP = global i32 0
@.str.12 = [5 x i8] c"poll\00"
@SIGTERM = global i32 0
@__const.main.reset_colorcode = [6 x i8] c"\1B[39m\00"
@.str.13 = [5 x i8] c"wait\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca [2 x %struct.pollfd]
%9 = alloca [6 x i8]
%10 = alloca i32
%11 = icmp slt i32 %0, 2
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 @print_usage(i8* %13, i32 1)
br label %253
15: ; preds = %2
%16 = bitcast i8** %3 to i8*
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__const.main.reset_colorcode, i64 0, i64 0), i8** %3
%17 = bitcast i8** %4 to i8*
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %4
%18 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i8 %18, -1
br i1 %19, label %50, label %20
20: ; preds = %15, %47
%21 = phi i8 [ %48, %47 ], [ %18, %15 ]
%22 = sext i8 %21 to i32
switch i32 %22, label %47 [
i32 111, label %23
i32 101, label %32
i32 104, label %41
i32 63, label %44
]
23: ; preds = %20
%24 = load i32, i32* @optarg
%25 = call i32 @choose_color(i32 %24, i8** %3)
%26 = icmp eq i32 %25, 0
br i1 %26, label %47, label %27
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8*, i8** %1
%31 = call i32 @print_usage(i8* %30, i32 1)
br label %251
32: ; preds = %20
%33 = load i32, i32* @optarg
%34 = call i32 @choose_color(i32 %33, i8** %4)
%35 = icmp eq i32 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%39 = load i8*, i8** %1
%40 = call i32 @print_usage(i8* %39, i32 1)
br label %251
41: ; preds = %20
%42 = load i8*, i8** %1
%43 = call i32 @print_help(i8* %42)
br label %251
44: ; preds = %20
%45 = load i8*, i8** %1
%46 = call i32 @print_usage(i8* %45, i32 1)
br label %251
47: ; preds = %32, %23, %20
%48 = call signext i8 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp eq i8 %48, -1
br i1 %49, label %50, label %20
50: ; preds = %47, %15
%51 = bitcast [2 x i32]* %5 to i8*
%52 = bitcast [2 x i32]* %6 to i8*
%53 = load i32, i32* @AF_LOCAL
%54 = load i32, i32* @SOCK_SEQPACKET
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%56 = call i64 @socketpair(i32 %53, i32 %54, i32 0, i32* %55)
%57 = icmp eq i64 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %50
%59 = load i32, i32* @AF_LOCAL
%60 = load i32, i32* @SOCK_SEQPACKET
%61 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%62 = call i64 @socketpair(i32 %59, i32 %60, i32 0, i32* %61)
%63 = icmp eq i64 %62, 0
br i1 %63, label %66, label %64
64: ; preds = %58, %50
%65 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
br label %249
66: ; preds = %58
%67 = load i32, i32* %55
%68 = load i32, i32* @F_SETFD
%69 = load i32, i32* @FD_CLOEXEC
%70 = call i32 @fcntl(i32 %67, i32 %68, i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %104, label %72
72: ; preds = %66
%73 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%74 = load i32, i32* %73
%75 = load i32, i32* @F_SETFD
%76 = load i32, i32* @FD_CLOEXEC
%77 = call i32 @fcntl(i32 %74, i32 %75, i32 %76)
%78 = icmp eq i32 %77, -1
br i1 %78, label %104, label %79
79: ; preds = %72
%80 = load i32, i32* %61
%81 = load i32, i32* @F_SETFD
%82 = load i32, i32* @FD_CLOEXEC
%83 = call i32 @fcntl(i32 %80, i32 %81, i32 %82)
%84 = icmp eq i32 %83, -1
br i1 %84, label %104, label %85
85: ; preds = %79
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%87 = load i32, i32* %86
%88 = load i32, i32* @F_SETFD
%89 = load i32, i32* @FD_CLOEXEC
%90 = call i32 @fcntl(i32 %87, i32 %88, i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %104, label %92
92: ; preds = %85
%93 = load i32, i32* %55
%94 = load i32, i32* @F_SETFL
%95 = load i32, i32* @O_NONBLOCK
%96 = call i32 @fcntl(i32 %93, i32 %94, i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %104, label %98
98: ; preds = %92
%99 = load i32, i32* %61
%100 = load i32, i32* @F_SETFL
%101 = load i32, i32* @O_NONBLOCK
%102 = call i32 @fcntl(i32 %99, i32 %100, i32 %101)
%103 = icmp eq i32 %102, -1
br i1 %103, label %104, label %106
104: ; preds = %98, %92, %85, %79, %72, %66
%105 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
br label %249
106: ; preds = %98
%107 = bitcast i32* %7 to i8*
store i32 1, i32* %7
%108 = load i32, i32* %55
%109 = load i32, i32* @SOL_SOCKET
%110 = load i32, i32* @SO_TIMESTAMP
%111 = call i64 @setsockopt(i32 %108, i32 %109, i32 %110, i32* %7, i32 4)
%112 = icmp slt i64 %111, 0
br i1 %112, label %119, label %113
113: ; preds = %106
%114 = load i32, i32* %61
%115 = load i32, i32* @SOL_SOCKET
%116 = load i32, i32* @SO_TIMESTAMP
%117 = call i64 @setsockopt(i32 %114, i32 %115, i32 %116, i32* %7, i32 4)
%118 = icmp slt i64 %117, 0
br i1 %118, label %119, label %121
119: ; preds = %113, %106
%120 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
br label %247
121: ; preds = %113
%122 = load i32, i32* @optind
%123 = add i32 %0, 1
%124 = sub i32 %123, %122
%125 = call i8** @calloc(i32 8, i32 %124)
%126 = bitcast i8** %125 to i8*
%127 = icmp eq i8** %125, null
br i1 %127, label %139, label %128
128: ; preds = %121
%129 = icmp slt i32 %122, %0
br i1 %129, label %130, label %141
130: ; preds = %128
%131 = sext i32 %122 to i64
%132 = getelementptr i8*, i8** %1, i64 %131
%133 = bitcast i8** %132 to i8*
%134 = xor i32 %122, -1
%135 = add i32 %134, %0
%136 = zext i32 %135 to i64
%137 = shl nuw nsw i64 %136, 3
%138 = add nuw nsw i64 %137, 8
br label %141
139: ; preds = %121
%140 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %247
141: ; preds = %130, %128
%142 = call i32 (...) @fork()
switch i32 %142, label %168 [
i32 -1, label %143
i32 0, label %146
]
143: ; preds = %141
%144 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%145 = call i32 @free(i8** %125)
br label %247
146: ; preds = %141, %156
%147 = load i32, i32* %73
%148 = load i32, i32* @STDOUT_FILENO
%149 = call i64 @dup2(i32 %147, i32 %148)
%150 = icmp slt i64 %149, 0
br i1 %150, label %156, label %151
151: ; preds = %146
%152 = load i32, i32* %86
%153 = load i32, i32* @STDERR_FILENO
%154 = call i64 @dup2(i32 %152, i32 %153)
%155 = icmp slt i64 %154, 0
br i1 %155, label %156, label %163
156: ; preds = %146, %151
%157 = load i64, i64* @errno
%158 = load i64, i64* @EINTR
%159 = icmp eq i64 %157, %158
br i1 %159, label %146, label %160
160: ; preds = %156
%161 = call i32 @free(i8** %125)
%162 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %247
163: ; preds = %151
%164 = load i8*, i8** %125
%165 = call i32 @execvp(i8* %164, i8** %125)
%166 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.11, i64 0, i64 0))
%167 = call i32 @free(i8** %125)
br label %247
168: ; preds = %141
%169 = call i32 @free(i8** %125)
%170 = load i32, i32* %73
%171 = call i32 @close(i32 %170)
%172 = load i32, i32* %86
%173 = call i32 @close(i32 %172)
%174 = bitcast [2 x %struct.pollfd]* %8 to i8*
%175 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0
%176 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 0
%177 = load i32, i32* %55
store i32 %177, i32* %176
%178 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 1
%179 = load i32, i32* @POLLIN
store i32 %179, i32* %178
%180 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 2
store i32 0, i32* %180
%181 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 0, i32 3
store i32 0, i32* %181
%182 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 0
%183 = load i32, i32* %61
store i32 %183, i32* %182
%184 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 1
store i32 %179, i32* %184
%185 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 2
store i32 0, i32* %185
%186 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %8, i64 0, i64 1, i32 3
store i32 0, i32* %186
br label %187
187: ; preds = %232, %168
%188 = call i32 @poll(%struct.pollfd* %175, i32 2, i32 -1)
%189 = icmp sgt i32 %188, 0
br i1 %189, label %190, label %220
190: ; preds = %187
%191 = load i32, i32* %180
%192 = load i32, i32* @POLLHUP
%193 = and i32 %192, %191
%194 = icmp eq i32 %193, 0
%195 = load i32, i32* %185
%196 = and i32 %195, %192
%197 = icmp eq i32 %196, 0
%198 = select i1 %194, i1 true, i1 %197
%199 = load i32, i32* @POLLIN
%200 = and i32 %199, %191
%201 = icmp eq i32 %200, 0
br i1 %201, label %210, label %202
202: ; preds = %190
%203 = load i32, i32* %55
%204 = load i8*, i8** %3
%205 = call i32 @dye_pipe(i32 %203, i8* %204)
%206 = icmp eq i32 %205, 0
br i1 %206, label %228, label %207
207: ; preds = %202
%208 = load i32, i32* %185
%209 = load i32, i32* @POLLIN
br label %210
210: ; preds = %207, %190
%211 = phi i32 [ %209, %207 ], [ %199, %190 ]
%212 = phi i32 [ %208, %207 ], [ %195, %190 ]
%213 = and i32 %211, %212
%214 = icmp eq i32 %213, 0
br i1 %214, label %231, label %215
215: ; preds = %210
%216 = load i32, i32* %61
%217 = load i8*, i8** %4
%218 = call i32 @dye_pipe(i32 %216, i8* %217)
%219 = icmp eq i32 %218, 0
br i1 %219, label %228, label %231
220: ; preds = %187
%221 = icmp slt i32 %188, 0
br i1 %221, label %222, label %228
222: ; preds = %220
%223 = load i64, i64* @errno
%224 = load i64, i64* @EINTR
%225 = icmp eq i64 %223, %224
br i1 %225, label %232, label %226
226: ; preds = %222
%227 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
br label %228
228: ; preds = %202, %215, %220, %226
%229 = load i32, i32* @SIGTERM
%230 = call i32 @kill(i32 %142, i32 %229)
br label %233
231: ; preds = %210, %215
br i1 %198, label %232, label %233
232: ; preds = %231, %222
br label %187
233: ; preds = %231, %228
%234 = getelementptr inbounds [6 x i8], [6 x i8]* %9, i64 0, i64 0
%235 = load i32, i32* @STDOUT_FILENO
%236 = call i32 @strlen(i8* %234)
%237 = call i32 @do_write(i32 %235, i8* %234, i32 %236)
%238 = call i64 @wait(i32* %10)
%239 = icmp slt i64 %238, 0
br i1 %239, label %240, label %242
240: ; preds = %233
%241 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.13, i64 0, i64 0))
br label %245
242: ; preds = %233
%243 = load i32, i32* %10
%244 = call i32 @WEXITSTATUS(i32 %243)
br label %245
245: ; preds = %242, %240
%246 = phi i32 [ 128, %240 ], [ %244, %242 ]
br label %247
247: ; preds = %139, %245, %163, %160, %143, %119
%248 = phi i32 [ 128, %119 ], [ 128, %139 ], [ 128, %143 ], [ 128, %160 ], [ 128, %163 ], [ %246, %245 ]
br label %249
249: ; preds = %247, %104, %64
%250 = phi i32 [ 128, %64 ], [ 128, %104 ], [ %248, %247 ]
br label %251
251: ; preds = %249, %44, %41, %36, %27
%252 = phi i32 [ 128, %44 ], [ 0, %41 ], [ 128, %36 ], [ 128, %27 ], [ %250, %249 ]
br label %253
253: ; preds = %251, %12
%254 = phi i32 [ 128, %12 ], [ %252, %251 ]
ret i32 %254
}