#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_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_4__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_2__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_3__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ servaddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ ECONNRESET;
int EPOLLET;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_MOD;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(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 /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_2__);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
size_t read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char const *argv[]) {
  int i, maxi, listenfd, connfd, sockfd, epfd, nfds;
  ssize_t n;
  char BUF[4096];
  socklen_t clilen;
  struct epoll_event ev, events[20];
  epfd = epoll_create(256);
  struct sockaddr_in cliaddr, servaddr;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  ev.data.fd = listenfd;
  ev.events = EPOLLIN | EPOLLET;
  epoll_ctl(epfd, EPOLL_CTL_ADD, listenfd, &ev);
  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  servaddr.sin_port = htons(9877);
  bind(listenfd, (struct sockaddr *)&servaddr, sizeof(servaddr));
  listen(listenfd, 20);
  maxi = 0;
  for (;;) {
    nfds = epoll_wait(epfd, events, 20, 0);
    for (i = 0; i < nfds; ++i) {
      if (events[i].data.fd == listenfd) {
        connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
        if (connfd < 0) {
          perror("connfd < 0");
          exit(1);
        }
        char *str = inet_ntoa(cliaddr.sin_addr);
        printf("accept a connect from %s\n", str);
        ev.data.fd = connfd;
        ev.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_ADD, connfd, &ev);
      } else if (events[i].events & EPOLLIN) {
        printf("EPOLLIN\n");
        if ((sockfd = events[i].data.fd) < 0)
          continue;
        if ((n = read(sockfd, BUF, 4096)) < 0) {
          if (errno == ECONNRESET) {
            close(sockfd);
            events[i].data.fd = -1;
          } else {
            printf("readline error\n");
          }
        } else if (n == 0) {
          close(sockfd);
          events[i].data.fd = -1;
        }
        BUF[n] = '\0';
        printf("AFTER EPOLLIN\n");
        ev.data.fd = sockfd;
        ev.events = EPOLLOUT | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &ev);
      } else if (events[i].events & EPOLLOUT) {
        sockfd = events[i].data.fd;
        write(sockfd, BUF, n);
        ev.data.fd = sockfd;
        ev.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &ev);
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x100,%edi
call   1110 <epoll_create@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x104c(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    0x2d2d(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1050(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
lea    -0x1050(%rbp),%rcx
call   1090 <epoll_ctl@plt>
lea    -0x1110(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1108(%rbp)
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
call   1070 <htonl@plt>
mov    %eax,-0x1110(%rbp)
mov    $0x2695,%edi
call   1050 <htons@plt>
mov    %eax,-0x110c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x1110(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <bind@plt>
mov    -0x1c(%rbp),%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x28(%rbp),%edi
lea    -0x10f0(%rbp),%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
call   10c0 <epoll_wait@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    15a6 <main+0x396>
movslq -0x14(%rbp),%rax
mov    -0x10ec(%rbp,%rax,8),%eax
cmp    -0x1c(%rbp),%eax
jne    13db <main+0x1cb>
mov    -0x1c(%rbp),%edi
lea    -0x1100(%rbp),%rsi
lea    -0x1044(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1373 <main+0x163>
lea    0xc9c(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x1100(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x1118(%rbp)
mov    -0x1118(%rbp),%rsi
lea    0xc78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x104c(%rbp)
mov    0x2c36(%rip),%rax
mov    (%rax),%eax
mov    0x2be5(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1050(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2c13(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%edx
lea    -0x1050(%rbp),%rcx
call   1090 <epoll_ctl@plt>
jmp    1593 <main+0x383>
movslq -0x14(%rbp),%rax
mov    -0x10f0(%rbp,%rax,8),%eax
mov    0x2bf3(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     150f <main+0x2ff>
lea    0xc3c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movslq -0x14(%rbp),%rax
mov    -0x10ec(%rbp,%rax,8),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1422 <main+0x212>
jmp    1598 <main+0x388>
mov    -0x24(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    $0x1000,%edx
call   10a0 <read@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jae    148d <main+0x27d>
mov    0x2b55(%rip),%rax
mov    (%rax),%rax
mov    0x2b6b(%rip),%rcx
cmp    (%rcx),%rax
jne    147a <main+0x26a>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0x10ec(%rbp,%rax,8)
ff ff ff ff
jmp    1488 <main+0x278>
lea    0xba4(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    14b4 <main+0x2a4>
cmpq   $0x0,-0x38(%rbp)
jne    14af <main+0x29f>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0x10ec(%rbp,%rax,8)
ff ff ff ff
jmp    14b4 <main+0x2a4>
mov    -0x38(%rbp),%rax
movb   $0x0,-0x1040(%rbp,%rax,1)
lea    0xb6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x104c(%rbp)
mov    0x2aca(%rip),%rax
mov    (%rax),%eax
mov    0x2ab1(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1050(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2abf(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
lea    -0x1050(%rbp),%rcx
call   1090 <epoll_ctl@plt>
jmp    158e <main+0x37e>
movslq -0x14(%rbp),%rax
mov    -0x10f0(%rbp,%rax,8),%eax
mov    0x2a87(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1589 <main+0x379>
movslq -0x14(%rbp),%rax
mov    -0x10ec(%rbp,%rax,8),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x1040(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1030 <write@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x104c(%rbp)
mov    0x2a83(%rip),%rax
mov    (%rax),%eax
mov    0x2a32(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x1050(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2a40(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
lea    -0x1050(%rbp),%rcx
call   1090 <epoll_ctl@plt>
jmp    158e <main+0x37e>
jmp    1593 <main+0x383>
jmp    1598 <main+0x388>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    131a <main+0x10a>
jmp    12fa <main+0xea>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10d8,%rsp
mov    $0x100,%edi
call   1120 <epoll_create@plt>
mov    %eax,%ebx
mov    0x2da4(%rip),%r14
mov    (%r14),%edi
mov    0x2d6a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%ebp
mov    0x2d80(%rip),%rcx
mov    0x2d41(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %ebp,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %ebp,%edx
call   10a0 <epoll_ctl@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    $0x2695,%edi
call   1060 <htons@plt>
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
mov    %ebp,%edi
mov    $0x14,%esi
call   10c0 <listen@plt>
nopl   0x0(%rax,%rax,1)
mov    %ebp,%r12d
lea    0x30(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
call   10d0 <epoll_wait@plt>
test   %eax,%eax
jle    12f0 <main+0xd0>
mov    %eax,%r14d
xor    %r15d,%r15d
mov    %r12d,%ebp
jmp    135d <main+0x13d>
movb   $0x0,0xd0(%rsp,%rax,1)
lea    0xd06(%rip),%rdi
call   1030 <puts@plt>
mov    %r12d,0x4(%rsp)
mov    0x2c78(%rip),%rax
mov    (%rax),%eax
mov    0x2c77(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %r12d,%edx
mov    %rsp,%rcx
call   10a0 <epoll_ctl@plt>
add    $0x1,%r15
cmp    %r15,%r14
je     12e0 <main+0xc0>
mov    0x34(%rsp,%r15,8),%r12d
cmp    %ebp,%r12d
jne    13c0 <main+0x1a0>
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rdx
call   1110 <accept@plt>
test   %eax,%eax
js     146a <main+0x24a>
mov    %eax,%r12d
mov    0x20(%rsp),%edi
call   1050 <inet_ntoa@plt>
lea    0xc78(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12d,0x4(%rsp)
mov    0x2bff(%rip),%rax
mov    (%rax),%eax
mov    0x2c2e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2c1a(%rip),%rax
jmp    1345 <main+0x125>
mov    0x30(%rsp,%r15,8),%eax
mov    0x2c14(%rip),%rcx
test   %eax,(%rcx)
je     142c <main+0x20c>
lea    (%r15,%r15,1),%r13
lea    0xc50(%rip),%rdi
call   1030 <puts@plt>
mov    0x34(%rsp,%r13,4),%r12d
test   %r12d,%r12d
js     1354 <main+0x134>
mov    %r12d,%edi
lea    0xd0(%rsp),%rsi
mov    $0x1000,%edx
call   10b0 <read@plt>
test   %rax,%rax
mov    %rax,0x8(%rsp)
jne    1310 <main+0xf0>
mov    %r12d,%edi
call   1090 <close@plt>
mov    0x8(%rsp),%rax
movl   $0xffffffff,0x34(%rsp,%r13,4)
ff ff
jmp    1310 <main+0xf0>
mov    0x2b7d(%rip),%rcx
test   %eax,(%rcx)
je     1354 <main+0x134>
mov    %r12d,%edi
lea    0xd0(%rsp),%rsi
mov    0x8(%rsp),%rdx
call   1040 <write@plt>
mov    %r12d,0x4(%rsp)
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    0x2b7b(%rip),%rcx
jmp    1339 <main+0x119>
lea    0xb8f(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@INADDR_ANY = global i32 0
@.str = [11 x i8] c"connfd < 0\00"
@.str.1 = [26 x i8] c"accept a connect from %s\0A\00"
@.str.2 = [9 x i8] c"EPOLLIN\0A\00"
@errno = global i64 0
@ECONNRESET = global i64 0
@.str.3 = [16 x i8] c"readline error\0A\00"
@.str.4 = [15 x i8] c"AFTER EPOLLIN\0A\00"
@EPOLLOUT = global i32 0
@EPOLL_CTL_MOD = 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 i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca [4096 x i8]
%15 = alloca i32
%16 = alloca %struct.epoll_event
%17 = alloca [20 x %struct.epoll_event]
%18 = alloca %struct.sockaddr_in
%19 = alloca %struct.sockaddr_in
%20 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = call i32 @epoll_create(i32 256)
store i32 %21, i32* %11
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = call i32 @socket(i32 %22, i32 %23, i32 0)
store i32 %24, i32* %8
%25 = load i32, i32* %8
%26 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = load i32, i32* @EPOLLIN
%29 = load i32, i32* @EPOLLET
%30 = or i32 %28, %29
%31 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 0
store i32 %30, i32* %31
%32 = load i32, i32* %11
%33 = load i32, i32* @EPOLL_CTL_ADD
%34 = load i32, i32* %8
%35 = call i32 @epoll_ctl(i32 %32, i32 %33, i32 %34, %struct.epoll_event* %16)
%36 = call i32 @bzero(%struct.sockaddr_in* %19, i32 12)
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* @INADDR_ANY
%40 = call i32 @htonl(i32 %39)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%42 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %41, i32 0, i32 0
store i32 %40, i32* %42
%43 = call i32 @htons(i32 9877)
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 1
store i32 %43, i32* %44
%45 = load i32, i32* %8
%46 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%47 = call i32 @bind(i32 %45, %struct.sockaddr* %46, i32 12)
%48 = load i32, i32* %8
%49 = call i32 @listen(i32 %48, i32 20)
store i32 0, i32* %7
br label %50
50: ; preds = %197, %2
%51 = load i32, i32* %11
%52 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 0
%53 = call i32 @epoll_wait(i32 %51, %struct.epoll_event* %52, i32 20, i32 0)
store i32 %53, i32* %12
store i32 0, i32* %6
br label %54
54: ; preds = %194, %50
%55 = load i32, i32* %6
%56 = load i32, i32* %12
%57 = icmp slt i32 %55, %56
br i1 %57, label %58, label %197
58: ; preds = %54
%59 = load i32, i32* %6
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %60
%62 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %61, i32 0, i32 1
%63 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = load i32, i32* %8
%66 = icmp eq i32 %64, %65
br i1 %66, label %67, label %94
67: ; preds = %58
%68 = load i32, i32* %8
%69 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%70 = call i32 @accept(i32 %68, %struct.sockaddr* %69, i32* %15)
store i32 %70, i32* %9
%71 = load i32, i32* %9
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %67
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i8* @inet_ntoa(i32 %79)
store i8* %80, i8** %20
%81 = load i8*, i8** %20
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %81)
%83 = load i32, i32* %9
%84 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 1
%85 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %84, i32 0, i32 0
store i32 %83, i32* %85
%86 = load i32, i32* @EPOLLIN
%87 = load i32, i32* @EPOLLET
%88 = or i32 %86, %87
%89 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 0
store i32 %88, i32* %89
%90 = load i32, i32* %11
%91 = load i32, i32* @EPOLL_CTL_ADD
%92 = load i32, i32* %9
%93 = call i32 @epoll_ctl(i32 %90, i32 %91, i32 %92, %struct.epoll_event* %16)
br label %193
94: ; preds = %58
%95 = load i32, i32* %6
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %96
%98 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = load i32, i32* @EPOLLIN
%101 = and i32 %99, %100
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %160
103: ; preds = %94
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%105 = load i32, i32* %6
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %106
%108 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %107, i32 0, i32 1
%109 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %108, i32 0, i32 0
%110 = load i32, i32* %109
store i32 %110, i32* %10
%111 = icmp slt i32 %110, 0
br i1 %111, label %112, label %113
112: ; preds = %103
br label %194
113: ; preds = %103
%114 = load i32, i32* %10
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%116 = call i64 @read(i32 %114, i8* %115, i32 4096)
store i64 %116, i64* %13
%117 = icmp ult i64 %116, 0
br i1 %117, label %118, label %133
118: ; preds = %113
%119 = load i64, i64* @errno
%120 = load i64, i64* @ECONNRESET
%121 = icmp eq i64 %119, %120
br i1 %121, label %122, label %130
122: ; preds = %118
%123 = load i32, i32* %10
%124 = call i32 @close(i32 %123)
%125 = load i32, i32* %6
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %126
%128 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %127, i32 0, i32 1
%129 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %128, i32 0, i32 0
store i32 -1, i32* %129
br label %132
130: ; preds = %118
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %132
132: ; preds = %130, %122
br label %145
133: ; preds = %113
%134 = load i64, i64* %13
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %144
136: ; preds = %133
%137 = load i32, i32* %10
%138 = call i32 @close(i32 %137)
%139 = load i32, i32* %6
%140 = sext i32 %139 to i64
%141 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %140
%142 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %141, i32 0, i32 1
%143 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %142, i32 0, i32 0
store i32 -1, i32* %143
br label %144
144: ; preds = %136, %133
br label %145
145: ; preds = %144, %132
%146 = load i64, i64* %13
%147 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 %146
store i8 0, i8* %147
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
%149 = load i32, i32* %10
%150 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 1
%151 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %150, i32 0, i32 0
store i32 %149, i32* %151
%152 = load i32, i32* @EPOLLOUT
%153 = load i32, i32* @EPOLLET
%154 = or i32 %152, %153
%155 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 0
store i32 %154, i32* %155
%156 = load i32, i32* %11
%157 = load i32, i32* @EPOLL_CTL_MOD
%158 = load i32, i32* %10
%159 = call i32 @epoll_ctl(i32 %156, i32 %157, i32 %158, %struct.epoll_event* %16)
br label %192
160: ; preds = %94
%161 = load i32, i32* %6
%162 = sext i32 %161 to i64
%163 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %162
%164 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %163, i32 0, i32 0
%165 = load i32, i32* %164
%166 = load i32, i32* @EPOLLOUT
%167 = and i32 %165, %166
%168 = icmp ne i32 %167, 0
br i1 %168, label %169, label %191
169: ; preds = %160
%170 = load i32, i32* %6
%171 = sext i32 %170 to i64
%172 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %17, i64 0, i64 %171
%173 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %172, i32 0, i32 1
%174 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %173, i32 0, i32 0
%175 = load i32, i32* %174
store i32 %175, i32* %10
%176 = load i32, i32* %10
%177 = getelementptr inbounds [4096 x i8], [4096 x i8]* %14, i64 0, i64 0
%178 = load i64, i64* %13
%179 = call i32 @write(i32 %176, i8* %177, i64 %178)
%180 = load i32, i32* %10
%181 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 1
%182 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %181, i32 0, i32 0
store i32 %180, i32* %182
%183 = load i32, i32* @EPOLLIN
%184 = load i32, i32* @EPOLLET
%185 = or i32 %183, %184
%186 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %16, i32 0, i32 0
store i32 %185, i32* %186
%187 = load i32, i32* %11
%188 = load i32, i32* @EPOLL_CTL_MOD
%189 = load i32, i32* %10
%190 = call i32 @epoll_ctl(i32 %187, i32 %188, i32 %189, %struct.epoll_event* %16)
br label %191
191: ; preds = %169, %160
br label %192
192: ; preds = %191, %145
br label %193
193: ; preds = %192, %76
br label %194
194: ; preds = %193, %112
%195 = load i32, i32* %6
%196 = add nsw i32 %195, 1
store i32 %196, i32* %6
br label %54
197: ; preds = %54
br label %50
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_4__, i32, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@INADDR_ANY = global i32 0
@.str = [11 x i8] c"connfd < 0\00"
@.str.1 = [26 x i8] c"accept a connect from %s\0A\00"
@errno = global i64 0
@ECONNRESET = global i64 0
@EPOLLOUT = global i32 0
@EPOLL_CTL_MOD = global i32 0
@str = [8 x i8] c"EPOLLIN\00"
@str.5 = [14 x i8] c"AFTER EPOLLIN\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [4096 x i8]
%4 = alloca i32
%5 = alloca %struct.epoll_event
%6 = alloca [20 x %struct.epoll_event]
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.sockaddr_in
%9 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.epoll_event* %5 to i8*
%12 = bitcast [20 x %struct.epoll_event]* %6 to i8*
%13 = tail call i32 @epoll_create(i32 256)
%14 = bitcast %struct.sockaddr_in* %7 to i8*
%15 = bitcast %struct.sockaddr_in* %8 to i8*
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = tail call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* @EPOLLIN
%21 = load i32, i32* @EPOLLET
%22 = or i32 %21, %20
%23 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0
store i32 %22, i32* %23
%24 = load i32, i32* @EPOLL_CTL_ADD
%25 = call i32 @epoll_ctl(i32 %13, i32 %24, i32 %18, %struct.epoll_event* %5)
%26 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0, i32 0
store i32 %30, i32* %31
%32 = call i32 @htons(i32 9877)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 1
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%35 = call i32 @bind(i32 %18, %struct.sockaddr* %34, i32 12)
%36 = call i32 @listen(i32 %18, i32 20)
%37 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%38 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 0
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
br label %40
40: ; preds = %102, %2
%41 = phi i64 [ undef, %2 ], [ %103, %102 ]
br label %42
42: ; preds = %40, %42
%43 = call i32 @epoll_wait(i32 %13, %struct.epoll_event* %38, i32 20, i32 0)
%44 = icmp sgt i32 %43, 0
br i1 %44, label %45, label %42
45: ; preds = %42
%46 = zext i32 %43 to i64
br label %47
47: ; preds = %45, %102
%48 = phi i64 [ 0, %45 ], [ %104, %102 ]
%49 = phi i64 [ %41, %45 ], [ %103, %102 ]
%50 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 %48, i32 1, i32 0
%51 = load i32, i32* %50
%52 = icmp eq i32 %51, %18
br i1 %52, label %53, label %66
53: ; preds = %47
%54 = call i32 @accept(i32 %18, %struct.sockaddr* %37, i32* %4)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %59
56: ; preds = %53
%57 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %53
%60 = load i32, i32* %39
%61 = call i8* @inet_ntoa(i32 %60)
%62 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %61)
store i32 %54, i32* %19
%63 = load i32, i32* @EPOLLIN
%64 = load i32, i32* @EPOLLET
%65 = or i32 %64, %63
store i32 %65, i32* %23
br label %96
66: ; preds = %47
%67 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 %48, i32 0
%68 = load i32, i32* %67
%69 = load i32, i32* @EPOLLIN
%70 = and i32 %69, %68
%71 = icmp eq i32 %70, 0
br i1 %71, label %87, label %72
72: ; preds = %66
%73 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str, i64 0, i64 0))
%74 = load i32, i32* %50
%75 = icmp slt i32 %74, 0
br i1 %75, label %102, label %76
76: ; preds = %72
%77 = call i64 @read(i32 %74, i8* %9, i32 4096)
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @close(i32 %74)
store i32 -1, i32* %50
br label %81
81: ; preds = %76, %79
%82 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %77
store i8 0, i8* %82
%83 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.5, i64 0, i64 0))
store i32 %74, i32* %19
%84 = load i32, i32* @EPOLLOUT
%85 = load i32, i32* @EPOLLET
%86 = or i32 %85, %84
store i32 %86, i32* %23
br label %96
87: ; preds = %66
%88 = load i32, i32* @EPOLLOUT
%89 = and i32 %88, %68
%90 = icmp eq i32 %89, 0
br i1 %90, label %102, label %91
91: ; preds = %87
%92 = call i32 @write(i32 %51, i8* %9, i64 %49)
store i32 %51, i32* %19
%93 = load i32, i32* @EPOLLIN
%94 = load i32, i32* @EPOLLET
%95 = or i32 %94, %93
store i32 %95, i32* %23
br label %96
96: ; preds = %81, %91, %59
%97 = phi i32* [ @EPOLL_CTL_ADD, %59 ], [ @EPOLL_CTL_MOD, %91 ], [ @EPOLL_CTL_MOD, %81 ]
%98 = phi i32 [ %54, %59 ], [ %51, %91 ], [ %74, %81 ]
%99 = phi i64 [ %49, %59 ], [ %49, %91 ], [ %77, %81 ]
%100 = load i32, i32* %97
%101 = call i32 @epoll_ctl(i32 %13, i32 %100, i32 %98, %struct.epoll_event* %5)
br label %102
102: ; preds = %96, %87, %72
%103 = phi i64 [ %49, %72 ], [ %49, %87 ], [ %99, %96 ]
%104 = add nuw nsw i64 %48, 1
%105 = icmp eq i64 %104, %46
br i1 %105, label %40, label %47
}