#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 {
  int events;
  TYPE_1__ data;
};

/* Variables and functions */
int EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
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*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ memset(char **, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char **, int);
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  int p1 = open("pipe1", O_RDONLY);
  int hub = epoll_create1(0);
  struct epoll_event ev, events[10];
  ev.events = EPOLLIN | EPOLLET;
  ev.data.fd = 0;
  epoll_ctl(hub, EPOLL_CTL_ADD, 0, &ev);
  ev.data.fd = p1;
  epoll_ctl(hub, EPOLL_CTL_ADD, p1, &ev);
  char buff[10];
  for (;;) {
    int n, nfds = epoll_wait(hub, events, 10, -1);
    for (n = 0; n < nfds; ++n) {
      memset(&buff, 0, sizeof(char) * 10);
      if (events[n].data.fd == 0) {
        read(0, &buff, 10);
        buff[9] = '\0';
        printf("%s", buff);
      }
      if (events[n].data.fd == p1) {
        read(p1, &buff, 10);
        buff[9] = '\0';
        printf("%s", buff);
      }
      fflush(stdout);
    }
  }
  close(hub);
  close(p1);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
lea    0xe57(%rip),%rdi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
xor    %edi,%edi
call   10a0 <epoll_create1@plt>
mov    %eax,-0x18(%rbp)
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    0x2df5(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
lea    -0x20(%rbp),%rcx
call   1050 <epoll_ctl@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2dda(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1050 <epoll_ctl@plt>
mov    -0x18(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   1080 <epoll_wait@plt>
mov    %eax,-0x84(%rbp)
movl   $0x0,-0x80(%rbp)
mov    -0x80(%rbp),%eax
cmp    -0x84(%rbp),%eax
jge    12d3 <main+0x153>
lea    -0x7a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
movslq -0x80(%rbp),%rax
cmpl   $0x0,-0x6c(%rbp,%rax,8)
jne    1281 <main+0x101>
lea    -0x7a(%rbp),%rsi
xor    %edi,%edi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,-0x71(%rbp)
lea    -0x7a(%rbp),%rsi
lea    0xd8a(%rip),%rdi
call   1030 <printf@plt>
movslq -0x80(%rbp),%rax
mov    -0x6c(%rbp,%rax,8),%eax
cmp    -0x14(%rbp),%eax
jne    12b7 <main+0x137>
mov    -0x14(%rbp),%edi
lea    -0x7a(%rbp),%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,-0x71(%rbp)
lea    -0x7a(%rbp),%rsi
lea    0xd54(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
call   1070 <fflush@plt>
mov    -0x80(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x80(%rbp)
jmp    122f <main+0xaf>
jmp    120c <main+0x8c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    0x2e4b(%rip),%rax
mov    (%rax),%esi
lea    0xe62(%rip),%rdi
call   1090 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
call   10a0 <epoll_create1@plt>
mov    %eax,%ebp
mov    0x2e33(%rip),%rax
mov    0x2e04(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,0x8(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e05(%rip),%r15
mov    (%r15),%esi
lea    0x8(%rsp),%r14
mov    %ebp,%edi
xor    %edx,%edx
mov    %r14,%rcx
call   1050 <epoll_ctl@plt>
mov    %ebx,0xc(%rsp)
mov    (%r15),%esi
mov    %ebp,0x10(%rsp)
mov    %ebp,%edi
mov    %ebx,%edx
mov    %r14,%rcx
call   1050 <epoll_ctl@plt>
lea    0x16(%rsp),%rbp
mov    0x2dbe(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    0x10(%rsp),%edi
lea    0x20(%rsp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   1080 <epoll_wait@plt>
test   %eax,%eax
jle    1210 <main+0x90>
mov    %eax,%r14d
xor    %r15d,%r15d
jmp    1252 <main+0xd2>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x0(%r13),%edi
call   1070 <fflush@plt>
add    $0x1,%r15
cmp    %r15,%r14
je     1210 <main+0x90>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    (%r15,%r15,1),%r12
mov    0x24(%rsp,%r15,8),%eax
test   %eax,%eax
je     1280 <main+0x100>
cmp    %ebx,%eax
jne    1240 <main+0xc0>
jmp    12ac <main+0x12c>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %edi,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,0x1f(%rsp)
lea    0xd6b(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
mov    0x24(%rsp,%r12,4),%eax
cmp    %ebx,%eax
jne    1240 <main+0xc0>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xa,%edx
call   1060 <read@plt>
movb   $0x0,0x1f(%rsp)
lea    0xd3f(%rip),%rdi
mov    %rbp,%rsi
call   1030 <printf@plt>
jmp    1240 <main+0xc0>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [6 x i8] c"pipe1\00"
@O_RDONLY = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.epoll_event
%9 = alloca [10 x %struct.epoll_event]
%10 = alloca [10 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* @O_RDONLY
%14 = call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %13)
store i32 %14, i32* %6
%15 = call i32 @epoll_create1(i32 0)
store i32 %15, i32* %7
%16 = load i32, i32* @EPOLLIN
%17 = load i32, i32* @EPOLLET
%18 = or i32 %16, %17
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 0
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 1
%21 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %20, i32 0, i32 0
store i32 0, i32* %21
%22 = load i32, i32* %7
%23 = load i32, i32* @EPOLL_CTL_ADD
%24 = call i32 @epoll_ctl(i32 %22, i32 %23, i32 0, %struct.epoll_event* %8)
%25 = load i32, i32* %6
%26 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %8, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* %7
%29 = load i32, i32* @EPOLL_CTL_ADD
%30 = load i32, i32* %6
%31 = call i32 @epoll_ctl(i32 %28, i32 %29, i32 %30, %struct.epoll_event* %8)
br label %32
32: ; preds = %78, %2
%33 = load i32, i32* %7
%34 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %9, i64 0, i64 0
%35 = call i32 @epoll_wait(i32 %33, %struct.epoll_event* %34, i32 10, i32 -1)
store i32 %35, i32* %12
store i32 0, i32* %11
br label %36
36: ; preds = %75, %32
%37 = load i32, i32* %11
%38 = load i32, i32* %12
%39 = icmp slt i32 %37, %38
br i1 %39, label %40, label %78
40: ; preds = %36
%41 = bitcast [10 x i8]* %10 to i8**
%42 = call i32 @memset(i8** %41, i32 0, i32 10)
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %9, i64 0, i64 %44
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %45, i32 0, i32 1
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = icmp eq i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %40
%51 = bitcast [10 x i8]* %10 to i8**
%52 = call i32 @read(i32 0, i8** %51, i32 10)
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 9
store i8 0, i8* %53
%54 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%55 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %50, %40
%57 = load i32, i32* %11
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %9, i64 0, i64 %58
%60 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %59, i32 0, i32 1
%61 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %60, i32 0, i32 0
%62 = load i32, i32* %61
%63 = load i32, i32* %6
%64 = icmp eq i32 %62, %63
br i1 %64, label %65, label %72
65: ; preds = %56
%66 = load i32, i32* %6
%67 = bitcast [10 x i8]* %10 to i8**
%68 = call i32 @read(i32 %66, i8** %67, i32 10)
%69 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 9
store i8 0, i8* %69
%70 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%71 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %65, %56
%73 = load i32, i32* @stdout
%74 = call i32 @fflush(i32 %73)
br label %75
75: ; preds = %72
%76 = load i32, i32* %11
%77 = add nsw i32 %76, 1
store i32 %77, i32* %11
br label %36
78: ; preds = %36
br label %32
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@.str = [6 x i8] c"pipe1\00"
@O_RDONLY = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.epoll_event
%4 = alloca [10 x %struct.epoll_event]
%5 = alloca [10 x i8]
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @epoll_create1(i32 0)
%9 = bitcast %struct.epoll_event* %3 to i8*
%10 = bitcast [10 x %struct.epoll_event]* %4 to i8*
%11 = load i32, i32* @EPOLLIN
%12 = load i32, i32* @EPOLLET
%13 = or i32 %12, %11
%14 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 0
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1, i32 0
store i32 0, i32* %15
%16 = load i32, i32* @EPOLL_CTL_ADD
%17 = call i32 @epoll_ctl(i32 %8, i32 %16, i32 0, %struct.epoll_event* %3)
store i32 %7, i32* %15
%18 = load i32, i32* @EPOLL_CTL_ADD
%19 = call i32 @epoll_ctl(i32 %8, i32 %18, i32 %7, %struct.epoll_event* %3)
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%21 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %4, i64 0, i64 0
%22 = bitcast [10 x i8]* %5 to i8**
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 9
br label %24
24: ; preds = %27, %2
%25 = call i32 @epoll_wait(i32 %8, %struct.epoll_event* %21, i32 10, i32 -1)
%26 = icmp sgt i32 %25, 0
br i1 %26, label %28, label %27
27: ; preds = %46, %24
br label %24
28: ; preds = %24
%29 = zext i32 %25 to i64
br label %30
30: ; preds = %28, %46
%31 = phi i64 [ 0, %28 ], [ %49, %46 ]
%32 = call i32 @memset(i8** %22, i32 0, i32 10)
%33 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %4, i64 0, i64 %31, i32 1, i32 0
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %40
36: ; preds = %30
%37 = call i32 @read(i32 0, i8** %22, i32 10)
store i8 0, i8* %23
%38 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
%39 = load i32, i32* %33
br label %40
40: ; preds = %36, %30
%41 = phi i32 [ %39, %36 ], [ %34, %30 ]
%42 = icmp eq i32 %41, %7
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @read(i32 %7, i8** %22, i32 10)
store i8 0, i8* %23
%45 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %46
46: ; preds = %43, %40
%47 = load i32, i32* @stdout
%48 = call i32 @fflush(i32 %47)
%49 = add nuw nsw i64 %31, 1
%50 = icmp eq i64 %49, %29
br i1 %50, label %27, label %30
}