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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EPOLL_CTL_DEL;
int /*<<< orphan*/ INADDR_ANY;
int SOCK_NONBLOCK;
int SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
scalar_t__ epoll_ctl(int, int /*<<< orphan*/, int, struct sockaddr_in *);
int epoll_wait(int, struct sockaddr_in *, int, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
scalar_t__ read(int, char *, int);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, const char *argv[]) {
  int i = 0;
  char buff[1024];
  ssize_t msg_len = 0;
  int srv_fd = -1;
  int cli_fd = -1;
  int epoll_fd = -1;
  struct sockaddr_in srv_addr;
  struct sockaddr_in cli_addr;
  socklen_t cli_addr_len;
  struct epoll_event e, es[2];
  memset(&srv_addr, 0, sizeof(srv_addr));
  memset(&cli_addr, 0, sizeof(cli_addr));
  memset(&e, 0, sizeof(e));
  srv_fd = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
  if (srv_fd < 0) {
    printf("Cannot create socket\n");
    return 1;
  }
  srv_addr.sin_family = AF_INET;
  srv_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  srv_addr.sin_port = htons(5555);
  if (bind(srv_fd, (struct sockaddr *)&srv_addr, sizeof(srv_addr)) < 0) {
    printf("Cannot bind socket\n");
    close(srv_fd);
    return 1;
  }
  if (listen(srv_fd, 1) < 0) {
    printf("Cannot listen\n");
    close(srv_fd);
    return 1;
  }
  epoll_fd = epoll_create(2);
  if (epoll_fd < 0) {
    printf("Cannot create epoll\n");
    close(srv_fd);
    return 1;
  }
  e.events = EPOLLIN;
  e.data.fd = srv_fd;
  if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, srv_fd, &e) < 0) {
    printf("Cannot add server socket to epoll\n");
    close(epoll_fd);
    close(srv_fd);
    return 1;
  }
  for (;;) {
    i = epoll_wait(epoll_fd, es, 2, -1);
    if (i < 0) {
      printf("Cannot wait for events\n");
      close(epoll_fd);
      close(srv_fd);
      return 1;
    }
    for (--i; i > -1; --i) {
      if (es[i].data.fd == srv_fd) {
        cli_fd = accept(srv_fd, (struct sockaddr *)&cli_addr, &cli_addr_len);
        if (cli_fd < 0) {
          printf("Cannot accept client\n");
          close(epoll_fd);
          close(srv_fd);
          return 1;
        }
        e.data.fd = cli_fd;
        if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, cli_fd, &e) < 0) {
          printf("Cannot accept client\n");
          close(epoll_fd);
          close(srv_fd);
          return 1;
        }
      }
      if (es[i].data.fd == cli_fd) {
        if (es[i].events & EPOLLIN) {
          msg_len = read(cli_fd, buff, 1024);
          if (msg_len > 0) {
            write(cli_fd, buff, msg_len);
          }
          close(cli_fd);
          epoll_ctl(epoll_fd, EPOLL_CTL_DEL, cli_fd, &e);
          cli_fd = -1;
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movq   $0x0,-0x428(%rbp)
movl   $0xffffffff,-0x42c(%rbp)
ff ff ff
movl   $0xffffffff,-0x430(%rbp)
ff ff ff
movl   $0xffffffff,-0x434(%rbp)
ff ff ff
lea    -0x448(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    -0x460(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    -0x478(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
mov    0x2d3d(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
mov    %eax,-0x42c(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jge    12af <main+0xcf>
lea    0xd62(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x438(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,-0x43c(%rbp)
mov    $0x15b3,%edi
call   1040 <htons@plt>
mov    %eax,-0x440(%rbp)
mov    -0x42c(%rbp),%edi
lea    -0x448(%rbp),%rsi
mov    $0x14,%edx
call   10d0 <bind@plt>
cmp    $0x0,%rax
jge    1326 <main+0x146>
lea    0xd0c(%rip),%rdi
call   1050 <printf@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    -0x42c(%rbp),%edi
mov    $0x1,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jge    1363 <main+0x183>
lea    0xce3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    $0x2,%edi
call   10f0 <epoll_create@plt>
mov    %eax,-0x434(%rbp)
cmpl   $0x0,-0x434(%rbp)
jge    13a3 <main+0x1c3>
lea    0xcb2(%rip),%rdi
call   1050 <printf@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x478(%rbp)
mov    -0x42c(%rbp),%eax
mov    %eax,-0x474(%rbp)
mov    -0x434(%rbp),%edi
mov    0x2c05(%rip),%rax
mov    (%rax),%esi
mov    -0x42c(%rbp),%edx
lea    -0x478(%rbp),%rcx
call   1090 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    1417 <main+0x237>
lea    0xc5e(%rip),%rdi
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
jmp    141c <main+0x23c>
mov    -0x434(%rbp),%edi
lea    -0x4a0(%rbp),%rsi
mov    $0x2,%edx
mov    $0xffffffff,%ecx
call   10c0 <epoll_wait@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1473 <main+0x293>
lea    0xc25(%rip),%rdi
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jle    1645 <main+0x465>
movslq -0x14(%rbp),%rcx
lea    -0x4a0(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
cmp    -0x42c(%rbp),%eax
jne    156b <main+0x38b>
mov    -0x42c(%rbp),%edi
lea    -0x460(%rbp),%rsi
lea    -0x464(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0x430(%rbp)
cmpl   $0x0,-0x430(%rbp)
jge    1501 <main+0x321>
lea    0xbaf(%rip),%rdi
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
mov    -0x430(%rbp),%eax
mov    %eax,-0x474(%rbp)
mov    -0x434(%rbp),%edi
mov    0x2ab6(%rip),%rax
mov    (%rax),%esi
mov    -0x430(%rbp),%edx
lea    -0x478(%rbp),%rcx
call   1090 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    1566 <main+0x386>
lea    0xb4a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x434(%rbp),%edi
call   1080 <close@plt>
mov    -0x42c(%rbp),%edi
call   1080 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    164a <main+0x46a>
jmp    156b <main+0x38b>
movslq -0x14(%rbp),%rcx
lea    -0x4a0(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    0x4(%rax),%eax
cmp    -0x430(%rbp),%eax
jne    1632 <main+0x452>
movslq -0x14(%rbp),%rcx
lea    -0x4a0(%rbp),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    0x2a31(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     162d <main+0x44d>
mov    -0x430(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jle    15f7 <main+0x417>
mov    -0x430(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x428(%rbp),%rdx
call   1030 <write@plt>
mov    -0x430(%rbp),%edi
call   1080 <close@plt>
mov    -0x434(%rbp),%edi
mov    0x29e9(%rip),%rax
mov    (%rax),%esi
mov    -0x430(%rbp),%edx
lea    -0x478(%rbp),%rcx
call   1090 <epoll_ctl@plt>
movl   $0xffffffff,-0x430(%rbp)
ff ff ff
jmp    1632 <main+0x452>
jmp    1637 <main+0x457>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    147c <main+0x29c>
jmp    141c <main+0x23c>
mov    -0x4(%rbp),%eax
add    $0x4a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x478,%rsp
lea    0x18(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
lea    0x58(%rsp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1070 <memset@plt>
mov    0x2db7(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d7d(%rip),%rax
mov    0x2d7e(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
xor    %edx,%edx
call   1100 <socket@plt>
test   %eax,%eax
js     12ee <main+0x10e>
mov    %eax,%ebx
mov    0x0(%rbp),%eax
mov    %eax,0x28(%rsp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%edi
call   1060 <htonl@plt>
mov    %eax,0x24(%rsp)
mov    $0x15b3,%edi
call   1050 <htons@plt>
mov    %eax,0x20(%rsp)
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x14,%edx
call   10d0 <bind@plt>
test   %rax,%rax
js     12ff <main+0x11f>
mov    %ebx,%edi
mov    $0x1,%esi
call   10b0 <listen@plt>
test   %rax,%rax
js     130b <main+0x12b>
mov    $0x2,%edi
call   10f0 <epoll_create@plt>
test   %eax,%eax
js     142b <main+0x24b>
mov    %eax,%ebp
mov    0x2d20(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebx,0x4(%rsp)
mov    0x2d08(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %ebp,%edi
mov    %ebx,%edx
call   1090 <epoll_ctl@plt>
test   %rax,%rax
js     1439 <main+0x259>
lea    0x30(%rsp),%rsi
mov    $0xffffffff,%r14d
mov    %ebp,%edi
jmp    131e <main+0x13e>
lea    0xd8e(%rip),%rdi
call   1030 <puts@plt>
jmp    1465 <main+0x285>
lea    0xd6a(%rip),%rdi
jmp    1432 <main+0x252>
lea    0xd50(%rip),%rdi
jmp    1432 <main+0x252>
mov    %ebp,%edi
lea    0x30(%rsp),%rsi
mov    $0x2,%edx
mov    $0xffffffff,%ecx
call   10c0 <epoll_wait@plt>
test   %eax,%eax
js     144b <main+0x26b>
test   %eax,%eax
je     1317 <main+0x137>
mov    %eax,%r12d
add    $0x1,%r12
jmp    135a <main+0x17a>
mov    %r15d,%r14d
cs nopw 0x0(%rax,%rax,1)
nop
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
jbe    1317 <main+0x137>
lea    -0x2(%r12),%eax
lea    (%rax,%rax,4),%r13
mov    0x34(%rsp,%r13,4),%r15d
cmp    %ebx,%r15d
jne    13b7 <main+0x1d7>
mov    %ebx,%edi
lea    0x58(%rsp),%rsi
lea    0x2c(%rsp),%rdx
call   10e0 <accept@plt>
test   %eax,%eax
js     1442 <main+0x262>
mov    %eax,%r14d
mov    %eax,0x4(%rsp)
mov    0x2c3c(%rip),%rax
mov    (%rax),%esi
mov    %ebp,%edi
mov    %r14d,%edx
mov    %rsp,%rcx
call   1090 <epoll_ctl@plt>
test   %rax,%rax
js     1442 <main+0x262>
lea    (%rsp,%r13,4),%rax
add    $0x34,%rax
mov    (%rax),%r15d
cmp    %r14d,%r15d
jne    1350 <main+0x170>
mov    0x2c15(%rip),%rax
mov    (%rax),%eax
test   %eax,0x30(%rsp,%r13,4)
je     1342 <main+0x162>
mov    %ebx,%r13d
mov    %ebp,%ebx
mov    %r15d,%edi
lea    0x70(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
test   %rax,%rax
jle    13fd <main+0x21d>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %r15d,%edi
call   1080 <close@plt>
mov    0x2bec(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%ebp
mov    %ebx,%edi
mov    %r15d,%edx
mov    %rsp,%rcx
call   1090 <epoll_ctl@plt>
mov    $0xffffffff,%r14d
mov    %r13d,%ebx
jmp    1350 <main+0x170>
lea    0xc1c(%rip),%rdi
call   1030 <puts@plt>
jmp    145e <main+0x27e>
lea    0xbec(%rip),%rdi
jmp    1452 <main+0x272>
lea    0xbb7(%rip),%rdi
jmp    1452 <main+0x272>
lea    0xbc3(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%edi
call   1080 <close@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0x1,%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_4__, i32, %struct.TYPE_3__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.TYPE_3__ = type { i32 }
%struct.epoll_event = type { i32, %struct.TYPE_4__, i32, %struct.TYPE_3__, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOCK_NONBLOCK = global i32 0
@.str = [22 x i8] c"Cannot create socket\0A\00"
@INADDR_ANY = global i32 0
@.str.1 = [20 x i8] c"Cannot bind socket\0A\00"
@.str.2 = [15 x i8] c"Cannot listen\0A\00"
@.str.3 = [21 x i8] c"Cannot create epoll\0A\00"
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.4 = [35 x i8] c"Cannot add server socket to epoll\0A\00"
@.str.5 = [24 x i8] c"Cannot wait for events\0A\00"
@.str.6 = [22 x i8] c"Cannot accept client\0A\00"
@EPOLL_CTL_DEL = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca i64
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.sockaddr_in
%14 = alloca i32
%15 = alloca %struct.epoll_event
%16 = alloca [2 x %struct.epoll_event]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
store i64 0, i64* %8
store i32 -1, i32* %9
store i32 -1, i32* %10
store i32 -1, i32* %11
%17 = call i32 @memset(%struct.sockaddr_in* %12, i32 0, i32 20)
%18 = call i32 @memset(%struct.sockaddr_in* %13, i32 0, i32 20)
%19 = bitcast %struct.epoll_event* %15 to %struct.sockaddr_in*
%20 = call i32 @memset(%struct.sockaddr_in* %19, i32 0, i32 20)
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = load i32, i32* @SOCK_NONBLOCK
%24 = or i32 %22, %23
%25 = call i32 @socket(i32 %21, i32 %24, i32 0)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %182
30: ; preds = %2
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 4
store i32 %31, i32* %32
%33 = load i32, i32* @INADDR_ANY
%34 = call i32 @htonl(i32 %33)
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 3
%36 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %35, i32 0, i32 0
store i32 %34, i32* %36
%37 = call i32 @htons(i32 5555)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %37, i32* %38
%39 = load i32, i32* %9
%40 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%41 = call i64 @bind(i32 %39, %struct.sockaddr* %40, i32 20)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %47
43: ; preds = %30
%44 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
%45 = load i32, i32* %9
%46 = call i32 @close(i32 %45)
store i32 1, i32* %3
br label %182
47: ; preds = %30
%48 = load i32, i32* %9
%49 = call i64 @listen(i32 %48, i32 1)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %55
51: ; preds = %47
%52 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%53 = load i32, i32* %9
%54 = call i32 @close(i32 %53)
store i32 1, i32* %3
br label %182
55: ; preds = %47
%56 = call i32 @epoll_create(i32 2)
store i32 %56, i32* %11
%57 = load i32, i32* %11
%58 = icmp slt i32 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%61 = load i32, i32* %9
%62 = call i32 @close(i32 %61)
store i32 1, i32* %3
br label %182
63: ; preds = %55
%64 = load i32, i32* @EPOLLIN
%65 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %15, i32 0, i32 0
store i32 %64, i32* %65
%66 = load i32, i32* %9
%67 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %15, i32 0, i32 1
%68 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %67, i32 0, i32 0
store i32 %66, i32* %68
%69 = load i32, i32* %11
%70 = load i32, i32* @EPOLL_CTL_ADD
%71 = load i32, i32* %9
%72 = bitcast %struct.epoll_event* %15 to %struct.sockaddr_in*
%73 = call i64 @epoll_ctl(i32 %69, i32 %70, i32 %71, %struct.sockaddr_in* %72)
%74 = icmp slt i64 %73, 0
br i1 %74, label %75, label %81
75: ; preds = %63
%76 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.4, i64 0, i64 0))
%77 = load i32, i32* %11
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* %9
%80 = call i32 @close(i32 %79)
store i32 1, i32* %3
br label %182
81: ; preds = %63
br label %82
82: ; preds = %181, %81
%83 = load i32, i32* %11
%84 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %16, i64 0, i64 0
%85 = bitcast %struct.epoll_event* %84 to %struct.sockaddr_in*
%86 = call i32 @epoll_wait(i32 %83, %struct.sockaddr_in* %85, i32 2, i32 -1)
store i32 %86, i32* %6
%87 = load i32, i32* %6
%88 = icmp slt i32 %87, 0
br i1 %88, label %89, label %95
89: ; preds = %82
%90 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0))
%91 = load i32, i32* %11
%92 = call i32 @close(i32 %91)
%93 = load i32, i32* %9
%94 = call i32 @close(i32 %93)
store i32 1, i32* %3
br label %182
95: ; preds = %82
%96 = load i32, i32* %6
%97 = add nsw i32 %96, -1
store i32 %97, i32* %6
br label %98
98: ; preds = %178, %95
%99 = load i32, i32* %6
%100 = icmp sgt i32 %99, -1
br i1 %100, label %101, label %181
101: ; preds = %98
%102 = load i32, i32* %6
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %16, i64 0, i64 %103
%105 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %104, i32 0, i32 1
%106 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %105, i32 0, i32 0
%107 = load i32, i32* %106
%108 = load i32, i32* %9
%109 = icmp eq i32 %107, %108
br i1 %109, label %110, label %139
110: ; preds = %101
%111 = load i32, i32* %9
%112 = bitcast %struct.sockaddr_in* %13 to %struct.sockaddr*
%113 = call i32 @accept(i32 %111, %struct.sockaddr* %112, i32* %14)
store i32 %113, i32* %10
%114 = load i32, i32* %10
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %122
116: ; preds = %110
%117 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%118 = load i32, i32* %11
%119 = call i32 @close(i32 %118)
%120 = load i32, i32* %9
%121 = call i32 @close(i32 %120)
store i32 1, i32* %3
br label %182
122: ; preds = %110
%123 = load i32, i32* %10
%124 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %15, i32 0, i32 1
%125 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %124, i32 0, i32 0
store i32 %123, i32* %125
%126 = load i32, i32* %11
%127 = load i32, i32* @EPOLL_CTL_ADD
%128 = load i32, i32* %10
%129 = bitcast %struct.epoll_event* %15 to %struct.sockaddr_in*
%130 = call i64 @epoll_ctl(i32 %126, i32 %127, i32 %128, %struct.sockaddr_in* %129)
%131 = icmp slt i64 %130, 0
br i1 %131, label %132, label %138
132: ; preds = %122
%133 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0))
%134 = load i32, i32* %11
%135 = call i32 @close(i32 %134)
%136 = load i32, i32* %9
%137 = call i32 @close(i32 %136)
store i32 1, i32* %3
br label %182
138: ; preds = %122
br label %139
139: ; preds = %138, %101
%140 = load i32, i32* %6
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %16, i64 0, i64 %141
%143 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %142, i32 0, i32 1
%144 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %143, i32 0, i32 0
%145 = load i32, i32* %144
%146 = load i32, i32* %10
%147 = icmp eq i32 %145, %146
br i1 %147, label %148, label %177
148: ; preds = %139
%149 = load i32, i32* %6
%150 = sext i32 %149 to i64
%151 = getelementptr inbounds [2 x %struct.epoll_event], [2 x %struct.epoll_event]* %16, i64 0, i64 %150
%152 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %151, i32 0, i32 0
%153 = load i32, i32* %152
%154 = load i32, i32* @EPOLLIN
%155 = and i32 %153, %154
%156 = icmp ne i32 %155, 0
br i1 %156, label %157, label %176
157: ; preds = %148
%158 = load i32, i32* %10
%159 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%160 = call i64 @read(i32 %158, i8* %159, i32 1024)
store i64 %160, i64* %8
%161 = load i64, i64* %8
%162 = icmp sgt i64 %161, 0
br i1 %162, label %163, label %168
163: ; preds = %157
%164 = load i32, i32* %10
%165 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%166 = load i64, i64* %8
%167 = call i32 @write(i32 %164, i8* %165, i64 %166)
br label %168
168: ; preds = %163, %157
%169 = load i32, i32* %10
%170 = call i32 @close(i32 %169)
%171 = load i32, i32* %11
%172 = load i32, i32* @EPOLL_CTL_DEL
%173 = load i32, i32* %10
%174 = bitcast %struct.epoll_event* %15 to %struct.sockaddr_in*
%175 = call i64 @epoll_ctl(i32 %171, i32 %172, i32 %173, %struct.sockaddr_in* %174)
store i32 -1, i32* %10
br label %176
176: ; preds = %168, %148
br label %177
177: ; preds = %176, %139
br label %178
178: ; preds = %177
%179 = load i32, i32* %6
%180 = add nsw i32 %179, -1
store i32 %180, i32* %6
br label %98
181: ; preds = %98
br label %82
182: ; preds = %132, %116, %89, %75, %59, %51, %43, %28
%183 = load i32, i32* %3
ret i32 %183
}

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