#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 {
  int sin_port;
  TYPE_2__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_3__ {
  int fd;
};
struct epoll_event {
  int events;
  TYPE_1__ data;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EPOLLET;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ PF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr const *, int);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ do_use_fd(int);
int epoll_create1(int /*<<< orphan*/);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int htons(int);
int /*<<< orphan*/ inet_addr(char *);
char *inet_ntoa(TYPE_2__);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ setnonblocking(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  struct epoll_event ev, events[10];
  struct sockaddr_in server, client;
  socklen_t client_len = sizeof(client);
  int listen_sock, conn_sock, nfds, epollfd;
  listen_sock = socket(AF_INET, SOCK_STREAM, PF_UNSPEC);
  if (listen_sock == -1) {
    perror("socket");
    return errno;
  }
  bzero(&server, sizeof(server));
  server.sin_family = AF_INET;
  server.sin_port = htons(1122);
  server.sin_addr.s_addr = inet_addr("192.168.0.111");
  if (bind(listen_sock, (const struct sockaddr *)&server, sizeof(server)) ==
      -1) {
    perror("bind");
    return errno;
  }
  if (listen(listen_sock, 10) == -1) {
    perror("listen");
    return errno;
  }
  epollfd = epoll_create1(0);
  if (epollfd == -1) {
    perror("epoll_create1");
    exit(EXIT_FAILURE);
  }
  ev.events = EPOLLIN;
  ev.data.fd = listen_sock;
  if (epoll_ctl(epollfd, EPOLL_CTL_ADD, listen_sock, &ev) == -1) {
    perror("epoll_ctl: listen_sock");
    exit(EXIT_FAILURE);
  }
  for (;;) {
    nfds = epoll_wait(epollfd, events, 10, -1);
    if (nfds == -1) {
      perror("epoll_wait");
      break;
    }
    for (int n = 0; n < nfds; ++n) {
      if (events[n].data.fd == listen_sock) {
        bzero(&client, sizeof(client));
        conn_sock =
            accept(listen_sock, (struct sockaddr *)&client, &client_len);
        if (conn_sock == -1) {
          perror("accept");
          exit(EXIT_FAILURE);
        }
        printf("new client %s:%d connected\n", inet_ntoa(client.sin_addr),
               client.sin_port);
        setnonblocking(conn_sock);
        ev.events = EPOLLIN | EPOLLET;
        ev.data.fd = conn_sock;
        if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock, &ev) == -1) {
          perror("epoll_ctl: conn_sock");
          exit(EXIT_FAILURE);
        }
      } else {
        do_use_fd(events[n].data.fd);
      }
    }
  }
  close(listen_sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xc,-0x84(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
mov    %eax,-0x88(%rbp)
cmpl   $0xffffffff,-0x88(%rbp)
jne    127c <main+0x6c>
lea    0xd9a(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    153b <main+0x32b>
lea    -0x70(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x2d4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    $0x462,%edi
call   1040 <htons@plt>
mov    %eax,-0x70(%rbp)
lea    0xd5d(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x6c(%rbp)
mov    -0x88(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ec <main+0xdc>
lea    0xd3f(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2cd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    153b <main+0x32b>
mov    -0x88(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1322 <main+0x112>
lea    0xd0e(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    153b <main+0x32b>
xor    %edi,%edi
call   1120 <epoll_create1@plt>
mov    %eax,-0x94(%rbp)
cmpl   $0xffffffff,-0x94(%rbp)
jne    1356 <main+0x146>
lea    0xcde(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    0x2c7b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x88(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x94(%rbp),%edi
mov    0x2c58(%rip),%rax
mov    (%rax),%esi
mov    -0x88(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    13ac <main+0x19c>
lea    0xc96(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2c0b(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    13b1 <main+0x1a1>
mov    -0x94(%rbp),%edi
lea    -0x60(%rbp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
mov    %eax,-0x90(%rbp)
cmpl   $0xffffffff,-0x90(%rbp)
jne    13ee <main+0x1de>
lea    0xc62(%rip),%rdi
call   10e0 <perror@plt>
jmp    1529 <main+0x319>
movl   $0x0,-0x98(%rbp)
mov    -0x98(%rbp),%eax
cmp    -0x90(%rbp),%eax
jge    1524 <main+0x314>
movslq -0x98(%rbp),%rax
mov    -0x5c(%rbp,%rax,8),%eax
cmp    -0x88(%rbp),%eax
jne    14fb <main+0x2eb>
lea    -0x80(%rbp),%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    -0x88(%rbp),%edi
lea    -0x80(%rbp),%rsi
lea    -0x84(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x8c(%rbp)
cmpl   $0xffffffff,-0x8c(%rbp)
jne    1472 <main+0x262>
lea    0xbf2(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b45(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x7c(%rbp),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rsi
mov    -0x80(%rbp),%edx
lea    0xbd1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x8c(%rbp),%edi
call   10d0 <setnonblocking@plt>
mov    0x2b3a(%rip),%rax
mov    (%rax),%eax
mov    0x2b01(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x94(%rbp),%edi
mov    0x2b0e(%rip),%rax
mov    (%rax),%esi
mov    -0x8c(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    14f6 <main+0x2e6>
lea    0xb91(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2ac1(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
jmp    150b <main+0x2fb>
movslq -0x98(%rbp),%rax
mov    -0x5c(%rbp,%rax,8),%edi
call   1090 <do_use_fd@plt>
jmp    1510 <main+0x300>
mov    -0x98(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x98(%rbp)
jmp    13f8 <main+0x1e8>
jmp    13b1 <main+0x1a1>
mov    -0x88(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
movl   $0xc,0xc(%rsp)
mov    0x2db0(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%esi
mov    0x2da5(%rip),%rax
mov    (%rax),%edx
call   1130 <socket@plt>
cmp    $0xffffffff,%eax
jne    1258 <main+0x48>
lea    0xdaa(%rip),%rdi
jmp    12c6 <main+0xb6>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    $0x462,%edi
call   1040 <htons@plt>
mov    %eax,0x10(%rsp)
lea    0xd7f(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x14(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0xffffffff,%eax
jne    12ae <main+0x9e>
lea    0xd69(%rip),%rdi
jmp    12c6 <main+0xb6>
mov    %ebx,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12e6 <main+0xd6>
lea    0xd54(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2ce6(%rip),%rax
mov    (%rax),%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   1120 <epoll_create1@plt>
cmp    $0xffffffff,%eax
je     145c <main+0x24c>
mov    %eax,%r14d
mov    0x2cd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %ebx,0x4(%rsp)
mov    0x2cc0(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
mov    %r14d,%edi
mov    %ebx,%edx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     1465 <main+0x255>
lea    0x30(%rsp),%rsi
mov    %r14d,%edi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
cmp    $0xffffffff,%eax
jne    135e <main+0x14e>
lea    0xcfb(%rip),%rdi
call   10e0 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
jmp    12d4 <main+0xc4>
lea    0x20(%rsp),%rbp
jmp    138c <main+0x17c>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14d,%edi
lea    0x30(%rsp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
cmp    $0xffffffff,%eax
je     1344 <main+0x134>
test   %eax,%eax
jle    1370 <main+0x160>
mov    %eax,%r12d
xor    %r13d,%r13d
jmp    13ae <main+0x19e>
nopl   0x0(%rax,%rax,1)
call   1090 <do_use_fd@plt>
add    $0x1,%r13
cmp    %r13,%r12
je     1370 <main+0x160>
mov    0x34(%rsp,%r13,8),%edi
cmp    %ebx,%edi
jne    13a0 <main+0x190>
mov    %rbp,%rdi
mov    $0xc,%esi
call   10f0 <bzero@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     1442 <main+0x232>
mov    %eax,%r15d
mov    0x24(%rsp),%edi
call   1030 <inet_ntoa@plt>
mov    0x20(%rsp),%edx
lea    0xc69(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r15d,%edi
call   10d0 <setnonblocking@plt>
mov    0x2ba2(%rip),%rax
mov    (%rax),%eax
mov    0x2bc9(%rip),%rcx
or     (%rcx),%eax
mov    %eax,(%rsp)
mov    %r15d,0x4(%rsp)
mov    0x2bb0(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
mov    %r15d,%edx
mov    %rsp,%rcx
call   1070 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    13a5 <main+0x195>
lea    0xc34(%rip),%rdi
jmp    1449 <main+0x239>
lea    0xc08(%rip),%rdi
call   10e0 <perror@plt>
mov    0x2b5b(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
lea    0xbbe(%rip),%rdi
jmp    1449 <main+0x239>
lea    0xbc3(%rip),%rdi
jmp    1449 <main+0x239>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@PF_UNSPEC = global i32 0
@.str = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.1 = [14 x i8] c"192.168.0.111\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [14 x i8] c"epoll_create1\00"
@EXIT_FAILURE = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [23 x i8] c"epoll_ctl: listen_sock\00"
@.str.6 = [11 x i8] c"epoll_wait\00"
@.str.7 = [7 x i8] c"accept\00"
@.str.8 = [28 x i8] c"new client %s:%d connected\0A\00"
@EPOLLET = global i32 0
@.str.9 = [21 x i8] c"epoll_ctl: conn_sock\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.epoll_event
%3 = alloca [10 x %struct.epoll_event]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %1
store i32 12, i32* %6
%12 = load i32, i32* @AF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = load i32, i32* @PF_UNSPEC
%15 = call i32 @socket(i32 %12, i32 %13, i32 %14)
store i32 %15, i32* %7
%16 = load i32, i32* %7
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %0
%19 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @errno
store i32 %20, i32* %1
br label %144
21: ; preds = %0
%22 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %23, i32* %24
%25 = call i32 @htons(i32 1122)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %25, i32* %26
%27 = call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%29 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %7
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %37
34: ; preds = %21
%35 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @errno
store i32 %36, i32* %1
br label %144
37: ; preds = %21
%38 = load i32, i32* %7
%39 = call i32 @listen(i32 %38, i32 10)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32, i32* @errno
store i32 %43, i32* %1
br label %144
44: ; preds = %37
%45 = call i32 @epoll_create1(i32 0)
store i32 %45, i32* %10
%46 = load i32, i32* %10
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %44
%53 = load i32, i32* @EPOLLIN
%54 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* %7
%56 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 1
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %56, i32 0, i32 0
store i32 %55, i32* %57
%58 = load i32, i32* %10
%59 = load i32, i32* @EPOLL_CTL_ADD
%60 = load i32, i32* %7
%61 = call i32 @epoll_ctl(i32 %58, i32 %59, i32 %60, %struct.epoll_event* %2)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %67
63: ; preds = %52
%64 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %52
br label %68
68: ; preds = %140, %67
%69 = load i32, i32* %10
%70 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %3, i64 0, i64 0
%71 = call i32 @epoll_wait(i32 %69, %struct.epoll_event* %70, i32 10, i32 -1)
store i32 %71, i32* %9
%72 = load i32, i32* %9
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %76
74: ; preds = %68
%75 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
br label %141
76: ; preds = %68
store i32 0, i32* %11
br label %77
77: ; preds = %137, %76
%78 = load i32, i32* %11
%79 = load i32, i32* %9
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %140
81: ; preds = %77
%82 = load i32, i32* %11
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %3, i64 0, i64 %83
%85 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %84, i32 0, i32 1
%86 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %85, i32 0, i32 0
%87 = load i32, i32* %86
%88 = load i32, i32* %7
%89 = icmp eq i32 %87, %88
br i1 %89, label %90, label %128
90: ; preds = %81
%91 = call i32 @bzero(%struct.sockaddr_in* %5, i32 12)
%92 = load i32, i32* %7
%93 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%94 = call i32 @accept(i32 %92, %struct.sockaddr* %93, i32* %6)
store i32 %94, i32* %8
%95 = load i32, i32* %8
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %101
97: ; preds = %90
%98 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%99 = load i32, i32* @EXIT_FAILURE
%100 = call i32 @exit(i32 %99)
unreachable
101: ; preds = %90
%102 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
%103 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %102, i32 0, i32 0
%104 = load i32, i32* %103
%105 = call i8* @inet_ntoa(i32 %104)
%106 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%107 = load i32, i32* %106
%108 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %105, i32 %107)
%109 = load i32, i32* %8
%110 = call i32 @setnonblocking(i32 %109)
%111 = load i32, i32* @EPOLLIN
%112 = load i32, i32* @EPOLLET
%113 = or i32 %111, %112
%114 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 0
store i32 %113, i32* %114
%115 = load i32, i32* %8
%116 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i32 0, i32 1
%117 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %116, i32 0, i32 0
store i32 %115, i32* %117
%118 = load i32, i32* %10
%119 = load i32, i32* @EPOLL_CTL_ADD
%120 = load i32, i32* %8
%121 = call i32 @epoll_ctl(i32 %118, i32 %119, i32 %120, %struct.epoll_event* %2)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %127
123: ; preds = %101
%124 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %101
br label %136
128: ; preds = %81
%129 = load i32, i32* %11
%130 = sext i32 %129 to i64
%131 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %3, i64 0, i64 %130
%132 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %131, i32 0, i32 1
%133 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %132, i32 0, i32 0
%134 = load i32, i32* %133
%135 = call i32 @do_use_fd(i32 %134)
br label %136
136: ; preds = %128, %127
br label %137
137: ; preds = %136
%138 = load i32, i32* %11
%139 = add nsw i32 %138, 1
store i32 %139, i32* %11
br label %77
140: ; preds = %77
br label %68
141: ; preds = %74
%142 = load i32, i32* %7
%143 = call i32 @close(i32 %142)
store i32 0, i32* %1
br label %144
144: ; preds = %141, %41, %34, %18
%145 = load i32, i32* %1
ret i32 %145
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_3__ }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_4__, i32 }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@PF_UNSPEC = global i32 0
@.str = [7 x i8] c"socket\00"
@errno = global i32 0
@.str.1 = [14 x i8] c"192.168.0.111\00"
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [7 x i8] c"listen\00"
@.str.4 = [14 x i8] c"epoll_create1\00"
@EXIT_FAILURE = global i32 0
@EPOLLIN = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [23 x i8] c"epoll_ctl: listen_sock\00"
@.str.6 = [11 x i8] c"epoll_wait\00"
@.str.7 = [7 x i8] c"accept\00"
@.str.8 = [28 x i8] c"new client %s:%d connected\0A\00"
@EPOLLET = global i32 0
@.str.9 = [21 x i8] c"epoll_ctl: conn_sock\00"
define i32 @main() {
%1 = alloca %struct.epoll_event
%2 = alloca [10 x %struct.epoll_event]
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = bitcast %struct.epoll_event* %1 to i8*
%7 = bitcast [10 x %struct.epoll_event]* %2 to i8*
%8 = bitcast %struct.sockaddr_in* %3 to i8*
%9 = bitcast %struct.sockaddr_in* %4 to i8*
%10 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = load i32, i32* @PF_UNSPEC
%14 = tail call i32 @socket(i32 %11, i32 %12, i32 %13)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %19
16: ; preds = %0
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @errno
br label %110
19: ; preds = %0
%20 = call i32 @bzero(%struct.sockaddr_in* %3, 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 = tail call i32 @htons(i32 1122)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %23, i32* %24
%25 = tail call i32 @inet_addr(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @bind(i32 %14, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %19
%31 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @errno
br label %110
33: ; preds = %19
%34 = call i32 @listen(i32 %14, i32 10)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @errno
br label %110
39: ; preds = %33
%40 = call i32 @epoll_create1(i32 0)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %39
%43 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %39
%47 = load i32, i32* @EPOLLIN
%48 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1, i32 0
store i32 %14, i32* %49
%50 = load i32, i32* @EPOLL_CTL_ADD
%51 = call i32 @epoll_ctl(i32 %40, i32 %50, i32 %14, %struct.epoll_event* %1)
%52 = icmp eq i32 %51, -1
br i1 %52, label %61, label %53
53: ; preds = %46
%54 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 0
%55 = call i32 @epoll_wait(i32 %40, %struct.epoll_event* %54, i32 10, i32 -1)
%56 = icmp eq i32 %55, -1
br i1 %56, label %73, label %57
57: ; preds = %53
%58 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
br label %68
61: ; preds = %46
%62 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
%63 = load i32, i32* @EXIT_FAILURE
%64 = call i32 @exit(i32 %63)
unreachable
65: ; preds = %107, %68
%66 = call i32 @epoll_wait(i32 %40, %struct.epoll_event* %54, i32 10, i32 -1)
%67 = icmp eq i32 %66, -1
br i1 %67, label %73, label %68
68: ; preds = %57, %65
%69 = phi i32 [ %55, %57 ], [ %66, %65 ]
%70 = icmp sgt i32 %69, 0
br i1 %70, label %71, label %65
71: ; preds = %68
%72 = zext i32 %69 to i64
br label %76
73: ; preds = %65, %53
%74 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @close(i32 %14)
br label %110
76: ; preds = %71, %107
%77 = phi i64 [ 0, %71 ], [ %108, %107 ]
%78 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 %77, i32 1, i32 0
%79 = load i32, i32* %78
%80 = icmp eq i32 %79, %14
br i1 %80, label %81, label %105
81: ; preds = %76
%82 = call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%83 = call i32 @accept(i32 %14, %struct.sockaddr* %58, i32* %5)
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %89
85: ; preds = %81
%86 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0))
%87 = load i32, i32* @EXIT_FAILURE
%88 = call i32 @exit(i32 %87)
unreachable
89: ; preds = %81
%90 = load i32, i32* %59
%91 = call i8* @inet_ntoa(i32 %90)
%92 = load i32, i32* %60
%93 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.8, i64 0, i64 0), i8* %91, i32 %92)
%94 = call i32 @setnonblocking(i32 %83)
%95 = load i32, i32* @EPOLLIN
%96 = load i32, i32* @EPOLLET
%97 = or i32 %96, %95
store i32 %97, i32* %48
store i32 %83, i32* %49
%98 = load i32, i32* @EPOLL_CTL_ADD
%99 = call i32 @epoll_ctl(i32 %40, i32 %98, i32 %83, %struct.epoll_event* %1)
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %107
101: ; preds = %89
%102 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0))
%103 = load i32, i32* @EXIT_FAILURE
%104 = call i32 @exit(i32 %103)
unreachable
105: ; preds = %76
%106 = call i32 @do_use_fd(i32 %79)
br label %107
107: ; preds = %105, %89
%108 = add nuw nsw i64 %77, 1
%109 = icmp eq i64 %108, %72
br i1 %109, label %65, label %76
110: ; preds = %73, %36, %30, %16
%111 = phi i32 [ %18, %16 ], [ %32, %30 ], [ %38, %36 ], [ 0, %73 ]
ret i32 %111
}