#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 fd;
  int events;
  int revents;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int POLLERR;
int POLLHUP;
int POLLIN;
int POLLNVAL;
scalar_t__ WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ close(int);
int fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int poll(struct pollfd *, int, int);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char **, size_t);
int /*<<< orphan*/ snprintf(char *, size_t, char *);
scalar_t__ strlen(char *);
scalar_t__ wait(int *);
scalar_t__ write(int, char **, scalar_t__);
int main(int argc, char **argv) {
  int ret;
  int pipefds[2];
  char buffer[1024];
  size_t bufsize = sizeof(buffer);
  ssize_t bytes;
  if (pipe(pipefds) < 0) {
    perror("pipe error\n");
    return 1;
  }
  int pid = fork();
  if (pid < 0) {
    perror("fork error\n");
    return 1;
  } else if (pid == 0) {
    close(pipefds[0]);
    snprintf(buffer, bufsize, "Hello from write end of pipe!");
    if (write(pipefds[1], &buffer, strlen(buffer) + 1) < 0) {
      perror("write error\n");
      close(pipefds[1]);
      return 1;
    }
    close(pipefds[1]);
  } else {
    close(pipefds[1]);
    struct pollfd infds[] = {
        {.fd = pipefds[0], .events = POLLIN},
    };
    for (;;) {
      ret = poll(infds, 1, -1);
      if (ret <= 0) {
        perror("poll with POLLIN failed\n");
        close(pipefds[0]);
        return 1;
      }
      if (infds[0].revents & POLLIN) {
        bytes = read(pipefds[0], &buffer, bufsize - 1);
        if (bytes < 0) {
          perror("read error\n");
          close(pipefds[0]);
          return 1;
        } else if (bytes > 0) {
          buffer[bytes] = '\0';
          printf("read on pipe: %s\n", buffer);
        }
      }
      if (infds[0].revents & (POLLHUP | POLLERR | POLLNVAL)) {
        printf("the peer closed its end of the pipe\n");
        break;
      }
    }
    int wstatus;
    if (wait(&wstatus) < 0) {
      perror("wait error\n");
      close(pipefds[0]);
      return 1;
    } else if (!WIFEXITED(wstatus) || WEXITSTATUS(wstatus)) {
      perror("child process didn't exit successfully\n");
      close(pipefds[0]);
      return 1;
    }
    close(pipefds[0]);
  }
  return 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)
movq   $0x400,-0x428(%rbp)
lea    -0x1c(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jge    121f <main+0x4f>
lea    0xdf2(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
mov    $0x0,%al
call   10f0 <fork@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jge    1251 <main+0x81>
lea    0xdcc(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
cmpl   $0x0,-0x434(%rbp)
jne    12f3 <main+0x123>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rsi
lea    0xd9d(%rip),%rdx
call   1060 <snprintf@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x454(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x450(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    12e6 <main+0x116>
lea    0xd69(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
jmp    14d3 <main+0x303>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x440(%rbp)
mov    0x2cc5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x43c(%rbp)
movl   $0x0,-0x438(%rbp)
lea    -0x440(%rbp),%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jg     1360 <main+0x190>
lea    0xcfc(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
mov    -0x438(%rbp),%eax
mov    0x2c63(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1403 <main+0x233>
mov    -0x1c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x428(%rbp),%rdx
sub    $0x1,%rdx
call   1090 <read@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
jae    13c7 <main+0x1f7>
lea    0xcae(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
cmpq   $0x0,-0x430(%rbp)
jbe    13f9 <main+0x229>
mov    -0x430(%rbp),%rax
movb   $0x0,-0x420(%rbp,%rax,1)
lea    -0x420(%rbp),%rsi
lea    0xc76(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13fe <main+0x22e>
jmp    1403 <main+0x233>
mov    -0x438(%rbp),%eax
mov    0x2bd8(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2bc7(%rip),%rdx
or     (%rdx),%ecx
mov    0x2bb6(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1442 <main+0x272>
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1447 <main+0x277>
jmp    131d <main+0x14d>
lea    -0x444(%rbp),%rdi
call   10e0 <wait@plt>
cmp    $0x0,%rax
jge    147d <main+0x2ad>
lea    0xc3b(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
mov    -0x444(%rbp),%edi
call   10d0 <WIFEXITED@plt>
cmp    $0x0,%eax
je     14a6 <main+0x2d6>
mov    -0x444(%rbp),%edi
call   10b0 <WEXITSTATUS@plt>
cmp    $0x0,%rax
je     14c6 <main+0x2f6>
lea    0xbfe(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    14df <main+0x30f>
jmp    14cb <main+0x2fb>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
jmp    14d8 <main+0x308>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
lea    0x4(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
js     136c <main+0x19c>
xor    %eax,%eax
call   10f0 <fork@plt>
test   %eax,%eax
js     1375 <main+0x1a5>
je     130a <main+0x13a>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0x4(%rsp),%eax
mov    %eax,0x10(%rsp)
mov    0x2daf(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x14(%rsp)
movl   $0x0,0x18(%rsp)
lea    0x10(%rsp),%r14
mov    0x2dab(%rip),%r13
mov    0x2d9c(%rip),%rbp
mov    0x2d8d(%rip),%r15
lea    0x20(%rsp),%rbx
jmp    1270 <main+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x0(%rbp),%eax
or     0x0(%r13),%eax
or     (%r15),%eax
test   %eax,0x18(%rsp)
jne    12c2 <main+0xf2>
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0xffffffff,%edx
call   10a0 <poll@plt>
test   %eax,%eax
jle    1391 <main+0x1c1>
mov    (%r12),%eax
test   %eax,0x18(%rsp)
je     1260 <main+0x90>
mov    0x4(%rsp),%edi
mov    $0x3ff,%edx
mov    %rbx,%rsi
call   1090 <read@plt>
test   %rax,%rax
je     1260 <main+0x90>
movb   $0x0,0x20(%rsp,%rax,1)
lea    0xda6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1260 <main+0x90>
lea    0xdd9(%rip),%rdi
call   1030 <puts@plt>
lea    0xc(%rsp),%rdi
call   10e0 <wait@plt>
test   %rax,%rax
js     139a <main+0x1ca>
mov    0xc(%rsp),%edi
call   10d0 <WIFEXITED@plt>
test   %eax,%eax
je     1388 <main+0x1b8>
mov    0xc(%rsp),%edi
call   10b0 <WEXITSTATUS@plt>
test   %rax,%rax
jne    1388 <main+0x1b8>
mov    0x4(%rsp),%edi
jmp    1353 <main+0x183>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
movups 0xcfe(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movups 0xd00(%rip),%xmm0
movups %xmm0,0x2e(%rsp)
mov    0x8(%rsp),%ebx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <write@plt>
test   %rax,%rax
js     13b6 <main+0x1e6>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc8d(%rip),%rdi
jmp    137c <main+0x1ac>
lea    0xc90(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%eax
jmp    135a <main+0x18a>
lea    0xceb(%rip),%rdi
jmp    13a1 <main+0x1d1>
lea    0xcab(%rip),%rdi
jmp    13a1 <main+0x1d1>
lea    0xccd(%rip),%rdi
call   10c0 <perror@plt>
mov    0x4(%rsp),%edi
call   1070 <close@plt>
mov    $0x1,%eax
jmp    135a <main+0x18a>
lea    0xc79(%rip),%rdi
call   10c0 <perror@plt>
mov    0x8(%rsp),%edi
jmp    13aa <main+0x1da>

LLVM IR (-O0):
%struct.pollfd = type { i32, i32, i32 }
@.str = [12 x i8] c"pipe error\0A\00"
@.str.1 = [12 x i8] c"fork error\0A\00"
@.str.2 = [30 x i8] c"Hello from write end of pipe!\00"
@.str.3 = [13 x i8] c"write error\0A\00"
@POLLIN = global i32 0
@.str.4 = [25 x i8] c"poll with POLLIN failed\0A\00"
@.str.5 = [12 x i8] c"read error\0A\00"
@.str.6 = [18 x i8] c"read on pipe: %s\0A\00"
@POLLHUP = global i32 0
@POLLERR = global i32 0
@POLLNVAL = global i32 0
@.str.7 = [37 x i8] c"the peer closed its end of the pipe\0A\00"
@.str.8 = [12 x i8] c"wait error\0A\00"
@.str.9 = [40 x i8] c"child process didn't exit successfully\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca [1024 x i8]
%9 = alloca i64
%10 = alloca i64
%11 = alloca i32
%12 = alloca [1 x %struct.pollfd]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i64 1024, i64* %9
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%15 = call i64 @pipe(i32* %14)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %146
19: ; preds = %2
%20 = call i32 (...) @fork()
store i32 %20, i32* %11
%21 = load i32, i32* %11
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %3
br label %146
25: ; preds = %19
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%33 = load i64, i64* %9
%34 = call i32 @snprintf(i8* %32, i64 %33, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%36 = load i32, i32* %35
%37 = bitcast [1024 x i8]* %8 to i8**
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = add nsw i64 %39, 1
%41 = call i64 @write(i32 %36, i8** %37, i64 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %28
%44 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%45 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%46 = load i32, i32* %45
%47 = call i32 @close(i32 %46)
store i32 1, i32* %3
br label %146
48: ; preds = %28
%49 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%50 = load i32, i32* %49
%51 = call i32 @close(i32 %50)
br label %144
52: ; preds = %25
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %12, i64 0, i64 0
%57 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %56, i32 0, i32 0
%58 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%59 = load i32, i32* %58
store i32 %59, i32* %57
%60 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %56, i32 0, i32 1
%61 = load i32, i32* @POLLIN
store i32 %61, i32* %60
%62 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %56, i32 0, i32 2
store i32 0, i32* %62
br label %63
63: ; preds = %117, %52
%64 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %12, i64 0, i64 0
%65 = call i32 @poll(%struct.pollfd* %64, i32 1, i32 -1)
store i32 %65, i32* %6
%66 = load i32, i32* %6
%67 = icmp sle i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %63
%69 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%70 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%71 = load i32, i32* %70
%72 = call i32 @close(i32 %71)
store i32 1, i32* %3
br label %146
73: ; preds = %63
%74 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %12, i64 0, i64 0
%75 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %74, i32 0, i32 2
%76 = load i32, i32* %75
%77 = load i32, i32* @POLLIN
%78 = and i32 %76, %77
%79 = icmp ne i32 %78, 0
br i1 %79, label %80, label %104
80: ; preds = %73
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%82 = load i32, i32* %81
%83 = bitcast [1024 x i8]* %8 to i8**
%84 = load i64, i64* %9
%85 = sub i64 %84, 1
%86 = call i64 @read(i32 %82, i8** %83, i64 %85)
store i64 %86, i64* %10
%87 = load i64, i64* %10
%88 = icmp ult i64 %87, 0
br i1 %88, label %89, label %94
89: ; preds = %80
%90 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
%91 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%92 = load i32, i32* %91
%93 = call i32 @close(i32 %92)
store i32 1, i32* %3
br label %146
94: ; preds = %80
%95 = load i64, i64* %10
%96 = icmp ugt i64 %95, 0
br i1 %96, label %97, label %102
97: ; preds = %94
%98 = load i64, i64* %10
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 %98
store i8 0, i8* %99
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %100)
br label %102
102: ; preds = %97, %94
br label %103
103: ; preds = %102
br label %104
104: ; preds = %103, %73
%105 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %12, i64 0, i64 0
%106 = getelementptr inbounds %struct.pollfd, %struct.pollfd* %105, i32 0, i32 2
%107 = load i32, i32* %106
%108 = load i32, i32* @POLLHUP
%109 = load i32, i32* @POLLERR
%110 = or i32 %108, %109
%111 = load i32, i32* @POLLNVAL
%112 = or i32 %110, %111
%113 = and i32 %107, %112
%114 = icmp ne i32 %113, 0
br i1 %114, label %115, label %117
115: ; preds = %104
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.7, i64 0, i64 0))
br label %118
117: ; preds = %104
br label %63
118: ; preds = %115
%119 = call i64 @wait(i32* %13)
%120 = icmp slt i64 %119, 0
br i1 %120, label %121, label %126
121: ; preds = %118
%122 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%123 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%124 = load i32, i32* %123
%125 = call i32 @close(i32 %124)
store i32 1, i32* %3
br label %146
126: ; preds = %118
%127 = load i32, i32* %13
%128 = call i32 @WIFEXITED(i32 %127)
%129 = icmp ne i32 %128, 0
br i1 %129, label %130, label %134
130: ; preds = %126
%131 = load i32, i32* %13
%132 = call i64 @WEXITSTATUS(i32 %131)
%133 = icmp ne i64 %132, 0
br i1 %133, label %134, label %139
134: ; preds = %130, %126
%135 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%136 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%137 = load i32, i32* %136
%138 = call i32 @close(i32 %137)
store i32 1, i32* %3
br label %146
139: ; preds = %130
br label %140
140: ; preds = %139
%141 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%142 = load i32, i32* %141
%143 = call i32 @close(i32 %142)
br label %144
144: ; preds = %140, %48
br label %145
145: ; preds = %144
store i32 0, i32* %3
br label %146
146: ; preds = %145, %134, %121, %89, %68, %43, %23, %17
%147 = load i32, i32* %3
ret i32 %147
}

LLVM IR (-O2):
%struct.pollfd = type { i32, i32, i32 }
@.str = [12 x i8] c"pipe error\0A\00"
@.str.1 = [12 x i8] c"fork error\0A\00"
@.str.2 = [30 x i8] c"Hello from write end of pipe!\00"
@.str.3 = [13 x i8] c"write error\0A\00"
@POLLIN = global i32 0
@.str.4 = [25 x i8] c"poll with POLLIN failed\0A\00"
@.str.6 = [18 x i8] c"read on pipe: %s\0A\00"
@POLLHUP = global i32 0
@POLLERR = global i32 0
@POLLNVAL = global i32 0
@.str.8 = [12 x i8] c"wait error\0A\00"
@.str.9 = [40 x i8] c"child process didn't exit successfully\0A\00"
@str = [36 x i8] c"the peer closed its end of the pipe\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [1024 x i8]
%5 = alloca [1 x %struct.pollfd]
%6 = alloca i32
%7 = bitcast [2 x i32]* %3 to i8*
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i64 @pipe(i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %103
14: ; preds = %2
%15 = call i32 (...) @fork()
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %103
19: ; preds = %14
%20 = icmp eq i32 %15, 0
br i1 %20, label %21, label %38
21: ; preds = %19
%22 = load i32, i32* %9
%23 = call i32 @close(i32 %22)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%25 = load i32, i32* %24
%26 = bitcast [1024 x i8]* %4 to i8**
%27 = call i64 @strlen(i8* %8)
%28 = add nsw i64 %27, 1
%29 = call i64 @write(i32 %25, i8** %26, i64 %28)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %21
%32 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* %24
%34 = call i32 @close(i32 %33)
br label %103
35: ; preds = %21
%36 = load i32, i32* %24
%37 = call i32 @close(i32 %36)
br label %103
38: ; preds = %19
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = bitcast [1 x %struct.pollfd]* %5 to i8*
%43 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0
%44 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 0
%45 = load i32, i32* %9
store i32 %45, i32* %44
%46 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 1
%47 = load i32, i32* @POLLIN
store i32 %47, i32* %46
%48 = getelementptr inbounds [1 x %struct.pollfd], [1 x %struct.pollfd]* %5, i64 0, i64 0, i32 2
store i32 0, i32* %48
%49 = bitcast [1024 x i8]* %4 to i8**
br label %50
50: ; preds = %69, %38
%51 = call i32 @poll(%struct.pollfd* %43, i32 1, i32 -1)
%52 = icmp slt i32 %51, 1
br i1 %52, label %53, label %57
53: ; preds = %50
%54 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%55 = load i32, i32* %9
%56 = call i32 @close(i32 %55)
br label %103
57: ; preds = %50
%58 = load i32, i32* %48
%59 = load i32, i32* @POLLIN
%60 = and i32 %59, %58
%61 = icmp eq i32 %60, 0
br i1 %61, label %69, label %62
62: ; preds = %57
%63 = load i32, i32* %9
%64 = call i64 @read(i32 %63, i8** %49, i64 1023)
%65 = icmp eq i64 %64, 0
br i1 %65, label %69, label %66
66: ; preds = %62
%67 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %64
store i8 0, i8* %67
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %8)
br label %69
69: ; preds = %66, %62, %57
%70 = load i32, i32* %48
%71 = load i32, i32* @POLLHUP
%72 = load i32, i32* @POLLERR
%73 = or i32 %72, %71
%74 = load i32, i32* @POLLNVAL
%75 = or i32 %73, %74
%76 = and i32 %75, %70
%77 = icmp eq i32 %76, 0
br i1 %77, label %50, label %78
78: ; preds = %69
%79 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str, i64 0, i64 0))
%80 = bitcast i32* %6 to i8*
%81 = call i64 @wait(i32* %6)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0))
%85 = load i32, i32* %9
br label %97
86: ; preds = %78
%87 = load i32, i32* %6
%88 = call i32 @WIFEXITED(i32 %87)
%89 = icmp eq i32 %88, 0
br i1 %89, label %94, label %90
90: ; preds = %86
%91 = load i32, i32* %6
%92 = call i64 @WEXITSTATUS(i32 %91)
%93 = icmp eq i64 %92, 0
br i1 %93, label %100, label %94
94: ; preds = %90, %86
%95 = call i32 @perror(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.9, i64 0, i64 0))
%96 = load i32, i32* %9
br label %97
97: ; preds = %83, %94
%98 = phi i32 [ %85, %83 ], [ %96, %94 ]
%99 = call i32 @close(i32 %98)
br label %103
100: ; preds = %90
%101 = load i32, i32* %9
%102 = call i32 @close(i32 %101)
br label %103
103: ; preds = %35, %100, %97, %53, %17, %31, %12
%104 = phi i32 [ 1, %12 ], [ 1, %17 ], [ 1, %31 ], [ 1, %53 ], [ 1, %97 ], [ 0, %100 ], [ 0, %35 ]
ret i32 %104
}