#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};
typedef size_t ssize_t;
typedef int pid_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_DEL;
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int epoll_create1(int /*<<< orphan*/);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ execvp(char *, char **);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char **, int);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  int out_fds[2];
  int err_fds[2];
  int status;
  pid_t pid;
  if (argc < 2) {
    printf("Usage: %s <command> [command arguments...]\n", argv[0]);
    return EXIT_FAILURE;
  }
  status = pipe(out_fds);
  if (status == -1) {
    perror("pipe");
    return EXIT_FAILURE;
  }
  status = pipe(err_fds);
  if (status == -1) {
    perror("pipe");
    return EXIT_FAILURE;
  }
  pid = fork();
  if (pid == -1) {
    perror("fork");
    return EXIT_FAILURE;
  }
  if (pid == 0) {
    close(out_fds[0]);
    close(err_fds[0]);
    dup2(out_fds[1], STDOUT_FILENO);
    dup2(err_fds[1], STDERR_FILENO);
    execvp(argv[1], &argv[1]);
  } else {
    struct epoll_event ev, events[2];
    int epollfd;
    int fds = 2;
    close(out_fds[1]);
    close(err_fds[1]);
    epollfd = epoll_create1(0);
    ev.events = EPOLLIN;
    ev.data.fd = out_fds[0];
    epoll_ctl(epollfd, EPOLL_CTL_ADD, out_fds[0], &ev);
    ev.data.fd = err_fds[0];
    epoll_ctl(epollfd, EPOLL_CTL_ADD, err_fds[0], &ev);
    while (fds > 0) {
      int n;
      int nfds = epoll_wait(epollfd, events, fds, -1);
      for (n = 0; n < nfds; ++n) {
        int color = 32;
        char buf[80];
        ssize_t s = read(events[n].data.fd, &buf, sizeof(buf) - 1);
        if (s > 0) {
          buf[s] = '\0';
          if (events[n].data.fd == err_fds[0])
            color = 31;
          printf("\033[0;%dm%s\033[0m", color, buf);
        } else {
          epoll_ctl(epollfd, EPOLL_CTL_DEL, events[n].data.fd, NULL);
          --fds;
        }
      }
    }
    wait(&status);
    return status;
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1209 <main+0x49>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    146a <main+0x2aa>
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    123c <main+0x7c>
lea    0xe06(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    146a <main+0x2aa>
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    126f <main+0xaf>
lea    0xdd3(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    146a <main+0x2aa>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    12a0 <main+0xe0>
lea    0xda7(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    146a <main+0x2aa>
cmpl   $0x0,-0x28(%rbp)
jne    12f6 <main+0x136>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
mov    0x2d24(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x1c(%rbp),%edi
mov    0x2ceb(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10b0 <execvp@plt>
jmp    145e <main+0x29e>
movl   $0x2,-0x48(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <epoll_create1@plt>
mov    %eax,-0x44(%rbp)
mov    0x2cba(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2c9d(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1070 <epoll_ctl@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0x44(%rbp),%edi
mov    0x2c7f(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%edx
lea    -0x30(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmpl   $0x0,-0x48(%rbp)
jle    144a <main+0x28a>
mov    -0x44(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    -0x48(%rbp),%edx
mov    $0xffffffff,%ecx
call   1090 <epoll_wait@plt>
mov    %eax,-0x50(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x4c(%rbp),%eax
cmp    -0x50(%rbp),%eax
jge    1445 <main+0x285>
movl   $0x20,-0x54(%rbp)
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x4f,%edx
call   1080 <read@plt>
mov    %rax,-0xb8(%rbp)
cmpq   $0x0,-0xb8(%rbp)
jbe    140c <main+0x24c>
mov    -0xb8(%rbp),%rax
movb   $0x0,-0xb0(%rbp,%rax,1)
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%eax
cmp    -0x20(%rbp),%eax
jne    13ef <main+0x22f>
movl   $0x1f,-0x54(%rbp)
mov    -0x54(%rbp),%esi
lea    -0xb0(%rbp),%rdx
lea    0xc36(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1432 <main+0x272>
mov    -0x44(%rbp),%edi
mov    0x2be2(%rip),%rax
mov    (%rax),%esi
movslq -0x4c(%rbp),%rax
mov    -0x40(%rbp,%rax,8),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <epoll_ctl@plt>
mov    -0x48(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x48(%rbp)
jmp    1437 <main+0x277>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1387 <main+0x1c7>
jmp    135f <main+0x19f>
lea    -0x24(%rbp),%rdi
call   10d0 <wait@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    146a <main+0x2aa>
mov    0x2b4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     11f8 <main+0x38>
mov    (%rbx),%rsi
lea    0xe1d(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
jmp    13a3 <main+0x1e3>
lea    0x10(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     13b5 <main+0x1f5>
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
mov    %eax,0x4(%rsp)
cmp    $0xffffffff,%eax
je     13b5 <main+0x1f5>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     1344 <main+0x184>
cmp    $0xffffffff,%eax
je     13be <main+0x1fe>
mov    0x14(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10c0 <epoll_create1@plt>
mov    %eax,%r15d
mov    0x2d7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x10(%rsp),%edx
mov    %edx,0x18(%rsp)
mov    0x2d5e(%rip),%rbp
mov    0x0(%rbp),%esi
lea    0x18(%rsp),%rbx
mov    %r15d,%edi
mov    %rbx,%rcx
call   1070 <epoll_ctl@plt>
mov    0x8(%rsp),%edx
mov    %edx,0x18(%rsp)
mov    0x0(%rbp),%esi
mov    %r15d,%edi
mov    %rbx,%rcx
call   1070 <epoll_ctl@plt>
mov    $0x2,%ebp
lea    0x30(%rsp),%rbx
lea    0xd8a(%rip),%r12
jmp    12b8 <main+0xf8>
xchg   %ax,%ax
test   %ebp,%ebp
jle    1395 <main+0x1d5>
mov    %r15d,%edi
lea    0x20(%rsp),%rsi
mov    %ebp,%edx
mov    $0xffffffff,%ecx
call   1090 <epoll_wait@plt>
test   %eax,%eax
jle    12b0 <main+0xf0>
mov    %eax,%r14d
xor    %r13d,%r13d
jmp    1304 <main+0x144>
nopl   0x0(%rax,%rax,1)
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    0x20(%rsp,%r13,8),%edx
mov    %r15d,%edi
xor    %ecx,%ecx
call   1070 <epoll_ctl@plt>
add    $0xffffffff,%ebp
add    $0x1,%r13
cmp    %r13,%r14
je     12b0 <main+0xf0>
mov    0x20(%rsp,%r13,8),%edi
mov    %rbx,%rsi
mov    $0x4f,%edx
call   1080 <read@plt>
test   %rax,%rax
je     12e0 <main+0x120>
mov    0x20(%rsp,%r13,8),%ecx
xor    %edx,%edx
cmp    0x8(%rsp),%ecx
movb   $0x0,0x30(%rsp,%rax,1)
sete   %dl
mov    $0x20,%esi
sub    %edx,%esi
mov    %r12,%rdi
mov    %rbx,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    12fb <main+0x13b>
mov    0x10(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0x14(%rsp),%edi
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
mov    0x2c4d(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   10b0 <execvp@plt>
mov    0x2c1f(%rip),%rax
mov    (%rax),%eax
jmp    13a3 <main+0x1e3>
lea    0x4(%rsp),%rdi
call   10d0 <wait@plt>
mov    0x4(%rsp),%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc70(%rip),%rdi
jmp    13c5 <main+0x205>
lea    0xc6c(%rip),%rdi
call   10a0 <perror@plt>
jmp    11ea <main+0x2a>

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

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@.str = [44 x i8] c"Usage: %s <command> [command arguments...]\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"pipe\00"
@.str.2 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.3 = [14 x i8] c"\1B[0;%dm%s\1B[0m\00"
@EPOLL_CTL_DEL = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = alloca i32
%6 = alloca %struct.epoll_event
%7 = alloca [2 x %struct.epoll_event]
%8 = alloca [80 x i8]
%9 = bitcast [2 x i32]* %3 to i8*
%10 = bitcast [2 x i32]* %4 to i8*
%11 = bitcast i32* %5 to i8*
%12 = icmp slt i32 %0, 2
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %1
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
br label %110
17: ; preds = %2
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%19 = call i32 @pipe(i32* %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
br label %110
24: ; preds = %17
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%26 = call i32 @pipe(i32* %25)
store i32 %26, i32* %5
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* @EXIT_FAILURE
br label %110
31: ; preds = %24
%32 = call i32 (...) @fork()
switch i32 %32, label %53 [
i32 -1, label %33
i32 0, label %36
]
33: ; preds = %31
%34 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%35 = load i32, i32* @EXIT_FAILURE
br label %110
36: ; preds = %31
%37 = load i32, i32* %18
%38 = call i32 @close(i32 %37)
%39 = load i32, i32* %25
%40 = call i32 @close(i32 %39)
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = load i32, i32* @STDOUT_FILENO
%44 = call i32 @dup2(i32 %42, i32 %43)
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%46 = load i32, i32* %45
%47 = load i32, i32* @STDERR_FILENO
%48 = call i32 @dup2(i32 %46, i32 %47)
%49 = getelementptr inbounds i8*, i8** %1, i64 1
%50 = load i8*, i8** %49
%51 = call i32 @execvp(i8* %50, i8** %49)
%52 = load i32, i32* @EXIT_SUCCESS
br label %110
53: ; preds = %31
%54 = bitcast %struct.epoll_event* %6 to i8*
%55 = bitcast [2 x %struct.epoll_event]* %7 to i8*
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = call i32 @epoll_create1(i32 0)
%63 = load i32, i32* @EPOLLIN
%64 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 1
store i32 %63, i32* %64
%65 = load i32, i32* %18
%66 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 0, i32 0
store i32 %65, i32* %66
%67 = load i32, i32* @EPOLL_CTL_ADD
%68 = call i32 @epoll_ctl(i32 %62, i32 %67, i32 %65, %struct.epoll_event* %6)
%69 = load i32, i32* %25
store i32 %69, i32* %66
%70 = load i32, i32* @EPOLL_CTL_ADD
%71 = call i32 @epoll_ctl(i32 %62, i32 %70, i32 %69, %struct.epoll_event* %6)
%72 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %7, i64 0, i64 0
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%74 = bitcast [80 x i8]* %8 to i8**
br label %78
75: ; preds = %103, %78
%76 = phi i32 [ %79, %78 ], [ %104, %103 ]
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %107
78: ; preds = %53, %75
%79 = phi i32 [ 2, %53 ], [ %76, %75 ]
%80 = call i32 @epoll_wait(i32 %62, %struct.epoll_event* %72, i32 %79, i32 -1)
%81 = icmp sgt i32 %80, 0
br i1 %81, label %82, label %75
82: ; preds = %78
%83 = zext i32 %80 to i64
br label %84
84: ; preds = %82, %103
%85 = phi i64 [ 0, %82 ], [ %105, %103 ]
%86 = phi i32 [ %79, %82 ], [ %104, %103 ]
%87 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %7, i64 0, i64 %85, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i64 @read(i32 %88, i8** %74, i32 79)
%90 = icmp eq i64 %89, 0
br i1 %90, label %98, label %91
91: ; preds = %84
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 %89
store i8 0, i8* %92
%93 = load i32, i32* %87
%94 = load i32, i32* %25
%95 = icmp eq i32 %93, %94
%96 = select i1 %95, i32 31, i32 32
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i32 %96, i8* %73)
br label %103
98: ; preds = %84
%99 = load i32, i32* @EPOLL_CTL_DEL
%100 = load i32, i32* %87
%101 = call i32 @epoll_ctl(i32 %62, i32 %99, i32 %100, %struct.epoll_event* null)
%102 = add nsw i32 %86, -1
br label %103
103: ; preds = %98, %91
%104 = phi i32 [ %86, %91 ], [ %102, %98 ]
%105 = add nuw nsw i64 %85, 1
%106 = icmp eq i64 %105, %83
br i1 %106, label %75, label %84
107: ; preds = %75
%108 = call i32 @wait(i32* %5)
%109 = load i32, i32* %5
br label %110
110: ; preds = %36, %107, %33, %28, %21, %13
%111 = phi i32 [ %16, %13 ], [ %23, %21 ], [ %30, %28 ], [ %35, %33 ], [ %52, %36 ], [ %109, %107 ]
ret i32 %111
}