#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_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_4__ {
  int fd;
};
struct epoll_event {
  TYPE_2__ data;
  void *events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ serverDetail;
typedef int /*<<< orphan*/ clientDetail;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
void *EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_DEL;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, 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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ listen(int, int);
struct epoll_event *malloc(int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ setnonblocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int serverSock, clientSock;
  struct sockaddr_in serverDetail, clientDetail;
  char buf[16];
  FILE *readfp[64];
  FILE *writefp[64];
  socklen_t addrSize;
  int i, j;
  struct epoll_event *ep_events;
  struct epoll_event epollEvent;
  int epfd, event_cnt;
  serverSock = socket(PF_INET, SOCK_STREAM, 0);
  memset(&serverDetail, 0, sizeof(serverDetail));
  serverDetail.sin_family = AF_INET;
  serverDetail.sin_addr.s_addr = inet_addr("127.0.0.1");
  serverDetail.sin_port = htons(9000);
  bind(serverSock, (struct sockaddr *)&serverDetail, sizeof(serverDetail));
  listen(serverSock, 5);
  readfp[serverSock - 3] = fdopen(serverSock, "r");
  writefp[serverSock - 3] = fdopen(serverSock, "w");
  epfd = epoll_create(64);
  ep_events = malloc(sizeof(struct epoll_event) * 64);
  epollEvent.events = EPOLLIN;
  epollEvent.data.fd = serverSock;
  epoll_ctl(epfd, EPOLL_CTL_ADD, serverSock, &epollEvent);
  while (1) {
    event_cnt = epoll_wait(epfd, ep_events, 64, -1);
    printf("wait: %d\n", event_cnt);
    if (event_cnt == -1) {
      puts("wait error\n");
      break;
    }
    for (i = 0; i < event_cnt; ++i) {
      printf("loop %d\n", i);
      if (ep_events[i].data.fd == serverSock) {
        printf("Server %d\n", serverSock);
        addrSize = sizeof(clientDetail);
        clientSock =
            accept(serverSock, (struct sockaddr *)&clientDetail, &addrSize);
        setnonblocking(clientSock);
        readfp[clientSock - 4] = fdopen(clientSock, "r");
        writefp[clientSock - 4] = fdopen(clientSock, "w");
        epollEvent.events = EPOLLIN;
        epollEvent.data.fd = clientSock;
        epoll_ctl(epfd, EPOLL_CTL_ADD, clientSock, &epollEvent);
        printf("conneted client: %d\n", clientSock);
      } else {
        for (j = 1; j < clientSock - 3; j++) {
          if (feof(readfp[j])) {
            epoll_ctl(epfd, EPOLL_CTL_DEL, ep_events[i].data.fd, NULL);
            close(ep_events[i].data.fd);
            printf("disconnect client: %d\n", ep_events[i].data.fd);
          } else {
            printf("client else\n");
            fgets(buf, 16, readfp[j]);
            fputs(buf, writefp[j]);
            fflush(writefp[j]);
            printf("client success!\n");
          }
        }
      }
    }
  }
  printf("closing\n");
  for (i = 0; i < clientSock - 3; i++) {
    fclose(writefp[i]);
    fclose(readfp[i]);
  }
  close(serverSock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xd58(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x2328,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1130 <bind@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   1100 <listen@plt>
mov    -0x14(%rbp),%edi
lea    0xd25(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
cltq
mov    %rcx,-0x250(%rbp,%rax,8)
ff
mov    -0x14(%rbp),%edi
lea    0xd05(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,%rcx
mov    -0x14(%rbp),%eax
sub    $0x3,%eax
cltq
mov    %rcx,-0x450(%rbp,%rax,8)
ff
mov    $0x40,%edi
call   1160 <epoll_create@plt>
mov    %eax,-0x47c(%rbp)
mov    $0x400,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x468(%rbp)
mov    0x2c91(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x470(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x478(%rbp)
mov    -0x47c(%rbp),%edi
mov    0x2c69(%rip),%rax
mov    (%rax),%esi
mov    -0x14(%rbp),%edx
lea    -0x478(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
mov    -0x47c(%rbp),%edi
mov    -0x468(%rbp),%rsi
mov    $0x40,%edx
mov    $0xffffffff,%ecx
call   1120 <epoll_wait@plt>
mov    %eax,-0x480(%rbp)
mov    -0x480(%rbp),%esi
lea    0xc67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0xffffffff,-0x480(%rbp)
jne    13cc <main+0x17c>
lea    0xc56(%rip),%rdi
call   1030 <puts@plt>
jmp    1639 <main+0x3e9>
movl   $0x0,-0x458(%rbp)
mov    -0x458(%rbp),%eax
cmp    -0x480(%rbp),%eax
jge    1634 <main+0x3e4>
mov    -0x458(%rbp),%esi
lea    0xc2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x468(%rbp),%rax
movslq -0x458(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0x14(%rbp),%eax
jne    14e7 <main+0x297>
mov    -0x14(%rbp),%esi
lea    0xc07(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0xc,-0x454(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x454(%rbp),%rdx
call   1150 <accept@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1140 <setnonblocking@plt>
mov    -0x18(%rbp),%edi
lea    0xbab(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
cltq
mov    %rcx,-0x250(%rbp,%rax,8)
ff
mov    -0x18(%rbp),%edi
lea    0xb8b(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%eax
sub    $0x4,%eax
cltq
mov    %rcx,-0x450(%rbp,%rax,8)
ff
mov    0x2b38(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x470(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x478(%rbp)
mov    -0x47c(%rbp),%edi
mov    0x2b10(%rip),%rax
mov    (%rax),%esi
mov    -0x18(%rbp),%edx
lea    -0x478(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
mov    -0x18(%rbp),%esi
lea    0xb5d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    161b <main+0x3cb>
movl   $0x1,-0x45c(%rbp)
mov    -0x45c(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    1616 <main+0x3c6>
movslq -0x45c(%rbp),%rax
mov    -0x250(%rbp,%rax,8),%rdi
ff
call   10d0 <feof@plt>
cmp    $0x0,%rax
je     1598 <main+0x348>
mov    -0x47c(%rbp),%edi
mov    0x2ac8(%rip),%rax
mov    (%rax),%esi
mov    -0x468(%rbp),%rax
movslq -0x458(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   10a0 <epoll_ctl@plt>
mov    -0x468(%rbp),%rax
movslq -0x458(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1090 <close@plt>
mov    -0x468(%rbp),%rax
movslq -0x458(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%esi
lea    0xac1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    15fd <main+0x3ad>
lea    0xac5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x50(%rbp),%rdi
movslq -0x45c(%rbp),%rax
mov    -0x250(%rbp,%rax,8),%rdx
ff
mov    $0x10,%esi
call   10b0 <fgets@plt>
lea    -0x50(%rbp),%rdi
movslq -0x45c(%rbp),%rax
mov    -0x450(%rbp,%rax,8),%rsi
ff
call   1070 <fputs@plt>
movslq -0x45c(%rbp),%rax
mov    -0x450(%rbp,%rax,8),%rdi
ff
call   10f0 <fflush@plt>
lea    0xa7b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    1602 <main+0x3b2>
mov    -0x45c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x45c(%rbp)
jmp    14f1 <main+0x2a1>
jmp    161b <main+0x3cb>
jmp    1620 <main+0x3d0>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    13d6 <main+0x186>
jmp    1378 <main+0x128>
lea    0xa42(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x458(%rbp)
mov    -0x458(%rbp),%eax
mov    -0x18(%rbp),%ecx
sub    $0x3,%ecx
cmp    %ecx,%eax
jge    16a1 <main+0x451>
movslq -0x458(%rbp),%rax
mov    -0x450(%rbp,%rax,8),%rdi
ff
call   1040 <fclose@plt>
movslq -0x458(%rbp),%rax
mov    -0x250(%rbp,%rax,8),%rdi
ff
call   1040 <fclose@plt>
mov    -0x458(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x458(%rbp)
jmp    1651 <main+0x401>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x480,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
mov    0x2d4f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,%r12d
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x38(%rsp)
lea    0xd5b(%rip),%rdi
call   10c0 <inet_addr@plt>
mov    %eax,0x34(%rsp)
mov    $0x2328,%edi
call   1050 <htons@plt>
mov    %eax,0x30(%rsp)
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1130 <bind@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   1100 <listen@plt>
lea    0xd2a(%rip),%rsi
mov    %r12d,%edi
call   1110 <fdopen@plt>
movslq %r12d,%rbx
mov    %rax,0x258(%rsp,%rbx,8)
lea    0xd12(%rip),%rsi
mov    %ebx,%edi
call   1110 <fdopen@plt>
mov    %rax,0x58(%rsp,%rbx,8)
mov    $0x40,%edi
call   1160 <epoll_create@plt>
mov    %eax,%r14d
mov    $0x400,%edi
call   10e0 <malloc@plt>
mov    %rax,%rbp
mov    0x2cb1(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %ebx,0x20(%rsp)
mov    0x2c96(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rcx
mov    %r14d,%edi
mov    %ebx,%edx
call   10a0 <epoll_ctl@plt>
mov    %r14d,0x4(%rsp)
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
mov    $0xffffffff,%ecx
call   1120 <epoll_wait@plt>
mov    %eax,%r13d
lea    0xc9f(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0xffffffff,%r13d
je     159f <main+0x34f>
mov    %rax,0x8(%rsp)
mov    %r12d,0x18(%rsp)
mov    %rbp,0x40(%rsp)
jmp    13d3 <main+0x183>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x4(%rsp),%edi
mov    %rbp,%rsi
mov    $0x40,%edx
mov    $0xffffffff,%ecx
call   1120 <epoll_wait@plt>
mov    %eax,%r13d
lea    0xc4e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1060 <printf@plt>
cmp    $0xffffffff,%r13d
je     15a4 <main+0x354>
test   %r13d,%r13d
jle    13a0 <main+0x150>
mov    %r13d,%eax
mov    %rax,0x48(%rsp)
xor    %r13d,%r13d
jmp    14a5 <main+0x255>
nopl   0x0(%rax,%rax,1)
lea    0xc36(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
movl   $0xc,0x1c(%rsp)
mov    %r12d,%edi
lea    0x50(%rsp),%rsi
lea    0x1c(%rsp),%rdx
call   1150 <accept@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1140 <setnonblocking@plt>
mov    %ebx,%edi
lea    0xbdd(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rbx,0x8(%rsp)
movslq %ebx,%rbx
mov    %rax,0x250(%rsp,%rbx,8)
mov    %ebx,%edi
lea    0xbc1(%rip),%rsi
call   1110 <fdopen@plt>
mov    %rax,0x50(%rsp,%rbx,8)
mov    0x2b7c(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %ebx,0x20(%rsp)
mov    0x2b61(%rip),%rax
mov    (%rax),%esi
mov    0x4(%rsp),%edi
mov    %ebx,%edx
lea    0x20(%rsp),%rcx
call   10a0 <epoll_ctl@plt>
lea    0xbb0(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%r13
add    $0x1,%r13
cmp    0x48(%rsp),%r13
je     13a0 <main+0x150>
lea    0xb78(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,0x10(%rsp)
shl    $0x4,%r13
cmp    %r12d,0x0(%rbp,%r13,1)
je     13f0 <main+0x1a0>
mov    0x8(%rsp),%rax
cmp    $0x5,%eax
jl     1491 <main+0x241>
add    %rbp,%r13
lea    -0x3(%rax),%r12d
mov    $0x1,%ebp
jmp    153e <main+0x2ee>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xb6d(%rip),%rdi
call   1030 <puts@plt>
lea    0x60(%rsp),%r15
mov    %r15,%rdi
mov    $0x10,%esi
mov    %r14,%rdx
call   10b0 <fgets@plt>
mov    0x70(%rsp,%rbp,8),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   1070 <fputs@plt>
mov    %rbx,%rdi
call   10f0 <fflush@plt>
lea    0xb40(%rip),%rdi
call   1030 <puts@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
je     1590 <main+0x340>
mov    0x270(%rsp,%rbp,8),%r14
mov    %r14,%rdi
call   10d0 <feof@plt>
test   %rax,%rax
je     14f0 <main+0x2a0>
mov    0x2a9e(%rip),%rax
mov    (%rax),%esi
mov    0x0(%r13),%edx
mov    0x4(%rsp),%edi
xor    %ecx,%ecx
call   10a0 <epoll_ctl@plt>
mov    0x0(%r13),%edi
call   1090 <close@plt>
mov    0x0(%r13),%esi
lea    0xace(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1535 <main+0x2e5>
nopl   0x0(%rax,%rax,1)
mov    0x18(%rsp),%r12d
mov    0x40(%rsp),%rbp
jmp    1491 <main+0x241>
mov    %rax,0x8(%rsp)
lea    0xa6d(%rip),%rdi
call   1030 <puts@plt>
lea    0xac9(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%rbp
cmp    $0x4,%ebp
jl     15f0 <main+0x3a0>
add    $0xfffffffd,%ebp
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    0x70(%rsp,%rbx,8),%rdi
call   1040 <fclose@plt>
mov    0x270(%rsp,%rbx,8),%rdi
call   1040 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    15d0 <main+0x380>
mov    %r12d,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x478,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.epoll_event = type { %struct.TYPE_4__, i8* }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [10 x i8] c"127.0.0.1\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [2 x i8] c"w\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@.str.3 = [10 x i8] c"wait: %d\0A\00"
@.str.4 = [12 x i8] c"wait error\0A\00"
@.str.5 = [9 x i8] c"loop %d\0A\00"
@.str.6 = [11 x i8] c"Server %d\0A\00"
@.str.7 = [21 x i8] c"conneted client: %d\0A\00"
@EPOLL_CTL_DEL = global i32 0
@.str.8 = [23 x i8] c"disconnect client: %d\0A\00"
@str = [12 x i8] c"client else\00"
@str.12 = [16 x i8] c"client success!\00"
@str.13 = [8 x i8] c"closing\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca [16 x i8]
%6 = alloca [64 x i32*]
%7 = alloca [64 x i32*]
%8 = alloca i32
%9 = alloca %struct.epoll_event
%10 = bitcast %struct.sockaddr_in* %3 to i8*
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%13 = bitcast [64 x i32*]* %6 to i8*
%14 = bitcast [64 x i32*]* %7 to i8*
%15 = bitcast i32* %8 to i8*
%16 = bitcast %struct.epoll_event* %9 to i8*
%17 = load i32, i32* @PF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = call i32 @memset(%struct.sockaddr_in* %3, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %23, i32* %24
%25 = call i32 @htons(i32 9000)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @bind(i32 %19, %struct.sockaddr* %27, i32 12)
%29 = call i32 @listen(i32 %19, i32 5)
%30 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = add nsw i32 %19, -3
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [64 x i32*], [64 x i32*]* %6, i64 0, i64 %32
store i32* %30, i32** %33
%34 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = getelementptr inbounds [64 x i32*], [64 x i32*]* %7, i64 0, i64 %32
store i32* %34, i32** %35
%36 = call i32 @epoll_create(i32 64)
%37 = call %struct.epoll_event* @malloc(i32 1024)
%38 = load i8*, i8** @EPOLLIN
%39 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 1
store i8* %38, i8** %39
%40 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %9, i64 0, i32 0, i32 0
store i32 %19, i32* %40
%41 = load i32, i32* @EPOLL_CTL_ADD
%42 = call i32 @epoll_ctl(i32 %36, i32 %41, i32 %19, %struct.epoll_event* %9)
%43 = call i32 @epoll_wait(i32 %36, %struct.epoll_event* %37, i32 64, i32 -1)
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %43)
%45 = icmp eq i32 %43, -1
br i1 %45, label %59, label %46
46: ; preds = %2
%47 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %53
48: ; preds = %119, %53
%49 = phi i32 [ %55, %53 ], [ %120, %119 ]
%50 = call i32 @epoll_wait(i32 %36, %struct.epoll_event* %37, i32 64, i32 -1)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = icmp eq i32 %50, -1
br i1 %52, label %59, label %53
53: ; preds = %46, %48
%54 = phi i32 [ %43, %46 ], [ %50, %48 ]
%55 = phi i32 [ undef, %46 ], [ %49, %48 ]
%56 = icmp sgt i32 %54, 0
br i1 %56, label %57, label %48
57: ; preds = %53
%58 = zext i32 %54 to i64
br label %67
59: ; preds = %48, %2
%60 = phi i32 [ undef, %2 ], [ %49, %48 ]
%61 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.13, i64 0, i64 0))
%63 = icmp sgt i32 %60, 3
br i1 %63, label %64, label %133
64: ; preds = %59
%65 = add nsw i32 %60, -3
%66 = zext i32 %65 to i64
br label %123
67: ; preds = %57, %119
%68 = phi i64 [ 0, %57 ], [ %121, %119 ]
%69 = phi i32 [ %55, %57 ], [ %120, %119 ]
%70 = trunc i64 %68 to i32
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0), i32 %70)
%72 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %37, i64 %68, i32 0, i32 0
%73 = load i32, i32* %72
%74 = icmp eq i32 %73, %19
br i1 %74, label %80, label %75
75: ; preds = %67
%76 = icmp sgt i32 %69, 4
br i1 %76, label %77, label %119
77: ; preds = %75
%78 = add nsw i32 %69, -3
%79 = zext i32 %78 to i64
br label %94
80: ; preds = %67
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0), i32 %19)
store i32 12, i32* %8
%82 = call i32 @accept(i32 %19, %struct.sockaddr* %47, i32* %8)
%83 = call i32 @setnonblocking(i32 %82)
%84 = call i32* @fdopen(i32 %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%85 = add nsw i32 %82, -4
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds [64 x i32*], [64 x i32*]* %6, i64 0, i64 %86
store i32* %84, i32** %87
%88 = call i32* @fdopen(i32 %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%89 = getelementptr inbounds [64 x i32*], [64 x i32*]* %7, i64 0, i64 %86
store i32* %88, i32** %89
%90 = load i8*, i8** @EPOLLIN
store i8* %90, i8** %39
store i32 %82, i32* %40
%91 = load i32, i32* @EPOLL_CTL_ADD
%92 = call i32 @epoll_ctl(i32 %36, i32 %91, i32 %82, %struct.epoll_event* %9)
%93 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0), i32 %82)
br label %119
94: ; preds = %77, %116
%95 = phi i64 [ 1, %77 ], [ %117, %116 ]
%96 = getelementptr inbounds [64 x i32*], [64 x i32*]* %6, i64 0, i64 %95
%97 = load i32*, i32** %96
%98 = call i64 @feof(i32* %97)
%99 = icmp eq i64 %98, 0
br i1 %99, label %108, label %100
100: ; preds = %94
%101 = load i32, i32* @EPOLL_CTL_DEL
%102 = load i32, i32* %72
%103 = call i32 @epoll_ctl(i32 %36, i32 %101, i32 %102, %struct.epoll_event* null)
%104 = load i32, i32* %72
%105 = call i32 @close(i32 %104)
%106 = load i32, i32* %72
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0), i32 %106)
br label %116
108: ; preds = %94
%109 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%110 = call i32 @fgets(i8* %12, i32 16, i32* %97)
%111 = getelementptr inbounds [64 x i32*], [64 x i32*]* %7, i64 0, i64 %95
%112 = load i32*, i32** %111
%113 = call i32 @fputs(i8* %12, i32* %112)
%114 = call i32 @fflush(i32* %112)
%115 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.12, i64 0, i64 0))
br label %116
116: ; preds = %100, %108
%117 = add nuw nsw i64 %95, 1
%118 = icmp eq i64 %117, %79
br i1 %118, label %119, label %94
119: ; preds = %116, %75, %80
%120 = phi i32 [ %82, %80 ], [ %69, %75 ], [ %69, %116 ]
%121 = add nuw nsw i64 %68, 1
%122 = icmp eq i64 %121, %58
br i1 %122, label %48, label %67
123: ; preds = %64, %123
%124 = phi i64 [ 0, %64 ], [ %131, %123 ]
%125 = getelementptr inbounds [64 x i32*], [64 x i32*]* %7, i64 0, i64 %124
%126 = load i32*, i32** %125
%127 = call i32 @fclose(i32* %126)
%128 = getelementptr inbounds [64 x i32*], [64 x i32*]* %6, i64 0, i64 %124
%129 = load i32*, i32** %128
%130 = call i32 @fclose(i32* %129)
%131 = add nuw nsw i64 %124, 1
%132 = icmp eq i64 %131, %66
br i1 %132, label %133, label %123
133: ; preds = %123, %59
%134 = call i32 @close(i32 %19)
ret i32 0
}