#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 events;
  int fd;
  int revents;
};

/* Variables and functions */
int POLLERR;
int POLLIN;
int close(int);
int dup2(int, int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int pipe(int *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ syserr(char *);
int wait(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int pipe_dsc[2], buf_len, finished, ret, i;
  char buf[1024];
  struct pollfd entries[2];
  if (pipe(pipe_dsc) == -1)
    syserr("Error in pipe\n");
  switch (fork()) {
  case -1:
    syserr("Error in fork\n");
  case 0:
    if (dup2(pipe_dsc[1], 1) != 1)
      syserr("Error in child, dup2\n");
    if (close(pipe_dsc[0]) == -1)
      syserr("Error in child, close (pipe_dsc[0])\n");
    if (close(pipe_dsc[1]) == -1)
      syserr("Error in child, close (pipe_dsc[1])\n");
    execl("./child-poll", "child-poll", NULL);
    syserr("Error in execl\n");
  default:
    if (close(pipe_dsc[1]) == -1)
      syserr("Error in parent, close (pipe_dsc[1])\n");
  }
  for (i = 0; i < 2; ++i)
    entries[i].events = POLLIN;
  entries[0].fd = 0;
  entries[1].fd = pipe_dsc[0];
  finished = 0;
  printf("Type something (CTRL-D to exit)\n");
  while (!finished) {
    for (i = 0; i < 2; ++i)
      entries[i].revents = 0;
    if ((ret = poll(entries, 2, -1)) == -1)
      syserr("Error in poll\n");
    else if (ret > 0)
      for (i = 0; i < 2; ++i)
        if (entries[i].revents & (POLLIN | POLLERR)) {
          if ((buf_len = read(entries[i].fd, buf, 1024 - 1)) == -1)
            syserr("Error in read\n");
          if ((i == 0) && (buf_len == 0)) {
            printf("Goodbye\n");
            finished = 1;
          } else {
            buf[buf_len < 1024 - 1 ? buf_len : 1024 - 1] = '\0';
            printf("Read %d byte(s) from descriptor %d: %s\n", buf_len,
                   entries[i].fd, buf);
          }
        }
  }
  if (close(pipe_dsc[0]) == -1)
    syserr("Error in parent, close (pipe_dsc[0])\n");
  if (wait(0) == -1)
    syserr("Error in wait\n");
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11e7 <main+0x37>
lea    0xe1e(%rip),%rdi
call   1050 <syserr@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x454(%rbp)
sub    $0xffffffff,%eax
je     1217 <main+0x67>
jmp    1204 <main+0x54>
mov    -0x454(%rbp),%eax
test   %eax,%eax
je     1223 <main+0x73>
jmp    12a2 <main+0xf2>
lea    0xdf1(%rip),%rdi
call   1050 <syserr@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0x1,%eax
je     1245 <main+0x95>
lea    0xdde(%rip),%rdi
call   1050 <syserr@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1262 <main+0xb2>
lea    0xdd7(%rip),%rdi
call   1050 <syserr@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    127f <main+0xcf>
lea    0xddf(%rip),%rdi
call   1050 <syserr@plt>
lea    0xdf8(%rip),%rdi
lea    0xdf3(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   10b0 <execl@plt>
lea    0xdee(%rip),%rdi
call   1050 <syserr@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    12bf <main+0x10f>
lea    0xde1(%rip),%rdi
call   1050 <syserr@plt>
jmp    12c4 <main+0x114>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    1300 <main+0x150>
mov    0x2d04(%rip),%rax
mov    (%rax),%ecx
movslq -0x28(%rbp),%rdx
lea    -0x450(%rbp),%rax
imul   $0xc,%rdx,%rdx
add    %rdx,%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    12cb <main+0x11b>
movl   $0x0,-0x44c(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x440(%rbp)
movl   $0x0,-0x20(%rbp)
lea    0xda0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x20(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    133e <main+0x18e>
jmp    14f1 <main+0x341>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    1376 <main+0x1c6>
movslq -0x28(%rbp),%rcx
lea    -0x450(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
movl   $0x0,0x8(%rax)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1345 <main+0x195>
lea    -0x450(%rbp),%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   1090 <poll@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    13a9 <main+0x1f9>
lea    0xd43(%rip),%rdi
call   1050 <syserr@plt>
jmp    14ec <main+0x33c>
cmpl   $0x0,-0x24(%rbp)
jle    14e7 <main+0x337>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x28(%rbp)
jge    14e2 <main+0x332>
movslq -0x28(%rbp),%rcx
lea    -0x450(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
mov    0x2c00(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bff(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     14cf <main+0x31f>
movslq -0x28(%rbp),%rcx
lea    -0x450(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%edi
lea    -0x430(%rbp),%rsi
mov    $0x3ff,%edx
call   1080 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
jne    1434 <main+0x284>
lea    0xcc2(%rip),%rdi
call   1050 <syserr@plt>
cmpl   $0x0,-0x28(%rbp)
jne    1462 <main+0x2b2>
cmpl   $0x0,-0x1c(%rbp)
jne    1462 <main+0x2b2>
lea    0xcb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x20(%rbp)
jmp    14ca <main+0x31a>
cmpl   $0x3ff,-0x1c(%rbp)
jge    147d <main+0x2cd>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x458(%rbp)
jmp    148d <main+0x2dd>
mov    $0x3ff,%eax
mov    %eax,-0x458(%rbp)
jmp    148d <main+0x2dd>
mov    -0x458(%rbp),%eax
cltq
movb   $0x0,-0x430(%rbp,%rax,1)
mov    -0x1c(%rbp),%esi
movslq -0x28(%rbp),%rcx
lea    -0x450(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%edx
lea    -0x430(%rbp),%rcx
lea    0xc46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    14cf <main+0x31f>
jmp    14d4 <main+0x324>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    13ba <main+0x20a>
jmp    14e7 <main+0x337>
jmp    14ec <main+0x33c>
jmp    1328 <main+0x178>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    150e <main+0x35e>
lea    0xc28(%rip),%rdi
call   1050 <syserr@plt>
xor    %edi,%edi
call   10c0 <wait@plt>
cmp    $0xffffffff,%eax
jne    152a <main+0x37a>
lea    0xc32(%rip),%rdi
call   1050 <syserr@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
jne    11ec <main+0x2c>
lea    0xe19(%rip),%rdi
call   1060 <syserr@plt>
xor    %eax,%eax
call   10e0 <fork@plt>
test   %eax,%eax
je     120c <main+0x4c>
cmp    $0xffffffff,%eax
jne    1280 <main+0xc0>
lea    0xe08(%rip),%rdi
call   1060 <syserr@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
cmp    $0x1,%eax
je     122b <main+0x6b>
lea    0xdf8(%rip),%rdi
call   1060 <syserr@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1245 <main+0x85>
lea    0xdf4(%rip),%rdi
call   1060 <syserr@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    125f <main+0x9f>
lea    0xdff(%rip),%rdi
call   1060 <syserr@plt>
lea    0xe18(%rip),%rdi
lea    0xe13(%rip),%rsi
xor    %edx,%edx
call   10c0 <execl@plt>
lea    0xe10(%rip),%rdi
call   1060 <syserr@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    129a <main+0xda>
lea    0xe06(%rip),%rdi
call   1060 <syserr@plt>
mov    0x2d3f(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x10(%rsp)
mov    %eax,0x1c(%rsp)
movl   $0x0,0x14(%rsp)
mov    0x8(%rsp),%eax
mov    %eax,0x20(%rsp)
lea    0xe78(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rbx
mov    0x2d13(%rip),%r14
lea    0x30(%rsp),%r15
jmp    12f8 <main+0x138>
nopl   0x0(%rax)
lea    0xdda(%rip),%rdi
call   1060 <syserr@plt>
xor    %r13d,%r13d
test   %r13d,%r13d
jne    140a <main+0x24a>
movl   $0x0,0x18(%rsp)
movl   $0x0,0x24(%rsp)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
cmp    $0xffffffff,%eax
je     12e0 <main+0x120>
test   %eax,%eax
jle    12ec <main+0x12c>
mov    (%r14),%eax
or     (%r12),%eax
test   %eax,0x18(%rsp)
je     138b <main+0x1cb>
mov    0x14(%rsp),%edi
mov    %r15,%rsi
mov    $0x3ff,%edx
call   1090 <read@plt>
test   %eax,%eax
je     1390 <main+0x1d0>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    1358 <main+0x198>
lea    0xd7d(%rip),%rdi
call   1060 <syserr@plt>
cmp    $0x3ff,%ebp
mov    %ebp,%eax
mov    $0x3ff,%ecx
cmovge %ecx,%eax
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    0x14(%rsp),%edx
xor    %r13d,%r13d
lea    0xd62(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    13a2 <main+0x1e2>
xor    %r13d,%r13d
jmp    13a2 <main+0x1e2>
lea    0xdc5(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%r13d
mov    (%r14),%eax
or     (%r12),%eax
test   %eax,0x24(%rsp)
je     12ef <main+0x12f>
mov    0x20(%rsp),%edi
mov    %r15,%rsi
mov    $0x3ff,%edx
call   1090 <read@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    13d7 <main+0x217>
lea    0xcfe(%rip),%rdi
call   1060 <syserr@plt>
cmp    $0x3ff,%ebp
mov    %ebp,%eax
mov    $0x3ff,%ecx
cmovge %ecx,%eax
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    0x20(%rsp),%edx
lea    0xce6(%rip),%rdi
mov    %ebp,%esi
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    12ef <main+0x12f>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
cmp    $0xffffffff,%eax
jne    1424 <main+0x264>
lea    0xce8(%rip),%rdi
call   1060 <syserr@plt>
xor    %edi,%edi
call   10d0 <wait@plt>
cmp    $0xffffffff,%eax
jne    143c <main+0x27c>
lea    0xcf6(%rip),%rdi
call   1060 <syserr@plt>
xor    %edi,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [15 x i8] c"Error in pipe\0A\00"
@.str.1 = [15 x i8] c"Error in fork\0A\00"
@.str.2 = [22 x i8] c"Error in child, dup2\0A\00"
@.str.3 = [37 x i8] c"Error in child, close (pipe_dsc[0])\0A\00"
@.str.4 = [37 x i8] c"Error in child, close (pipe_dsc[1])\0A\00"
@.str.5 = [13 x i8] c"./child-poll\00"
@.str.6 = [11 x i8] c"child-poll\00"
@.str.7 = [16 x i8] c"Error in execl\0A\00"
@.str.8 = [38 x i8] c"Error in parent, close (pipe_dsc[1])\0A\00"
@POLLIN = global i32 0
@.str.9 = [33 x i8] c"Type something (CTRL-D to exit)\0A\00"
@.str.10 = [15 x i8] c"Error in poll\0A\00"
@POLLERR = global i32 0
@.str.11 = [15 x i8] c"Error in read\0A\00"
@.str.12 = [9 x i8] c"Goodbye\0A\00"
@.str.13 = [40 x i8] c"Read %d byte(s) from descriptor %d: %s\0A\00"
@.str.14 = [38 x i8] c"Error in parent, close (pipe_dsc[0])\0A\00"
@.str.15 = [15 x i8] c"Error in wait\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [1024 x i8]
%12 = alloca [2 x %struct.pollfd]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %2
%19 = call i32 (...) @fork()
switch i32 %19, label %46 [
i32 -1, label %20
i32 0, label %22
]
20: ; preds = %18
%21 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %18, %20
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @dup2(i32 %24, i32 1)
%26 = icmp ne i32 %25, 1
br i1 %26, label %27, label %29
27: ; preds = %22
%28 = call i32 @syserr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %29
29: ; preds = %27, %22
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %29
%35 = call i32 @syserr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %43
41: ; preds = %36
%42 = call i32 @syserr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %43
43: ; preds = %41, %36
%44 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* null)
%45 = call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %46
46: ; preds = %18, %43
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @syserr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %53
53: ; preds = %51, %46
br label %54
54: ; preds = %53
store i32 0, i32* %10
br label %55
55: ; preds = %64, %54
%56 = load i32, i32* %10
%57 = icmp slt i32 %56, 2
br i1 %57, label %58, label %67
58: ; preds = %55
%59 = load i32, i32* @POLLIN
%60 = load i32, i32* %10
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 %61
%63 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %62, i32 0, i32 0
store i32 %59, i32* %63
br label %64
64: ; preds = %58
%65 = load i32, i32* %10
%66 = add nsw i32 %65, 1
store i32 %66, i32* %10
br label %55
67: ; preds = %55
%68 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%69 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %68, i32 0, i32 1
store i32 0, i32* %69
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%71 = load i32, i32* %70
%72 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 1
%73 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %72, i32 0, i32 1
store i32 %71, i32* %73
store i32 0, i32* %8
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.9, i64 0, i64 0))
br label %75
75: ; preds = %159, %67
%76 = load i32, i32* %8
%77 = icmp ne i32 %76, 0
%78 = xor i1 %77, true
br i1 %78, label %79, label %160
79: ; preds = %75
store i32 0, i32* %10
br label %80
80: ; preds = %88, %79
%81 = load i32, i32* %10
%82 = icmp slt i32 %81, 2
br i1 %82, label %83, label %91
83: ; preds = %80
%84 = load i32, i32* %10
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 %85
%87 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %86, i32 0, i32 2
store i32 0, i32* %87
br label %88
88: ; preds = %83
%89 = load i32, i32* %10
%90 = add nsw i32 %89, 1
store i32 %90, i32* %10
br label %80
91: ; preds = %80
%92 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 0
%93 = call i32 @poll(%struct.pollfd* %92, i32 2, i32 -1)
store i32 %93, i32* %9
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %97
95: ; preds = %91
%96 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %159
97: ; preds = %91
%98 = load i32, i32* %9
%99 = icmp sgt i32 %98, 0
br i1 %99, label %100, label %158
100: ; preds = %97
store i32 0, i32* %10
br label %101
101: ; preds = %154, %100
%102 = load i32, i32* %10
%103 = icmp slt i32 %102, 2
br i1 %103, label %104, label %157
104: ; preds = %101
%105 = load i32, i32* %10
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 %106
%108 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %107, i32 0, i32 2
%109 = load i32, i32* %108
%110 = load i32, i32* @POLLIN
%111 = load i32, i32* @POLLERR
%112 = or i32 %110, %111
%113 = and i32 %109, %112
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %153
115: ; preds = %104
%116 = load i32, i32* %10
%117 = sext i32 %116 to i64
%118 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 %117
%119 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %118, i32 0, i32 1
%120 = load i32, i32* %119
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%122 = call i32 @read(i32 %120, i8* %121, i32 1023)
store i32 %122, i32* %7
%123 = icmp eq i32 %122, -1
br i1 %123, label %124, label %126
124: ; preds = %115
%125 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %126
126: ; preds = %124, %115
%127 = load i32, i32* %10
%128 = icmp eq i32 %127, 0
br i1 %128, label %129, label %134
129: ; preds = %126
%130 = load i32, i32* %7
%131 = icmp eq i32 %130, 0
br i1 %131, label %132, label %134
132: ; preds = %129
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0))
store i32 1, i32* %8
br label %152
134: ; preds = %129, %126
%135 = load i32, i32* %7
%136 = icmp slt i32 %135, 1023
br i1 %136, label %137, label %139
137: ; preds = %134
%138 = load i32, i32* %7
br label %140
139: ; preds = %134
br label %140
140: ; preds = %139, %137
%141 = phi i32 [ %138, %137 ], [ 1023, %139 ]
%142 = sext i32 %141 to i64
%143 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 %142
store i8 0, i8* %143
%144 = load i32, i32* %7
%145 = load i32, i32* %10
%146 = sext i32 %145 to i64
%147 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %12, i64 0, i64 %146
%148 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %147, i32 0, i32 1
%149 = load i32, i32* %148
%150 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0), i32 %144, i32 %149, i8* %150)
br label %152
152: ; preds = %140, %132
br label %153
153: ; preds = %152, %104
br label %154
154: ; preds = %153
%155 = load i32, i32* %10
%156 = add nsw i32 %155, 1
store i32 %156, i32* %10
br label %101
157: ; preds = %101
br label %158
158: ; preds = %157, %97
br label %159
159: ; preds = %158, %95
br label %75
160: ; preds = %75
%161 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%162 = load i32, i32* %161
%163 = call i32 @close(i32 %162)
%164 = icmp eq i32 %163, -1
br i1 %164, label %165, label %167
165: ; preds = %160
%166 = call i32 @syserr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0))
br label %167
167: ; preds = %165, %160
%168 = call i32 @wait(i32 0)
%169 = icmp eq i32 %168, -1
br i1 %169, label %170, label %172
170: ; preds = %167
%171 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0))
br label %172
172: ; preds = %170, %167
%173 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [15 x i8] c"Error in pipe\0A\00"
@.str.1 = [15 x i8] c"Error in fork\0A\00"
@.str.2 = [22 x i8] c"Error in child, dup2\0A\00"
@.str.3 = [37 x i8] c"Error in child, close (pipe_dsc[0])\0A\00"
@.str.4 = [37 x i8] c"Error in child, close (pipe_dsc[1])\0A\00"
@.str.5 = [13 x i8] c"./child-poll\00"
@.str.6 = [11 x i8] c"child-poll\00"
@.str.7 = [16 x i8] c"Error in execl\0A\00"
@.str.8 = [38 x i8] c"Error in parent, close (pipe_dsc[1])\0A\00"
@POLLIN = global i32 0
@.str.10 = [15 x i8] c"Error in poll\0A\00"
@POLLERR = global i32 0
@.str.11 = [15 x i8] c"Error in read\0A\00"
@.str.13 = [40 x i8] c"Read %d byte(s) from descriptor %d: %s\0A\00"
@.str.14 = [38 x i8] c"Error in parent, close (pipe_dsc[0])\0A\00"
@.str.15 = [15 x i8] c"Error in wait\0A\00"
@str = [32 x i8] c"Type something (CTRL-D to exit)\00"
@str.16 = [8 x i8] c"Goodbye\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = alloca [2 x %struct.pollfd]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = bitcast [2 x %struct.pollfd]* %5 to i8*
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %2
%15 = call i32 (...) @fork()
switch i32 %15, label %40 [
i32 -1, label %16
i32 0, label %18
]
16: ; preds = %14
%17 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %14, %16
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @dup2(i32 %20, i32 1)
%22 = icmp eq i32 %21, 1
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @syserr(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %23, %18
%26 = load i32, i32* %9
%27 = call i32 @close(i32 %26)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %25
%30 = call i32 @syserr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %25
%32 = load i32, i32* %19
%33 = call i32 @close(i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 @syserr(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0))
br label %37
37: ; preds = %35, %31
%38 = call i32 @execl(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32* null)
%39 = call i32 @syserr(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %14, %37
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %47
45: ; preds = %40
%46 = call i32 @syserr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.8, i64 0, i64 0))
br label %47
47: ; preds = %40, %45
%48 = load i32, i32* @POLLIN
%49 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 0, i32 0
store i32 %48, i32* %49
%50 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 1, i32 0
store i32 %48, i32* %50
%51 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 0
%52 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 0, i32 1
store i32 0, i32* %52
%53 = load i32, i32* %9
%54 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 1, i32 1
store i32 %53, i32* %54
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%56 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 0, i32 2
%57 = getelementptr inbounds [2 x %struct.pollfd], [2 x %struct.pollfd]* %5, i64 0, i64 1, i32 2
br label %58
58: ; preds = %47, %107
store i32 0, i32* %56
store i32 0, i32* %57
%59 = call i32 @poll(%struct.pollfd* %51, i32 2, i32 -1)
%60 = icmp eq i32 %59, -1
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
br label %107
63: ; preds = %58
%64 = icmp sgt i32 %59, 0
br i1 %64, label %65, label %107
65: ; preds = %63
%66 = load i32, i32* %56
%67 = load i32, i32* @POLLIN
%68 = load i32, i32* @POLLERR
%69 = or i32 %68, %67
%70 = and i32 %69, %66
%71 = icmp eq i32 %70, 0
br i1 %71, label %86, label %72
72: ; preds = %65
%73 = load i32, i32* %52
%74 = call i32 @read(i32 %73, i8* %7, i32 1023)
switch i32 %74, label %79 [
i32 -1, label %75
i32 0, label %77
]
75: ; preds = %72
%76 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %79
77: ; preds = %72
%78 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.16, i64 0, i64 0))
br label %86
79: ; preds = %72, %75
%80 = icmp slt i32 %74, 1023
%81 = select i1 %80, i32 %74, i32 1023
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %82
store i8 0, i8* %83
%84 = load i32, i32* %52
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0), i32 %74, i32 %84, i8* %7)
br label %86
86: ; preds = %65, %79, %77
%87 = phi i32 [ 1, %77 ], [ 0, %79 ], [ 0, %65 ]
%88 = load i32, i32* %57
%89 = load i32, i32* @POLLIN
%90 = load i32, i32* @POLLERR
%91 = or i32 %90, %89
%92 = and i32 %91, %88
%93 = icmp eq i32 %92, 0
br i1 %93, label %107, label %94
94: ; preds = %86
%95 = load i32, i32* %54
%96 = call i32 @read(i32 %95, i8* %7, i32 1023)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %100
98: ; preds = %94
%99 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %100
100: ; preds = %94, %98
%101 = icmp slt i32 %96, 1023
%102 = select i1 %101, i32 %96, i32 1023
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %103
store i8 0, i8* %104
%105 = load i32, i32* %54
%106 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.13, i64 0, i64 0), i32 %96, i32 %105, i8* %7)
br label %107
107: ; preds = %86, %100, %63, %61
%108 = phi i32 [ 0, %61 ], [ 0, %63 ], [ %87, %100 ], [ %87, %86 ]
%109 = icmp eq i32 %108, 0
br i1 %109, label %58, label %110
110: ; preds = %107
%111 = load i32, i32* %9
%112 = call i32 @close(i32 %111)
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %116
114: ; preds = %110
%115 = call i32 @syserr(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.14, i64 0, i64 0))
br label %116
116: ; preds = %114, %110
%117 = call i32 @wait(i32 0)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %121
119: ; preds = %116
%120 = call i32 @syserr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.15, i64 0, i64 0))
br label %121
121: ; preds = %119, %116
%122 = call i32 @exit(i32 0)
unreachable
}