#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 /*<<< orphan*/ fd;
};
struct epoll_event {
  TYPE_1__ data;
  int /*<<< orphan*/ events;
};

/* Variables and functions */
int /*<<< orphan*/ EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int create_socket(int);
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int main(int argc, char const *argv[]) {
  int epfd;
  int fd[10];
  int port = 5000;
  epfd = epoll_create(10);
  for (int i = 0; i < 10; i++) {
    struct epoll_event ep_ev;
    ep_ev.events = EPOLLIN;
    fd[i] = create_socket(port + i);
    epoll_ctl(epfd, EPOLL_CTL_ADD, fd[i], &ep_ev);
  }
  struct epoll_event ev;
  for (;;) {
    int ret = epoll_wait(epfd, &ev, 10, 100);
    if (ret == 1) {
      char buf[1];
      puts("New event!");
      read(ev.data.fd, buf, 1);
      puts(buf);
      break;
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1388,-0x44(%rbp)
mov    $0xa,%edi
call   1080 <epoll_create@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x48(%rbp)
cmpl   $0xa,-0x48(%rbp)
jge    11e7 <main+0x87>
mov    0x2e46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x44(%rbp),%edi
add    -0x48(%rbp),%edi
call   1060 <create_socket@plt>
mov    %eax,%ecx
movslq -0x48(%rbp),%rax
mov    %ecx,-0x40(%rbp,%rax,4)
mov    -0x14(%rbp),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
movslq -0x48(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%edx
lea    -0x50(%rbp),%rcx
call   1040 <epoll_ctl@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1191 <main+0x31>
jmp    11ec <main+0x8c>
mov    -0x14(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0xa,%edx
mov    $0x64,%ecx
call   1070 <epoll_wait@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x1,-0x5c(%rbp)
jne    123a <main+0xda>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
mov    -0x58(%rbp),%edi
lea    -0x5d(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
lea    -0x5d(%rbp),%rdi
call   1030 <puts@plt>
jmp    123f <main+0xdf>
jmp    11ec <main+0x8c>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    $0xa,%edi
call   1080 <epoll_create@plt>
mov    %eax,%ebx
mov    0x2e6a(%rip),%r15
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x1388,%edi
call   1060 <create_socket@plt>
mov    0x2e4a(%rip),%r12
mov    (%r12),%esi
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x1389,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138a,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138b,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138c,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138d,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138e,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x138f,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x1390,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
mov    (%r15),%eax
mov    %eax,0xc(%rsp)
mov    $0x1391,%edi
call   1060 <create_socket@plt>
mov    (%r12),%esi
mov    %ebx,%edi
mov    %eax,%edx
mov    %r14,%rcx
call   1040 <epoll_ctl@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xa,%edx
mov    $0x64,%ecx
call   1070 <epoll_wait@plt>
cmp    $0x1,%eax
jne    12e0 <main+0x180>
lea    0xd00(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
lea    0x17(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [11 x i8] c"New event!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [10 x i32]
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.epoll_event
%11 = alloca %struct.epoll_event
%12 = alloca i32
%13 = alloca [1 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 5000, i32* %8
%14 = call i32 @epoll_create(i32 10)
store i32 %14, i32* %6
store i32 0, i32* %9
br label %15
15: ; preds = %35, %2
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 10
br i1 %17, label %18, label %38
18: ; preds = %15
%19 = load i32, i32* @EPOLLIN
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %10, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* %8
%22 = load i32, i32* %9
%23 = add nsw i32 %21, %22
%24 = call i32 @create_socket(i32 %23)
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %26
store i32 %24, i32* %27
%28 = load i32, i32* %6
%29 = load i32, i32* @EPOLL_CTL_ADD
%30 = load i32, i32* %9
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds [10 x i32], [10 x i32]* %7, i64 0, i64 %31
%33 = load i32, i32* %32
%34 = call i32 @epoll_ctl(i32 %28, i32 %29, i32 %33, %struct.epoll_event* %10)
br label %35
35: ; preds = %18
%36 = load i32, i32* %9
%37 = add nsw i32 %36, 1
store i32 %37, i32* %9
br label %15
38: ; preds = %15
br label %39
39: ; preds = %53, %38
%40 = load i32, i32* %6
%41 = call i32 @epoll_wait(i32 %40, %struct.epoll_event* %11, i32 10, i32 100)
store i32 %41, i32* %12
%42 = load i32, i32* %12
%43 = icmp eq i32 %42, 1
br i1 %43, label %44, label %53
44: ; preds = %39
%45 = call i32 @puts(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %11, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%50 = call i32 @read(i32 %48, i8* %49, i32 1)
%51 = getelementptr inbounds [1 x i8], [1 x i8]* %13, i64 0, i64 0
%52 = call i32 @puts(i8* %51)
br label %54
53: ; preds = %39
br label %39
54: ; preds = %44
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [11 x i8] c"New event!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.epoll_event
%4 = alloca %struct.epoll_event
%5 = alloca [1 x i8]
%6 = tail call i32 @epoll_create(i32 10)
%7 = bitcast %struct.epoll_event* %3 to i8*
%8 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %3, i64 0, i32 1
%9 = load i32, i32* @EPOLLIN
store i32 %9, i32* %8
%10 = call i32 @create_socket(i32 5000)
%11 = load i32, i32* @EPOLL_CTL_ADD
%12 = call i32 @epoll_ctl(i32 %6, i32 %11, i32 %10, %struct.epoll_event* %3)
%13 = load i32, i32* @EPOLLIN
store i32 %13, i32* %8
%14 = call i32 @create_socket(i32 5001)
%15 = load i32, i32* @EPOLL_CTL_ADD
%16 = call i32 @epoll_ctl(i32 %6, i32 %15, i32 %14, %struct.epoll_event* %3)
%17 = load i32, i32* @EPOLLIN
store i32 %17, i32* %8
%18 = call i32 @create_socket(i32 5002)
%19 = load i32, i32* @EPOLL_CTL_ADD
%20 = call i32 @epoll_ctl(i32 %6, i32 %19, i32 %18, %struct.epoll_event* %3)
%21 = load i32, i32* @EPOLLIN
store i32 %21, i32* %8
%22 = call i32 @create_socket(i32 5003)
%23 = load i32, i32* @EPOLL_CTL_ADD
%24 = call i32 @epoll_ctl(i32 %6, i32 %23, i32 %22, %struct.epoll_event* %3)
%25 = load i32, i32* @EPOLLIN
store i32 %25, i32* %8
%26 = call i32 @create_socket(i32 5004)
%27 = load i32, i32* @EPOLL_CTL_ADD
%28 = call i32 @epoll_ctl(i32 %6, i32 %27, i32 %26, %struct.epoll_event* %3)
%29 = load i32, i32* @EPOLLIN
store i32 %29, i32* %8
%30 = call i32 @create_socket(i32 5005)
%31 = load i32, i32* @EPOLL_CTL_ADD
%32 = call i32 @epoll_ctl(i32 %6, i32 %31, i32 %30, %struct.epoll_event* %3)
%33 = load i32, i32* @EPOLLIN
store i32 %33, i32* %8
%34 = call i32 @create_socket(i32 5006)
%35 = load i32, i32* @EPOLL_CTL_ADD
%36 = call i32 @epoll_ctl(i32 %6, i32 %35, i32 %34, %struct.epoll_event* %3)
%37 = load i32, i32* @EPOLLIN
store i32 %37, i32* %8
%38 = call i32 @create_socket(i32 5007)
%39 = load i32, i32* @EPOLL_CTL_ADD
%40 = call i32 @epoll_ctl(i32 %6, i32 %39, i32 %38, %struct.epoll_event* %3)
%41 = load i32, i32* @EPOLLIN
store i32 %41, i32* %8
%42 = call i32 @create_socket(i32 5008)
%43 = load i32, i32* @EPOLL_CTL_ADD
%44 = call i32 @epoll_ctl(i32 %6, i32 %43, i32 %42, %struct.epoll_event* %3)
%45 = load i32, i32* @EPOLLIN
store i32 %45, i32* %8
%46 = call i32 @create_socket(i32 5009)
%47 = load i32, i32* @EPOLL_CTL_ADD
%48 = call i32 @epoll_ctl(i32 %6, i32 %47, i32 %46, %struct.epoll_event* %3)
%49 = bitcast %struct.epoll_event* %4 to i8*
br label %50
50: ; preds = %50, %2
%51 = call i32 @epoll_wait(i32 %6, %struct.epoll_event* %4, i32 10, i32 100)
%52 = icmp eq i32 %51, 1
br i1 %52, label %53, label %50
53: ; preds = %50
%54 = getelementptr inbounds [1 x i8], [1 x i8]* %5, i64 0, i64 0
%55 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%56 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %4, i64 0, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @read(i32 %57, i8* %54, i32 1)
%59 = call i32 @puts(i8* %54)
ret i32 0
}