#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 */

/* Type definitions */
struct sockaddr_storage {
  int ss_family;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_family;
  int /*<<< orphan*/ ai_addrlen;
  struct sockaddr *ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int pid_t;
typedef int /*<<< orphan*/ hostname;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int const AF_INET;
int const AF_INET6;
int const AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
scalar_t__ EAGAIN;
int const EAI_BADFLAGS;
int const EAI_SOCKTYPE;
int const EAI_SYSTEM;
scalar_t__ EBADF;
scalar_t__ EDESTADDRREQ;
scalar_t__ EHOSTDOWN;
scalar_t__ EHOSTUNREACH;
scalar_t__ EINVAL;
scalar_t__ EISCONN;
scalar_t__ ENETDOWN;
scalar_t__ ENETUNREACH;
scalar_t__ ENONET;
scalar_t__ ENOPROTOOPT;
scalar_t__ ENOTSOCK;
scalar_t__ EOPNOTSUPP;
scalar_t__ EPROTO;
scalar_t__ EWOULDBLOCK;
int EXIT_SUCCESS;
int EX_OSERR;
int /*<<< orphan*/ HOST_NAME_MAX;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int /*<<< orphan*/ SO_REUSEPORT;
int /*<<< orphan*/ TCP_NODELAY;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ addr_str(int, struct sockaddr *);
int /*<<< orphan*/ af_name(int);
int /*<<< orphan*/ assert(int);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ gai_strerror(int const);
int getaddrinfo(char const *const, char const *const, struct addrinfo *,
                struct addrinfo **);
int gethostname(char *, int);
int listen(int, int /*<<< orphan*/);
int lsdir(char const *const, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ *open_memstream(char **, size_t *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int const *, int);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int socksend(int, char *, size_t);
int /*<<< orphan*/ warn(char *, ...);
int /*<<< orphan*/ warnx(char *, ...);
int main_d(const bool detach, const bool safe, const bool keep,
           const int net_fam, const char *const rootdir, const char *const host,
           const char *const port) {
  assert(net_fam == AF_INET || net_fam == AF_INET6 || net_fam == AF_UNSPEC);
  assert(rootdir != NULL);
  assert(port != NULL);
  {
    char hostname[HOST_NAME_MAX + 1];
    if (gethostname(hostname, sizeof(hostname)) == -1)
      warn("Cannot get local hostname");
    else
      warnx("Hostname: %s", hostname);
  }
  struct addrinfo *ai = NULL;
  const struct addrinfo *ai_p = NULL;
  struct addrinfo hints;
  (void)memset(&hints, 0, sizeof(struct addrinfo));
  hints.ai_family = net_fam;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  const int eai = getaddrinfo(host, port, &hints, &ai);
  assert(eai != EAI_SOCKTYPE);
  assert(eai != EAI_BADFLAGS);
  if (eai != 0) {
    if (eai == EAI_SYSTEM)
      warn("Cannot get local address info (sys)");
    else
      warnx("Cannot get local address info (net): %s", gai_strerror(eai));
    freeaddrinfo(ai);
    return (EX_OSERR);
  }
  int sock = -1;
  const int opt = 1;
  for (ai_p = ai; ai_p; ai_p = ai_p->ai_next) {
    warnx("Trying to listen on %s address `%s'", af_name(ai_p->ai_family),
          addr_str(ai_p->ai_family, ai_p->ai_addr));
    sock = socket(ai_p->ai_family, ai_p->ai_socktype, ai_p->ai_protocol);
    if (sock == -1) {
      warn("  FAILED: Cannot create socket");
      continue;
    }
    (void)setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(int));
    (void)setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(int));
    (void)setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof(int));
    if (bind(sock, ai_p->ai_addr, ai_p->ai_addrlen) == -1) {
      assert(errno != EBADF);
      assert(errno != ENOTSOCK);
      assert(errno != EINVAL);
      assert(errno != EISCONN);
      warn("  FAILED: Cannot bind socket");
      (void)close(sock);
      continue;
    }
    if (listen(sock, 0) == -1) {
      assert(errno != EBADF);
      assert(errno != EDESTADDRREQ);
      assert(errno != EINVAL);
      assert(errno != ENOTSOCK);
      warn("  FAILED: Cannot listen on socket");
      (void)close(sock);
      continue;
    }
    warnx("  SUCCESS: Listening on port %s", port);
    break;
  }
  freeaddrinfo(ai);
  if (ai_p == NULL)
    return (EX_OSERR);
  if (detach) {
    pid_t pid = fork();
    switch (pid) {
    case -1:
      warn("Cannot detach process");
      (void)close(sock);
      return (EX_OSERR);
    case 0:
      break;
    default:
      warnx("Forked child with PID %d", pid);
      return (EXIT_SUCCESS);
    }
  }
  char *dirlist = NULL;
  size_t dirlist_len = 0;
  FILE *dirlist_f = NULL;
  dirlist_f = open_memstream(&dirlist, &dirlist_len);
  if (dirlist_f == NULL) {
    warn("Cannot allocate memory for directory listing");
    return (EX_OSERR);
  }
  if (lsdir(rootdir, dirlist_f) == false || fwrite("\0", 1, 1, dirlist_f) < 1) {
    warn("Cannot load directory listing for `%s'", rootdir);
    (void)close(sock);
    (void)fclose(dirlist_f);
    free(dirlist);
    return (EX_OSERR);
  }
  (void)fclose(dirlist_f);
  warnx("Loaded directory `%s'", rootdir);
  int csock = -1;
  struct sockaddr_storage addr;
  socklen_t addr_len;
  errno = 0;
  do {
    assert(errno != EWOULDBLOCK);
    assert(errno != EAGAIN);
    addr_len = sizeof(struct sockaddr_storage);
    csock = accept(sock, (struct sockaddr *)&addr, &addr_len);
  } while (csock == -1 &&
           (errno == EHOSTUNREACH || errno == EHOSTDOWN ||
            errno == ENETUNREACH || errno == ENETDOWN || errno == ENOPROTOOPT ||
            errno == ENONET || errno == EOPNOTSUPP || errno == EPROTO));
  if (csock == -1) {
    assert(errno != EWOULDBLOCK);
    assert(errno != EAGAIN);
    warn("Cannot accept connection");
    (void)close(sock);
    free(dirlist);
    return (EX_OSERR);
  }
  (void)close(sock);
  warnx("Accepted connection from %s address `%s'", af_name(addr.ss_family),
        addr_str(addr.ss_family, (struct sockaddr *)&addr));
  if (socksend(csock, dirlist, dirlist_len) == false) {
    warn("Cannot send directory listing");
    (void)close(csock);
    free(dirlist);
    return (EX_OSERR);
  }
  warnx("Sent directory listing");
  (void)close(csock);
  free(dirlist);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main_d>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    0x10(%rbp),%rax
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    %r9,-0x28(%rbp)
mov    -0x14(%rbp),%ecx
mov    $0x1,%al
mov    0x2d21(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xa5(%rbp)
je     22dc <main_d+0x6c>
mov    -0x14(%rbp),%ecx
mov    $0x1,%al
mov    0x2caf(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0xa5(%rbp)
je     22dc <main_d+0x6c>
mov    -0x14(%rbp),%eax
mov    0x2ce7(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
mov    %al,-0xa5(%rbp)
mov    -0xa5(%rbp),%al
movzbl %al,%edi
and    $0x1,%edi
call   20d0 <assert@plt>
mov    -0x20(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x10(%rbp),%rax
test   %rax,%rax
setne  %al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2c98(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xb0(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    %eax,%esi
call   2140 <gethostname@plt>
cmp    $0xffffffff,%eax
jne    2366 <main_d+0xf6>
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
jmp    237b <main_d+0x10b>
mov    -0xb0(%rbp),%rsi
lea    0xcc0(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   20b0 <memset@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    0x2b81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2c0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x10(%rbp),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   2160 <getaddrinfo@plt>
mov    %eax,-0x74(%rbp)
mov    -0x74(%rbp),%eax
mov    0x2c0e(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    -0x74(%rbp),%eax
mov    0x2b5d(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
cmpl   $0x0,-0x74(%rbp)
je     246b <main_d+0x1fb>
mov    -0x74(%rbp),%eax
mov    0x2b52(%rip),%rcx
cmp    (%rcx),%eax
jne    2439 <main_d+0x1c9>
lea    0xc14(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
jmp    2451 <main_d+0x1e1>
mov    -0x74(%rbp),%edi
call   20a0 <gai_strerror@plt>
mov    %eax,%esi
lea    0xc1b(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    -0x40(%rbp),%rdi
call   2180 <freeaddrinfo@plt>
mov    0x2a97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
movl   $0xffffffff,-0x78(%rbp)
movl   $0x1,-0x7c(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     2704 <main_d+0x494>
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
call   20e0 <af_name@plt>
mov    %eax,-0xb4(%rbp)
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rsi
call   2120 <addr_str@plt>
mov    -0xb4(%rbp),%esi
mov    %eax,%edx
lea    0xbce(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    -0x48(%rbp),%rax
mov    (%rax),%edi
mov    -0x48(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x48(%rbp),%rax
mov    0x10(%rax),%edx
call   2190 <socket@plt>
mov    %eax,-0x78(%rbp)
cmpl   $0xffffffff,-0x78(%rbp)
jne    24ff <main_d+0x28f>
lea    0xbbe(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
jmp    26f3 <main_d+0x483>
mov    -0x78(%rbp),%edi
mov    0x2ad7(%rip),%rax
mov    (%rax),%esi
mov    0x29de(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    -0x78(%rbp),%edi
mov    0x2ab3(%rip),%rax
mov    (%rax),%esi
mov    0x2a5a(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    -0x78(%rbp),%edi
mov    0x2a27(%rip),%rax
mov    (%rax),%esi
mov    0x2a7e(%rip),%rax
mov    (%rax),%edx
lea    -0x7c(%rbp),%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    -0x78(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x48(%rbp),%rax
mov    0x4(%rax),%edx
call   2110 <bind@plt>
cmp    $0xffffffff,%eax
jne    262a <main_d+0x3ba>
mov    0x2996(%rip),%rax
mov    (%rax),%rax
mov    0x2974(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2975(%rip),%rax
mov    (%rax),%rax
mov    0x2983(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2954(%rip),%rax
mov    (%rax),%rax
mov    0x293a(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2933(%rip),%rax
mov    (%rax),%rax
mov    0x2981(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
lea    0xaba(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
jmp    26f3 <main_d+0x483>
mov    -0x78(%rbp),%edi
xor    %esi,%esi
call   20f0 <listen@plt>
cmp    $0xffffffff,%eax
jne    26dc <main_d+0x46c>
mov    0x28e4(%rip),%rax
mov    (%rax),%rax
mov    0x28c2(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x28c3(%rip),%rax
mov    (%rax),%rax
mov    0x28f1(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x28a2(%rip),%rax
mov    (%rax),%rax
mov    0x2888(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2881(%rip),%rax
mov    (%rax),%rax
mov    0x288f(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
lea    0xa25(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
jmp    26f3 <main_d+0x483>
mov    0x10(%rbp),%rsi
lea    0xa28(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
jmp    2704 <main_d+0x494>
mov    -0x48(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x48(%rbp)
jmp    2481 <main_d+0x211>
mov    -0x40(%rbp),%rdi
call   2180 <freeaddrinfo@plt>
cmpq   $0x0,-0x48(%rbp)
jne    2729 <main_d+0x4b9>
mov    0x27d9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
cmpl   $0x0,-0x8(%rbp)
je     27ba <main_d+0x54a>
xor    %eax,%eax
call   2170 <fork@plt>
mov    %eax,-0x80(%rbp)
mov    -0x80(%rbp),%eax
mov    %eax,-0xb8(%rbp)
sub    $0xffffffff,%eax
je     2767 <main_d+0x4f7>
jmp    2754 <main_d+0x4e4>
mov    -0xb8(%rbp),%eax
test   %eax,%eax
je     278e <main_d+0x51e>
jmp    2793 <main_d+0x523>
lea    0x9c1(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
mov    0x2774(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
jmp    27b5 <main_d+0x545>
mov    -0x80(%rbp),%esi
lea    0x9a8(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    0x275d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
jmp    27ba <main_d+0x54a>
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0x98(%rbp)
lea    -0x88(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   2040 <open_memstream@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    2822 <main_d+0x5b2>
lea    0x954(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    0x26e0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
mov    -0x20(%rbp),%rdi
mov    -0x98(%rbp),%rsi
call   2060 <lsdir@plt>
cmp    $0x0,%eax
je     285e <main_d+0x5ee>
mov    -0x98(%rbp),%rcx
lea    0x7cf(%rip),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   2150 <fwrite@plt>
cmp    $0x1,%eax
jge    28a1 <main_d+0x631>
mov    -0x20(%rbp),%rsi
lea    0x922(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
mov    -0x98(%rbp),%rdi
call   2080 <fclose@plt>
mov    -0x88(%rbp),%rdi
call   2030 <free@plt>
mov    0x2661(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
mov    -0x98(%rbp),%rdi
call   2080 <fclose@plt>
mov    -0x20(%rbp),%rsi
lea    0x8fa(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
movl   $0xffffffff,-0x9c(%rbp)
ff ff ff
mov    0x2658(%rip),%rax
movq   $0x0,(%rax)
mov    0x264a(%rip),%rax
mov    (%rax),%rax
mov    0x2638(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x2629(%rip),%rax
mov    (%rax),%rax
mov    0x25d7(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
movl   $0x4,-0xa4(%rbp)
mov    -0x78(%rbp),%edi
lea    -0xa0(%rbp),%rsi
lea    -0xa4(%rbp),%rdx
call   2130 <accept@plt>
mov    %eax,-0x9c(%rbp)
xor    %eax,%eax
cmpl   $0xffffffff,-0x9c(%rbp)
mov    %al,-0xb9(%rbp)
jne    2a6b <main_d+0x7fb>
mov    0x25cd(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2621(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x25ab(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2577(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x2589(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x25fd(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x2567(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x25d3(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x2545(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x25e1(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x2523(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2587(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x2501(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2505(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0xba(%rbp)
je     2a5f <main_d+0x7ef>
mov    0x24df(%rip),%rax
mov    (%rax),%rax
mov    0x24f5(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0xba(%rbp)
mov    -0xba(%rbp),%al
mov    %al,-0xb9(%rbp)
mov    -0xb9(%rbp),%al
test   $0x1,%al
jne    28d7 <main_d+0x667>
cmpl   $0xffffffff,-0x9c(%rbp)
jne    2afb <main_d+0x88b>
mov    0x249b(%rip),%rax
mov    (%rax),%rax
mov    0x2489(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
mov    0x247a(%rip),%rax
mov    (%rax),%rax
mov    0x2428(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   20d0 <assert@plt>
lea    0x6f9(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
mov    -0x88(%rbp),%rdi
call   2030 <free@plt>
mov    0x2407(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
mov    -0x78(%rbp),%edi
call   20c0 <close@plt>
mov    -0xa0(%rbp),%edi
call   20e0 <af_name@plt>
mov    %eax,-0xc0(%rbp)
mov    -0xa0(%rbp),%edi
lea    -0xa0(%rbp),%rsi
call   2120 <addr_str@plt>
mov    -0xc0(%rbp),%esi
mov    %eax,%edx
lea    0x6ac(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    -0x9c(%rbp),%edi
mov    -0x88(%rbp),%rsi
mov    -0x90(%rbp),%rdx
call   2100 <socksend@plt>
cmp    $0x0,%eax
jne    2b94 <main_d+0x924>
lea    0x6a5(%rip),%rdi
mov    $0x0,%al
call   2050 <warn@plt>
mov    -0x9c(%rbp),%edi
call   20c0 <close@plt>
mov    -0x88(%rbp),%rdi
call   2030 <free@plt>
mov    0x236e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    2bc5 <main_d+0x955>
lea    0x68d(%rip),%rdi
mov    $0x0,%al
call   2090 <warnx@plt>
mov    -0x9c(%rbp),%edi
call   20c0 <close@plt>
mov    -0x88(%rbp),%rdi
call   2030 <free@plt>
mov    0x2348(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main_d>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %r9,%r14
mov    %r8,%r13
mov    %ecx,%r15d
mov    %edi,-0x44(%rbp)
xor    %edi,%edi
test   %ecx,%ecx
sete   %dil
call   20d0 <assert@plt>
xor    %edi,%edi
test   %r13,%r13
setne  %dil
call   20d0 <assert@plt>
xor    %edi,%edi
cmpq   $0x0,0x10(%rbp)
setne  %dil
call   20d0 <assert@plt>
mov    %rsp,%r12
mov    0x2d06(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %rsp,%rbx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   2140 <gethostname@plt>
cmp    $0xffffffff,%eax
je     22f8 <main_d+0x88>
lea    0xd48(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   2090 <warnx@plt>
jmp    2306 <main_d+0x96>
lea    0xd1b(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    %r12,%rsp
movq   $0x0,-0x38(%rbp)
lea    -0x88(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   20b0 <memset@plt>
mov    %r15d,-0x88(%rbp)
mov    0x2c2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2c8f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
lea    -0x38(%rbp),%rcx
mov    %r14,%rdi
mov    0x10(%rbp),%rsi
mov    %rbx,%rdx
call   2160 <getaddrinfo@plt>
mov    %eax,%r14d
xor    %ebx,%ebx
test   %eax,%eax
setne  %bl
mov    %ebx,%edi
call   20d0 <assert@plt>
mov    %ebx,%edi
call   20d0 <assert@plt>
test   %r14d,%r14d
je     23af <main_d+0x13f>
mov    %r14d,%edi
call   20a0 <gai_strerror@plt>
lea    0xcbc(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   2090 <warnx@plt>
mov    -0x38(%rbp),%rdi
call   2180 <freeaddrinfo@plt>
mov    0x2b8a(%rip),%rax
mov    (%rax),%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
movl   $0x1,-0x4c(%rbp)
mov    -0x38(%rbp),%r14
test   %r14,%r14
je     25aa <main_d+0x33a>
mov    %r13,-0x60(%rbp)
mov    0x2c1a(%rip),%r13
lea    -0x4c(%rbp),%r12
mov    0x2b7f(%rip),%r15
jmp    23f7 <main_d+0x187>
nopl   0x0(%rax,%rax,1)
lea    0xca6(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    0x18(%r14),%r14
test   %r14,%r14
je     238e <main_d+0x11e>
mov    (%r14),%edi
call   20e0 <af_name@plt>
mov    %eax,%ebx
mov    (%r14),%edi
mov    0x8(%r14),%rsi
call   2120 <addr_str@plt>
lea    0xc55(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   2090 <warnx@plt>
mov    0x14(%r14),%esi
mov    (%r14),%edi
mov    0x10(%r14),%edx
call   2190 <socket@plt>
cmp    $0xffffffff,%eax
je     23e0 <main_d+0x170>
mov    %eax,%ebx
mov    0x0(%r13),%esi
mov    0x2adf(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    0x0(%r13),%esi
mov    0x2b4a(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    0x2b19(%rip),%rax
mov    (%rax),%esi
mov    0x2b60(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    %r12,%rcx
mov    $0x4,%r8d
call   2070 <setsockopt@plt>
mov    0x8(%r14),%rsi
mov    0x4(%r14),%edx
mov    %ebx,%edi
call   2110 <bind@plt>
cmp    $0xffffffff,%eax
je     2530 <main_d+0x2c0>
mov    %ebx,%edi
xor    %esi,%esi
call   20f0 <listen@plt>
cmp    $0xffffffff,%eax
jne    25b1 <main_d+0x341>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a78(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2aa8(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a50(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a60(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
lea    0xba6(%rip),%rdi
jmp    2597 <main_d+0x327>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a04(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a1c(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x29dc(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2a14(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
lea    0xb15(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    %ebx,%edi
call   20c0 <close@plt>
jmp    23ee <main_d+0x17e>
xor    %edi,%edi
jmp    2392 <main_d+0x122>
lea    0xb33(%rip),%rdi
mov    0x10(%rbp),%rsi
xor    %eax,%eax
call   2090 <warnx@plt>
mov    -0x38(%rbp),%rdi
call   2180 <freeaddrinfo@plt>
cmpl   $0x0,-0x44(%rbp)
je     2600 <main_d+0x390>
xor    %eax,%eax
call   2170 <fork@plt>
test   %eax,%eax
je     2600 <main_d+0x390>
cmp    $0xffffffff,%eax
jne    27d1 <main_d+0x561>
lea    0xb1e(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    %ebx,%edi
call   20c0 <close@plt>
jmp    2397 <main_d+0x127>
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x58(%rbp)
lea    -0x40(%rbp),%rdi
lea    -0x58(%rbp),%rsi
call   2040 <open_memstream@plt>
test   %rax,%rax
je     27be <main_d+0x54e>
mov    %rax,%r14
mov    -0x60(%rbp),%r13
mov    %r13,%rdi
mov    %rax,%rsi
call   2060 <lsdir@plt>
test   %eax,%eax
je     2790 <main_d+0x520>
lea    0x9d1(%rip),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   2150 <fwrite@plt>
test   %eax,%eax
jle    2790 <main_d+0x520>
mov    %r14,%rdi
call   2080 <fclose@plt>
lea    0xb1e(%rip),%rdi
xor    %r12d,%r12d
mov    %r13,%rsi
xor    %eax,%eax
call   2090 <warnx@plt>
movq   $0x0,(%r15)
lea    -0x30(%rbp),%r14
lea    -0x48(%rbp),%r13
xor    %edi,%edi
mov    0x28bb(%rip),%rax
cmp    (%rax),%r12
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x2863(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
movl   $0x4,-0x48(%rbp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r13,%rdx
call   2130 <accept@plt>
cmp    $0xffffffff,%eax
jne    27ed <main_d+0x57d>
mov    (%r15),%r12
mov    0x28c0(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x2844(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x28c8(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x28b4(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x28c8(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x2890(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x2838(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
mov    0x2838(%rip),%rax
cmp    (%rax),%r12
je     268c <main_d+0x41c>
xor    %edi,%edi
mov    0x27fe(%rip),%rax
cmp    (%rax),%r12
setne  %dil
call   20d0 <assert@plt>
mov    (%r15),%rax
xor    %edi,%edi
mov    0x27a6(%rip),%rcx
cmp    (%rcx),%rax
setne  %dil
call   20d0 <assert@plt>
lea    0xa27(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    0x279d(%rip),%r14
jmp    2862 <main_d+0x5f2>
lea    0x9d0(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   2050 <warn@plt>
mov    %ebx,%edi
call   20c0 <close@plt>
mov    %r14,%rdi
call   2080 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   2030 <free@plt>
jmp    2397 <main_d+0x127>
lea    0x975(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
jmp    2397 <main_d+0x127>
lea    0x949(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   2090 <warnx@plt>
mov    0x2750(%rip),%rax
jmp    239e <main_d+0x12e>
mov    %eax,%r12d
mov    %ebx,%edi
call   20c0 <close@plt>
mov    -0x30(%rbp),%edi
call   20e0 <af_name@plt>
mov    %eax,%ebx
mov    -0x30(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   2120 <addr_str@plt>
lea    0x9a9(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
xor    %eax,%eax
call   2090 <warnx@plt>
mov    -0x40(%rbp),%rsi
mov    -0x58(%rbp),%rdx
mov    %r12d,%edi
call   2100 <socksend@plt>
test   %eax,%eax
je     284a <main_d+0x5da>
lea    0x9ca(%rip),%rdi
xor    %eax,%eax
call   2090 <warnx@plt>
mov    0x26f0(%rip),%r14
jmp    285f <main_d+0x5ef>
lea    0x995(%rip),%rdi
xor    %eax,%eax
call   2050 <warn@plt>
mov    0x26c9(%rip),%r14
mov    %r12d,%ebx
mov    %ebx,%edi
call   20c0 <close@plt>
mov    -0x40(%rbp),%rdi
call   2030 <free@plt>
mov    (%r14),%eax
jmp    23a0 <main_d+0x130>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, %struct.sockaddr*, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
@AF_INET = constant i32 0
@AF_INET6 = constant i32 0
@AF_UNSPEC = constant i32 0
@HOST_NAME_MAX = global i32 0
@.str = [26 x i8] c"Cannot get local hostname\00"
@.str.1 = [13 x i8] c"Hostname: %s\00"
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@EAI_SOCKTYPE = constant i32 0
@EAI_BADFLAGS = constant i32 0
@EAI_SYSTEM = constant i32 0
@.str.2 = [36 x i8] c"Cannot get local address info (sys)\00"
@.str.3 = [40 x i8] c"Cannot get local address info (net): %s\00"
@EX_OSERR = global i32 0
@.str.4 = [36 x i8] c"Trying to listen on %s address `%s'\00"
@.str.5 = [31 x i8] c" FAILED: Cannot create socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_REUSEPORT = global i32 0
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@errno = global i64 0
@EBADF = global i64 0
@ENOTSOCK = global i64 0
@EINVAL = global i64 0
@EISCONN = global i64 0
@.str.6 = [29 x i8] c" FAILED: Cannot bind socket\00"
@EDESTADDRREQ = global i64 0
@.str.7 = [34 x i8] c" FAILED: Cannot listen on socket\00"
@.str.8 = [32 x i8] c" SUCCESS: Listening on port %s\00"
@.str.9 = [22 x i8] c"Cannot detach process\00"
@.str.10 = [25 x i8] c"Forked child with PID %d\00"
@EXIT_SUCCESS = global i32 0
@.str.11 = [45 x i8] c"Cannot allocate memory for directory listing\00"
@.str.12 = [2 x i8] zeroinitializer
@.str.13 = [39 x i8] c"Cannot load directory listing for `%s'\00"
@.str.14 = [22 x i8] c"Loaded directory `%s'\00"
@EWOULDBLOCK = global i64 0
@EAGAIN = global i64 0
@EHOSTUNREACH = global i64 0
@EHOSTDOWN = global i64 0
@ENETUNREACH = global i64 0
@ENETDOWN = global i64 0
@ENOPROTOOPT = global i64 0
@ENONET = global i64 0
@EOPNOTSUPP = global i64 0
@EPROTO = global i64 0
@.str.15 = [25 x i8] c"Cannot accept connection\00"
@.str.16 = [41 x i8] c"Accepted connection from %s address `%s'\00"
@.str.17 = [30 x i8] c"Cannot send directory listing\00"
@.str.18 = [23 x i8] c"Sent directory listing\00"
define i32 @main_d(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca %struct.addrinfo*
%19 = alloca %struct.addrinfo*
%20 = alloca %struct.addrinfo
%21 = alloca i32
%22 = alloca i32
%23 = alloca i32
%24 = alloca i32
%25 = alloca i8*
%26 = alloca i64
%27 = alloca i32*
%28 = alloca i32
%29 = alloca %struct.sockaddr_storage
%30 = alloca i32
store i32 %0, i32* %9
store i32 %1, i32* %10
store i32 %2, i32* %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i8* %6, i8** %15
%31 = load i32, i32* %12
%32 = load i32, i32* @AF_INET
%33 = icmp eq i32 %31, %32
br i1 %33, label %42, label %34
34: ; preds = %7
%35 = load i32, i32* %12
%36 = load i32, i32* @AF_INET6
%37 = icmp eq i32 %35, %36
br i1 %37, label %42, label %38
38: ; preds = %34
%39 = load i32, i32* %12
%40 = load i32, i32* @AF_UNSPEC
%41 = icmp eq i32 %39, %40
br label %42
42: ; preds = %38, %34, %7
%43 = phi i1 [ true, %34 ], [ true, %7 ], [ %41, %38 ]
%44 = zext i1 %43 to i32
%45 = call i32 @assert(i32 %44)
%46 = load i8*, i8** %13
%47 = icmp ne i8* %46, null
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = load i8*, i8** %15
%51 = icmp ne i8* %50, null
%52 = zext i1 %51 to i32
%53 = call i32 @assert(i32 %52)
%54 = load i32, i32* @HOST_NAME_MAX
%55 = add nsw i32 %54, 1
%56 = zext i32 %55 to i64
%57 = call i8* @llvm.stacksave()
store i8* %57, i8** %16
%58 = alloca i8, i64 %56
store i64 %56, i64* %17
%59 = trunc i64 %56 to i32
%60 = call i32 @gethostname(i8* %58, i32 %59)
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %64
62: ; preds = %42
%63 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %66
64: ; preds = %42
%65 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %58)
br label %66
66: ; preds = %64, %62
%67 = load i8*, i8** %16
store %struct.addrinfo* null, %struct.addrinfo** %18
store %struct.addrinfo* null, %struct.addrinfo** %19
%68 = call i32 @memset(%struct.addrinfo* %20, i32 0, i32 40)
%69 = load i32, i32* %12
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 0
store i32 %69, i32* %70
%71 = load i32, i32* @SOCK_STREAM
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 4
store i32 %71, i32* %72
%73 = load i32, i32* @AI_PASSIVE
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 6
store i32 %73, i32* %74
%75 = load i8*, i8** %14
%76 = load i8*, i8** %15
%77 = call i32 @getaddrinfo(i8* %75, i8* %76, %struct.addrinfo* %20, %struct.addrinfo** %18)
store i32 %77, i32* %21
%78 = load i32, i32* %21
%79 = load i32, i32* @EAI_SOCKTYPE
%80 = icmp ne i32 %78, %79
%81 = zext i1 %80 to i32
%82 = call i32 @assert(i32 %81)
%83 = load i32, i32* %21
%84 = load i32, i32* @EAI_BADFLAGS
%85 = icmp ne i32 %83, %84
%86 = zext i1 %85 to i32
%87 = call i32 @assert(i32 %86)
%88 = load i32, i32* %21
%89 = icmp ne i32 %88, 0
br i1 %89, label %90, label %104
90: ; preds = %66
%91 = load i32, i32* %21
%92 = load i32, i32* @EAI_SYSTEM
%93 = icmp eq i32 %91, %92
br i1 %93, label %94, label %96
94: ; preds = %90
%95 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %100
96: ; preds = %90
%97 = load i32, i32* %21
%98 = call i32 @gai_strerror(i32 %97)
%99 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %96, %94
%101 = load %struct.addrinfo*, %struct.addrinfo** %18
%102 = call i32 @freeaddrinfo(%struct.addrinfo* %101)
%103 = load i32, i32* @EX_OSERR
store i32 %103, i32* %8
br label %375
104: ; preds = %66
store i32 -1, i32* %22
store i32 1, i32* %23
%105 = load %struct.addrinfo*, %struct.addrinfo** %18
store %struct.addrinfo* %105, %struct.addrinfo** %19
br label %106
106: ; preds = %213, %104
%107 = load %struct.addrinfo*, %struct.addrinfo** %19
%108 = icmp ne %struct.addrinfo* %107, null
br i1 %108, label %109, label %217
109: ; preds = %106
%110 = load %struct.addrinfo*, %struct.addrinfo** %19
%111 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %110, i32 0, i32 0
%112 = load i32, i32* %111
%113 = call i32 @af_name(i32 %112)
%114 = load %struct.addrinfo*, %struct.addrinfo** %19
%115 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %114, i32 0, i32 0
%116 = load i32, i32* %115
%117 = load %struct.addrinfo*, %struct.addrinfo** %19
%118 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %117, i32 0, i32 2
%119 = load %struct.sockaddr*, %struct.sockaddr** %118
%120 = call i32 @addr_str(i32 %116, %struct.sockaddr* %119)
%121 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %113, i32 %120)
%122 = load %struct.addrinfo*, %struct.addrinfo** %19
%123 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %122, i32 0, i32 0
%124 = load i32, i32* %123
%125 = load %struct.addrinfo*, %struct.addrinfo** %19
%126 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %125, i32 0, i32 4
%127 = load i32, i32* %126
%128 = load %struct.addrinfo*, %struct.addrinfo** %19
%129 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %128, i32 0, i32 3
%130 = load i32, i32* %129
%131 = call i32 @socket(i32 %124, i32 %127, i32 %130)
store i32 %131, i32* %22
%132 = load i32, i32* %22
%133 = icmp eq i32 %132, -1
br i1 %133, label %134, label %136
134: ; preds = %109
%135 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %213
136: ; preds = %109
%137 = load i32, i32* %22
%138 = load i32, i32* @SOL_SOCKET
%139 = load i32, i32* @SO_REUSEADDR
%140 = call i32 @setsockopt(i32 %137, i32 %138, i32 %139, i32* %23, i32 4)
%141 = load i32, i32* %22
%142 = load i32, i32* @SOL_SOCKET
%143 = load i32, i32* @SO_REUSEPORT
%144 = call i32 @setsockopt(i32 %141, i32 %142, i32 %143, i32* %23, i32 4)
%145 = load i32, i32* %22
%146 = load i32, i32* @IPPROTO_TCP
%147 = load i32, i32* @TCP_NODELAY
%148 = call i32 @setsockopt(i32 %145, i32 %146, i32 %147, i32* %23, i32 4)
%149 = load i32, i32* %22
%150 = load %struct.addrinfo*, %struct.addrinfo** %19
%151 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %150, i32 0, i32 2
%152 = load %struct.sockaddr*, %struct.sockaddr** %151
%153 = load %struct.addrinfo*, %struct.addrinfo** %19
%154 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %153, i32 0, i32 1
%155 = load i32, i32* %154
%156 = call i32 @bind(i32 %149, %struct.sockaddr* %152, i32 %155)
%157 = icmp eq i32 %156, -1
br i1 %157, label %158, label %182
158: ; preds = %136
%159 = load i64, i64* @errno
%160 = load i64, i64* @EBADF
%161 = icmp ne i64 %159, %160
%162 = zext i1 %161 to i32
%163 = call i32 @assert(i32 %162)
%164 = load i64, i64* @errno
%165 = load i64, i64* @ENOTSOCK
%166 = icmp ne i64 %164, %165
%167 = zext i1 %166 to i32
%168 = call i32 @assert(i32 %167)
%169 = load i64, i64* @errno
%170 = load i64, i64* @EINVAL
%171 = icmp ne i64 %169, %170
%172 = zext i1 %171 to i32
%173 = call i32 @assert(i32 %172)
%174 = load i64, i64* @errno
%175 = load i64, i64* @EISCONN
%176 = icmp ne i64 %174, %175
%177 = zext i1 %176 to i32
%178 = call i32 @assert(i32 %177)
%179 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%180 = load i32, i32* %22
%181 = call i32 @close(i32 %180)
br label %213
182: ; preds = %136
%183 = load i32, i32* %22
%184 = call i32 @listen(i32 %183, i32 0)
%185 = icmp eq i32 %184, -1
br i1 %185, label %186, label %210
186: ; preds = %182
%187 = load i64, i64* @errno
%188 = load i64, i64* @EBADF
%189 = icmp ne i64 %187, %188
%190 = zext i1 %189 to i32
%191 = call i32 @assert(i32 %190)
%192 = load i64, i64* @errno
%193 = load i64, i64* @EDESTADDRREQ
%194 = icmp ne i64 %192, %193
%195 = zext i1 %194 to i32
%196 = call i32 @assert(i32 %195)
%197 = load i64, i64* @errno
%198 = load i64, i64* @EINVAL
%199 = icmp ne i64 %197, %198
%200 = zext i1 %199 to i32
%201 = call i32 @assert(i32 %200)
%202 = load i64, i64* @errno
%203 = load i64, i64* @ENOTSOCK
%204 = icmp ne i64 %202, %203
%205 = zext i1 %204 to i32
%206 = call i32 @assert(i32 %205)
%207 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%208 = load i32, i32* %22
%209 = call i32 @close(i32 %208)
br label %213
210: ; preds = %182
%211 = load i8*, i8** %15
%212 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %211)
br label %217
213: ; preds = %186, %158, %134
%214 = load %struct.addrinfo*, %struct.addrinfo** %19
%215 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %214, i32 0, i32 5
%216 = load %struct.addrinfo*, %struct.addrinfo** %215
store %struct.addrinfo* %216, %struct.addrinfo** %19
br label %106
217: ; preds = %210, %106
%218 = load %struct.addrinfo*, %struct.addrinfo** %18
%219 = call i32 @freeaddrinfo(%struct.addrinfo* %218)
%220 = load %struct.addrinfo*, %struct.addrinfo** %19
%221 = icmp eq %struct.addrinfo* %220, null
br i1 %221, label %222, label %224
222: ; preds = %217
%223 = load i32, i32* @EX_OSERR
store i32 %223, i32* %8
br label %375
224: ; preds = %217
%225 = load i32, i32* %9
%226 = icmp ne i32 %225, 0
br i1 %226, label %227, label %241
227: ; preds = %224
%228 = call i32 (...) @fork()
store i32 %228, i32* %24
%229 = load i32, i32* %24
switch i32 %229, label %236 [
i32 -1, label %230
i32 0, label %235
]
230: ; preds = %227
%231 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%232 = load i32, i32* %22
%233 = call i32 @close(i32 %232)
%234 = load i32, i32* @EX_OSERR
store i32 %234, i32* %8
br label %375
235: ; preds = %227
br label %240
236: ; preds = %227
%237 = load i32, i32* %24
%238 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %237)
%239 = load i32, i32* @EXIT_SUCCESS
store i32 %239, i32* %8
br label %375
240: ; preds = %235
br label %241
241: ; preds = %240, %224
store i8* null, i8** %25
store i64 0, i64* %26
store i32* null, i32** %27
%242 = call i32* @open_memstream(i8** %25, i64* %26)
store i32* %242, i32** %27
%243 = load i32*, i32** %27
%244 = icmp eq i32* %243, null
br i1 %244, label %245, label %248
245: ; preds = %241
%246 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0))
%247 = load i32, i32* @EX_OSERR
store i32 %247, i32* %8
br label %375
248: ; preds = %241
%249 = load i8*, i8** %13
%250 = load i32*, i32** %27
%251 = call i32 @lsdir(i8* %249, i32* %250)
%252 = icmp eq i32 %251, 0
br i1 %252, label %257, label %253
253: ; preds = %248
%254 = load i32*, i32** %27
%255 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1, i32 1, i32* %254)
%256 = icmp slt i32 %255, 1
br i1 %256, label %257, label %267
257: ; preds = %253, %248
%258 = load i8*, i8** %13
%259 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* %258)
%260 = load i32, i32* %22
%261 = call i32 @close(i32 %260)
%262 = load i32*, i32** %27
%263 = call i32 @fclose(i32* %262)
%264 = load i8*, i8** %25
%265 = call i32 @free(i8* %264)
%266 = load i32, i32* @EX_OSERR
store i32 %266, i32* %8
br label %375
267: ; preds = %253
%268 = load i32*, i32** %27
%269 = call i32 @fclose(i32* %268)
%270 = load i8*, i8** %13
%271 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i8* %270)
store i32 -1, i32* %28
store i64 0, i64* @errno
br label %272
272: ; preds = %323, %267
%273 = load i64, i64* @errno
%274 = load i64, i64* @EWOULDBLOCK
%275 = icmp ne i64 %273, %274
%276 = zext i1 %275 to i32
%277 = call i32 @assert(i32 %276)
%278 = load i64, i64* @errno
%279 = load i64, i64* @EAGAIN
%280 = icmp ne i64 %278, %279
%281 = zext i1 %280 to i32
%282 = call i32 @assert(i32 %281)
store i32 4, i32* %30
%283 = load i32, i32* %22
%284 = bitcast %struct.sockaddr_storage* %29 to %struct.sockaddr*
%285 = call i32 @accept(i32 %283, %struct.sockaddr* %284, i32* %30)
store i32 %285, i32* %28
br label %286
286: ; preds = %272
%287 = load i32, i32* %28
%288 = icmp eq i32 %287, -1
br i1 %288, label %289, label %323
289: ; preds = %286
%290 = load i64, i64* @errno
%291 = load i64, i64* @EHOSTUNREACH
%292 = icmp eq i64 %290, %291
br i1 %292, label %321, label %293
293: ; preds = %289
%294 = load i64, i64* @errno
%295 = load i64, i64* @EHOSTDOWN
%296 = icmp eq i64 %294, %295
br i1 %296, label %321, label %297
297: ; preds = %293
%298 = load i64, i64* @errno
%299 = load i64, i64* @ENETUNREACH
%300 = icmp eq i64 %298, %299
br i1 %300, label %321, label %301
301: ; preds = %297
%302 = load i64, i64* @errno
%303 = load i64, i64* @ENETDOWN
%304 = icmp eq i64 %302, %303
br i1 %304, label %321, label %305
305: ; preds = %301
%306 = load i64, i64* @errno
%307 = load i64, i64* @ENOPROTOOPT
%308 = icmp eq i64 %306, %307
br i1 %308, label %321, label %309
309: ; preds = %305
%310 = load i64, i64* @errno
%311 = load i64, i64* @ENONET
%312 = icmp eq i64 %310, %311
br i1 %312, label %321, label %313
313: ; preds = %309
%314 = load i64, i64* @errno
%315 = load i64, i64* @EOPNOTSUPP
%316 = icmp eq i64 %314, %315
br i1 %316, label %321, label %317
317: ; preds = %313
%318 = load i64, i64* @errno
%319 = load i64, i64* @EPROTO
%320 = icmp eq i64 %318, %319
br label %321
321: ; preds = %317, %313, %309, %305, %301, %297, %293, %289
%322 = phi i1 [ true, %313 ], [ true, %309 ], [ true, %305 ], [ true, %301 ], [ true, %297 ], [ true, %293 ], [ true, %289 ], [ %320, %317 ]
br label %323
323: ; preds = %321, %286
%324 = phi i1 [ false, %286 ], [ %322, %321 ]
br i1 %324, label %272, label %325
325: ; preds = %323
%326 = load i32, i32* %28
%327 = icmp eq i32 %326, -1
br i1 %327, label %328, label %345
328: ; preds = %325
%329 = load i64, i64* @errno
%330 = load i64, i64* @EWOULDBLOCK
%331 = icmp ne i64 %329, %330
%332 = zext i1 %331 to i32
%333 = call i32 @assert(i32 %332)
%334 = load i64, i64* @errno
%335 = load i64, i64* @EAGAIN
%336 = icmp ne i64 %334, %335
%337 = zext i1 %336 to i32
%338 = call i32 @assert(i32 %337)
%339 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0))
%340 = load i32, i32* %22
%341 = call i32 @close(i32 %340)
%342 = load i8*, i8** %25
%343 = call i32 @free(i8* %342)
%344 = load i32, i32* @EX_OSERR
store i32 %344, i32* %8
br label %375
345: ; preds = %325
%346 = load i32, i32* %22
%347 = call i32 @close(i32 %346)
%348 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %29, i32 0, i32 0
%349 = load i32, i32* %348
%350 = call i32 @af_name(i32 %349)
%351 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %29, i32 0, i32 0
%352 = load i32, i32* %351
%353 = bitcast %struct.sockaddr_storage* %29 to %struct.sockaddr*
%354 = call i32 @addr_str(i32 %352, %struct.sockaddr* %353)
%355 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i32 %350, i32 %354)
%356 = load i32, i32* %28
%357 = load i8*, i8** %25
%358 = load i64, i64* %26
%359 = call i32 @socksend(i32 %356, i8* %357, i64 %358)
%360 = icmp eq i32 %359, 0
br i1 %360, label %361, label %368
361: ; preds = %345
%362 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.17, i64 0, i64 0))
%363 = load i32, i32* %28
%364 = call i32 @close(i32 %363)
%365 = load i8*, i8** %25
%366 = call i32 @free(i8* %365)
%367 = load i32, i32* @EX_OSERR
store i32 %367, i32* %8
br label %375
368: ; preds = %345
%369 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.18, i64 0, i64 0))
%370 = load i32, i32* %28
%371 = call i32 @close(i32 %370)
%372 = load i8*, i8** %25
%373 = call i32 @free(i8* %372)
%374 = load i32, i32* @EXIT_SUCCESS
store i32 %374, i32* %8
br label %375
375: ; preds = %368, %361, %328, %257, %245, %236, %230, %222, %100
%376 = load i32, i32* %8
ret i32 %376
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, %struct.sockaddr*, i32, i32, %struct.addrinfo*, i32 }
%struct.sockaddr = type { i32 }
%struct.sockaddr_storage = type { i32 }
@AF_INET = constant i32 0
@AF_INET6 = constant i32 0
@AF_UNSPEC = constant i32 0
@HOST_NAME_MAX = global i32 0
@.str = [26 x i8] c"Cannot get local hostname\00"
@.str.1 = [13 x i8] c"Hostname: %s\00"
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@EAI_SOCKTYPE = constant i32 0
@EAI_BADFLAGS = constant i32 0
@EAI_SYSTEM = constant i32 0
@.str.3 = [40 x i8] c"Cannot get local address info (net): %s\00"
@EX_OSERR = global i32 0
@.str.4 = [36 x i8] c"Trying to listen on %s address `%s'\00"
@.str.5 = [31 x i8] c" FAILED: Cannot create socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@SO_REUSEPORT = global i32 0
@IPPROTO_TCP = global i32 0
@TCP_NODELAY = global i32 0
@errno = global i64 0
@EBADF = global i64 0
@ENOTSOCK = global i64 0
@EINVAL = global i64 0
@EISCONN = global i64 0
@.str.6 = [29 x i8] c" FAILED: Cannot bind socket\00"
@EDESTADDRREQ = global i64 0
@.str.7 = [34 x i8] c" FAILED: Cannot listen on socket\00"
@.str.8 = [32 x i8] c" SUCCESS: Listening on port %s\00"
@.str.9 = [22 x i8] c"Cannot detach process\00"
@.str.10 = [25 x i8] c"Forked child with PID %d\00"
@EXIT_SUCCESS = global i32 0
@.str.11 = [45 x i8] c"Cannot allocate memory for directory listing\00"
@.str.12 = [2 x i8] zeroinitializer
@.str.13 = [39 x i8] c"Cannot load directory listing for `%s'\00"
@.str.14 = [22 x i8] c"Loaded directory `%s'\00"
@EWOULDBLOCK = global i64 0
@EAGAIN = global i64 0
@EHOSTUNREACH = global i64 0
@EHOSTDOWN = global i64 0
@ENETUNREACH = global i64 0
@ENETDOWN = global i64 0
@ENOPROTOOPT = global i64 0
@ENONET = global i64 0
@EOPNOTSUPP = global i64 0
@EPROTO = global i64 0
@.str.15 = [25 x i8] c"Cannot accept connection\00"
@.str.16 = [41 x i8] c"Accepted connection from %s address `%s'\00"
@.str.17 = [30 x i8] c"Cannot send directory listing\00"
@.str.18 = [23 x i8] c"Sent directory listing\00"
define i32 @main_d(i32 %0, i32 %1, i32 %2, i32 %3, i8* %4, i8* %5, i8* %6) {
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i64
%13 = alloca %struct.sockaddr_storage
%14 = alloca i32
%15 = icmp eq i32 %3, 0
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ne i8* %4, null
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = icmp ne i8* %6, null
%22 = zext i1 %21 to i32
%23 = tail call i32 @assert(i32 %22)
%24 = load i32, i32* @HOST_NAME_MAX
%25 = add nsw i32 %24, 1
%26 = zext i32 %25 to i64
%27 = tail call i8* @llvm.stacksave()
%28 = alloca i8, i64 %26
%29 = call i32 @gethostname(i8* %28, i32 %25)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %7
%32 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %35
33: ; preds = %7
%34 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %28)
br label %35
35: ; preds = %33, %31
%36 = bitcast %struct.addrinfo** %8 to i8*
store %struct.addrinfo* null, %struct.addrinfo** %8
%37 = bitcast %struct.addrinfo* %9 to i8*
%38 = call i32 @memset(%struct.addrinfo* %9, i32 0, i32 40)
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i64 0, i32 0
store i32 %3, i32* %39
%40 = load i32, i32* @SOCK_STREAM
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i64 0, i32 4
store i32 %40, i32* %41
%42 = load i32, i32* @AI_PASSIVE
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %9, i64 0, i32 6
store i32 %42, i32* %43
%44 = call i32 @getaddrinfo(i8* %5, i8* %6, %struct.addrinfo* %9, %struct.addrinfo** %8)
%45 = icmp ne i32 %44, 0
%46 = zext i1 %45 to i32
%47 = call i32 @assert(i32 %46)
%48 = call i32 @assert(i32 %46)
br i1 %45, label %49, label %55
49: ; preds = %35
%50 = call i32 @gai_strerror(i32 %44)
%51 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.3, i64 0, i64 0), i32 %50)
%52 = load %struct.addrinfo*, %struct.addrinfo** %8
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
%54 = load i32, i32* @EX_OSERR
br label %269
55: ; preds = %35
%56 = bitcast i32* %10 to i8*
store i32 1, i32* %10
%57 = load %struct.addrinfo*, %struct.addrinfo** %8
%58 = icmp eq %struct.addrinfo* %57, null
br i1 %58, label %148, label %59
59: ; preds = %55, %142
%60 = phi %struct.addrinfo* [ %144, %142 ], [ %57, %55 ]
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @af_name(i32 %62)
%64 = load i32, i32* %61
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 2
%66 = load %struct.sockaddr*, %struct.sockaddr** %65
%67 = call i32 @addr_str(i32 %64, %struct.sockaddr* %66)
%68 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i32 %63, i32 %67)
%69 = load i32, i32* %61
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 4
%71 = load i32, i32* %70
%72 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 3
%73 = load i32, i32* %72
%74 = call i32 @socket(i32 %69, i32 %71, i32 %73)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %78
76: ; preds = %59
%77 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
br label %142
78: ; preds = %59
%79 = load i32, i32* @SOL_SOCKET
%80 = load i32, i32* @SO_REUSEADDR
%81 = call i32 @setsockopt(i32 %74, i32 %79, i32 %80, i32* %10, i32 4)
%82 = load i32, i32* @SOL_SOCKET
%83 = load i32, i32* @SO_REUSEPORT
%84 = call i32 @setsockopt(i32 %74, i32 %82, i32 %83, i32* %10, i32 4)
%85 = load i32, i32* @IPPROTO_TCP
%86 = load i32, i32* @TCP_NODELAY
%87 = call i32 @setsockopt(i32 %74, i32 %85, i32 %86, i32* %10, i32 4)
%88 = load %struct.sockaddr*, %struct.sockaddr** %65
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 1
%90 = load i32, i32* %89
%91 = call i32 @bind(i32 %74, %struct.sockaddr* %88, i32 %90)
%92 = icmp eq i32 %91, -1
br i1 %92, label %93, label %116
93: ; preds = %78
%94 = load i64, i64* @errno
%95 = load i64, i64* @EBADF
%96 = icmp ne i64 %94, %95
%97 = zext i1 %96 to i32
%98 = call i32 @assert(i32 %97)
%99 = load i64, i64* @errno
%100 = load i64, i64* @ENOTSOCK
%101 = icmp ne i64 %99, %100
%102 = zext i1 %101 to i32
%103 = call i32 @assert(i32 %102)
%104 = load i64, i64* @errno
%105 = load i64, i64* @EINVAL
%106 = icmp ne i64 %104, %105
%107 = zext i1 %106 to i32
%108 = call i32 @assert(i32 %107)
%109 = load i64, i64* @errno
%110 = load i64, i64* @EISCONN
%111 = icmp ne i64 %109, %110
%112 = zext i1 %111 to i32
%113 = call i32 @assert(i32 %112)
%114 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
%115 = call i32 @close(i32 %74)
br label %142
116: ; preds = %78
%117 = call i32 @listen(i32 %74, i32 0)
%118 = icmp eq i32 %117, -1
br i1 %118, label %119, label %152
119: ; preds = %116
%120 = load i64, i64* @errno
%121 = load i64, i64* @EBADF
%122 = icmp ne i64 %120, %121
%123 = zext i1 %122 to i32
%124 = call i32 @assert(i32 %123)
%125 = load i64, i64* @errno
%126 = load i64, i64* @EDESTADDRREQ
%127 = icmp ne i64 %125, %126
%128 = zext i1 %127 to i32
%129 = call i32 @assert(i32 %128)
%130 = load i64, i64* @errno
%131 = load i64, i64* @EINVAL
%132 = icmp ne i64 %130, %131
%133 = zext i1 %132 to i32
%134 = call i32 @assert(i32 %133)
%135 = load i64, i64* @errno
%136 = load i64, i64* @ENOTSOCK
%137 = icmp ne i64 %135, %136
%138 = zext i1 %137 to i32
%139 = call i32 @assert(i32 %138)
%140 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%141 = call i32 @close(i32 %74)
br label %142
142: ; preds = %119, %93, %76
%143 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 5
%144 = load %struct.addrinfo*, %struct.addrinfo** %143
%145 = icmp eq %struct.addrinfo* %144, null
br i1 %145, label %146, label %59
146: ; preds = %142
%147 = load %struct.addrinfo*, %struct.addrinfo** %8
br label %148
148: ; preds = %146, %55
%149 = phi %struct.addrinfo* [ %147, %146 ], [ null, %55 ]
%150 = call i32 @freeaddrinfo(%struct.addrinfo* %149)
%151 = load i32, i32* @EX_OSERR
br label %267
152: ; preds = %116
%153 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.8, i64 0, i64 0), i8* %6)
%154 = load %struct.addrinfo*, %struct.addrinfo** %8
%155 = call i32 @freeaddrinfo(%struct.addrinfo* %154)
%156 = icmp eq i32 %0, 0
br i1 %156, label %166, label %157
157: ; preds = %152
%158 = call i32 (...) @fork()
switch i32 %158, label %163 [
i32 -1, label %159
i32 0, label %166
]
159: ; preds = %157
%160 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i64 0, i64 0))
%161 = call i32 @close(i32 %74)
%162 = load i32, i32* @EX_OSERR
br label %267
163: ; preds = %157
%164 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i32 %158)
%165 = load i32, i32* @EXIT_SUCCESS
br label %267
166: ; preds = %157, %152
%167 = bitcast i8** %11 to i8*
store i8* null, i8** %11
%168 = bitcast i64* %12 to i8*
store i64 0, i64* %12
%169 = call i32* @open_memstream(i8** %11, i64* %12)
%170 = icmp eq i32* %169, null
br i1 %170, label %171, label %174
171: ; preds = %166
%172 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.11, i64 0, i64 0))
%173 = load i32, i32* @EX_OSERR
br label %265
174: ; preds = %166
%175 = call i32 @lsdir(i8* %4, i32* %169)
%176 = icmp eq i32 %175, 0
br i1 %176, label %180, label %177
177: ; preds = %174
%178 = call i32 @fwrite(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i32 1, i32 1, i32* %169)
%179 = icmp slt i32 %178, 1
br i1 %179, label %180, label %187
180: ; preds = %177, %174
%181 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.13, i64 0, i64 0), i8* %4)
%182 = call i32 @close(i32 %74)
%183 = call i32 @fclose(i32* %169)
%184 = load i8*, i8** %11
%185 = call i32 @free(i8* %184)
%186 = load i32, i32* @EX_OSERR
br label %265
187: ; preds = %177
%188 = call i32 @fclose(i32* %169)
%189 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0), i8* %4)
%190 = bitcast %struct.sockaddr_storage* %13 to i8*
%191 = bitcast i32* %14 to i8*
store i64 0, i64* @errno
%192 = bitcast %struct.sockaddr_storage* %13 to %struct.sockaddr*
br label %193
193: ; preds = %206, %187
%194 = phi i64 [ %207, %206 ], [ 0, %187 ]
%195 = load i64, i64* @EWOULDBLOCK
%196 = icmp ne i64 %194, %195
%197 = zext i1 %196 to i32
%198 = call i32 @assert(i32 %197)
%199 = load i64, i64* @errno
%200 = load i64, i64* @EAGAIN
%201 = icmp ne i64 %199, %200
%202 = zext i1 %201 to i32
%203 = call i32 @assert(i32 %202)
store i32 4, i32* %14
%204 = call i32 @accept(i32 %74, %struct.sockaddr* %192, i32* %14)
%205 = icmp eq i32 %204, -1
br i1 %205, label %206, label %242
206: ; preds = %193
%207 = load i64, i64* @errno
%208 = load i64, i64* @EHOSTUNREACH
%209 = icmp eq i64 %207, %208
%210 = load i64, i64* @EHOSTDOWN
%211 = icmp eq i64 %207, %210
%212 = select i1 %209, i1 true, i1 %211
%213 = load i64, i64* @ENETUNREACH
%214 = icmp eq i64 %207, %213
%215 = select i1 %212, i1 true, i1 %214
%216 = load i64, i64* @ENETDOWN
%217 = icmp eq i64 %207, %216
%218 = select i1 %215, i1 true, i1 %217
%219 = load i64, i64* @ENOPROTOOPT
%220 = icmp eq i64 %207, %219
%221 = select i1 %218, i1 true, i1 %220
%222 = load i64, i64* @ENONET
%223 = icmp eq i64 %207, %222
%224 = select i1 %221, i1 true, i1 %223
%225 = load i64, i64* @EOPNOTSUPP
%226 = icmp eq i64 %207, %225
%227 = select i1 %224, i1 true, i1 %226
%228 = load i64, i64* @EPROTO
%229 = icmp eq i64 %207, %228
%230 = select i1 %227, i1 true, i1 %229
br i1 %230, label %193, label %231
231: ; preds = %206
%232 = load i64, i64* @EWOULDBLOCK
%233 = icmp ne i64 %207, %232
%234 = zext i1 %233 to i32
%235 = call i32 @assert(i32 %234)
%236 = load i64, i64* @errno
%237 = load i64, i64* @EAGAIN
%238 = icmp ne i64 %236, %237
%239 = zext i1 %238 to i32
%240 = call i32 @assert(i32 %239)
%241 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.15, i64 0, i64 0))
br label %258
242: ; preds = %193
%243 = call i32 @close(i32 %74)
%244 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %13, i64 0, i32 0
%245 = load i32, i32* %244
%246 = call i32 @af_name(i32 %245)
%247 = load i32, i32* %244
%248 = call i32 @addr_str(i32 %247, %struct.sockaddr* %192)
%249 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.16, i64 0, i64 0), i32 %246, i32 %248)
%250 = load i8*, i8** %11
%251 = load i64, i64* %12
%252 = call i32 @socksend(i32 %204, i8* %250, i64 %251)
%253 = icmp eq i32 %252, 0
br i1 %253, label %254, label %256
254: ; preds = %242
%255 = call i32 (i8*, ...) @warn(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.17, i64 0, i64 0))
br label %258
256: ; preds = %242
%257 = call i32 (i8*, ...) @warnx(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.18, i64 0, i64 0))
br label %258
258: ; preds = %256, %254, %231
%259 = phi i32 [ %204, %256 ], [ %204, %254 ], [ %74, %231 ]
%260 = phi i32* [ @EXIT_SUCCESS, %256 ], [ @EX_OSERR, %254 ], [ @EX_OSERR, %231 ]
%261 = call i32 @close(i32 %259)
%262 = load i8*, i8** %11
%263 = call i32 @free(i8* %262)
%264 = load i32, i32* %260
br label %265
265: ; preds = %258, %180, %171
%266 = phi i32 [ %173, %171 ], [ %186, %180 ], [ %264, %258 ]
br label %267
267: ; preds = %159, %163, %265, %148
%268 = phi i32 [ %151, %148 ], [ %266, %265 ], [ %162, %159 ], [ %165, %163 ]
br label %269
269: ; preds = %267, %49
%270 = phi i32 [ %54, %49 ], [ %268, %267 ]
ret i32 %270
}