#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ srvaddr;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ line;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int ECONNREFUSED;
int EPOLLET;
int EPOLLIN;
int EPOLLOUT;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_MOD;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int 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);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ setnonblocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  int listenfd, epfd, maxi, i, nfds, connfd, sockfd;
  ssize_t n;
  char line[1000];
  socklen_t clilen;
  struct epoll_event ev, events[20];
  epfd = epoll_create(256);
  struct sockaddr_in srvaddr;
  struct sockaddr_in cliaddr;
  listenfd = socket(AF_INET, SOCK_STREAM, 0);
  setnonblocking(listenfd);
  ev.data.fd = listenfd;
  ev.events = EPOLLIN | EPOLLET;
  epoll_ctl(epfd, EPOLL_CTL_ADD, listenfd, &ev);
  bzero(&srvaddr, sizeof(srvaddr));
  srvaddr.sin_family = AF_INET;
  char *local_addr = "127.0.0.1";
  inet_aton(local_addr, &(srvaddr.sin_addr));
  srvaddr.sin_port = htons(5556);
  if ((bind(listenfd, (struct sockaddr *)&srvaddr, sizeof(srvaddr))) == -1) {
    perror("bind error");
    exit(1);
  }
  if ((listen(listenfd, 20)) == -1) {
    perror("listen error");
    exit(1);
  }
  printf("%s\n", "Wait connect...");
  maxi = 0;
  for (;;) {
    nfds = epoll_wait(epfd, events, 20, 500);
    for (i = 0; i < nfds; ++i) {
      if (events[i].data.fd == listenfd) {
        connfd = accept(listenfd, (struct sockaddr *)&cliaddr, &clilen);
        if (connfd == -1) {
          perror("accept error");
          exit(1);
        }
        setnonblocking(connfd);
        char *str = inet_ntoa(cliaddr.sin_addr);
        printf("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("%s: %d\n", "EPOLLIN", i);
        if ((sockfd = events[i].data.fd) < 0) {
          continue;
        }
        memset(line, 0, sizeof(line));
        if ((n = recv(sockfd, line, 1000, 0)) < 0) {
          if (n == ECONNREFUSED) {
            perror("network error");
            close(sockfd);
            events[i].data.fd = -1;
          }
        } else if (n == 0) {
          perror("read empty");
          close(sockfd);
          events[i].data.fd = -1;
        }
        line[1000] = '\0';
        printf("Read from client:(%d) %s\n", n, line);
        ev.data.fd = sockfd;
        ev.events = EPOLLOUT | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &ev);
      } else if (events[i].events & EPOLLOUT) {
        printf("%s: %d\n", "EPOLLOUT", i);
        sockfd = events[i].data.fd;
        write(sockfd, "Hel", 13);
        ev.data.fd = sockfd;
        ev.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &ev);
      }
    }
  }
  printf("%d\n", listenfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x500,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x100,%edi
call   1130 <epoll_create@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d8b(%rip),%rax
mov    (%rax),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10f0 <setnonblocking@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%eax
mov    0x2d15(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x430(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2d33(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x430(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
lea    -0x4e0(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4d8(%rbp)
lea    0xd23(%rip),%rax
mov    %rax,-0x4f8(%rbp)
mov    -0x4f8(%rbp),%rdi
lea    -0x4e0(%rbp),%rsi
call   10b0 <inet_aton@plt>
mov    $0x15b4,%edi
call   1060 <htons@plt>
mov    %eax,-0x4dc(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x4e0(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0xffffffff,%eax
jne    133a <main+0x10a>
lea    0xcdf(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x14,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1366 <main+0x136>
lea    0xcbe(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
lea    0xd22(%rip),%rdi
lea    0xcae(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x4d0(%rbp),%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   10d0 <epoll_wait@plt>
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    166d <main+0x43d>
movslq -0x20(%rbp),%rax
mov    -0x4cc(%rbp,%rax,8),%eax
cmp    -0x14(%rbp),%eax
jne    146e <main+0x23e>
mov    -0x14(%rbp),%edi
lea    -0x4f0(%rbp),%rsi
lea    -0x424(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x28(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
jne    13fe <main+0x1ce>
lea    0xc43(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1140 <exit@plt>
mov    -0x28(%rbp),%edi
call   10f0 <setnonblocking@plt>
mov    -0x4f0(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x500(%rbp)
mov    -0x500(%rbp),%rsi
lea    0xc19(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2ba3(%rip),%rax
mov    (%rax),%eax
mov    0x2b62(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x430(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2b80(%rip),%rax
mov    (%rax),%esi
mov    -0x28(%rbp),%edx
lea    -0x430(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    165a <main+0x42a>
movslq -0x20(%rbp),%rax
mov    -0x4d0(%rbp,%rax,8),%eax
mov    0x2b60(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     15bd <main+0x38d>
mov    -0x20(%rbp),%edx
lea    0xbbb(%rip),%rdi
lea    0xbbc(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x20(%rbp),%rax
mov    -0x4cc(%rbp,%rax,8),%eax
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    14bf <main+0x28f>
jmp    165f <main+0x42f>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1080 <memset@plt>
mov    -0x2c(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    152e <main+0x2fe>
mov    -0x30(%rbp),%eax
mov    0x2ad2(%rip),%rcx
cmp    (%rcx),%eax
jne    1529 <main+0x2f9>
lea    0xb53(%rip),%rdi
call   1100 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1090 <close@plt>
movslq -0x20(%rbp),%rax
movl   $0xffffffff,-0x4cc(%rbp,%rax,8)
ff ff ff ff
jmp    1560 <main+0x330>
cmpl   $0x0,-0x30(%rbp)
jne    155b <main+0x32b>
lea    0xb2f(%rip),%rdi
call   1100 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1090 <close@plt>
movslq -0x20(%rbp),%rax
movl   $0xffffffff,-0x4cc(%rbp,%rax,8)
ff ff ff ff
jmp    1560 <main+0x330>
movb   $0x0,-0x38(%rbp)
mov    -0x30(%rbp),%esi
lea    -0x420(%rbp),%rdx
lea    0xb04(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2a24(%rip),%rax
mov    (%rax),%eax
mov    0x2a13(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x430(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2a19(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
lea    -0x430(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1655 <main+0x425>
movslq -0x20(%rbp),%rax
mov    -0x4d0(%rbp,%rax,8),%eax
mov    0x29e1(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1650 <main+0x420>
mov    -0x20(%rbp),%edx
lea    0xa6c(%rip),%rdi
lea    0xaa8(%rip),%rsi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x20(%rbp),%rax
mov    -0x4cc(%rbp,%rax,8),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%edi
lea    0xa92(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x42c(%rbp)
mov    0x29bc(%rip),%rax
mov    (%rax),%eax
mov    0x297b(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x430(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2981(%rip),%rax
mov    (%rax),%esi
mov    -0x2c(%rbp),%edx
lea    -0x430(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1655 <main+0x425>
jmp    165a <main+0x42a>
jmp    165f <main+0x42f>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    13a5 <main+0x175>
jmp    1382 <main+0x152>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4b8,%rsp
mov    $0x100,%edi
call   1140 <epoll_create@plt>
mov    %eax,%ebx
mov    0x2d84(%rip),%r14
mov    (%r14),%edi
mov    0x2d4a(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1100 <setnonblocking@plt>
mov    0x2d59(%rip),%rcx
mov    0x2d1a(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %ebp,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebx,0xc(%rsp)
mov    %ebx,%edi
mov    %ebp,%edx
call   10b0 <epoll_ctl@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
lea    0xd2e(%rip),%rdi
mov    %r15,%rsi
call   10c0 <inet_aton@plt>
mov    $0x15b4,%edi
call   1070 <htons@plt>
mov    %eax,0x14(%rsp)
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1308 <main+0xc8>
lea    0xd07(%rip),%rdi
jmp    1556 <main+0x316>
mov    %ebp,%edi
mov    $0x14,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1325 <main+0xe5>
lea    0xcf5(%rip),%rdi
jmp    1556 <main+0x316>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
mov    0xc(%rsp),%r15d
cs nopw 0x0(%rax,%rax,1)
mov    %r15d,%edi
lea    0x30(%rsp),%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   10e0 <epoll_wait@plt>
test   %eax,%eax
jle    1340 <main+0x100>
mov    %eax,%r14d
xor    %r12d,%r12d
jmp    13de <main+0x19e>
lea    0xcf6(%rip),%rdi
mov    0x2c5f(%rip),%rax
cmp    (%rax),%r15d
je     14cf <main+0x28f>
movb   $0x0,0x4b8(%rsp)
lea    0xcf0(%rip),%rdi
mov    %r15d,%esi
lea    0xd0(%rsp),%rdx
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13d,0x4(%rsp)
mov    0x2c01(%rip),%rax
mov    (%rax),%eax
mov    0x2c00(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2c04(%rip),%rax
mov    0xc(%rsp),%r15d
mov    (%rax),%esi
mov    %r15d,%edi
mov    %r13d,%edx
mov    %rsp,%rcx
call   10b0 <epoll_ctl@plt>
add    $0x1,%r12
cmp    %r12,%r14
je     1340 <main+0x100>
cmp    %ebp,0x34(%rsp,%r12,8)
jne    1450 <main+0x210>
mov    %ebp,%edi
lea    0x20(%rsp),%rsi
lea    0x1c(%rsp),%rdx
call   1130 <accept@plt>
cmp    $0xffffffff,%eax
je     154f <main+0x30f>
mov    %eax,%r13d
mov    %eax,%edi
call   1100 <setnonblocking@plt>
mov    0x20(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xc26(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r13d,0x4(%rsp)
mov    0x2b79(%rip),%rax
mov    (%rax),%eax
mov    0x2ba8(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2b94(%rip),%rax
jmp    13c1 <main+0x181>
nopl   0x0(%rax)
lea    (%r12,%r12,1),%rbx
mov    0x30(%rsp,%r12,8),%eax
mov    0x2b80(%rip),%rcx
test   %eax,(%rcx)
je     14e9 <main+0x2a9>
lea    0xbe1(%rip),%rdi
lea    0xbe2(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x34(%rsp,%rbx,4),%r13d
test   %r13d,%r13d
js     13d1 <main+0x191>
lea    0xd0(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x3e8,%edx
call   1090 <memset@plt>
mov    %r13d,%edi
mov    %r15,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r15d
test   %eax,%eax
js     1363 <main+0x123>
lea    0xba5(%rip),%rdi
jne    137a <main+0x13a>
call   1110 <perror@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
movl   $0xffffffff,0x34(%rsp,%rbx,4)
ff
jmp    137a <main+0x13a>
mov    0x2ac0(%rip),%rcx
test   %eax,(%rcx)
je     13d1 <main+0x191>
lea    0xb51(%rip),%rdi
lea    0xb8d(%rip),%rsi
mov    %r12d,%edx
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x34(%rsp,%rbx,4),%r13d
mov    %r13d,%edi
lea    0xb7d(%rip),%rsi
mov    $0xd,%edx
call   1050 <write@plt>
mov    %r13d,0x4(%rsp)
mov    0x2a73(%rip),%rax
mov    (%rax),%eax
mov    0x2aa2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2a76(%rip),%rax
jmp    13c1 <main+0x181>
lea    0xadc(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>

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

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_in = type { i32, i32, 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
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [11 x i8] c"bind error\00"
@.str.2 = [13 x i8] c"listen error\00"
@.str.4 = [16 x i8] c"Wait connect...\00"
@.str.5 = [13 x i8] c"accept error\00"
@.str.6 = [17 x i8] c"connect from %s\0A\00"
@.str.7 = [8 x i8] c"%s: %d\0A\00"
@.str.8 = [8 x i8] c"EPOLLIN\00"
@ECONNREFUSED = global i32 0
@.str.9 = [14 x i8] c"network error\00"
@.str.10 = [11 x i8] c"read empty\00"
@.str.11 = [26 x i8] c"Read from client:(%d) %s\0A\00"
@EPOLLOUT = global i32 0
@EPOLL_CTL_MOD = global i32 0
@.str.12 = [9 x i8] c"EPOLLOUT\00"
@.str.13 = [4 x i8] c"Hel\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1000 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 [1000 x i8], [1000 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 = tail call i32 @setnonblocking(i32 %18)
%20 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 1, i32 0
store i32 %18, i32* %20
%21 = load i32, i32* @EPOLLIN
%22 = load i32, i32* @EPOLLET
%23 = or i32 %22, %21
%24 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i64 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* @EPOLL_CTL_ADD
%26 = call i32 @epoll_ctl(i32 %13, i32 %25, i32 %18, %struct.epoll_event* %5)
%27 = call i32 @bzero(%struct.sockaddr_in* %7, i32 12)
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 2
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0
%31 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32* %30)
%32 = call i32 @htons(i32 5556)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 1
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%35 = call i32 @bind(i32 %18, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %2
%38 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %2
%41 = call i32 @listen(i32 %18, i32 20)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %46
43: ; preds = %40
%44 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %40
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%48 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%49 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 0
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 1000
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i64 0, i32 0
br label %52
52: ; preds = %55, %46
%53 = call i32 @epoll_wait(i32 %13, %struct.epoll_event* %49, i32 20, i32 500)
%54 = icmp sgt i32 %53, 0
br i1 %54, label %56, label %55
55: ; preds = %123, %52
br label %52
56: ; preds = %52
%57 = zext i32 %53 to i64
br label %58
58: ; preds = %56, %123
%59 = phi i64 [ 0, %56 ], [ %124, %123 ]
%60 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 %59, i32 1, i32 0
%61 = load i32, i32* %60
%62 = icmp eq i32 %61, %18
br i1 %62, label %63, label %77
63: ; preds = %58
%64 = call i32 @accept(i32 %18, %struct.sockaddr* %48, i32* %4)
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %69
66: ; preds = %63
%67 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %63
%70 = call i32 @setnonblocking(i32 %64)
%71 = load i32, i32* %51
%72 = call i8* @inet_ntoa(i32 %71)
%73 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %72)
store i32 %64, i32* %20
%74 = load i32, i32* @EPOLLIN
%75 = load i32, i32* @EPOLLET
%76 = or i32 %75, %74
store i32 %76, i32* %24
br label %118
77: ; preds = %58
%78 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %6, i64 0, i64 %59, i32 0
%79 = load i32, i32* %78
%80 = load i32, i32* @EPOLLIN
%81 = and i32 %80, %79
%82 = icmp eq i32 %81, 0
br i1 %82, label %106, label %83
83: ; preds = %77
%84 = trunc i64 %59 to i32
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0), i32 %84)
%86 = load i32, i32* %60
%87 = icmp slt i32 %86, 0
br i1 %87, label %123, label %88
88: ; preds = %83
%89 = call i32 @memset(i8* %9, i32 0, i32 1000)
%90 = call i32 @recv(i32 %86, i8* %9, i32 1000, i32 0)
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %88
%93 = load i32, i32* @ECONNREFUSED
%94 = icmp eq i32 %90, %93
br i1 %94, label %97, label %101
95: ; preds = %88
%96 = icmp eq i32 %90, 0
br i1 %96, label %97, label %101
97: ; preds = %95, %92
%98 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), %92 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.10, i64 0, i64 0), %95 ]
%99 = call i32 @perror(i8* %98)
%100 = call i32 @close(i32 %86)
store i32 -1, i32* %60
br label %101
101: ; preds = %97, %95, %92
store i8 0, i8* %50
%102 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.11, i64 0, i64 0), i32 %90, i8* %9)
store i32 %86, i32* %20
%103 = load i32, i32* @EPOLLOUT
%104 = load i32, i32* @EPOLLET
%105 = or i32 %104, %103
store i32 %105, i32* %24
br label %118
106: ; preds = %77
%107 = load i32, i32* @EPOLLOUT
%108 = and i32 %107, %79
%109 = icmp eq i32 %108, 0
br i1 %109, label %123, label %110
110: ; preds = %106
%111 = trunc i64 %59 to i32
%112 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i32 %111)
%113 = load i32, i32* %60
%114 = call i32 @write(i32 %113, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.13, i64 0, i64 0), i32 13)
store i32 %113, i32* %20
%115 = load i32, i32* @EPOLLIN
%116 = load i32, i32* @EPOLLET
%117 = or i32 %116, %115
store i32 %117, i32* %24
br label %118
118: ; preds = %101, %110, %69
%119 = phi i32* [ @EPOLL_CTL_ADD, %69 ], [ @EPOLL_CTL_MOD, %110 ], [ @EPOLL_CTL_MOD, %101 ]
%120 = phi i32 [ %64, %69 ], [ %113, %110 ], [ %86, %101 ]
%121 = load i32, i32* %119
%122 = call i32 @epoll_ctl(i32 %13, i32 %121, i32 %120, %struct.epoll_event* %5)
br label %123
123: ; preds = %118, %106, %83
%124 = add nuw nsw i64 %59, 1
%125 = icmp eq i64 %124, %57
br i1 %125, label %55, label %58
}