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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EPOLLHUP;
int EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ accept_new_client(int, int);
int /*<<< orphan*/ assert(int);
scalar_t__ bind(int, struct sockaddr const *, int);
int epoll_create(int);
scalar_t__ 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*/ handle_client_req(int, int);
int /*<<< orphan*/ htons(int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ remove_client(int, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  static struct epoll_event eventsbuff[1024];
  printf("*** Initializing server\n");
  int mainsock;
  if ((mainsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) {
    perror("socket(2) failed");
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in serveraddr;
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_port = htons(3000);
  serveraddr.sin_addr.s_addr = INADDR_ANY;
  if (bind(mainsock, (const struct sockaddr *)&serveraddr, sizeof(serveraddr)) <
      0) {
    perror("bind(2) failed");
    exit(EXIT_FAILURE);
  }
  if (listen(mainsock, 10) < 0) {
    perror("listen(2) failed");
    exit(EXIT_FAILURE);
  }
  int epoll_fd;
  if ((epoll_fd = epoll_create(10)) < 0) {
    perror("epoll_create(2) failed");
    exit(EXIT_FAILURE);
  }
  struct epoll_event epevent;
  epevent.events = EPOLLIN | EPOLLHUP;
  epevent.data.fd = mainsock;
  if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mainsock, &epevent) < 0) {
    perror("epoll_ctl(2) failed");
    exit(EXIT_FAILURE);
  }
  printf("*** Server initialized; entering main loop\n");
  while (1) {
    int n;
    if ((n = epoll_wait(epoll_fd, eventsbuff, sizeof(eventsbuff), -1)) < 0) {
      perror("epoll_wait(2) error");
      exit(EXIT_FAILURE);
    }
    int i;
    for (i = 0; i < n; i++) {
      if (eventsbuff[i].data.fd == mainsock) {
        accept_new_client(epoll_fd, mainsock);
      } else if (eventsbuff[i].events & EPOLLHUP) {
        remove_client(epoll_fd, eventsbuff[i].data.fd, 1);
      } else {
        assert(eventsbuff[i].events & EPOLLIN);
        handle_client_req(epoll_fd, eventsbuff[i].data.fd);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe0a(%rip),%rdi
call   1050 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    1241 <main+0x61>
lea    0xdeb(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0xbb8,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    129b <main+0xbb>
lea    0xda2(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    12cc <main+0xec>
lea    0xd80(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0xa,%edi
call   10e0 <epoll_create@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12fc <main+0x11c>
lea    0xd61(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%eax
mov    0x2c9c(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2cb7(%rip),%rax
mov    (%rax),%esi
mov    -0x8(%rbp),%edx
lea    -0x28(%rbp),%rcx
call   1060 <epoll_ctl@plt>
cmp    $0x0,%rax
jge    1353 <main+0x173>
lea    0xd21(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
lea    0xd1b(%rip),%rdi
call   1050 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    0x2d37(%rip),%rsi
mov    $0x2000,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
jge    139e <main+0x1be>
lea    0xd16(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c19(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x2c(%rbp),%eax
jge    1465 <main+0x285>
movslq -0x30(%rbp),%rcx
lea    0x2ce4(%rip),%rax
mov    0x4(%rax,%rcx,8),%eax
cmp    -0x8(%rbp),%eax
jne    13d9 <main+0x1f9>
mov    -0x1c(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1090 <accept_new_client@plt>
jmp    1452 <main+0x272>
movslq -0x30(%rbp),%rcx
lea    0x2cbc(%rip),%rax
mov    (%rax,%rcx,8),%eax
mov    0x2bba(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     141a <main+0x23a>
mov    -0x1c(%rbp),%edi
movslq -0x30(%rbp),%rcx
lea    0x2c99(%rip),%rax
mov    0x4(%rax,%rcx,8),%esi
mov    $0x1,%edx
call   1080 <remove_client@plt>
jmp    144d <main+0x26d>
movslq -0x30(%rbp),%rcx
lea    0x2c7b(%rip),%rax
mov    (%rax,%rcx,8),%edi
mov    0x2bb1(%rip),%rax
and    (%rax),%edi
call   1070 <assert@plt>
mov    -0x1c(%rbp),%edi
movslq -0x30(%rbp),%rcx
lea    0x2c5c(%rip),%rax
mov    0x4(%rax,%rcx,8),%esi
call   1030 <handle_client_req@plt>
jmp    1452 <main+0x272>
jmp    1457 <main+0x277>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13a5 <main+0x1c5>
jmp    135f <main+0x17f>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
mov    0x2de7(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2dad(%rip),%rax
mov    (%rax),%esi
mov    0x2db4(%rip),%rax
mov    (%rax),%edx
call   1100 <socket@plt>
test   %eax,%eax
jns    122b <main+0x4b>
lea    0xdda(%rip),%rdi
jmp    131f <main+0x13f>
mov    %eax,%r14d
mov    0x0(%rbp),%eax
mov    %eax,0x20(%rsp)
mov    $0xbb8,%edi
call   1050 <htons@plt>
mov    %eax,0x1c(%rsp)
mov    0x2d86(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
lea    0x18(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    1273 <main+0x93>
lea    0xda3(%rip),%rdi
jmp    131f <main+0x13f>
mov    %r14d,%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
test   %rax,%rax
jns    1291 <main+0xb1>
lea    0xd94(%rip),%rdi
jmp    131f <main+0x13f>
mov    $0xa,%edi
call   10e0 <epoll_create@plt>
test   %eax,%eax
jns    12a8 <main+0xc8>
lea    0xd8b(%rip),%rdi
jmp    131f <main+0x13f>
mov    %eax,%ebx
mov    0x2d2f(%rip),%rcx
mov    0x2cf0(%rip),%r12
mov    (%r12),%eax
or     (%rcx),%eax
mov    %eax,0x10(%rsp)
mov    %r14d,0x14(%rsp)
mov    0x2d0a(%rip),%rax
mov    (%rax),%esi
lea    0x10(%rsp),%rcx
mov    %ebx,%edi
mov    %r14d,%edx
call   1060 <epoll_ctl@plt>
test   %rax,%rax
jns    12ed <main+0x10d>
lea    0xd5d(%rip),%rdi
jmp    131f <main+0x13f>
lea    0xd94(%rip),%rdi
call   1040 <puts@plt>
lea    0x2da0(%rip),%rbp
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
test   %eax,%eax
jns    1332 <main+0x152>
lea    0xd3d(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c85(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    %ebx,0xc(%rsp)
jmp    1358 <main+0x178>
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x2000,%edx
mov    $0xffffffff,%ecx
call   10b0 <epoll_wait@plt>
test   %eax,%eax
js     1318 <main+0x138>
test   %eax,%eax
je     1340 <main+0x160>
mov    %eax,%r13d
xor    %r15d,%r15d
jmp    1383 <main+0x1a3>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %r14d,%esi
call   1090 <accept_new_client@plt>
add    $0x1,%r15
cmp    %r15,%r13
je     1340 <main+0x160>
mov    0x4(%rbp,%r15,8),%esi
cmp    %r14d,%esi
je     1370 <main+0x190>
mov    0x0(%rbp,%r15,8),%edi
test   %edi,(%r12)
je     13a6 <main+0x1c6>
mov    %ebx,%edi
mov    $0x1,%edx
call   1080 <remove_client@plt>
jmp    137a <main+0x19a>
mov    %r12,%rbx
lea    (%r15,%r15,1),%r12
mov    0x2c2c(%rip),%rax
and    (%rax),%edi
call   1070 <assert@plt>
mov    0x4(%rbp,%r12,4),%esi
mov    %rbx,%r12
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   1030 <handle_client_req@plt>
jmp    137a <main+0x19a>

LLVM IR (-O0):
%struct.epoll_event = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__, i32, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.eventsbuff = internal global [1024 x %struct.epoll_event] zeroinitializer
@.str = [25 x i8] c"*** Initializing server\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [17 x i8] c"socket(2) failed\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [15 x i8] c"bind(2) failed\00"
@.str.3 = [17 x i8] c"listen(2) failed\00"
@.str.4 = [23 x i8] c"epoll_create(2) failed\00"
@EPOLLIN = global i32 0
@EPOLLHUP = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [20 x i8] c"epoll_ctl(2) failed\00"
@.str.6 = [44 x i8] c"*** Server initialized; entering main loop\0A\00"
@.str.7 = [20 x i8] c"epoll_wait(2) error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca %struct.epoll_event
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = load i32, i32* @IPPROTO_TCP
%12 = call i32 @socket(i32 %9, i32 %10, i32 %11)
store i32 %12, i32* %2
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %0
%15 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 3000)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %2
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i64 @bind(i32 %26, %struct.sockaddr* %27, i32 12)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %18
%31 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %18
%35 = load i32, i32* %2
%36 = call i64 @listen(i32 %35, i32 10)
%37 = icmp slt i64 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %34
%43 = call i32 @epoll_create(i32 10)
store i32 %43, i32* %4
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %49
45: ; preds = %42
%46 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @EXIT_FAILURE
%48 = call i32 @exit(i32 %47)
unreachable
49: ; preds = %42
%50 = load i32, i32* @EPOLLIN
%51 = load i32, i32* @EPOLLHUP
%52 = or i32 %50, %51
%53 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i32 0, i32 0
store i32 %52, i32* %53
%54 = load i32, i32* %2
%55 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %5, i32 0, i32 1
%56 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %55, i32 0, i32 0
store i32 %54, i32* %56
%57 = load i32, i32* %4
%58 = load i32, i32* @EPOLL_CTL_ADD
%59 = load i32, i32* %2
%60 = call i64 @epoll_ctl(i32 %57, i32 %58, i32 %59, %struct.epoll_event* %5)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %49
%63 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%64 = load i32, i32* @EXIT_FAILURE
%65 = call i32 @exit(i32 %64)
unreachable
66: ; preds = %49
%67 = call i32 @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.6, i64 0, i64 0))
br label %68
68: ; preds = %66, %134
%69 = load i32, i32* %4
%70 = call i32 @epoll_wait(i32 %69, %struct.epoll_event* getelementptr inbounds ([1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 0), i32 8192, i32 -1)
store i32 %70, i32* %6
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %68
store i32 0, i32* %7
br label %77
77: ; preds = %131, %76
%78 = load i32, i32* %7
%79 = load i32, i32* %6
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %134
81: ; preds = %77
%82 = load i32, i32* %7
%83 = sext i32 %82 to i64
%84 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %83
%85 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %84, i32 0, i32 1
%86 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %85, i32 0, i32 0
%87 = load i32, i32* %86
%88 = load i32, i32* %2
%89 = icmp eq i32 %87, %88
br i1 %89, label %90, label %94
90: ; preds = %81
%91 = load i32, i32* %4
%92 = load i32, i32* %2
%93 = call i32 @accept_new_client(i32 %91, i32 %92)
br label %130
94: ; preds = %81
%95 = load i32, i32* %7
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %96
%98 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %97, i32 0, i32 0
%99 = load i32, i32* %98
%100 = load i32, i32* @EPOLLHUP
%101 = and i32 %99, %100
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %112
103: ; preds = %94
%104 = load i32, i32* %4
%105 = load i32, i32* %7
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %106
%108 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %107, i32 0, i32 1
%109 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %108, i32 0, i32 0
%110 = load i32, i32* %109
%111 = call i32 @remove_client(i32 %104, i32 %110, i32 1)
br label %129
112: ; preds = %94
%113 = load i32, i32* %7
%114 = sext i32 %113 to i64
%115 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %114
%116 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %115, i32 0, i32 0
%117 = load i32, i32* %116
%118 = load i32, i32* @EPOLLIN
%119 = and i32 %117, %118
%120 = call i32 @assert(i32 %119)
%121 = load i32, i32* %4
%122 = load i32, i32* %7
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %123
%125 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %124, i32 0, i32 1
%126 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %125, i32 0, i32 0
%127 = load i32, i32* %126
%128 = call i32 @handle_client_req(i32 %121, i32 %127)
br label %129
129: ; preds = %112, %103
br label %130
130: ; preds = %129, %90
br label %131
131: ; preds = %130
%132 = load i32, i32* %7
%133 = add nsw i32 %132, 1
store i32 %133, i32* %7
br label %77
134: ; preds = %77
br label %68
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, %struct.TYPE_4__ }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { %struct.TYPE_3__, i32, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@main.eventsbuff = internal global [1024 x %struct.epoll_event] zeroinitializer
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@.str.1 = [17 x i8] c"socket(2) failed\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [15 x i8] c"bind(2) failed\00"
@.str.3 = [17 x i8] c"listen(2) failed\00"
@.str.4 = [23 x i8] c"epoll_create(2) failed\00"
@EPOLLIN = global i32 0
@EPOLLHUP = global i32 0
@EPOLL_CTL_ADD = global i32 0
@.str.5 = [20 x i8] c"epoll_ctl(2) failed\00"
@.str.7 = [20 x i8] c"epoll_wait(2) error\00"
@str = [24 x i8] c"*** Initializing server\00"
@str.8 = [43 x i8] c"*** Server initialized; entering main loop\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca %struct.epoll_event
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = load i32, i32* @IPPROTO_TCP
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %0
%10 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = bitcast %struct.sockaddr_in* %1 to i8*
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @htons(i32 3000)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
store i32 %17, i32* %18
%19 = load i32, i32* @INADDR_ANY
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%22 = call i64 @bind(i32 %7, %struct.sockaddr* %21, i32 12)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %13
%25 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %13
%29 = call i64 @listen(i32 %7, i32 10)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %28
%36 = call i32 @epoll_create(i32 10)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %35
%39 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %35
%43 = bitcast %struct.epoll_event* %2 to i8*
%44 = load i32, i32* @EPOLLIN
%45 = load i32, i32* @EPOLLHUP
%46 = or i32 %45, %44
%47 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 0
store i32 %46, i32* %47
%48 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %2, i64 0, i32 1, i32 0
store i32 %7, i32* %48
%49 = load i32, i32* @EPOLL_CTL_ADD
%50 = call i64 @epoll_ctl(i32 %36, i32 %49, i32 %7, %struct.epoll_event* %2)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %56
52: ; preds = %42
%53 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %42
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.8, i64 0, i64 0))
%58 = call i32 @epoll_wait(i32 %36, %struct.epoll_event* getelementptr inbounds ([1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 0), i32 8192, i32 -1)
%59 = icmp slt i32 %58, 0
br i1 %59, label %68, label %63
60: ; preds = %93, %63
%61 = call i32 @epoll_wait(i32 %36, %struct.epoll_event* getelementptr inbounds ([1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 0), i32 8192, i32 -1)
%62 = icmp slt i32 %61, 0
br i1 %62, label %68, label %63
63: ; preds = %56, %60
%64 = phi i32 [ %61, %60 ], [ %58, %56 ]
%65 = icmp eq i32 %64, 0
br i1 %65, label %60, label %66
66: ; preds = %63
%67 = zext i32 %64 to i64
br label %72
68: ; preds = %60, %56
%69 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%70 = load i32, i32* @EXIT_FAILURE
%71 = call i32 @exit(i32 %70)
unreachable
72: ; preds = %66, %93
%73 = phi i64 [ 0, %66 ], [ %94, %93 ]
%74 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %73, i32 1, i32 0
%75 = load i32, i32* %74
%76 = icmp eq i32 %75, %7
br i1 %76, label %77, label %79
77: ; preds = %72
%78 = call i32 @accept_new_client(i32 %36, i32 %7)
br label %93
79: ; preds = %72
%80 = getelementptr inbounds [1024 x %struct.epoll_event], [1024 x %struct.epoll_event]* @main.eventsbuff, i64 0, i64 %73, i32 0
%81 = load i32, i32* %80
%82 = load i32, i32* @EPOLLHUP
%83 = and i32 %82, %81
%84 = icmp eq i32 %83, 0
br i1 %84, label %87, label %85
85: ; preds = %79
%86 = call i32 @remove_client(i32 %36, i32 %75, i32 1)
br label %93
87: ; preds = %79
%88 = load i32, i32* @EPOLLIN
%89 = and i32 %88, %81
%90 = call i32 @assert(i32 %89)
%91 = load i32, i32* %74
%92 = call i32 @handle_client_req(i32 %36, i32 %91)
br label %93
93: ; preds = %77, %87, %85
%94 = add nuw nsw i64 %73, 1
%95 = icmp eq i64 %94, %67
br i1 %95, label %60, label %72
}