#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_CLOEXEC;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ MSG_DONTWAIT;
int accept_connect(int);
int epoll_create1(int /*<<< orphan*/);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int open_listen_socket();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ setnonblocking(int);
int epoll_loop() {
  int epollfd, nfds, n, listen_sock, conn_sock;
  struct epoll_event ev, events[10];
  epollfd = epoll_create1(EPOLL_CLOEXEC);
  if (epollfd == -1) {
    return -1;
  }
  listen_sock = open_listen_socket();
  ev.events = EPOLLIN;
  ev.data.fd = listen_sock;
  if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {
    perror("epoll_ctl: listen_sock");
  }
  for (;;) {
    nfds = epoll_wait(epollfd, events, 10, -1);
    if (nfds == -1) {
    }
    for (n = 0; n < nfds; ++n) {
      if (events[n].data.fd == listen_sock) {
        conn_sock = accept_connect(listen_sock);
        if (setnonblocking(conn_sock) < 0) {
          perror("setnonblocking");
        }
        ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = conn_sock;
        if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock, &ev) == -1) {
        }
      } else {
        int fd = events[n].data.fd;
        char buf[255];
        int len = recv(fd, buf, 255, MSG_DONTWAIT);
        buf[len] = '\0';
        printf("%s\n", buf);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<epoll_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   10b0 <epoll_create1@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11c4 <epoll_loop+0x34>
mov    $0xffffffff,%eax
add    $0x190,%rsp
pop    %rbp
ret
mov    $0x0,%al
call   1040 <open_listen_socket@plt>
mov    %eax,-0x10(%rbp)
mov    0x2e13(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    120d <epoll_loop+0x7d>
lea    0xdf8(%rip),%rdi
call   10a0 <perror@plt>
jmp    1212 <epoll_loop+0x82>
mov    -0x4(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   1080 <epoll_wait@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    123a <epoll_loop+0xaa>
jmp    123a <epoll_loop+0xaa>
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1330 <epoll_loop+0x1a0>
movslq -0xc(%rbp),%rax
mov    -0x6c(%rbp,%rax,8),%eax
cmp    -0x10(%rbp),%eax
jne    12cd <epoll_loop+0x13d>
mov    -0x10(%rbp),%edi
call   1060 <accept_connect@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1090 <setnonblocking@plt>
cmp    $0x0,%rax
jge    1287 <epoll_loop+0xf7>
lea    0xd95(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    0x2d29(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    0x2d34(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x20(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    12c8 <epoll_loop+0x138>
jmp    12c8 <epoll_loop+0x138>
jmp    131d <epoll_loop+0x18d>
movslq -0xc(%rbp),%rax
mov    -0x6c(%rbp,%rax,8),%eax
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%edi
lea    -0x180(%rbp),%rsi
mov    0x2cdf(%rip),%rax
mov    (%rax),%ecx
mov    $0xff,%edx
call   1030 <recv@plt>
mov    %eax,-0x184(%rbp)
movslq -0x184(%rbp),%rax
movb   $0x0,-0x180(%rbp,%rax,1)
lea    -0x180(%rbp),%rsi
lea    0xd0e(%rip),%rdi
call   1050 <printf@plt>
jmp    1322 <epoll_loop+0x192>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1241 <epoll_loop+0xb1>
jmp    1212 <epoll_loop+0x82>

x86 assembly (clang, -O2):
<epoll_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
call   10b0 <epoll_create1@plt>
cmp    $0xffffffff,%eax
je     12c8 <epoll_loop+0x138>
mov    %eax,%r12d
xor    %eax,%eax
call   1040 <open_listen_socket@plt>
mov    %eax,%ebp
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebp,0x4(%rsp)
mov    0x2e05(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %r12d,%edi
mov    %ebp,%edx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     12df <epoll_loop+0x14f>
lea    0x60(%rsp),%rbx
lea    0xe27(%rip),%r15
mov    %r12d,0xc(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r12d,%edi
lea    0x10(%rsp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   1080 <epoll_wait@plt>
test   %eax,%eax
jle    1210 <epoll_loop+0x80>
mov    %eax,%r13d
xor    %r14d,%r14d
mov    0x14(%rsp,%r14,8),%edi
cmp    %ebp,%edi
je     126d <epoll_loop+0xdd>
mov    0x2d87(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rsi
mov    $0xff,%edx
call   1030 <recv@plt>
cltq
movb   $0x0,0x60(%rsp,%rax,1)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
add    $0x1,%r14
cmp    %r14,%r13
jne    1231 <epoll_loop+0xa1>
jmp    1210 <epoll_loop+0x80>
mov    %ebp,%edi
call   1060 <accept_connect@plt>
mov    %eax,%r12d
mov    %eax,%edi
call   1090 <setnonblocking@plt>
test   %rax,%rax
js     12ba <epoll_loop+0x12a>
mov    0x2d36(%rip),%rax
mov    (%rax),%eax
mov    0x2d55(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    %r12d,0x4(%rsp)
mov    0x2d3c(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %r12d,%edx
mov    %edi,%r12d
mov    %rsp,%rcx
call   1070 <epoll_ctl@plt>
jmp    1262 <epoll_loop+0xd2>
lea    0xd56(%rip),%rdi
call   10a0 <perror@plt>
jmp    1283 <epoll_loop+0xf3>
mov    $0xffffffff,%eax
add    $0x168,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd1a(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f3 <epoll_loop+0x63>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
@EPOLL_CLOEXEC = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str = [23 x i8] c"epoll_ctl: listen_sock\00"
@.str.1 = [15 x i8] c"setnonblocking\00"
@EPOLLET = global i32 0
@MSG_DONTWAIT = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
define i32 @epoll_loop() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.epoll_event
%7 = alloca [10 x %struct.epoll_event]
%8 = alloca i32
%9 = alloca [255 x i8]
%10 = alloca i32
%11 = load i32, i32* @EPOLL_CLOEXEC
%12 = call i32 @epoll_create1(i32 %11)
store i32 %12, i32* %1
%13 = load i32, i32* %1
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %16
15: ; preds = %0
ret i32 -1
16: ; preds = %0
%17 = call i32 (...) @open_listen_socket()
store i32 %17, i32* %4
%18 = load i32, i32* @EPOLLIN
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %4
%21 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %1
%24 = load i32, i32* @EPOLL_CTL_ADD
%25 = load i32, i32* %4
%26 = call i32 @epoll_ctl(i32 %23, i32 %24, i32 %25, %struct.epoll_event* %6)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %16
%29 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %30
30: ; preds = %28, %16
br label %31
31: ; preds = %95, %30
%32 = load i32, i32* %1
%33 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %7, i64 0, i64 0
%34 = call i32 @epoll_wait(i32 %32, %struct.epoll_event* %33, i32 10, i32 -1)
store i32 %34, i32* %2
%35 = load i32, i32* %2
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %38
37: ; preds = %31
br label %38
38: ; preds = %37, %31
store i32 0, i32* %3
br label %39
39: ; preds = %92, %38
%40 = load i32, i32* %3
%41 = load i32, i32* %2
%42 = icmp slt i32 %40, %41
br i1 %42, label %43, label %95
43: ; preds = %39
%44 = load i32, i32* %3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %7, i64 0, i64 %45
%47 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %46, i32 0, i32 1
%48 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = load i32, i32* %4
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %75
52: ; preds = %43
%53 = load i32, i32* %4
%54 = call i32 @accept_connect(i32 %53)
store i32 %54, i32* %5
%55 = load i32, i32* %5
%56 = call i64 @setnonblocking(i32 %55)
%57 = icmp slt i64 %56, 0
br i1 %57, label %58, label %60
58: ; preds = %52
%59 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %60
60: ; preds = %58, %52
%61 = load i32, i32* @EPOLLIN
%62 = load i32, i32* @EPOLLET
%63 = or i32 %61, %62
%64 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 0
store i32 %63, i32* %64
%65 = load i32, i32* %5
%66 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i32 0, i32 1
%67 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %66, i32 0, i32 0
store i32 %65, i32* %67
%68 = load i32, i32* %1
%69 = load i32, i32* @EPOLL_CTL_ADD
%70 = load i32, i32* %5
%71 = call i32 @epoll_ctl(i32 %68, i32 %69, i32 %70, %struct.epoll_event* %6)
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %74
73: ; preds = %60
br label %74
74: ; preds = %73, %60
br label %91
75: ; preds = %43
%76 = load i32, i32* %3
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %7, i64 0, i64 %77
%79 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %78, i32 0, i32 1
%80 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i32 0, i32 0
%81 = load i32, i32* %80
store i32 %81, i32* %8
%82 = load i32, i32* %8
%83 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%84 = load i32, i32* @MSG_DONTWAIT
%85 = call i32 @recv(i32 %82, i8* %83, i32 255, i32 %84)
store i32 %85, i32* %10
%86 = load i32, i32* %10
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [255 x i8], [255 x i8]* %9, i64 0, i64 0
%90 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %89)
br label %91
91: ; preds = %75, %74
br label %92
92: ; preds = %91
%93 = load i32, i32* %3
%94 = add nsw i32 %93, 1
store i32 %94, i32* %3
br label %39
95: ; preds = %39
br label %31
}

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