#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 dummy;
};
struct sockaddr {
  int dummy;
};
struct TYPE_2__ {
  int fd;
};
struct epoll_event {
  TYPE_1__ data;
  void *events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ cli_addr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
void *EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_DEL;
int /*<<< orphan*/ EXIT_FAILURE;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ close(int);
int create_socket(char *);
int epoll_create(int);
int /*<<< orphan*/ epoll_ctl(int, int /*<<< orphan*/, int,
                             struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct epoll_event *malloc(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ puts(char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i, str_len;
  char buf[1024];
  int timeout;
  struct sockaddr_in cli_addr;
  socklen_t socklen;
  int socket_fd, connect_fd;
  struct epoll_event event;
  struct epoll_event *wait_events;
  int epollfd, event_cnt;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <port>\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  socket_fd = create_socket(argv[1]);
  if (socket_fd == -1) {
    fprintf(stderr, "create_socket() failed.\n");
    exit(EXIT_FAILURE);
  }
  epollfd = epoll_create(100);
  wait_events = malloc(sizeof(struct epoll_event) * 100);
  event.events = EPOLLIN;
  event.data.fd = socket_fd;
  epoll_ctl(epollfd, EPOLL_CTL_ADD, socket_fd, &event);
  socklen = sizeof(cli_addr);
  while (1) {
    timeout = 1000;
    event_cnt = epoll_wait(epollfd, wait_events, 100, timeout);
    if (event_cnt == -1) {
      fprintf(stderr, "epoll() failed\n");
      break;
    } else if (event_cnt == 0) {
      printf("time out!\n");
      continue;
    }
    puts("return epoll wait\n");
    for (i = 0; i < event_cnt; ++i) {
      if (wait_events[i].data.fd == socket_fd) {
        connect_fd = accept(socket_fd, (struct sockaddr *)&cli_addr, &socklen);
        event.events = EPOLLIN;
        event.data.fd = connect_fd;
        epoll_ctl(epollfd, EPOLL_CTL_ADD, connect_fd, &event);
        printf("new client connected\n");
      } else {
        str_len = read(wait_events[i].data.fd, buf, sizeof(buf));
        if (str_len <= 0) {
          epoll_ctl(epollfd, EPOLL_CTL_DEL, wait_events[i].data.fd, NULL);
          close(wait_events[i].data.fd);
          printf("client closed\n");
        } else {
          write(wait_events[i].data.fd, buf, str_len);
        }
      }
    }
  }
  close(epollfd);
  close(socket_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     121f <main+0x4f>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <create_socket@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0xffffffff,-0x430(%rbp)
jne    1264 <main+0x94>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
mov    0x2d63(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0x64,%edi
call   10e0 <epoll_create@plt>
mov    %eax,-0x454(%rbp)
mov    $0x640,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x450(%rbp)
mov    0x2d54(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x440(%rbp)
mov    -0x430(%rbp),%eax
mov    %eax,-0x448(%rbp)
mov    -0x454(%rbp),%edi
mov    0x2d29(%rip),%rax
mov    (%rax),%esi
mov    -0x430(%rbp),%edx
lea    -0x448(%rbp),%rcx
call   1070 <epoll_ctl@plt>
movl   $0x4,-0x42c(%rbp)
movl   $0x3e8,-0x424(%rbp)
mov    -0x454(%rbp),%edi
mov    -0x450(%rbp),%rsi
mov    -0x424(%rbp),%ecx
mov    $0x64,%edx
call   10c0 <epoll_wait@plt>
mov    %eax,-0x458(%rbp)
cmpl   $0xffffffff,-0x458(%rbp)
jne    1323 <main+0x153>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    0xd14(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    14be <main+0x2ee>
cmpl   $0x0,-0x458(%rbp)
jne    1341 <main+0x171>
lea    0xd04(%rip),%rdi
call   1050 <printf@plt>
jmp    12cd <main+0xfd>
jmp    1346 <main+0x176>
lea    0xcf9(%rip),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x458(%rbp),%eax
jge    14b9 <main+0x2e9>
mov    -0x450(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
cmp    -0x430(%rbp),%eax
jne    13f6 <main+0x226>
mov    -0x430(%rbp),%edi
lea    -0x428(%rbp),%rsi
lea    -0x42c(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0x434(%rbp)
mov    0x2c32(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x440(%rbp)
mov    -0x434(%rbp),%eax
mov    %eax,-0x448(%rbp)
mov    -0x454(%rbp),%edi
mov    0x2c07(%rip),%rax
mov    (%rax),%esi
mov    -0x434(%rbp),%edx
lea    -0x448(%rbp),%rcx
call   1070 <epoll_ctl@plt>
lea    0xc6d(%rip),%rdi
call   1050 <printf@plt>
jmp    14a6 <main+0x2d6>
mov    -0x450(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jg     147e <main+0x2ae>
mov    -0x454(%rbp),%edi
mov    0x2bc3(%rip),%rax
mov    (%rax),%esi
mov    -0x450(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1070 <epoll_ctl@plt>
mov    -0x450(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edi
call   1060 <close@plt>
lea    0xbfb(%rip),%rdi
call   1050 <printf@plt>
jmp    14a1 <main+0x2d1>
mov    -0x450(%rbp),%rax
movslq -0x14(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <write@plt>
jmp    14a6 <main+0x2d6>
jmp    14ab <main+0x2db>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1359 <main+0x189>
jmp    12cd <main+0xfd>
mov    -0x454(%rbp),%edi
call   1060 <close@plt>
mov    -0x430(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x460,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x428,%rsp
cmp    $0x2,%edi
jne    1384 <main+0x1c4>
mov    0x8(%rsi),%rdi
call   10a0 <create_socket@plt>
cmp    $0xffffffff,%eax
je     13a0 <main+0x1e0>
mov    %eax,%r15d
mov    $0x64,%edi
call   10d0 <epoll_create@plt>
mov    %eax,%r14d
mov    $0x640,%edi
call   1090 <malloc@plt>
mov    %rax,%rbp
mov    0x2dd0(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x10(%rsp)
mov    %r15d,0x8(%rsp)
mov    0x2db4(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rcx
mov    %r14d,%edi
mov    %r15d,%edx
call   1060 <epoll_ctl@plt>
movl   $0x4,0x4(%rsp)
lea    0x20(%rsp),%r12
jmp    125c <main+0x9c>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xe1a(%rip),%rdi
call   1030 <puts@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x64,%edx
mov    $0x3e8,%ecx
call   10b0 <epoll_wait@plt>
test   %eax,%eax
je     1250 <main+0x90>
mov    %eax,%r13d
cmp    $0xffffffff,%eax
je     1349 <main+0x189>
lea    0xdb3(%rip),%rdi
call   1030 <puts@plt>
test   %r13d,%r13d
jle    125c <main+0x9c>
mov    %r13d,%r13d
shl    $0x4,%r13
xor    %ebx,%ebx
jmp    12f6 <main+0x136>
nopl   (%rax)
mov    %r15d,%edi
lea    0x18(%rsp),%rsi
lea    0x4(%rsp),%rdx
call   10c0 <accept@plt>
mov    0x2d27(%rip),%rcx
mov    (%rcx),%rcx
mov    %rcx,0x10(%rsp)
mov    %eax,0x8(%rsp)
mov    0x2d0c(%rip),%rcx
mov    (%rcx),%esi
mov    %r14d,%edi
mov    %eax,%edx
lea    0x8(%rsp),%rcx
call   1060 <epoll_ctl@plt>
lea    0xd78(%rip),%rdi
call   1030 <puts@plt>
add    $0x10,%rbx
cmp    %rbx,%r13
je     125c <main+0x9c>
mov    0x0(%rbp,%rbx,1),%edi
cmp    %r15d,%edi
je     12a0 <main+0xe0>
mov    %r12,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1320 <main+0x160>
mov    0x0(%rbp,%rbx,1),%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    12e9 <main+0x129>
mov    0x2cd1(%rip),%rax
mov    (%rax),%esi
mov    0x0(%rbp,%rbx,1),%edx
mov    %r14d,%edi
xor    %ecx,%ecx
call   1060 <epoll_ctl@plt>
mov    0x0(%rbp,%rbx,1),%edi
call   1050 <close@plt>
lea    0xd07(%rip),%rdi
jmp    12e4 <main+0x124>
mov    0x2c78(%rip),%rax
mov    (%rax),%edi
lea    0xcd2(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14d,%edi
call   1050 <close@plt>
mov    %r15d,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x428,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c3d(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xc69(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    13b7 <main+0x1f7>
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
lea    0xc62(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2c02(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"create_socket() failed.\0A\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [16 x i8] c"epoll() failed\0A\00"
@.str.3 = [11 x i8] c"time out!\0A\00"
@.str.4 = [19 x i8] c"return epoll wait\0A\00"
@.str.5 = [22 x i8] c"new client connected\0A\00"
@EPOLL_CTL_DEL = global i32 0
@.str.6 = [15 x i8] c"client closed\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 [1024 x i8]
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.epoll_event
%15 = alloca %struct.epoll_event*
%16 = alloca i32
%17 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 2
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load i32, i32* @stderr
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %2
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 1
%31 = load i8*, i8** %30
%32 = call i32 @create_socket(i8* %31)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %40
35: ; preds = %28
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %28
%41 = call i32 @epoll_create(i32 100)
store i32 %41, i32* %16
%42 = call %struct.epoll_event* @malloc(i32 1600)
store %struct.epoll_event* %42, %struct.epoll_event** %15
%43 = load i8*, i8** @EPOLLIN
%44 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 1
store i8* %43, i8** %44
%45 = load i32, i32* %12
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 0
%47 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %46, i32 0, i32 0
store i32 %45, i32* %47
%48 = load i32, i32* %16
%49 = load i32, i32* @EPOLL_CTL_ADD
%50 = load i32, i32* %12
%51 = call i32 @epoll_ctl(i32 %48, i32 %49, i32 %50, %struct.epoll_event* %14)
store i32 4, i32* %11
br label %52
52: ; preds = %40, %65, %146
store i32 1000, i32* %9
%53 = load i32, i32* %16
%54 = load %struct.epoll_event*, %struct.epoll_event** %15
%55 = load i32, i32* %9
%56 = call i32 @epoll_wait(i32 %53, %struct.epoll_event* %54, i32 100, i32 %55)
store i32 %56, i32* %17
%57 = load i32, i32* %17
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %52
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %147
62: ; preds = %52
%63 = load i32, i32* %17
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %67
65: ; preds = %62
%66 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %52
67: ; preds = %62
br label %68
68: ; preds = %67
%69 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %6
br label %70
70: ; preds = %143, %68
%71 = load i32, i32* %6
%72 = load i32, i32* %17
%73 = icmp slt i32 %71, %72
br i1 %73, label %74, label %146
74: ; preds = %70
%75 = load %struct.epoll_event*, %struct.epoll_event** %15
%76 = load i32, i32* %6
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %75, i64 %77
%79 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %78, i32 0, i32 0
%80 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %79, i32 0, i32 0
%81 = load i32, i32* %80
%82 = load i32, i32* %12
%83 = icmp eq i32 %81, %82
br i1 %83, label %84, label %98
84: ; preds = %74
%85 = load i32, i32* %12
%86 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%87 = call i32 @accept(i32 %85, %struct.sockaddr* %86, i32* %11)
store i32 %87, i32* %13
%88 = load i8*, i8** @EPOLLIN
%89 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 1
store i8* %88, i8** %89
%90 = load i32, i32* %13
%91 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %14, i32 0, i32 0
%92 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %91, i32 0, i32 0
store i32 %90, i32* %92
%93 = load i32, i32* %16
%94 = load i32, i32* @EPOLL_CTL_ADD
%95 = load i32, i32* %13
%96 = call i32 @epoll_ctl(i32 %93, i32 %94, i32 %95, %struct.epoll_event* %14)
%97 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
br label %142
98: ; preds = %74
%99 = load %struct.epoll_event*, %struct.epoll_event** %15
%100 = load i32, i32* %6
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %99, i64 %101
%103 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %102, i32 0, i32 0
%104 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %103, i32 0, i32 0
%105 = load i32, i32* %104
%106 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%107 = call i32 @read(i32 %105, i8* %106, i32 1024)
store i32 %107, i32* %7
%108 = load i32, i32* %7
%109 = icmp sle i32 %108, 0
br i1 %109, label %110, label %130
110: ; preds = %98
%111 = load i32, i32* %16
%112 = load i32, i32* @EPOLL_CTL_DEL
%113 = load %struct.epoll_event*, %struct.epoll_event** %15
%114 = load i32, i32* %6
%115 = sext i32 %114 to i64
%116 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %113, i64 %115
%117 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %116, i32 0, i32 0
%118 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %117, i32 0, i32 0
%119 = load i32, i32* %118
%120 = call i32 @epoll_ctl(i32 %111, i32 %112, i32 %119, %struct.epoll_event* null)
%121 = load %struct.epoll_event*, %struct.epoll_event** %15
%122 = load i32, i32* %6
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %121, i64 %123
%125 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %124, i32 0, i32 0
%126 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %125, i32 0, i32 0
%127 = load i32, i32* %126
%128 = call i32 @close(i32 %127)
%129 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i64 0, i64 0))
br label %141
130: ; preds = %98
%131 = load %struct.epoll_event*, %struct.epoll_event** %15
%132 = load i32, i32* %6
%133 = sext i32 %132 to i64
%134 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %131, i64 %133
%135 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %134, i32 0, i32 0
%136 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %135, i32 0, i32 0
%137 = load i32, i32* %136
%138 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%139 = load i32, i32* %7
%140 = call i32 @write(i32 %137, i8* %138, i32 %139)
br label %141
141: ; preds = %130, %110
br label %142
142: ; preds = %141, %84
br label %143
143: ; preds = %142
%144 = load i32, i32* %6
%145 = add nsw i32 %144, 1
store i32 %145, i32* %6
br label %70
146: ; preds = %70
br label %52
147: ; preds = %59
%148 = load i32, i32* %16
%149 = call i32 @close(i32 %148)
%150 = load i32, i32* %12
%151 = call i32 @close(i32 %150)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.epoll_event = type { %struct.TYPE_2__, i8* }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s <port>\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [25 x i8] c"create_socket() failed.\0A\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [16 x i8] c"epoll() failed\0A\00"
@.str.4 = [19 x i8] c"return epoll wait\0A\00"
@EPOLL_CTL_DEL = global i32 0
@str = [14 x i8] c"client closed\00"
@str.7 = [21 x i8] c"new client connected\00"
@str.8 = [10 x i8] c"time out!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca %struct.epoll_event
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
%10 = bitcast %struct.epoll_event* %6 to i8*
%11 = icmp eq i32 %0, 2
br i1 %11, label %18, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %1
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i32 @create_socket(i8* %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
28: ; preds = %18
%29 = tail call i32 @epoll_create(i32 100)
%30 = tail call %struct.epoll_event* @malloc(i32 1600)
%31 = load i8*, i8** @EPOLLIN
%32 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 1
store i8* %31, i8** %32
%33 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %6, i64 0, i32 0, i32 0
store i32 %21, i32* %33
%34 = load i32, i32* @EPOLL_CTL_ADD
%35 = call i32 @epoll_ctl(i32 %29, i32 %34, i32 %21, %struct.epoll_event* %6)
store i32 4, i32* %5
%36 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
br label %37
37: ; preds = %49, %28
%38 = call i32 @epoll_wait(i32 %29, %struct.epoll_event* %30, i32 100, i32 1000)
switch i32 %38, label %46 [
i32 -1, label %39
i32 0, label %44
]
39: ; preds = %37
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
%42 = call i32 @close(i32 %29)
%43 = call i32 @close(i32 %21)
ret i32 0
44: ; preds = %37
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.8, i64 0, i64 0))
br label %49
46: ; preds = %37
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%48 = icmp sgt i32 %38, 0
br i1 %48, label %50, label %49
49: ; preds = %76, %46, %44
br label %37
50: ; preds = %46
%51 = zext i32 %38 to i64
br label %52
52: ; preds = %50, %76
%53 = phi i64 [ 0, %50 ], [ %77, %76 ]
%54 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %30, i64 %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = icmp eq i32 %55, %21
br i1 %56, label %57, label %63
57: ; preds = %52
%58 = call i32 @accept(i32 %21, %struct.sockaddr* %36, i32* %5)
%59 = load i8*, i8** @EPOLLIN
store i8* %59, i8** %32
store i32 %58, i32* %33
%60 = load i32, i32* @EPOLL_CTL_ADD
%61 = call i32 @epoll_ctl(i32 %29, i32 %60, i32 %58, %struct.epoll_event* %6)
%62 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.7, i64 0, i64 0))
br label %76
63: ; preds = %52
%64 = call i32 @read(i32 %55, i8* %7, i32 1024)
%65 = icmp slt i32 %64, 1
br i1 %65, label %66, label %73
66: ; preds = %63
%67 = load i32, i32* @EPOLL_CTL_DEL
%68 = load i32, i32* %54
%69 = call i32 @epoll_ctl(i32 %29, i32 %67, i32 %68, %struct.epoll_event* null)
%70 = load i32, i32* %54
%71 = call i32 @close(i32 %70)
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
br label %76
73: ; preds = %63
%74 = load i32, i32* %54
%75 = call i32 @write(i32 %74, i8* %7, i32 %64)
br label %76
76: ; preds = %57, %73, %66
%77 = add nuw nsw i64 %53, 1
%78 = icmp eq i64 %77, %51
br i1 %78, label %49, label %52
}