#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*/ socklen_t;
typedef int /*<<< orphan*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ EAGAIN;
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 /*<<< 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 /*<<< orphan*/ epoll_ctl_err_show();
int epoll_wait(int, struct epoll_event *, int, int);
scalar_t__ errno;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int read(int, char *, int);
int /*<<< orphan*/ setnonblocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int socket_send(int, char *, int);
int strlen(char *);
int main() {
  int i, maxi, listenfd, connfd, sockfd, epfd, nfds;
  ssize_t n;
  char line[512];
  socklen_t clilen;
  struct epoll_event ev, events[20];
  epfd = epoll_create(256);
  struct sockaddr_in clientaddr;
  struct sockaddr_in serveraddr;
  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(&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  char *local_addr = "127.0.0.1";
  inet_aton(local_addr, &(serveraddr.sin_addr));
  serveraddr.sin_port = htons(9876);
  bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
  listen(listenfd, 20);
  maxi = 0;
  for (;;) {
    nfds = epoll_wait(epfd, events, 20, -1);
    for (i = 0; i < nfds; ++i) {
      if (events[i].data.fd == listenfd) {
        while ((connfd = accept(listenfd, (struct sockaddr *)&clientaddr,
                                &clilen)) > 0) {
          setnonblocking(connfd);
          char *str = inet_ntoa(clientaddr.sin_addr);
          printf("connect from \n");
          ev.data.fd = connfd;
          ev.events = EPOLLIN | EPOLLET;
          epoll_ctl(epfd, EPOLL_CTL_ADD, connfd, &ev);
        }
      } else if (events[i].events & EPOLLIN) {
        if ((sockfd = events[i].data.fd) < 0) {
          continue;
        }
        memset(line, 0, 512);
        n = 0;
        int nread = 0;
        while ((nread = read(sockfd, line + n, 512)) > 0) {
          n += nread;
        }
        if (nread == -1 && errno != EAGAIN) {
          epoll_ctl_err_show();
          printf("readline error\n");
          close(sockfd);
          events[i].data.fd = -1;
        }
        if (nread == 0) {
          close(sockfd);
          continue;
        }
        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;
        int iRet = socket_send(sockfd, line, strlen(line) + 1);
        if (iRet == -1 || iRet != strlen(line) + 1) {
          perror("write error!");
        }
        ev.data.fd = sockfd;
        ev.events = EPOLLIN | EPOLLET;
        epoll_ctl(epfd, EPOLL_CTL_MOD, sockfd, &ev);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x330,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x100,%edi
call   1150 <epoll_create@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1110 <setnonblocking@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x23c(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
mov    0x2d0c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x240(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2d2a(%rip),%rax
mov    (%rax),%esi
mov    -0x10(%rbp),%edx
lea    -0x240(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
lea    -0x300(%rbp),%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2f8(%rbp)
lea    0xd1a(%rip),%rax
mov    %rax,-0x308(%rbp)
mov    -0x308(%rbp),%rdi
lea    -0x300(%rbp),%rsi
call   10c0 <inet_aton@plt>
mov    $0x2694,%edi
call   1060 <htons@plt>
mov    %eax,-0x2fc(%rbp)
mov    -0x10(%rbp),%edi
lea    -0x300(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
mov    -0x10(%rbp),%edi
mov    $0x14,%esi
call   10d0 <listen@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x2e0(%rbp),%rsi
mov    $0x14,%edx
mov    $0xffffffff,%ecx
call   10f0 <epoll_wait@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x20(%rbp),%eax
jge    165a <main+0x41a>
movslq -0x8(%rbp),%rax
mov    -0x2dc(%rbp,%rax,8),%eax
cmp    -0x10(%rbp),%eax
jne    140e <main+0x1ce>
jmp    1380 <main+0x140>
mov    -0x10(%rbp),%edi
lea    -0x2f0(%rbp),%rsi
lea    -0x234(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jle    1409 <main+0x1c9>
mov    -0x14(%rbp),%edi
call   1110 <setnonblocking@plt>
mov    -0x2f0(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,-0x310(%rbp)
lea    0xc47(%rip),%rdi
call   1070 <printf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x23c(%rbp)
mov    0x2c08(%rip),%rax
mov    (%rax),%eax
mov    0x2bc7(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x240(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2be5(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x240(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1380 <main+0x140>
jmp    1647 <main+0x407>
movslq -0x8(%rbp),%rax
mov    -0x2e0(%rbp,%rax,8),%eax
mov    0x2bc0(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1552 <main+0x312>
movslq -0x8(%rbp),%rax
mov    -0x2dc(%rbp,%rax,8),%eax
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    1447 <main+0x207>
jmp    164c <main+0x40c>
lea    -0x230(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x314(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x230(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    $0x200,%edx
call   10b0 <read@plt>
mov    %eax,-0x314(%rbp)
cmp    $0x0,%eax
jle    14a6 <main+0x266>
mov    -0x314(%rbp),%eax
add    -0x24(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    146b <main+0x22b>
cmpl   $0xffffffff,-0x314(%rbp)
jne    14f7 <main+0x2b7>
mov    0x2af6(%rip),%rax
mov    (%rax),%rax
mov    0x2ad4(%rip),%rcx
cmp    (%rcx),%rax
je     14f7 <main+0x2b7>
mov    $0x0,%al
call   10e0 <epoll_ctl_err_show@plt>
lea    0xb3e(%rip),%rdi
call   1070 <printf@plt>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
movslq -0x8(%rbp),%rax
movl   $0xffffffff,-0x2dc(%rbp,%rax,8)
ff ff ff ff
cmpl   $0x0,-0x314(%rbp)
jne    1511 <main+0x2d1>
mov    -0x18(%rbp),%edi
call   1090 <close@plt>
jmp    164c <main+0x40c>
mov    -0x18(%rbp),%eax
mov    %eax,-0x23c(%rbp)
mov    0x2a97(%rip),%rax
mov    (%rax),%eax
mov    0x2a7e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x240(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2a8c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
lea    -0x240(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1642 <main+0x402>
movslq -0x8(%rbp),%rax
mov    -0x2e0(%rbp,%rax,8),%eax
mov    0x2a54(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     163d <main+0x3fd>
movslq -0x8(%rbp),%rax
mov    -0x2dc(%rbp,%rax,8),%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x324(%rbp)
lea    -0x230(%rbp),%rax
mov    %rax,-0x320(%rbp)
lea    -0x230(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x324(%rbp),%edi
mov    -0x320(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1030 <socket_send@plt>
mov    %eax,-0x318(%rbp)
cmpl   $0xffffffff,-0x318(%rbp)
je     15f5 <main+0x3b5>
mov    -0x318(%rbp),%eax
mov    %eax,-0x328(%rbp)
lea    -0x230(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x328(%rbp),%eax
add    $0x1,%ecx
cmp    %ecx,%eax
je     1601 <main+0x3c1>
lea    0xa2d(%rip),%rdi
call   1120 <perror@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x23c(%rbp)
mov    0x29cf(%rip),%rax
mov    (%rax),%eax
mov    0x298e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x240(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x299c(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
lea    -0x240(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1642 <main+0x402>
jmp    1647 <main+0x407>
jmp    164c <main+0x40c>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    135b <main+0x11b>
jmp    1338 <main+0xf8>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x2e8,%rsp
mov    $0x100,%edi
call   1150 <epoll_create@plt>
mov    %eax,%ebx
mov    0x2d84(%rip),%r14
mov    (%r14),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
mov    %eax,%edi
call   1110 <setnonblocking@plt>
mov    0x2d58(%rip),%rcx
mov    0x2d19(%rip),%rbp
mov    0x0(%rbp),%eax
or     (%rcx),%eax
mov    %r13d,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2d35(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebx,%edi
mov    %r13d,%edx
call   10a0 <epoll_ctl@plt>
lea    0x30(%rsp),%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    (%r14),%eax
mov    %eax,0x38(%rsp)
lea    0xd2e(%rip),%rdi
mov    %r12,%rsi
call   10c0 <inet_aton@plt>
mov    $0x2694,%edi
call   1070 <htons@plt>
mov    %eax,0x34(%rsp)
mov    %r13d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
mov    %r13d,0x1c(%rsp)
mov    %r13d,%edi
mov    $0x14,%esi
call   10d0 <listen@plt>
lea    0x10(%rsp),%r13
lea    0x3c(%rsp),%r15
mov    %ebx,0xc(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
lea    0x40(%rsp),%rsi
mov    $0x14,%edx
mov    $0xffffffff,%ecx
call   10f0 <epoll_wait@plt>
test   %eax,%eax
jle    1320 <main+0xe0>
mov    %eax,%eax
mov    %rax,0x28(%rsp)
xor    %ecx,%ecx
jmp    1394 <main+0x154>
mov    %r14d,0x4(%rsp)
mov    0x0(%rbp),%eax
mov    0x2c64(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2c68(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %r14d,%edx
mov    %rbx,%rcx
call   10a0 <epoll_ctl@plt>
lea    0x10(%rsp),%r13
mov    %r12,%r15
mov    0x20(%rsp),%rcx
add    $0x1,%rcx
cmp    0x28(%rsp),%rcx
mov    0x2c1a(%rip),%rbp
mov    0xc(%rsp),%ebx
je     1320 <main+0xe0>
mov    0x44(%rsp,%rcx,8),%r14d
mov    0x1c(%rsp),%eax
cmp    %eax,%r14d
mov    %rcx,0x20(%rsp)
jne    1440 <main+0x200>
mov    %eax,%r14d
mov    %eax,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1140 <accept@plt>
test   %eax,%eax
mov    %rsp,%rbp
lea    0xc5f(%rip),%r12
jle    1379 <main+0x139>
mov    %eax,%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1110 <setnonblocking@plt>
mov    0x10(%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %r12,%rdi
call   1040 <puts@plt>
mov    %ebx,0x4(%rsp)
mov    0x2bb5(%rip),%rax
mov    (%rax),%eax
mov    0x2be4(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2bd0(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %ebx,%edx
mov    %rbp,%rcx
call   10a0 <epoll_ctl@plt>
mov    %r14d,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1140 <accept@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     13d0 <main+0x190>
jmp    1379 <main+0x139>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%r12
mov    0x40(%rsp,%rcx,8),%eax
mov    0x2b92(%rip),%rcx
test   %eax,(%rcx)
je     14fa <main+0x2ba>
test   %r14d,%r14d
lea    0x10(%rsp),%r13
mov    %r12,%r15
js     1379 <main+0x139>
xor    %ebx,%ebx
lea    0xe0(%rsp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1080 <memset@plt>
nopl   (%rax)
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rsi
add    $0xe0,%rsi
mov    %r14d,%edi
mov    $0x200,%edx
call   10b0 <read@plt>
add    %eax,%ebx
test   %eax,%eax
jg     1480 <main+0x240>
mov    %rsp,%rbx
je     1571 <main+0x331>
cmp    $0xffffffff,%eax
jne    1345 <main+0x105>
mov    0x2af6(%rip),%rax
mov    (%rax),%rax
mov    0x2ad4(%rip),%rcx
cmp    (%rcx),%rax
je     1345 <main+0x105>
xor    %eax,%eax
call   10e0 <epoll_ctl_err_show@plt>
lea    0xb3c(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    0x20(%rsp),%rax
movl   $0xffffffff,0x44(%rsp,%rax,8)
ff
jmp    1345 <main+0x105>
mov    0x2ab7(%rip),%rcx
test   %eax,(%rcx)
lea    0x10(%rsp),%r13
mov    %r12,%r15
je     1379 <main+0x139>
lea    0xe0(%rsp),%r15
mov    %r15,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edx
mov    %r14d,%edi
mov    %r15,%rsi
call   1030 <socket_send@plt>
cmp    $0xffffffff,%eax
je     157e <main+0x33e>
mov    %eax,%ebx
mov    %r15,%rdi
call   1060 <strlen@plt>
add    $0x1,%eax
cmp    %eax,%ebx
jne    157e <main+0x33e>
mov    %r14d,0x4(%rsp)
mov    0x0(%rbp),%eax
mov    0x2a8c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    0x2a68(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %r14d,%edx
mov    %rsp,%rcx
jmp    136c <main+0x12c>
mov    %r14d,%edi
call   1090 <close@plt>
jmp    1371 <main+0x131>
lea    0xa85(%rip),%rdi
call   1120 <perror@plt>
jmp    1545 <main+0x305>

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

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