#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_4__ TYPE_2__;
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct TYPE_4__ {
  int fd;
};
struct epoll_event {
  TYPE_2__ data;
  void *events;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ n;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
void *EPOLLIN;
int /*<<< orphan*/ EPOLL_CTL_ADD;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int epoll_create(int);
int epoll_ctl(int, int /*<<< orphan*/, int, struct epoll_event *);
int epoll_wait(int, struct epoll_event *, int, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recvfrom(int, char *, int, int /*<<< orphan*/,
                            int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void run_server(void) {
  struct epoll_event ev, events[10];
  int listen_sock, conn_sock, nfds, epollfd;
  int n;
  socklen_t addrlen;
  struct sockaddr_in addr;
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = INADDR_ANY;
  addr.sin_port = htons(1234);
  listen_sock = socket(AF_INET, SOCK_STREAM, 0);
  n = 1;
  setsockopt(listen_sock, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n));
  if (bind(listen_sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
    perror("bind");
    exit(1);
  }
  listen(listen_sock, 10);
  epollfd = epoll_create(10);
  if (epollfd == -1) {
    perror("epoll_create");
    exit(1);
  }
  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(1);
  }
  printf("Registered fd %d as listen_sock\n", listen_sock);
  while (1) {
    nfds = epoll_wait(epollfd, events, 10, -1);
    if (nfds == -1) {
      perror("epoll_wait");
      exit(1);
    }
    for (n = 0; n < nfds; n++) {
      int fd = events[n].data.fd;
      printf("Got fd %d\n", fd);
      if (fd == listen_sock) {
        addrlen = sizeof(struct sockaddr_in);
        conn_sock = accept(listen_sock, (struct sockaddr *)&addr, &addrlen);
        if (conn_sock == -1) {
          perror("accept");
          exit(1);
        }
        ev.events = EPOLLIN;
        ev.data.fd = conn_sock;
        if (epoll_ctl(epollfd, EPOLL_CTL_ADD, conn_sock, &ev) == -1) {
          perror("epoll_ctl: conn_sock");
          exit(1);
        }
        printf("Registered fd %d as conn_sock\n", conn_sock);
      } else {
        char *resp = "HTTP/1.1 200 OK\r\nServer: test\r\nConnection: "
                     "close\r\n\r\nHoi!\r\n\r\n";
        char buf[128];
        recvfrom(fd, buf, 128, 0, NULL, NULL);
        buf[127] = '\0';
        printf("R: %s\n", buf);
        write(fd, resp, strlen(resp));
        close(fd);
      }
    }
  }
}


x86 assembly (clang, -O0):
<run_server>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
lea    -0xd8(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd0(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,-0xd8(%rbp)
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0xb4(%rbp)
movl   $0x1,-0xc4(%rbp)
mov    -0xb4(%rbp),%edi
mov    0x2d56(%rip),%rax
mov    (%rax),%esi
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
lea    -0xc4(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0xb4(%rbp),%edi
lea    -0xd8(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jge    12e6 <run_server+0xd6>
lea    0xd29(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0xb4(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    $0xa,%edi
call   1110 <epoll_create@plt>
mov    %eax,-0xc0(%rbp)
cmpl   $0xffffffff,-0xc0(%rbp)
jne    1329 <run_server+0x119>
lea    0xceb(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0xb4(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc0(%rbp),%edi
mov    0x2c83(%rip),%rax
mov    (%rax),%esi
mov    -0xb4(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    137d <run_server+0x16d>
lea    0xca4(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0xb4(%rbp),%esi
lea    0xca0(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xc0(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
mov    %eax,-0xbc(%rbp)
cmpl   $0xffffffff,-0xbc(%rbp)
jne    13d6 <run_server+0x1c6>
lea    0xc84(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movl   $0x0,-0xc4(%rbp)
mov    -0xc4(%rbp),%eax
cmp    -0xbc(%rbp),%eax
jge    1597 <run_server+0x387>
movslq -0xc4(%rbp),%rcx
lea    -0xb0(%rbp),%rax
shl    $0x4,%rcx
add    %rcx,%rax
mov    (%rax),%eax
mov    %eax,-0xdc(%rbp)
mov    -0xdc(%rbp),%esi
lea    0xc3a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xdc(%rbp),%eax
cmp    -0xb4(%rbp),%eax
jne    14ee <run_server+0x2de>
movl   $0xc,-0xc8(%rbp)
mov    -0xb4(%rbp),%edi
lea    -0xd8(%rbp),%rsi
lea    -0xc8(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0xb8(%rbp)
cmpl   $0xffffffff,-0xb8(%rbp)
jne    1481 <run_server+0x271>
lea    0xbef(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b50(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
mov    -0xb8(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0xc0(%rbp),%edi
mov    0x2b2b(%rip),%rax
mov    (%rax),%esi
mov    -0xb8(%rbp),%edx
lea    -0x10(%rbp),%rcx
call   10a0 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    14d5 <run_server+0x2c5>
lea    0xba2(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0xb8(%rbp),%esi
lea    0xb9b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    157e <run_server+0x36e>
lea    0xba7(%rip),%rax
mov    %rax,-0xe8(%rbp)
mov    -0xdc(%rbp),%edi
lea    -0x170(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %eax,%eax
mov    %eax,%r9d
mov    %r9,%r8
call   10c0 <recvfrom@plt>
movb   $0x0,-0xf1(%rbp)
lea    -0x170(%rbp),%rsi
lea    0xba7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0xdc(%rbp),%eax
mov    %eax,-0x17c(%rbp)
mov    -0xe8(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0xe8(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x17c(%rbp),%edi
mov    -0x178(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0xdc(%rbp),%edi
call   1090 <close@plt>
jmp    1583 <run_server+0x373>
mov    -0xc4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc4(%rbp)
jmp    13e0 <run_server+0x1d0>
jmp    1391 <run_server+0x181>

x86 assembly (clang, -O2):
<run_server>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1080 <memset@plt>
mov    0x2da4(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    $0x4d2,%edi
call   1060 <htons@plt>
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,%r13d
movl   $0x1,0x4(%rsp)
mov    0x2d67(%rip),%rax
mov    (%rax),%esi
mov    0x2d26(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %r13d,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   10e0 <bind@plt>
test   %rax,%rax
jns    12c0 <run_server+0xb0>
lea    0xd45(%rip),%rdi
jmp    14c8 <run_server+0x2b8>
mov    %r13d,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    $0xa,%edi
call   1110 <epoll_create@plt>
cmp    $0xffffffff,%eax
jne    12e8 <run_server+0xd8>
lea    0xd22(%rip),%rdi
jmp    14c8 <run_server+0x2b8>
mov    %eax,%ebx
mov    0x2ce7(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %r13d,0x20(%rsp)
mov    0x2ccb(%rip),%rax
mov    (%rax),%esi
lea    0x20(%rsp),%rcx
mov    %ebx,%edi
mov    %r13d,%edx
call   10a0 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
jne    1327 <run_server+0x117>
lea    0xcf0(%rip),%rdi
jmp    14c8 <run_server+0x2b8>
lea    0xcfc(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x30(%rsp),%rsi
mov    %ebx,0x8(%rsp)
mov    %ebx,%edi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
cmp    $0xffffffff,%eax
jne    1363 <run_server+0x153>
lea    0xced(%rip),%rdi
jmp    14c8 <run_server+0x2b8>
mov    %eax,%r15d
lea    0xce9(%rip),%rbx
lea    0xd28(%rip),%r12
jmp    13a0 <run_server+0x190>
cs nopw 0x0(%rax,%rax,1)
mov    0x8(%rsp),%edi
lea    0x30(%rsp),%rsi
mov    $0xa,%edx
mov    $0xffffffff,%ecx
call   10d0 <epoll_wait@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
je     1357 <run_server+0x147>
movl   $0x0,0x4(%rsp)
test   %r15d,%r15d
jle    1380 <run_server+0x170>
xor    %eax,%eax
jmp    142a <run_server+0x21a>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14d,%edi
lea    0xd0(%rsp),%rbp
mov    %rbp,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
xor    %r9d,%r9d
call   10c0 <recvfrom@plt>
movb   $0x0,0x14f(%rsp)
lea    0xcea(%rip),%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    0x4(%rsp),%eax
add    $0x1,%eax
mov    %eax,0x4(%rsp)
cmp    %r15d,%eax
jge    1380 <run_server+0x170>
cltq
shl    $0x4,%rax
mov    0x30(%rsp,%rax,1),%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
cmp    %r13d,%r14d
jne    13c0 <run_server+0x1b0>
mov    %rbx,%rbp
movl   $0xc,0xc(%rsp)
mov    %r13d,%edi
lea    0x10(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
cmp    $0xffffffff,%eax
je     14b8 <run_server+0x2a8>
mov    %eax,%ebx
mov    0x2b62(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x28(%rsp)
mov    %ebx,0x20(%rsp)
mov    0x2b47(%rip),%rax
mov    (%rax),%esi
mov    0x8(%rsp),%edi
mov    %ebx,%edx
lea    0x20(%rsp),%rcx
call   10a0 <epoll_ctl@plt>
cmp    $0xffffffff,%eax
je     14c1 <run_server+0x2b1>
lea    0xbd6(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbp,%rbx
jmp    1416 <run_server+0x206>
lea    0xba2(%rip),%rdi
jmp    14c8 <run_server+0x2b8>
lea    0xba0(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.epoll_event = type { %struct.TYPE_4__, i8* }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [5 x i8] c"bind\00"
@.str.1 = [13 x i8] c"epoll_create\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [24 x i8] c"epoll_ctl: listen_sock:\00"
@.str.3 = [33 x i8] c"Registered fd %d as listen_sock\0A\00"
@.str.4 = [11 x i8] c"epoll_wait\00"
@.str.5 = [11 x i8] c"Got fd %d\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [21 x i8] c"epoll_ctl: conn_sock\00"
@.str.8 = [31 x i8] c"Registered fd %d as conn_sock\0A\00"
@.str.9 = [61 x i8] c"HTTP/1.1 200 OK\0D\0AServer: test\0D\0AConnection: close\0D\0A\0D\0AHoi!\0D\0A\0D\0A\00"
@.str.10 = [7 x i8] c"R: %s\0A\00"
define void @run_server() {
%1 = alloca %struct.epoll_event
%2 = alloca [10 x %struct.epoll_event]
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.sockaddr_in
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [128 x i8]
%13 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%18 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = call i32 @htons(i32 1234)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %19, i32* %20
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_STREAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %3
store i32 1, i32* %7
%24 = load i32, i32* %3
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i32* %7, i32 4)
%28 = load i32, i32* %3
%29 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%30 = call i64 @bind(i32 %28, %struct.sockaddr* %29, i32 12)
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %0
%33 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %0
%36 = load i32, i32* %3
%37 = call i32 @listen(i32 %36, i32 10)
%38 = call i32 @epoll_create(i32 10)
store i32 %38, i32* %6
%39 = load i32, i32* %6
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %35
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %35
%45 = load i8*, i8** @EPOLLIN
%46 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i32 0, i32 1
store i8* %45, i8** %46
%47 = load i32, i32* %3
%48 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i32 0, i32 0
%49 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* %6
%51 = load i32, i32* @EPOLL_CTL_ADD
%52 = load i32, i32* %3
%53 = call i32 @epoll_ctl(i32 %50, i32 %51, i32 %52, %struct.epoll_event* %1)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %58
55: ; preds = %44
%56 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %44
%59 = load i32, i32* %3
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %58, %131
%62 = load i32, i32* %6
%63 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 0
%64 = call i32 @epoll_wait(i32 %62, %struct.epoll_event* %63, i32 10, i32 -1)
store i32 %64, i32* %5
%65 = load i32, i32* %5
%66 = icmp eq i32 %65, -1
br i1 %66, label %67, label %70
67: ; preds = %61
%68 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %61
store i32 0, i32* %7
br label %71
71: ; preds = %128, %70
%72 = load i32, i32* %7
%73 = load i32, i32* %5
%74 = icmp slt i32 %72, %73
br i1 %74, label %75, label %131
75: ; preds = %71
%76 = load i32, i32* %7
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 %77
%79 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %78, i32 0, i32 0
%80 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %79, i32 0, i32 0
%81 = load i32, i32* %80
store i32 %81, i32* %10
%82 = load i32, i32* %10
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %10
%85 = load i32, i32* %3
%86 = icmp eq i32 %84, %85
br i1 %86, label %87, label %113
87: ; preds = %75
store i32 12, i32* %8
%88 = load i32, i32* %3
%89 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%90 = call i32 @accept(i32 %88, %struct.sockaddr* %89, i32* %8)
store i32 %90, i32* %4
%91 = load i32, i32* %4
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %96
93: ; preds = %87
%94 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %87
%97 = load i8*, i8** @EPOLLIN
%98 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i32 0, i32 1
store i8* %97, i8** %98
%99 = load i32, i32* %4
%100 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i32 0, i32 0
%101 = getelementptr inbounds %struct.TYPE_4__, %struct.TYPE_4__* %100, i32 0, i32 0
store i32 %99, i32* %101
%102 = load i32, i32* %6
%103 = load i32, i32* @EPOLL_CTL_ADD
%104 = load i32, i32* %4
%105 = call i32 @epoll_ctl(i32 %102, i32 %103, i32 %104, %struct.epoll_event* %1)
%106 = icmp eq i32 %105, -1
br i1 %106, label %107, label %110
107: ; preds = %96
%108 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%109 = call i32 @exit(i32 1)
unreachable
110: ; preds = %96
%111 = load i32, i32* %4
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %111)
br label %127
113: ; preds = %75
store i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0), i8** %11
%114 = load i32, i32* %10
%115 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%116 = call i32 @recvfrom(i32 %114, i8* %115, i32 128, i32 0, i32* null, i32* null)
%117 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 127
store i8 0, i8* %117
%118 = getelementptr inbounds [128 x i8], [128 x i8]* %12, i64 0, i64 0
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* %118)
%120 = load i32, i32* %10
%121 = load i8*, i8** %11
%122 = load i8*, i8** %11
%123 = call i32 @strlen(i8* %122)
%124 = call i32 @write(i32 %120, i8* %121, i32 %123)
%125 = load i32, i32* %10
%126 = call i32 @close(i32 %125)
br label %127
127: ; preds = %113, %110
br label %128
128: ; preds = %127
%129 = load i32, i32* %7
%130 = add nsw i32 %129, 1
store i32 %130, i32* %7
br label %71
131: ; preds = %71
br label %61
}

LLVM IR (-O2):
%struct.epoll_event = type { %struct.TYPE_4__, i8* }
%struct.TYPE_4__ = type { i32 }
%struct.sockaddr_in = type { i32, %struct.TYPE_3__, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [5 x i8] c"bind\00"
@.str.1 = [13 x i8] c"epoll_create\00"
@EPOLLIN = global i8* null
@EPOLL_CTL_ADD = global i32 0
@.str.2 = [24 x i8] c"epoll_ctl: listen_sock:\00"
@.str.3 = [33 x i8] c"Registered fd %d as listen_sock\0A\00"
@.str.4 = [11 x i8] c"epoll_wait\00"
@.str.5 = [11 x i8] c"Got fd %d\0A\00"
@.str.6 = [7 x i8] c"accept\00"
@.str.7 = [21 x i8] c"epoll_ctl: conn_sock\00"
@.str.8 = [31 x i8] c"Registered fd %d as conn_sock\0A\00"
@.str.9 = [61 x i8] c"HTTP/1.1 200 OK\0D\0AServer: test\0D\0AConnection: close\0D\0A\0D\0AHoi!\0D\0A\0D\0A\00"
@.str.10 = [7 x i8] c"R: %s\0A\00"
define void @run_server() {
%1 = alloca %struct.epoll_event
%2 = alloca [10 x %struct.epoll_event]
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
%6 = alloca [128 x i8]
%7 = bitcast %struct.epoll_event* %1 to i8*
%8 = bitcast [10 x %struct.epoll_event]* %2 to i8*
%9 = bitcast i32* %3 to i8*
%10 = bitcast i32* %4 to i8*
%11 = bitcast %struct.sockaddr_in* %5 to i8*
%12 = call i32 @memset(%struct.sockaddr_in* %5, i32 0, i32 12)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %13, i32* %14
%15 = load i32, i32* @INADDR_ANY
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %15, i32* %16
%17 = call i32 @htons(i32 1234)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 %17, i32* %18
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 1, i32* %3
%22 = load i32, i32* @SOL_SOCKET
%23 = load i32, i32* @SO_REUSEADDR
%24 = call i32 @setsockopt(i32 %21, i32 %22, i32 %23, i32* %3, i32 4)
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i64 @bind(i32 %21, %struct.sockaddr* %25, i32 12)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %0
%29 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %0
%32 = call i32 @listen(i32 %21, i32 10)
%33 = call i32 @epoll_create(i32 10)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
%39 = load i8*, i8** @EPOLLIN
%40 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 1
store i8* %39, i8** %40
%41 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %1, i64 0, i32 0, i32 0
store i32 %21, i32* %41
%42 = load i32, i32* @EPOLL_CTL_ADD
%43 = call i32 @epoll_ctl(i32 %33, i32 %42, i32 %21, %struct.epoll_event* %1)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %38
%46 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %38
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%50 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 0
%51 = call i32 @epoll_wait(i32 %33, %struct.epoll_event* %50, i32 10, i32 -1)
%52 = icmp eq i32 %51, -1
br i1 %52, label %62, label %53
53: ; preds = %48
%54 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%55 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 127
br label %59
56: ; preds = %94, %59
%57 = call i32 @epoll_wait(i32 %33, %struct.epoll_event* %50, i32 10, i32 -1)
%58 = icmp eq i32 %57, -1
br i1 %58, label %62, label %59
59: ; preds = %53, %56
%60 = phi i32 [ %51, %53 ], [ %57, %56 ]
store i32 0, i32* %3
%61 = icmp sgt i32 %60, 0
br i1 %61, label %65, label %56
62: ; preds = %56, %48
%63 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %59, %94
%66 = phi i32 [ %96, %94 ], [ 0, %59 ]
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds [10 x %struct.epoll_event], [10 x %struct.epoll_event]* %2, i64 0, i64 %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i32 %69)
%71 = icmp eq i32 %69, %21
br i1 %71, label %72, label %88
72: ; preds = %65
store i32 12, i32* %4
%73 = call i32 @accept(i32 %21, %struct.sockaddr* %25, i32* %4)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %78
75: ; preds = %72
%76 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %72
%79 = load i8*, i8** @EPOLLIN
store i8* %79, i8** %40
store i32 %73, i32* %41
%80 = load i32, i32* @EPOLL_CTL_ADD
%81 = call i32 @epoll_ctl(i32 %33, i32 %80, i32 %73, %struct.epoll_event* %1)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.7, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %78
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0), i32 %73)
br label %94
88: ; preds = %65
%89 = call i32 @recvfrom(i32 %69, i8* %54, i32 128, i32 0, i32* null, i32* null)
store i8 0, i8* %55
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.10, i64 0, i64 0), i8* %54)
%91 = call i32 @strlen(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0))
%92 = call i32 @write(i32 %69, i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.9, i64 0, i64 0), i32 %91)
%93 = call i32 @close(i32 %69)
br label %94
94: ; preds = %88, %86
%95 = load i32, i32* %3
%96 = add nsw i32 %95, 1
store i32 %96, i32* %3
%97 = icmp slt i32 %96, %60
br i1 %97, label %65, label %56
}