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

/* 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 /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
int atoi(char *);
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);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
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 /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, size_t);
int main(int argc, char *argv[]) {
  int i, maxi, listenfd, connfd, sockfd, epfd, nfds, portnumber;
  ssize_t n;
  char line[5];
  socklen_t clilen;
  if (2 == argc) {
    if ((portnumber = atoi(argv[1])) < 0) {
      fprintf(stderr, "Usage:%s portnumber\a\n", argv[0]);
      return 1;
    }
  } else {
    fprintf(stderr, "Usage:%s portnumber\a\n", argv[0]);
    return 1;
  }
  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);
  int opt = 1;
  setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt));
  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;
  serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
  serveraddr.sin_port = htons(portnumber);
  int nRet = bind(listenfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
  if (nRet < 0) {
    printf("bind error!\n");
    return -1;
  }
  listen(listenfd, 20);
  maxi = 0;
  clilen = sizeof(clientaddr);
  while (1) {
    nfds = epoll_wait(epfd, events, 20, 500);
    for (i = 0; i < nfds; ++i) {
      if (events[i].data.fd == listenfd) {
        connfd = accept(listenfd, (struct sockaddr *)&clientaddr, &clilen);
        if (connfd < 0) {
          perror("connfd<0");
          exit(1);
        }
        char *str = inet_ntoa(clientaddr.sin_addr);
        printf("accapt a connection 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, line, 5)) < 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;
        }
        line[n] = '\0';
        printf("read %s\n", line);
        ev.data.fd = sockfd;
        ev.events = EPOLLOUT | EPOLLET;
      } else if (events[i].events & EPOLLOUT) {
        sockfd = events[i].data.fd;
        write(sockfd, line, 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    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    12ad <main+0x6d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
jge    12a8 <main+0x68>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd69(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1679 <main+0x439>
jmp    12d5 <main+0x95>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd3c(%rip),%rsi
call   10c0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1679 <main+0x439>
mov    $0x100,%edi
call   1140 <epoll_create@plt>
mov    %eax,-0x28(%rbp)
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
mov    0x2cae(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x114(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cd6(%rip),%rax
mov    (%rax),%esi
mov    0x2c65(%rip),%rax
mov    (%rax),%edx
lea    -0x114(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2c9c(%rip),%rax
mov    (%rax),%eax
mov    0x2c43(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2c7c(%rip),%rax
mov    (%rax),%esi
mov    -0x1c(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
lea    -0x110(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2c66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108(%rbp)
mov    0x2c3f(%rip),%rax
mov    (%rax),%edi
call   1080 <htonl@plt>
mov    %eax,-0x110(%rbp)
mov    -0x30(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x10c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0xc,%edx
call   10f0 <bind@plt>
mov    %eax,-0x118(%rbp)
cmpl   $0x0,-0x118(%rbp)
jge    13e5 <main+0x1a5>
lea    0xc44(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1679 <main+0x439>
mov    -0x1c(%rbp),%edi
mov    $0x14,%esi
call   10d0 <listen@plt>
movl   $0x0,-0x18(%rbp)
movl   $0xc,-0x44(%rbp)
mov    -0x28(%rbp),%edi
lea    -0xf0(%rbp),%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   10e0 <epoll_wait@plt>
mov    %eax,-0x2c(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1674 <main+0x434>
movslq -0x14(%rbp),%rax
mov    -0xec(%rbp,%rax,8),%eax
cmp    -0x1c(%rbp),%eax
jne    14d8 <main+0x298>
mov    -0x1c(%rbp),%edi
lea    -0x100(%rbp),%rsi
lea    -0x44(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jge    1479 <main+0x239>
lea    0xbb9(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x100(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x120(%rbp)
mov    -0x120(%rbp),%rsi
lea    0xb93(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    0x2ad2(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2b0b(%rip),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    1661 <main+0x421>
movslq -0x14(%rbp),%rax
mov    -0xf0(%rbp,%rax,8),%eax
mov    0x2aee(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     15e9 <main+0x3a9>
lea    0xb4d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movslq -0x14(%rbp),%rax
mov    -0xec(%rbp,%rax,8),%eax
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    151f <main+0x2df>
jmp    1666 <main+0x426>
mov    -0x24(%rbp),%edi
lea    -0x3d(%rbp),%rsi
mov    $0x5,%edx
call   10b0 <read@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jae    1587 <main+0x347>
mov    0x2a4b(%rip),%rax
mov    (%rax),%rax
mov    0x2a69(%rip),%rcx
cmp    (%rcx),%rax
jne    1574 <main+0x334>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0xec(%rbp,%rax,8)
ff ff ff ff
jmp    1582 <main+0x342>
lea    0xad7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    15ae <main+0x36e>
cmpq   $0x0,-0x38(%rbp)
jne    15a9 <main+0x369>
mov    -0x24(%rbp),%edi
call   1090 <close@plt>
movslq -0x14(%rbp),%rax
movl   $0xffffffff,-0xec(%rbp,%rax,8)
ff ff ff ff
jmp    15ae <main+0x36e>
mov    -0x38(%rbp),%rax
movb   $0x0,-0x3d(%rbp,%rax,1)
lea    -0x3d(%rbp),%rsi
lea    0xaa0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x29c2(%rip),%rax
mov    (%rax),%eax
mov    0x29a9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
jmp    165c <main+0x41c>
movslq -0x14(%rbp),%rax
mov    -0xf0(%rbp,%rax,8),%eax
mov    0x299d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1657 <main+0x417>
movslq -0x14(%rbp),%rax
mov    -0xec(%rbp,%rax,8),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x3d(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1040 <write@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
mov    0x29a7(%rip),%rax
mov    (%rax),%eax
mov    0x294e(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x50(%rbp)
mov    -0x28(%rbp),%edi
mov    0x2967(%rip),%rax
mov    (%rax),%esi
mov    -0x24(%rbp),%edx
lea    -0x50(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
jmp    165c <main+0x41c>
jmp    1661 <main+0x421>
jmp    1666 <main+0x426>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1423 <main+0x1e3>
jmp    1400 <main+0x1c0>
mov    -0x4(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    %rsi,%rbp
cmp    $0x2,%edi
jne    1367 <main+0x117>
mov    0x8(%rbp),%rdi
call   1140 <atoi@plt>
test   %eax,%eax
js     1367 <main+0x117>
mov    %eax,%ebx
mov    $0x100,%edi
call   1150 <epoll_create@plt>
mov    %eax,%r14d
mov    0x2d4c(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d09(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,%r15d
movl   $0x1,0x10(%rsp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%esi
mov    0x2ccd(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    0x2cf9(%rip),%rcx
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
or     (%rcx),%eax
mov    %r15d,0x4(%rsp)
mov    %eax,(%rsp)
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %r14d,%edi
mov    %r15d,%edx
call   10b0 <epoll_ctl@plt>
lea    0x20(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x28(%rsp)
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   1090 <htonl@plt>
mov    %eax,0x20(%rsp)
mov    %ebx,%edi
call   1070 <htons@plt>
mov    %eax,0x24(%rsp)
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
test   %eax,%eax
jns    1397 <main+0x147>
lea    0xcf2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
jmp    1385 <main+0x135>
mov    0x2c42(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xc85(%rip),%rsi
call   10d0 <fprintf@plt>
mov    $0x1,%eax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,0xc(%rsp)
mov    %r15d,%edi
mov    $0x14,%esi
call   10e0 <listen@plt>
movl   $0xc,0x14(%rsp)
lea    0x1b(%rsp),%rbp
lea    0x50(%rsp),%r14
mov    0xc(%rsp),%ebx
nop
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x14,%edx
mov    $0x1f4,%ecx
call   10f0 <epoll_wait@plt>
test   %eax,%eax
jle    13c0 <main+0x170>
mov    %eax,%eax
mov    %rax,0x38(%rsp)
xor    %r13d,%r13d
jmp    142b <main+0x1db>
mov    %rbx,0x30(%rsp)
movb   $0x0,0x1b(%rsp,%rbx,1)
lea    0xc47(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12d,0x4(%rsp)
mov    0x2b8d(%rip),%rax
mov    (%rax),%eax
mov    0x2b8c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
nopl   0x0(%rax)
add    $0x1,%r13
cmp    %r13,0x38(%rsp)
je     13b6 <main+0x166>
mov    %rbp,%r14
mov    0x54(%rsp,%r13,8),%ebx
cmp    %r15d,%ebx
mov    0x2b9b(%rip),%rbp
jne    14b0 <main+0x260>
mov    %r15d,%edi
lea    0x40(%rsp),%rsi
lea    0x14(%rsp),%rdx
call   1130 <accept@plt>
test   %eax,%eax
js     1566 <main+0x316>
mov    %eax,%ebx
mov    0x40(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xbb4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,0x4(%rsp)
mov    0x2b18(%rip),%rax
mov    (%rax),%eax
or     0x0(%rbp),%eax
mov    %eax,(%rsp)
mov    0x2b41(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %ebx,%edx
mov    %rsp,%rcx
call   10b0 <epoll_ctl@plt>
mov    %r14,%rbp
jmp    1420 <main+0x1d0>
nopw   0x0(%rax,%rax,1)
mov    0x50(%rsp,%r13,8),%eax
test   %eax,0x0(%rbp)
je     1512 <main+0x2c2>
mov    %r13,%rbx
add    %r13,%rbx
lea    0xb7e(%rip),%rdi
call   1030 <puts@plt>
mov    0x54(%rsp,%rbx,4),%r12d
test   %r12d,%r12d
mov    %r14,%rbp
js     1420 <main+0x1d0>
mov    %rbx,%r14
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x5,%edx
call   10c0 <read@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    13e4 <main+0x194>
mov    %r12d,%edi
call   10a0 <close@plt>
movl   $0xffffffff,0x54(%rsp,%r14,4)
ff ff
jmp    13e4 <main+0x194>
mov    0x2a87(%rip),%rcx
test   %eax,(%rcx)
je     155e <main+0x30e>
mov    %ebx,%edi
mov    %r14,%rsi
mov    0x30(%rsp),%rdx
call   1050 <write@plt>
mov    %ebx,0x4(%rsp)
mov    0x2a61(%rip),%rax
mov    (%rax),%eax
or     0x0(%rbp),%eax
mov    %r14,%rbp
mov    %eax,(%rsp)
mov    0x2a6f(%rip),%rax
mov    (%rax),%esi
mov    0xc(%rsp),%edi
mov    %ebx,%edx
mov    %rsp,%rcx
call   10b0 <epoll_ctl@plt>
jmp    1420 <main+0x1d0>
mov    %r14,%rbp
jmp    1420 <main+0x1d0>
lea    0xaa9(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1160 <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 }
@stderr = global i32 0
@.str = [22 x i8] c"Usage:%s portnumber\07\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@EPOLLIN = global i32 0
@EPOLLET = global i32 0
@EPOLL_CTL_ADD = global i32 0
@INADDR_ANY = global i32 0
@.str.1 = [13 x i8] c"bind error!\0A\00"
@.str.2 = [9 x i8] c"connfd<0\00"
@.str.3 = [29 x i8] c"accapt a connection from %s\0A\00"
@.str.4 = [9 x i8] c"EPOLLIN\0A\00"
@errno = global i64 0
@ECONNRESET = global i64 0
@.str.5 = [16 x i8] c"readline error\0A\00"
@.str.6 = [9 x i8] c"read %s\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 i32
%14 = alloca i64
%15 = alloca [5 x i8]
%16 = alloca i32
%17 = alloca %struct.epoll_event
%18 = alloca [20 x %struct.epoll_event]
%19 = alloca %struct.sockaddr_in
%20 = alloca %struct.sockaddr_in
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* %4
%25 = icmp eq i32 2, %24
br i1 %25, label %26, label %39
26: ; preds = %2
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 @atoi(i8* %29)
store i32 %30, i32* %13
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %38
32: ; preds = %26
%33 = load i32, i32* @stderr
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 0
%36 = load i8*, i8** %35
%37 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %36)
store i32 1, i32* %3
br label %230
38: ; preds = %26
br label %45
39: ; preds = %2
%40 = load i32, i32* @stderr
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 0
%43 = load i8*, i8** %42
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %43)
store i32 1, i32* %3
br label %230
45: ; preds = %38
%46 = call i32 @epoll_create(i32 256)
store i32 %46, i32* %11
%47 = load i32, i32* @AF_INET
%48 = load i32, i32* @SOCK_STREAM
%49 = call i32 @socket(i32 %47, i32 %48, i32 0)
store i32 %49, i32* %8
store i32 1, i32* %21
%50 = load i32, i32* %8
%51 = load i32, i32* @SOL_SOCKET
%52 = load i32, i32* @SO_REUSEADDR
%53 = call i32 @setsockopt(i32 %50, i32 %51, i32 %52, i32* %21, i32 4)
%54 = load i32, i32* %8
%55 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %55, i32 0, i32 0
store i32 %54, i32* %56
%57 = load i32, i32* @EPOLLIN
%58 = load i32, i32* @EPOLLET
%59 = or i32 %57, %58
%60 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 0
store i32 %59, i32* %60
%61 = load i32, i32* %11
%62 = load i32, i32* @EPOLL_CTL_ADD
%63 = load i32, i32* %8
%64 = call i32 @epoll_ctl(i32 %61, i32 %62, i32 %63, %struct.epoll_event* %17)
%65 = call i32 @bzero(%struct.sockaddr_in* %20, i32 12)
%66 = load i32, i32* @AF_INET
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 2
store i32 %66, i32* %67
%68 = load i32, i32* @INADDR_ANY
%69 = call i32 @htonl(i32 %68)
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 0
%71 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %70, i32 0, i32 0
store i32 %69, i32* %71
%72 = load i32, i32* %13
%73 = call i32 @htons(i32 %72)
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 1
store i32 %73, i32* %74
%75 = load i32, i32* %8
%76 = bitcast %struct.sockaddr_in* %20 to %struct.sockaddr*
%77 = call i32 @bind(i32 %75, %struct.sockaddr* %76, i32 12)
store i32 %77, i32* %22
%78 = load i32, i32* %22
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %82
80: ; preds = %45
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %230
82: ; preds = %45
%83 = load i32, i32* %8
%84 = call i32 @listen(i32 %83, i32 20)
store i32 0, i32* %7
store i32 12, i32* %16
br label %85
85: ; preds = %82, %229
%86 = load i32, i32* %11
%87 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 0
%88 = call i32 @epoll_wait(i32 %86, %struct.epoll_event* %87, i32 20, i32 500)
store i32 %88, i32* %12
store i32 0, i32* %6
br label %89
89: ; preds = %226, %85
%90 = load i32, i32* %6
%91 = load i32, i32* %12
%92 = icmp slt i32 %90, %91
br i1 %92, label %93, label %229
93: ; preds = %89
%94 = load i32, i32* %6
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %95
%97 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %96, i32 0, i32 1
%98 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = load i32, i32* %8
%101 = icmp eq i32 %99, %100
br i1 %101, label %102, label %129
102: ; preds = %93
%103 = load i32, i32* %8
%104 = bitcast %struct.sockaddr_in* %19 to %struct.sockaddr*
%105 = call i32 @accept(i32 %103, %struct.sockaddr* %104, i32* %16)
store i32 %105, i32* %9
%106 = load i32, i32* %9
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %111
108: ; preds = %102
%109 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%110 = call i32 @exit(i32 1)
unreachable
111: ; preds = %102
%112 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %19, i32 0, i32 0
%113 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %112, i32 0, i32 0
%114 = load i32, i32* %113
%115 = call i8* @inet_ntoa(i32 %114)
store i8* %115, i8** %23
%116 = load i8*, i8** %23
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %116)
%118 = load i32, i32* %9
%119 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 1
%120 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %119, i32 0, i32 0
store i32 %118, i32* %120
%121 = load i32, i32* @EPOLLIN
%122 = load i32, i32* @EPOLLET
%123 = or i32 %121, %122
%124 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 0
store i32 %123, i32* %124
%125 = load i32, i32* %11
%126 = load i32, i32* @EPOLL_CTL_ADD
%127 = load i32, i32* %9
%128 = call i32 @epoll_ctl(i32 %125, i32 %126, i32 %127, %struct.epoll_event* %17)
br label %225
129: ; preds = %93
%130 = load i32, i32* %6
%131 = sext i32 %130 to i64
%132 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %131
%133 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %132, i32 0, i32 0
%134 = load i32, i32* %133
%135 = load i32, i32* @EPOLLIN
%136 = and i32 %134, %135
%137 = icmp ne i32 %136, 0
br i1 %137, label %138, label %192
138: ; preds = %129
%139 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%140 = load i32, i32* %6
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %141
%143 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %142, i32 0, i32 1
%144 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %143, i32 0, i32 0
%145 = load i32, i32* %144
store i32 %145, i32* %10
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %148
147: ; preds = %138
br label %226
148: ; preds = %138
%149 = load i32, i32* %10
%150 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%151 = call i64 @read(i32 %149, i8* %150, i32 5)
store i64 %151, i64* %14
%152 = icmp ult i64 %151, 0
br i1 %152, label %153, label %168
153: ; preds = %148
%154 = load i64, i64* @errno
%155 = load i64, i64* @ECONNRESET
%156 = icmp eq i64 %154, %155
br i1 %156, label %157, label %165
157: ; preds = %153
%158 = load i32, i32* %10
%159 = call i32 @close(i32 %158)
%160 = load i32, i32* %6
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %161
%163 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %162, i32 0, i32 1
%164 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %163, i32 0, i32 0
store i32 -1, i32* %164
br label %167
165: ; preds = %153
%166 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0))
br label %167
167: ; preds = %165, %157
br label %180
168: ; preds = %148
%169 = load i64, i64* %14
%170 = icmp eq i64 %169, 0
br i1 %170, label %171, label %179
171: ; preds = %168
%172 = load i32, i32* %10
%173 = call i32 @close(i32 %172)
%174 = load i32, i32* %6
%175 = sext i32 %174 to i64
%176 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %175
%177 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %176, i32 0, i32 1
%178 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %177, i32 0, i32 0
store i32 -1, i32* %178
br label %179
179: ; preds = %171, %168
br label %180
180: ; preds = %179, %167
%181 = load i64, i64* %14
%182 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 %181
store i8 0, i8* %182
%183 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %183)
%185 = load i32, i32* %10
%186 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 1
%187 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %186, i32 0, i32 0
store i32 %185, i32* %187
%188 = load i32, i32* @EPOLLOUT
%189 = load i32, i32* @EPOLLET
%190 = or i32 %188, %189
%191 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 0
store i32 %190, i32* %191
br label %224
192: ; preds = %129
%193 = load i32, i32* %6
%194 = sext i32 %193 to i64
%195 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %194
%196 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %195, i32 0, i32 0
%197 = load i32, i32* %196
%198 = load i32, i32* @EPOLLOUT
%199 = and i32 %197, %198
%200 = icmp ne i32 %199, 0
br i1 %200, label %201, label %223
201: ; preds = %192
%202 = load i32, i32* %6
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds [20 x %struct.epoll_event], [20 x %struct.epoll_event]* %18, i64 0, i64 %203
%205 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %204, i32 0, i32 1
%206 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %205, i32 0, i32 0
%207 = load i32, i32* %206
store i32 %207, i32* %10
%208 = load i32, i32* %10
%209 = getelementptr inbounds [5 x i8], [5 x i8]* %15, i64 0, i64 0
%210 = load i64, i64* %14
%211 = call i32 @write(i32 %208, i8* %209, i64 %210)
%212 = load i32, i32* %10
%213 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 1
%214 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %213, i32 0, i32 0
store i32 %212, i32* %214
%215 = load i32, i32* @EPOLLIN
%216 = load i32, i32* @EPOLLET
%217 = or i32 %215, %216
%218 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %17, i32 0, i32 0
store i32 %217, i32* %218
%219 = load i32, i32* %11
%220 = load i32, i32* @EPOLL_CTL_MOD
%221 = load i32, i32* %10
%222 = call i32 @epoll_ctl(i32 %219, i32 %220, i32 %221, %struct.epoll_event* %17)
br label %223
223: ; preds = %201, %192
br label %224
224: ; preds = %223, %180
br label %225
225: ; preds = %224, %111
br label %226
226: ; preds = %225, %147
%227 = load i32, i32* %6
%228 = add nsw i32 %227, 1
store i32 %228, i32* %6
br label %89
229: ; preds = %89
br label %85
230: ; preds = %80, %39, %32
%231 = load i32, i32* %3
ret i32 %231
}

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