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

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int fd;
};
struct timeval {
  int tv_sec;
  int events;
  TYPE_1__ data;
};
struct sockaddr {
  int dummy;
};
struct epoll_event {
  int tv_sec;
  int events;
  TYPE_1__ data;
};
typedef int ssize_t;
typedef int socklen_t;
typedef int /*<<< orphan*/ sbuf;
typedef int /*<<< orphan*/ last_recv;
typedef int /*<<< orphan*/ last_heartbeat;
typedef int /*<<< orphan*/ in_addr;
typedef int /*<<< orphan*/ hbuf;
typedef int /*<<< orphan*/ events;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
int EPOLLERR;
int EPOLLHUP;
scalar_t__ EWOULDBLOCK;
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int accept(int, struct sockaddr *, int *);
scalar_t__ add_fd_to_epoll(int, int);
int /*<<< orphan*/ close(int);
int epoll_create1(int /*<<< orphan*/);
int epoll_wait(int, struct timeval *, int, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int make_fd_non_blocking(int);
int /*<<< orphan*/ memset(struct timeval *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, ...);
int read(int, char *, int);
int /*<<< orphan*/ remove_client(int, int *, int *);
int /*<<< orphan*/ send_hmr_heartbeat(int);
int /*<<< orphan*/ send_hmr_reset(int);
int /*<<< orphan*/ stderr;
scalar_t__ write_exact(int, char *, int);
void event_loop(int sockfd, int hidfd) {
  int efd, i, s;
  struct epoll_event events[64];
  struct timeval last_recv, last_heartbeat;
  int clientfds[32];
  int client_count = 0;
  efd = epoll_create1(0);
  if (efd == -1) {
    perror("epoll_create");
    goto out;
  }
  if (add_fd_to_epoll(efd, hidfd) < 0 || add_fd_to_epoll(efd, sockfd) < 0) {
    goto out;
  }
  memset(events, 0, sizeof(events));
  memset(&last_recv, 0, sizeof(last_recv));
  memset(&last_heartbeat, 0, sizeof(last_heartbeat));
  while (1) {
    int n, item;
    n = epoll_wait(efd, events, 64, 2000);
    if (n < 0) {
      if (errno != EINTR) {
        perror("epoll_wait");
      }
      goto out;
    }
    if (client_count > 0) {
      struct timeval now;
      gettimeofday(&now, NULL);
      if (now.tv_sec - last_recv.tv_sec > 60) {
        send_hmr_reset(hidfd);
        last_recv = now;
      }
      if (now.tv_sec - last_heartbeat.tv_sec > 25) {
        send_hmr_heartbeat(hidfd);
        last_heartbeat = now;
      }
    }
    for (item = 0; item < n; item++) {
      struct epoll_event *ev = &events[item];
      if (ev->events & (EPOLLERR | EPOLLHUP)) {
        fprintf(stderr, "epoll error\n");
        if (ev->data.fd == sockfd || ev->data.fd == hidfd) {
          goto out;
        } else {
          remove_client(ev->data.fd, clientfds, &client_count);
          continue;
        }
      } else if (sockfd == ev->data.fd) {
        while (1) {
          struct sockaddr in_addr;
          socklen_t in_len;
          int infd;
          char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV];
          in_len = sizeof(in_addr);
          infd = accept(sockfd, &in_addr, &in_len);
          if (infd == -1) {
            if (errno == EAGAIN || errno == EWOULDBLOCK) {
              break;
            } else {
              perror("accept");
              break;
            }
          }
          s = getnameinfo(&in_addr, in_len, hbuf, sizeof(hbuf), sbuf,
                          sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV);
          if (s == 0) {
            printf("Accepted connection on descriptor %d "
                   "(host=%s, port=%s)\n",
                   infd, hbuf, sbuf);
          }
          s = make_fd_non_blocking(infd);
          if (s == -1) {
            close(infd);
            continue;
          }
          if (add_fd_to_epoll(efd, infd) < 0) {
            close(infd);
            continue;
          }
          if (client_count < 32) {
            if (client_count == 0) {
              send_hmr_reset(hidfd);
              send_hmr_heartbeat(hidfd);
              gettimeofday(&last_recv, NULL);
              last_heartbeat = last_recv;
            }
            clientfds[client_count++] = infd;
          }
        }
      } else if (hidfd == ev->data.fd) {
        char buf[8];
        ssize_t count = read(hidfd, buf, sizeof(buf));
        gettimeofday(&last_recv, NULL);
        if (count == 8) {
          int cl, length = buf[0];
          if (length < 8) {
            for (cl = 0; cl < client_count;) {
              if (write_exact(clientfds[cl], buf + 1, length) < 0) {
                remove_client(clientfds[cl], clientfds, &client_count);
              } else {
                cl++;
              }
            }
          }
        }
      } else {
        int done = 0;
        while (1) {
          ssize_t count;
          char buf[512];
          count = read(ev->data.fd, buf, sizeof buf);
          if (count == -1) {
            if (errno != EAGAIN && errno != EWOULDBLOCK) {
              perror("read");
              done = 1;
            }
            break;
          } else if (count == 0) {
            done = 1;
            break;
          }
        }
        if (done) {
          printf("Closed connection on descriptor %d\n", ev->data.fd);
          remove_client(ev->data.fd, clientfds, &client_count);
        }
      }
    }
  }
out:
  for (i = 0; i < client_count; i++) {
    close(clientfds[i]);
  }
  if (efd >= 0) {
    close(efd);
  }
}


x86 assembly (clang, -O0):
<event_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
movl   $0x0,-0x3c4(%rbp)
xor    %edi,%edi
call   1130 <epoll_create1@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1250 <event_loop+0x40>
lea    0xdba(%rip),%rdi
call   1110 <perror@plt>
jmp    192f <event_loop+0x71f>
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   10c0 <add_fd_to_epoll@plt>
cmp    $0x0,%rax
jl     127a <event_loop+0x6a>
mov    -0xc(%rbp),%edi
mov    -0x4(%rbp),%esi
call   10c0 <add_fd_to_epoll@plt>
cmp    $0x0,%rax
jge    127f <event_loop+0x6f>
jmp    192f <event_loop+0x71f>
lea    -0x320(%rbp),%rdi
xor    %esi,%esi
mov    $0x300,%edx
call   1070 <memset@plt>
lea    -0x330(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
lea    -0x340(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    -0xc(%rbp),%edi
lea    -0x320(%rbp),%rsi
mov    $0x40,%edx
mov    $0x7d0,%ecx
call   1100 <epoll_wait@plt>
mov    %eax,-0x3c8(%rbp)
cmpl   $0x0,-0x3c8(%rbp)
jge    130f <event_loop+0xff>
mov    0x2ccd(%rip),%rax
mov    (%rax),%rax
mov    0x2cb3(%rip),%rcx
cmp    (%rcx),%rax
je     130a <event_loop+0xfa>
lea    0xd08(%rip),%rdi
call   1110 <perror@plt>
jmp    192f <event_loop+0x71f>
cmpl   $0x0,-0x3c4(%rbp)
jle    139f <event_loop+0x18f>
lea    -0x3d8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x3d8(%rbp),%eax
sub    -0x330(%rbp),%eax
cmp    $0x3c,%eax
jle    1363 <event_loop+0x153>
mov    -0x8(%rbp),%edi
call   1040 <send_hmr_reset@plt>
mov    -0x3d8(%rbp),%rax
mov    %rax,-0x330(%rbp)
mov    -0x3d0(%rbp),%eax
mov    %eax,-0x328(%rbp)
mov    -0x3d8(%rbp),%eax
sub    -0x340(%rbp),%eax
cmp    $0x19,%eax
jle    139a <event_loop+0x18a>
mov    -0x8(%rbp),%edi
call   1030 <send_hmr_heartbeat@plt>
mov    -0x3d8(%rbp),%rax
mov    %rax,-0x340(%rbp)
mov    -0x3d0(%rbp),%eax
mov    %eax,-0x338(%rbp)
jmp    139f <event_loop+0x18f>
movl   $0x0,-0x3cc(%rbp)
mov    -0x3cc(%rbp),%eax
cmp    -0x3c8(%rbp),%eax
jge    192a <event_loop+0x71a>
movslq -0x3cc(%rbp),%rcx
lea    -0x320(%rbp),%rax
imul   $0xc,%rcx,%rcx
add    %rcx,%rax
mov    %rax,-0x3e0(%rbp)
mov    -0x3e0(%rbp),%rax
mov    0x4(%rax),%eax
mov    0x2be0(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2ba7(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     1460 <event_loop+0x250>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
lea    0xc0a(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%eax
cmp    -0x4(%rbp),%eax
je     1439 <event_loop+0x229>
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%eax
cmp    -0x8(%rbp),%eax
jne    143e <event_loop+0x22e>
jmp    192f <event_loop+0x71f>
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%edi
lea    -0x3c0(%rbp),%rsi
lea    -0x3c4(%rbp),%rdx
call   10e0 <remove_client@plt>
jmp    1916 <event_loop+0x706>
mov    -0x4(%rbp),%eax
mov    -0x3e0(%rbp),%rcx
cmp    0x8(%rcx),%eax
jne    171c <event_loop+0x50c>
jmp    1478 <event_loop+0x268>
mov    0x2b21(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x650(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x3f8(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x648(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x400(%rbp)
mov    0x2b25(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x640(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x638(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x408(%rbp)
movl   $0x4,-0x3ec(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x3e8(%rbp),%rsi
lea    -0x3ec(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x3f0(%rbp)
cmpl   $0xffffffff,-0x3f0(%rbp)
jne    1577 <event_loop+0x367>
mov    0x2a98(%rip),%rax
mov    (%rax),%rax
mov    0x2a5e(%rip),%rcx
cmp    (%rcx),%rax
je     154d <event_loop+0x33d>
mov    0x2a7e(%rip),%rax
mov    (%rax),%rax
mov    0x2a6c(%rip),%rcx
cmp    (%rcx),%rax
jne    155c <event_loop+0x34c>
movl   $0x9,-0x40c(%rbp)
jmp    16d6 <event_loop+0x4c6>
lea    0xac2(%rip),%rdi
call   1110 <perror@plt>
movl   $0x9,-0x40c(%rbp)
jmp    16d6 <event_loop+0x4c6>
mov    -0x638(%rbp),%r8
mov    -0x648(%rbp),%rdx
mov    -0x640(%rbp),%rax
mov    -0x650(%rbp),%rcx
mov    -0x3ec(%rbp),%esi
mov    %eax,%r9d
mov    0x2a1d(%rip),%rax
mov    (%rax),%eax
mov    0x2a3c(%rip),%rdi
or     (%rdi),%eax
lea    -0x3e8(%rbp),%rdi
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1090 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    15f4 <event_loop+0x3e4>
mov    -0x638(%rbp),%rcx
mov    -0x648(%rbp),%rdx
mov    -0x3f0(%rbp),%esi
lea    0xa3f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3f0(%rbp),%edi
call   10d0 <make_fd_non_blocking@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1626 <event_loop+0x416>
mov    -0x3f0(%rbp),%edi
call   1080 <close@plt>
movl   $0x8,-0x40c(%rbp)
jmp    16d6 <event_loop+0x4c6>
mov    -0xc(%rbp),%edi
mov    -0x3f0(%rbp),%esi
call   10c0 <add_fd_to_epoll@plt>
cmp    $0x0,%rax
jge    1658 <event_loop+0x448>
mov    -0x3f0(%rbp),%edi
call   1080 <close@plt>
movl   $0x8,-0x40c(%rbp)
jmp    16d6 <event_loop+0x4c6>
cmpl   $0x20,-0x3c4(%rbp)
jge    16cc <event_loop+0x4bc>
cmpl   $0x0,-0x3c4(%rbp)
jne    16ac <event_loop+0x49c>
mov    -0x8(%rbp),%edi
call   1040 <send_hmr_reset@plt>
mov    -0x8(%rbp),%edi
call   1030 <send_hmr_heartbeat@plt>
lea    -0x330(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
mov    -0x330(%rbp),%rax
mov    %rax,-0x340(%rbp)
mov    -0x328(%rbp),%eax
mov    %eax,-0x338(%rbp)
mov    -0x3f0(%rbp),%ecx
mov    -0x3c4(%rbp),%eax
mov    %eax,%edx
add    $0x1,%edx
mov    %edx,-0x3c4(%rbp)
cltq
mov    %ecx,-0x3c0(%rbp,%rax,4)
movl   $0x0,-0x40c(%rbp)
mov    -0x3f8(%rbp),%rax
mov    %rax,%rsp
mov    -0x40c(%rbp),%eax
mov    %eax,-0x654(%rbp)
test   %eax,%eax
je     1712 <event_loop+0x502>
jmp    16f9 <event_loop+0x4e9>
mov    -0x654(%rbp),%eax
sub    $0x8,%eax
je     1478 <event_loop+0x268>
jmp    170d <event_loop+0x4fd>
jmp    1717 <event_loop+0x507>
jmp    1478 <event_loop+0x268>
jmp    190c <event_loop+0x6fc>
mov    -0x8(%rbp),%eax
mov    -0x3e0(%rbp),%rcx
cmp    0x8(%rcx),%eax
jne    1813 <event_loop+0x603>
mov    -0x8(%rbp),%edi
lea    -0x414(%rbp),%rsi
mov    $0x8,%edx
call   10a0 <read@plt>
mov    %eax,-0x418(%rbp)
lea    -0x330(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1060 <gettimeofday@plt>
cmpl   $0x8,-0x418(%rbp)
jne    180e <event_loop+0x5fe>
movsbl -0x414(%rbp),%eax
mov    %eax,-0x420(%rbp)
cmpl   $0x8,-0x420(%rbp)
jge    1809 <event_loop+0x5f9>
movl   $0x0,-0x41c(%rbp)
mov    -0x41c(%rbp),%eax
cmp    -0x3c4(%rbp),%eax
jge    1804 <event_loop+0x5f4>
movslq -0x41c(%rbp),%rax
mov    -0x3c0(%rbp,%rax,4),%edi
lea    -0x414(%rbp),%rsi
add    $0x1,%rsi
mov    -0x420(%rbp),%edx
call   10f0 <write_exact@plt>
cmp    $0x0,%rax
jge    17f0 <event_loop+0x5e0>
movslq -0x41c(%rbp),%rax
mov    -0x3c0(%rbp,%rax,4),%edi
lea    -0x3c0(%rbp),%rsi
lea    -0x3c4(%rbp),%rdx
call   10e0 <remove_client@plt>
jmp    17ff <event_loop+0x5ef>
mov    -0x41c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x41c(%rbp)
jmp    178a <event_loop+0x57a>
jmp    1809 <event_loop+0x5f9>
jmp    180e <event_loop+0x5fe>
jmp    1907 <event_loop+0x6f7>
movl   $0x0,-0x424(%rbp)
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%edi
lea    -0x630(%rbp),%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
jne    189a <event_loop+0x68a>
mov    0x2766(%rip),%rax
mov    (%rax),%rax
mov    0x272c(%rip),%rcx
cmp    (%rcx),%rax
je     1895 <event_loop+0x685>
mov    0x274c(%rip),%rax
mov    (%rax),%rax
mov    0x273a(%rip),%rcx
cmp    (%rcx),%rax
je     1895 <event_loop+0x685>
lea    0x7df(%rip),%rdi
call   1110 <perror@plt>
movl   $0x1,-0x424(%rbp)
jmp    18c0 <event_loop+0x6b0>
cmpl   $0x0,-0x428(%rbp)
jne    18b6 <event_loop+0x6a6>
movl   $0x1,-0x424(%rbp)
jmp    18c0 <event_loop+0x6b0>
jmp    18bb <event_loop+0x6ab>
jmp    181d <event_loop+0x60d>
cmpl   $0x0,-0x424(%rbp)
je     1902 <event_loop+0x6f2>
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%esi
lea    0x78c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x3e0(%rbp),%rax
mov    0x8(%rax),%edi
lea    -0x3c0(%rbp),%rsi
lea    -0x3c4(%rbp),%rdx
call   10e0 <remove_client@plt>
jmp    1907 <event_loop+0x6f7>
jmp    190c <event_loop+0x6fc>
jmp    1911 <event_loop+0x701>
jmp    1916 <event_loop+0x706>
mov    -0x3cc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3cc(%rbp)
jmp    13a9 <event_loop+0x199>
jmp    12b8 <event_loop+0xa8>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x3c4(%rbp),%eax
jge    1963 <event_loop+0x753>
movslq -0x10(%rbp),%rax
mov    -0x3c0(%rbp,%rax,4),%edi
call   1080 <close@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1936 <event_loop+0x726>
cmpl   $0x0,-0xc(%rbp)
jl     1975 <event_loop+0x765>
mov    -0xc(%rbp),%edi
call   1080 <close@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<event_loop>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x5d8,%rsp
mov    %esi,%ebx
mov    %edi,%r13d
movl   $0x0,-0x2c(%rbp)
xor    %edi,%edi
call   1130 <epoll_create1@plt>
cmp    $0xffffffff,%eax
je     1795 <event_loop+0x585>
mov    %eax,%r12d
mov    %eax,%edi
mov    %ebx,%esi
call   10c0 <add_fd_to_epoll@plt>
test   %rax,%rax
js     174d <event_loop+0x53d>
mov    %r12d,%edi
mov    %r13d,%esi
call   10c0 <add_fd_to_epoll@plt>
test   %rax,%rax
js     174d <event_loop+0x53d>
mov    %ebx,-0x30(%rbp)
lea    -0x600(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x300,%edx
call   1070 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
lea    -0x78(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1070 <memset@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
mov    $0x7d0,%ecx
call   1100 <epoll_wait@plt>
test   %eax,%eax
js     1737 <event_loop+0x527>
mov    %eax,%r14d
mov    0x2cff(%rip),%r15
mov    %r12d,-0x4c(%rbp)
mov    %r13d,-0x50(%rbp)
jmp    1304 <event_loop+0xf4>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r12d,%edi
lea    -0x600(%rbp),%rsi
mov    $0x40,%edx
mov    $0x7d0,%ecx
call   1100 <epoll_wait@plt>
mov    %eax,%r14d
test   %eax,%eax
js     1737 <event_loop+0x527>
cmpl   $0x0,-0x2c(%rbp)
jle    1368 <event_loop+0x158>
lea    -0x300(%rbp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    -0x300(%rbp),%ebx
mov    %ebx,%eax
sub    -0x60(%rbp),%eax
cmp    $0x3d,%eax
jl     1344 <event_loop+0x134>
mov    -0x30(%rbp),%edi
call   1040 <send_hmr_reset@plt>
mov    -0x300(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x2f8(%rbp),%eax
mov    %eax,-0x58(%rbp)
sub    -0x78(%rbp),%ebx
cmp    $0x1a,%ebx
jl     1368 <event_loop+0x158>
mov    -0x30(%rbp),%edi
call   1030 <send_hmr_heartbeat@plt>
mov    -0x300(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x2f8(%rbp),%eax
mov    %eax,-0x70(%rbp)
test   %r14d,%r14d
je     12e0 <event_loop+0xd0>
mov    %r14d,%r14d
xor    %eax,%eax
mov    %r14,-0x68(%rbp)
jmp    139d <event_loop+0x18d>
mov    -0x48(%rbp),%rsp
mov    -0x4c(%rbp),%r12d
mov    -0x50(%rbp),%r13d
mov    -0x68(%rbp),%r14
mov    -0x40(%rbp),%rax
add    $0x1,%rax
cmp    %r14,%rax
je     12e0 <event_loop+0xd0>
mov    %rax,-0x40(%rbp)
lea    (%rax,%rax,2),%rbx
mov    0x2bec(%rip),%rax
mov    (%rax),%eax
or     (%r15),%eax
test   %eax,-0x5fc(%rbp,%rbx,4)
je     1400 <event_loop+0x1f0>
mov    0x2c0f(%rip),%rax
mov    (%rax),%edi
lea    0xc4e(%rip),%rsi
call   10b0 <fprintf@plt>
mov    -0x5f8(%rbp,%rbx,4),%edi
cmp    %r13d,%edi
mov    -0x30(%rbp),%eax
je     174d <event_loop+0x53d>
cmp    %eax,%edi
je     174d <event_loop+0x53d>
lea    -0x100(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <remove_client@plt>
jmp    138c <event_loop+0x17c>
nopl   0x0(%rax)
mov    -0x5f8(%rbp,%rbx,4),%edi
cmp    %r13d,%edi
lea    -0x300(%rbp),%r14
jne    15d6 <event_loop+0x3c6>
mov    %rsp,-0x48(%rbp)
mov    0x2b7e(%rip),%rax
mov    (%rax),%r15d
mov    %rsp,%r12
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %r13d,%edi
mov    0x2ba0(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x4,-0x34(%rbp)
mov    %r14,%rsi
lea    -0x34(%rbp),%rdx
call   1120 <accept@plt>
cmp    $0xffffffff,%eax
je     1671 <event_loop+0x461>
mov    %eax,%r14d
mov    %r15,%r8
lea    -0x300(%rbp),%r15
jmp    150b <event_loop+0x2fb>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14d,%edi
call   1080 <close@plt>
mov    -0x48(%rbp),%rbx
mov    %rbx,%rsp
mov    %rsp,-0x48(%rbp)
mov    0x2af6(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
mov    %r14,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2b18(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
mov    %r13,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
movl   $0x4,-0x34(%rbp)
mov    -0x50(%rbp),%edi
lea    -0x300(%rbp),%r15
mov    %r15,%rsi
lea    -0x34(%rbp),%rdx
call   1120 <accept@plt>
mov    %r14,%r8
mov    %eax,%r14d
cmp    $0xffffffff,%eax
je     1671 <event_loop+0x461>
mov    -0x34(%rbp),%esi
mov    0x2ad3(%rip),%rax
mov    (%rax),%eax
mov    0x2aa2(%rip),%rcx
or     (%rcx),%eax
sub    $0x8,%rsp
mov    %r15,%rdi
mov    %r12,%rdx
mov    %r8d,%ecx
mov    %rbx,%r8
mov    %r13d,%r9d
push   %rax
call   1090 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1558 <event_loop+0x348>
lea    0xae4(%rip),%rdi
mov    %r14d,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r14d,%edi
call   10d0 <make_fd_non_blocking@plt>
cmp    $0xffffffff,%eax
je     1490 <event_loop+0x280>
mov    -0x4c(%rbp),%edi
mov    %r14d,%esi
call   10c0 <add_fd_to_epoll@plt>
test   %rax,%rax
js     1490 <event_loop+0x280>
mov    -0x2c(%rbp),%eax
cmp    $0x1f,%eax
mov    -0x48(%rbp),%rbx
jg     149c <event_loop+0x28c>
test   %eax,%eax
jne    15c1 <event_loop+0x3b1>
mov    -0x30(%rbp),%r15d
mov    %r15d,%edi
call   1040 <send_hmr_reset@plt>
mov    %r15d,%edi
call   1030 <send_hmr_heartbeat@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
mov    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x2c(%rbp),%eax
lea    0x1(%rax),%ecx
mov    %ecx,-0x2c(%rbp)
cltq
mov    %r14d,-0x100(%rbp,%rax,4)
ff
jmp    149c <event_loop+0x28c>
mov    -0x30(%rbp),%eax
cmp    %eax,%edi
jne    16b3 <event_loop+0x4a3>
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   10a0 <read@plt>
mov    %eax,%ebx
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
call   1060 <gettimeofday@plt>
cmp    $0x8,%ebx
jne    1665 <event_loop+0x455>
movsbl -0x300(%rbp),%r14d
ff
cmp    $0x7,%r14d
jg     1665 <event_loop+0x455>
cmpl   $0x0,-0x2c(%rbp)
jle    1665 <event_loop+0x455>
xor    %r15d,%r15d
jmp    162a <event_loop+0x41a>
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
cmp    -0x2c(%rbp),%r15d
jge    1665 <event_loop+0x455>
movslq %r15d,%rbx
mov    -0x100(%rbp,%rbx,4),%edi
lea    -0x2ff(%rbp),%rsi
mov    %r14d,%edx
call   10f0 <write_exact@plt>
test   %rax,%rax
jns    1620 <event_loop+0x410>
mov    -0x100(%rbp,%rbx,4),%edi
lea    -0x100(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <remove_client@plt>
cmp    -0x2c(%rbp),%r15d
jl     162a <event_loop+0x41a>
mov    0x295c(%rip),%r15
jmp    1388 <event_loop+0x178>
mov    0x2940(%rip),%rax
mov    (%rax),%rax
mov    0x2906(%rip),%rcx
cmp    (%rcx),%rax
mov    0x293c(%rip),%r15
je     137c <event_loop+0x16c>
mov    0x2917(%rip),%rcx
cmp    (%rcx),%rax
je     137c <event_loop+0x16c>
lea    0x97c(%rip),%rdi
call   1110 <perror@plt>
jmp    137c <event_loop+0x16c>
lea    -0x5f8(,%rbx,4),%rbx
ff
add    %rbp,%rbx
xchg   %ax,%ax
mov    %r14,%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
test   %eax,%eax
je     1710 <event_loop+0x500>
cmp    $0xffffffff,%eax
je     16da <event_loop+0x4ca>
mov    (%rbx),%edi
jmp    16c0 <event_loop+0x4b0>
mov    0x28d7(%rip),%rax
mov    (%rax),%rax
mov    0x289d(%rip),%rcx
cmp    (%rcx),%rax
je     1388 <event_loop+0x178>
mov    0x28b5(%rip),%rcx
cmp    (%rcx),%rax
je     1388 <event_loop+0x178>
lea    0x95a(%rip),%rdi
call   1110 <perror@plt>
mov    (%rbx),%esi
lea    0x951(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rbx),%edi
lea    -0x100(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <remove_client@plt>
jmp    1388 <event_loop+0x178>
mov    0x287a(%rip),%rax
mov    (%rax),%rax
mov    0x2860(%rip),%rcx
cmp    (%rcx),%rax
jne    17af <event_loop+0x59f>
cmpl   $0x0,-0x2c(%rbp)
jle    1779 <event_loop+0x569>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    -0x100(%rbp,%rbx,4),%edi
call   1080 <close@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1760 <event_loop+0x550>
test   %r12d,%r12d
js     1786 <event_loop+0x576>
mov    %r12d,%edi
call   1080 <close@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x864(%rip),%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1110 <perror@plt>
lea    0x857(%rip),%rdi
call   1110 <perror@plt>
cmpl   $0x0,-0x2c(%rbp)
jg     1753 <event_loop+0x543>
jmp    1779 <event_loop+0x569>

LLVM IR (-O0):
%struct.epoll_event = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32, %struct.TYPE_2__ }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"epoll_create\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [11 x i8] c"epoll_wait\00"
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@stderr = global i32 0
@.str.2 = [13 x i8] c"epoll error\0A\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.3 = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.4 = [57 x i8] c"Accepted connection on descriptor %d (host=%s, port=%s)\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [36 x i8] c"Closed connection on descriptor %d\0A\00"
define void @event_loop(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x %struct.epoll_event]
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca [32 x i32]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca %struct.timeval
%16 = alloca %struct.epoll_event*
%17 = alloca %struct.sockaddr
%18 = alloca i32
%19 = alloca i32
%20 = alloca i8*
%21 = alloca i64
%22 = alloca i64
%23 = alloca i32
%24 = alloca [8 x i8]
%25 = alloca i32
%26 = alloca i32
%27 = alloca i32
%28 = alloca i32
%29 = alloca i32
%30 = alloca [512 x i8]
store i32 %0, i32* %3
store i32 %1, i32* %4
store i32 0, i32* %12
%31 = call i32 @epoll_create1(i32 0)
store i32 %31, i32* %5
%32 = load i32, i32* %5
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %36
34: ; preds = %2
%35 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %322
36: ; preds = %2
%37 = load i32, i32* %5
%38 = load i32, i32* %4
%39 = call i64 @add_fd_to_epoll(i32 %37, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %36
%42 = load i32, i32* %5
%43 = load i32, i32* %3
%44 = call i64 @add_fd_to_epoll(i32 %42, i32 %43)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41, %36
br label %322
47: ; preds = %41
%48 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %8, i64 0, i64 0
%49 = bitcast %struct.epoll_event* %48 to %struct.timeval*
%50 = call i32 @memset(%struct.timeval* %49, i32 0, i32 768)
%51 = call i32 @memset(%struct.timeval* %9, i32 0, i32 12)
%52 = call i32 @memset(%struct.timeval* %10, i32 0, i32 12)
br label %53
53: ; preds = %47, %321
%54 = load i32, i32* %5
%55 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %8, i64 0, i64 0
%56 = bitcast %struct.epoll_event* %55 to %struct.timeval*
%57 = call i32 @epoll_wait(i32 %54, %struct.timeval* %56, i32 64, i32 2000)
store i32 %57, i32* %13
%58 = load i32, i32* %13
%59 = icmp slt i32 %58, 0
br i1 %59, label %60, label %67
60: ; preds = %53
%61 = load i64, i64* @errno
%62 = load i64, i64* @EINTR
%63 = icmp ne i64 %61, %62
br i1 %63, label %64, label %66
64: ; preds = %60
%65 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %66
66: ; preds = %64, %60
br label %322
67: ; preds = %53
%68 = load i32, i32* %12
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %96
70: ; preds = %67
%71 = call i32 @gettimeofday(%struct.timeval* %15, i32* null)
%72 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%73 = load i32, i32* %72
%74 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%75 = load i32, i32* %74
%76 = sub nsw i32 %73, %75
%77 = icmp sgt i32 %76, 60
br i1 %77, label %78, label %83
78: ; preds = %70
%79 = load i32, i32* %4
%80 = call i32 @send_hmr_reset(i32 %79)
%81 = bitcast %struct.timeval* %9 to i8*
%82 = bitcast %struct.timeval* %15 to i8*
br label %83
83: ; preds = %78, %70
%84 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%85 = load i32, i32* %84
%86 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%87 = load i32, i32* %86
%88 = sub nsw i32 %85, %87
%89 = icmp sgt i32 %88, 25
br i1 %89, label %90, label %95
90: ; preds = %83
%91 = load i32, i32* %4
%92 = call i32 @send_hmr_heartbeat(i32 %91)
%93 = bitcast %struct.timeval* %10 to i8*
%94 = bitcast %struct.timeval* %15 to i8*
br label %95
95: ; preds = %90, %83
br label %96
96: ; preds = %95, %67
store i32 0, i32* %14
br label %97
97: ; preds = %318, %96
%98 = load i32, i32* %14
%99 = load i32, i32* %13
%100 = icmp slt i32 %98, %99
br i1 %100, label %101, label %321
101: ; preds = %97
%102 = load i32, i32* %14
%103 = sext i32 %102 to i64
%104 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %8, i64 0, i64 %103
store %struct.epoll_event* %104, %struct.epoll_event** %16
%105 = load %struct.epoll_event*, %struct.epoll_event** %16
%106 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %105, i32 0, i32 1
%107 = load i32, i32* %106
%108 = load i32, i32* @EPOLLERR
%109 = load i32, i32* @EPOLLHUP
%110 = or i32 %108, %109
%111 = and i32 %107, %110
%112 = icmp ne i32 %111, 0
br i1 %112, label %113, label %137
113: ; preds = %101
%114 = load i32, i32* @stderr
%115 = call i32 @fprintf(i32 %114, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%116 = load %struct.epoll_event*, %struct.epoll_event** %16
%117 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %116, i32 0, i32 2
%118 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %117, i32 0, i32 0
%119 = load i32, i32* %118
%120 = load i32, i32* %3
%121 = icmp eq i32 %119, %120
br i1 %121, label %129, label %122
122: ; preds = %113
%123 = load %struct.epoll_event*, %struct.epoll_event** %16
%124 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %123, i32 0, i32 2
%125 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %124, i32 0, i32 0
%126 = load i32, i32* %125
%127 = load i32, i32* %4
%128 = icmp eq i32 %126, %127
br i1 %128, label %129, label %130
129: ; preds = %122, %113
br label %322
130: ; preds = %122
%131 = load %struct.epoll_event*, %struct.epoll_event** %16
%132 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %131, i32 0, i32 2
%133 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %132, i32 0, i32 0
%134 = load i32, i32* %133
%135 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 0
%136 = call i32 @remove_client(i32 %134, i32* %135, i32* %12)
br label %318
137: ; preds = %101
%138 = load i32, i32* %3
%139 = load %struct.epoll_event*, %struct.epoll_event** %16
%140 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %139, i32 0, i32 2
%141 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %140, i32 0, i32 0
%142 = load i32, i32* %141
%143 = icmp eq i32 %138, %142
br i1 %143, label %144, label %223
144: ; preds = %137
br label %145
145: ; preds = %144, %218, %221
%146 = load i32, i32* @NI_MAXHOST
%147 = zext i32 %146 to i64
%148 = call i8* @llvm.stacksave()
store i8* %148, i8** %20
%149 = alloca i8, i64 %147
store i64 %147, i64* %21
%150 = load i32, i32* @NI_MAXSERV
%151 = zext i32 %150 to i64
%152 = alloca i8, i64 %151
store i64 %151, i64* %22
store i32 4, i32* %18
%153 = load i32, i32* %3
%154 = call i32 @accept(i32 %153, %struct.sockaddr* %17, i32* %18)
store i32 %154, i32* %19
%155 = load i32, i32* %19
%156 = icmp eq i32 %155, -1
br i1 %156, label %157, label %168
157: ; preds = %145
%158 = load i64, i64* @errno
%159 = load i64, i64* @EAGAIN
%160 = icmp eq i64 %158, %159
br i1 %160, label %165, label %161
161: ; preds = %157
%162 = load i64, i64* @errno
%163 = load i64, i64* @EWOULDBLOCK
%164 = icmp eq i64 %162, %163
br i1 %164, label %165, label %166
165: ; preds = %161, %157
store i32 9, i32* %23
br label %218
166: ; preds = %161
%167 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
store i32 9, i32* %23
br label %218
168: ; preds = %145
%169 = load i32, i32* %18
%170 = trunc i64 %147 to i32
%171 = trunc i64 %151 to i32
%172 = load i32, i32* @NI_NUMERICHOST
%173 = load i32, i32* @NI_NUMERICSERV
%174 = or i32 %172, %173
%175 = call i32 @getnameinfo(%struct.sockaddr* %17, i32 %169, i8* %149, i32 %170, i8* %152, i32 %171, i32 %174)
store i32 %175, i32* %7
%176 = load i32, i32* %7
%177 = icmp eq i32 %176, 0
br i1 %177, label %178, label %181
178: ; preds = %168
%179 = load i32, i32* %19
%180 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 %179, i8* %149, i8* %152)
br label %181
181: ; preds = %178, %168
%182 = load i32, i32* %19
%183 = call i32 @make_fd_non_blocking(i32 %182)
store i32 %183, i32* %7
%184 = load i32, i32* %7
%185 = icmp eq i32 %184, -1
br i1 %185, label %186, label %189
186: ; preds = %181
%187 = load i32, i32* %19
%188 = call i32 @close(i32 %187)
store i32 8, i32* %23
br label %218
189: ; preds = %181
%190 = load i32, i32* %5
%191 = load i32, i32* %19
%192 = call i64 @add_fd_to_epoll(i32 %190, i32 %191)
%193 = icmp slt i64 %192, 0
br i1 %193, label %194, label %197
194: ; preds = %189
%195 = load i32, i32* %19
%196 = call i32 @close(i32 %195)
store i32 8, i32* %23
br label %218
197: ; preds = %189
%198 = load i32, i32* %12
%199 = icmp slt i32 %198, 32
br i1 %199, label %200, label %217
200: ; preds = %197
%201 = load i32, i32* %12
%202 = icmp eq i32 %201, 0
br i1 %202, label %203, label %211
203: ; preds = %200
%204 = load i32, i32* %4
%205 = call i32 @send_hmr_reset(i32 %204)
%206 = load i32, i32* %4
%207 = call i32 @send_hmr_heartbeat(i32 %206)
%208 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%209 = bitcast %struct.timeval* %10 to i8*
%210 = bitcast %struct.timeval* %9 to i8*
br label %211
211: ; preds = %203, %200
%212 = load i32, i32* %19
%213 = load i32, i32* %12
%214 = add nsw i32 %213, 1
store i32 %214, i32* %12
%215 = sext i32 %213 to i64
%216 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %215
store i32 %212, i32* %216
br label %217
217: ; preds = %211, %197
store i32 0, i32* %23
br label %218
218: ; preds = %217, %194, %186, %166, %165
%219 = load i8*, i8** %20
%220 = load i32, i32* %23
switch i32 %220, label %343 [
i32 0, label %221
i32 9, label %222
i32 8, label %145
]
221: ; preds = %218
br label %145
222: ; preds = %218
br label %316
223: ; preds = %137
%224 = load i32, i32* %4
%225 = load %struct.epoll_event*, %struct.epoll_event** %16
%226 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %225, i32 0, i32 2
%227 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %226, i32 0, i32 0
%228 = load i32, i32* %227
%229 = icmp eq i32 %224, %228
br i1 %229, label %230, label %272
230: ; preds = %223
%231 = load i32, i32* %4
%232 = getelementptr inbounds [8 x i8], [8 x i8]* %24, i64 0, i64 0
%233 = call i32 @read(i32 %231, i8* %232, i32 8)
store i32 %233, i32* %25
%234 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%235 = load i32, i32* %25
%236 = icmp eq i32 %235, 8
br i1 %236, label %237, label %271
237: ; preds = %230
%238 = getelementptr inbounds [8 x i8], [8 x i8]* %24, i64 0, i64 0
%239 = load i8, i8* %238
%240 = sext i8 %239 to i32
store i32 %240, i32* %27
%241 = load i32, i32* %27
%242 = icmp slt i32 %241, 8
br i1 %242, label %243, label %270
243: ; preds = %237
store i32 0, i32* %26
br label %244
244: ; preds = %268, %243
%245 = load i32, i32* %26
%246 = load i32, i32* %12
%247 = icmp slt i32 %245, %246
br i1 %247, label %248, label %269
248: ; preds = %244
%249 = load i32, i32* %26
%250 = sext i32 %249 to i64
%251 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %250
%252 = load i32, i32* %251
%253 = getelementptr inbounds [8 x i8], [8 x i8]* %24, i64 0, i64 0
%254 = getelementptr inbounds i8, i8* %253, i64 1
%255 = load i32, i32* %27
%256 = call i64 @write_exact(i32 %252, i8* %254, i32 %255)
%257 = icmp slt i64 %256, 0
br i1 %257, label %258, label %265
258: ; preds = %248
%259 = load i32, i32* %26
%260 = sext i32 %259 to i64
%261 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %260
%262 = load i32, i32* %261
%263 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 0
%264 = call i32 @remove_client(i32 %262, i32* %263, i32* %12)
br label %268
265: ; preds = %248
%266 = load i32, i32* %26
%267 = add nsw i32 %266, 1
store i32 %267, i32* %26
br label %268
268: ; preds = %265, %258
br label %244
269: ; preds = %244
br label %270
270: ; preds = %269, %237
br label %271
271: ; preds = %270, %230
br label %315
272: ; preds = %223
store i32 0, i32* %28
br label %273
273: ; preds = %272, %298
%274 = load %struct.epoll_event*, %struct.epoll_event** %16
%275 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %274, i32 0, i32 2
%276 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %275, i32 0, i32 0
%277 = load i32, i32* %276
%278 = getelementptr inbounds [512 x i8], [512 x i8]* %30, i64 0, i64 0
%279 = call i32 @read(i32 %277, i8* %278, i32 512)
store i32 %279, i32* %29
%280 = load i32, i32* %29
%281 = icmp eq i32 %280, -1
br i1 %281, label %282, label %293
282: ; preds = %273
%283 = load i64, i64* @errno
%284 = load i64, i64* @EAGAIN
%285 = icmp ne i64 %283, %284
br i1 %285, label %286, label %292
286: ; preds = %282
%287 = load i64, i64* @errno
%288 = load i64, i64* @EWOULDBLOCK
%289 = icmp ne i64 %287, %288
br i1 %289, label %290, label %292
290: ; preds = %286
%291 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %28
br label %292
292: ; preds = %290, %286, %282
br label %299
293: ; preds = %273
%294 = load i32, i32* %29
%295 = icmp eq i32 %294, 0
br i1 %295, label %296, label %297
296: ; preds = %293
store i32 1, i32* %28
br label %299
297: ; preds = %293
br label %298
298: ; preds = %297
br label %273
299: ; preds = %296, %292
%300 = load i32, i32* %28
%301 = icmp ne i32 %300, 0
br i1 %301, label %302, label %314
302: ; preds = %299
%303 = load %struct.epoll_event*, %struct.epoll_event** %16
%304 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %303, i32 0, i32 2
%305 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %304, i32 0, i32 0
%306 = load i32, i32* %305
%307 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %306)
%308 = load %struct.epoll_event*, %struct.epoll_event** %16
%309 = getelementptr inbounds %struct.epoll_event, %struct.epoll_event* %308, i32 0, i32 2
%310 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %309, i32 0, i32 0
%311 = load i32, i32* %310
%312 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 0
%313 = call i32 @remove_client(i32 %311, i32* %312, i32* %12)
br label %314
314: ; preds = %302, %299
br label %315
315: ; preds = %314, %271
br label %316
316: ; preds = %315, %222
br label %317
317: ; preds = %316
br label %318
318: ; preds = %317, %130
%319 = load i32, i32* %14
%320 = add nsw i32 %319, 1
store i32 %320, i32* %14
br label %97
321: ; preds = %97
br label %53
322: ; preds = %129, %66, %46, %34
store i32 0, i32* %6
br label %323
323: ; preds = %333, %322
%324 = load i32, i32* %6
%325 = load i32, i32* %12
%326 = icmp slt i32 %324, %325
br i1 %326, label %327, label %336
327: ; preds = %323
%328 = load i32, i32* %6
%329 = sext i32 %328 to i64
%330 = getelementptr inbounds [32 x i32], [32 x i32]* %11, i64 0, i64 %329
%331 = load i32, i32* %330
%332 = call i32 @close(i32 %331)
br label %333
333: ; preds = %327
%334 = load i32, i32* %6
%335 = add nsw i32 %334, 1
store i32 %335, i32* %6
br label %323
336: ; preds = %323
%337 = load i32, i32* %5
%338 = icmp sge i32 %337, 0
br i1 %338, label %339, label %342
339: ; preds = %336
%340 = load i32, i32* %5
%341 = call i32 @close(i32 %340)
br label %342
342: ; preds = %339, %336
ret void
343: ; preds = %218
unreachable
}

LLVM IR (-O2):
%struct.epoll_event = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.timeval = type { i32, i32, %struct.TYPE_2__ }
%struct.sockaddr = type { i32 }
@.str = [13 x i8] c"epoll_create\00"
@errno = global i64 0
@EINTR = global i64 0
@.str.1 = [11 x i8] c"epoll_wait\00"
@EPOLLERR = global i32 0
@EPOLLHUP = global i32 0
@stderr = global i32 0
@.str.2 = [13 x i8] c"epoll error\0A\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@.str.3 = [7 x i8] c"accept\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.4 = [57 x i8] c"Accepted connection on descriptor %d (host=%s, port=%s)\0A\00"
@.str.5 = [5 x i8] c"read\00"
@.str.6 = [36 x i8] c"Closed connection on descriptor %d\0A\00"
define void @event_loop(i32 %0, i32 %1) {
%3 = alloca [64 x %struct.epoll_event]
%4 = alloca %struct.timeval
%5 = alloca %struct.timeval
%6 = alloca [32 x i32]
%7 = alloca i32
%8 = alloca %struct.timeval
%9 = alloca %struct.sockaddr
%10 = alloca i32
%11 = alloca [8 x i8]
%12 = alloca [512 x i8]
%13 = bitcast [64 x %struct.epoll_event]* %3 to i8*
%14 = bitcast %struct.timeval* %4 to i8*
%15 = bitcast %struct.timeval* %5 to i8*
%16 = bitcast [32 x i32]* %6 to i8*
%17 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%18 = tail call i32 @epoll_create1(i32 0)
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %22
20: ; preds = %2
%21 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %241
22: ; preds = %2
%23 = tail call i64 @add_fd_to_epoll(i32 %18, i32 %1)
%24 = icmp slt i64 %23, 0
br i1 %24, label %225, label %25
25: ; preds = %22
%26 = tail call i64 @add_fd_to_epoll(i32 %18, i32 %0)
%27 = icmp slt i64 %26, 0
br i1 %27, label %225, label %28
28: ; preds = %25
%29 = bitcast [64 x %struct.epoll_event]* %3 to %struct.timeval*
%30 = call i32 @memset(%struct.timeval* %29, i32 0, i32 768)
%31 = call i32 @memset(%struct.timeval* %4, i32 0, i32 12)
%32 = call i32 @memset(%struct.timeval* %5, i32 0, i32 12)
%33 = call i32 @epoll_wait(i32 %18, %struct.timeval* %29, i32 64, i32 2000)
%34 = icmp slt i32 %33, 0
br i1 %34, label %49, label %35
35: ; preds = %28
%36 = bitcast %struct.timeval* %8 to i8*
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i64 0, i32 0
%38 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%40 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 0
%41 = getelementptr inbounds [512 x i8], [512 x i8]* %12, i64 0, i64 0
%42 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 0
%43 = getelementptr inbounds [8 x i8], [8 x i8]* %11, i64 0, i64 1
%44 = bitcast %struct.sockaddr* %9 to i8*
%45 = bitcast i32* %10 to i8*
br label %55
46: ; preds = %222, %74
%47 = call i32 @epoll_wait(i32 %18, %struct.timeval* %29, i32 64, i32 2000)
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46, %28
%50 = load i64, i64* @errno
%51 = load i64, i64* @EINTR
%52 = icmp eq i64 %50, %51
br i1 %52, label %225, label %53
53: ; preds = %49
%54 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %225
55: ; preds = %35, %46
%56 = phi i32 [ %33, %35 ], [ %47, %46 ]
%57 = load i32, i32* %7
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %74
59: ; preds = %55
%60 = call i32 @gettimeofday(%struct.timeval* %8, i32* null)
%61 = load i32, i32* %37
%62 = load i32, i32* %38
%63 = sub nsw i32 %61, %62
%64 = icmp sgt i32 %63, 60
br i1 %64, label %65, label %67
65: ; preds = %59
%66 = call i32 @send_hmr_reset(i32 %1)
br label %67
67: ; preds = %65, %59
%68 = load i32, i32* %39
%69 = sub nsw i32 %61, %68
%70 = icmp sgt i32 %69, 25
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 @send_hmr_heartbeat(i32 %1)
br label %73
73: ; preds = %71, %67
br label %74
74: ; preds = %73, %55
%75 = icmp eq i32 %56, 0
br i1 %75, label %46, label %76
76: ; preds = %74
%77 = zext i32 %56 to i64
br label %78
78: ; preds = %76, %222
%79 = phi i64 [ 0, %76 ], [ %223, %222 ]
%80 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %3, i64 0, i64 %79, i32 1
%81 = load i32, i32* %80
%82 = load i32, i32* @EPOLLERR
%83 = load i32, i32* @EPOLLHUP
%84 = or i32 %83, %82
%85 = and i32 %84, %81
%86 = icmp eq i32 %85, 0
br i1 %86, label %97, label %87
87: ; preds = %78
%88 = load i32, i32* @stderr
%89 = call i32 @fprintf(i32 %88, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%90 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %3, i64 0, i64 %79, i32 2, i32 0
%91 = load i32, i32* %90
%92 = icmp eq i32 %91, %0
%93 = icmp eq i32 %91, %1
%94 = or i1 %92, %93
br i1 %94, label %225, label %95
95: ; preds = %87
%96 = call i32 @remove_client(i32 %91, i32* %40, i32* %7)
br label %222
97: ; preds = %78
%98 = getelementptr inbounds [64 x %struct.epoll_event], [64 x %struct.epoll_event]* %3, i64 0, i64 %79, i32 2, i32 0
%99 = load i32, i32* %98
%100 = icmp eq i32 %99, %0
br i1 %100, label %101, label %172
101: ; preds = %97
%102 = load i32, i32* @NI_MAXHOST
%103 = zext i32 %102 to i64
%104 = call i8* @llvm.stacksave()
%105 = alloca i8, i64 %103
%106 = load i32, i32* @NI_MAXSERV
%107 = zext i32 %106 to i64
%108 = alloca i8, i64 %107
store i32 4, i32* %10
%109 = call i32 @accept(i32 %0, %struct.sockaddr* %9, i32* %10)
%110 = icmp eq i32 %109, -1
br i1 %110, label %111, label %121
111: ; preds = %162, %101
%112 = phi i8* [ %104, %101 ], [ %165, %162 ]
%113 = load i64, i64* @errno
%114 = load i64, i64* @EAGAIN
%115 = icmp eq i64 %113, %114
%116 = load i64, i64* @EWOULDBLOCK
%117 = icmp eq i64 %113, %116
%118 = select i1 %115, i1 true, i1 %117
br i1 %118, label %161, label %119
119: ; preds = %111
%120 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
br label %161
121: ; preds = %101, %162
%122 = phi i32 [ %170, %162 ], [ %109, %101 ]
%123 = phi i8* [ %169, %162 ], [ %108, %101 ]
%124 = phi i32 [ %167, %162 ], [ %106, %101 ]
%125 = phi i8* [ %166, %162 ], [ %105, %101 ]
%126 = phi i8* [ %165, %162 ], [ %104, %101 ]
%127 = phi i32 [ %163, %162 ], [ %102, %101 ]
%128 = load i32, i32* %10
%129 = load i32, i32* @NI_NUMERICHOST
%130 = load i32, i32* @NI_NUMERICSERV
%131 = or i32 %130, %129
%132 = call i32 @getnameinfo(%struct.sockaddr* %9, i32 %128, i8* %125, i32 %127, i8* %123, i32 %124, i32 %131)
%133 = icmp eq i32 %132, 0
br i1 %133, label %134, label %136
134: ; preds = %121
%135 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i32 %122, i8* %125, i8* %123)
br label %136
136: ; preds = %134, %121
%137 = call i32 @make_fd_non_blocking(i32 %122)
%138 = icmp eq i32 %137, -1
br i1 %138, label %139, label %141
139: ; preds = %136
%140 = call i32 @close(i32 %122)
br label %162
141: ; preds = %136
%142 = call i64 @add_fd_to_epoll(i32 %18, i32 %122)
%143 = icmp slt i64 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %141
%145 = call i32 @close(i32 %122)
br label %162
146: ; preds = %141
%147 = load i32, i32* %7
%148 = icmp slt i32 %147, 32
br i1 %148, label %149, label %162
149: ; preds = %146
%150 = icmp eq i32 %147, 0
br i1 %150, label %151, label %156
151: ; preds = %149
%152 = call i32 @send_hmr_reset(i32 %1)
%153 = call i32 @send_hmr_heartbeat(i32 %1)
%154 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%155 = load i32, i32* %7
br label %156
156: ; preds = %151, %149
%157 = phi i32 [ %155, %151 ], [ %147, %149 ]
%158 = add nsw i32 %157, 1
store i32 %158, i32* %7
%159 = sext i32 %157 to i64
%160 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 %159
store i32 %122, i32* %160
br label %162
161: ; preds = %119, %111
br label %222
162: ; preds = %146, %156, %144, %139
%163 = load i32, i32* @NI_MAXHOST
%164 = zext i32 %163 to i64
%165 = call i8* @llvm.stacksave()
%166 = alloca i8, i64 %164
%167 = load i32, i32* @NI_MAXSERV
%168 = zext i32 %167 to i64
%169 = alloca i8, i64 %168
store i32 4, i32* %10
%170 = call i32 @accept(i32 %0, %struct.sockaddr* %9, i32* %10)
%171 = icmp eq i32 %170, -1
br i1 %171, label %111, label %121
172: ; preds = %97
%173 = icmp eq i32 %99, %1
br i1 %173, label %174, label %202
174: ; preds = %172
%175 = call i32 @read(i32 %1, i8* %42, i32 8)
%176 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%177 = icmp eq i32 %175, 8
br i1 %177, label %178, label %201
178: ; preds = %174
%179 = load i8, i8* %42
%180 = sext i8 %179 to i32
%181 = icmp slt i8 %179, 8
%182 = load i32, i32* %7
%183 = icmp sgt i32 %182, 0
%184 = select i1 %181, i1 %183, i1 false
br i1 %184, label %185, label %201
185: ; preds = %178, %197
%186 = phi i32 [ %198, %197 ], [ 0, %178 ]
%187 = sext i32 %186 to i64
%188 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 %187
%189 = load i32, i32* %188
%190 = call i64 @write_exact(i32 %189, i8* %43, i32 %180)
%191 = icmp slt i64 %190, 0
br i1 %191, label %192, label %195
192: ; preds = %185
%193 = load i32, i32* %188
%194 = call i32 @remove_client(i32 %193, i32* %40, i32* %7)
br label %197
195: ; preds = %185
%196 = add nsw i32 %186, 1
br label %197
197: ; preds = %195, %192
%198 = phi i32 [ %186, %192 ], [ %196, %195 ]
%199 = load i32, i32* %7
%200 = icmp slt i32 %198, %199
br i1 %200, label %185, label %201
201: ; preds = %197, %178, %174
br label %222
202: ; preds = %172, %214
%203 = phi i32 [ %215, %214 ], [ %99, %172 ]
%204 = call i32 @read(i32 %203, i8* %41, i32 512)
switch i32 %204, label %214 [
i32 -1, label %205
i32 0, label %217
]
205: ; preds = %202
%206 = load i64, i64* @errno
%207 = load i64, i64* @EAGAIN
%208 = icmp eq i64 %206, %207
%209 = load i64, i64* @EWOULDBLOCK
%210 = icmp eq i64 %206, %209
%211 = select i1 %208, i1 true, i1 %210
br i1 %211, label %216, label %212
212: ; preds = %205
%213 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
br label %217
214: ; preds = %202
%215 = load i32, i32* %98
br label %202
216: ; preds = %205
br label %222
217: ; preds = %202, %212
%218 = load i32, i32* %98
%219 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.6, i64 0, i64 0), i32 %218)
%220 = load i32, i32* %98
%221 = call i32 @remove_client(i32 %220, i32* %40, i32* %7)
br label %222
222: ; preds = %95, %216, %217, %201, %161
%223 = add nuw nsw i64 %79, 1
%224 = icmp eq i64 %223, %77
br i1 %224, label %46, label %78
225: ; preds = %87, %49, %53, %22, %25
%226 = load i32, i32* %7
%227 = icmp sgt i32 %226, 0
br i1 %227, label %228, label %237
228: ; preds = %225, %228
%229 = phi i64 [ %233, %228 ], [ 0, %225 ]
%230 = getelementptr inbounds [32 x i32], [32 x i32]* %6, i64 0, i64 %229
%231 = load i32, i32* %230
%232 = call i32 @close(i32 %231)
%233 = add nuw nsw i64 %229, 1
%234 = load i32, i32* %7
%235 = sext i32 %234 to i64
%236 = icmp slt i64 %233, %235
br i1 %236, label %228, label %237
237: ; preds = %228, %225
%238 = icmp sgt i32 %18, -1
br i1 %238, label %239, label %241
239: ; preds = %237
%240 = call i32 @close(i32 %18)
br label %241
241: ; preds = %20, %239, %237
ret void
}