#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  int ai_socktype;
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ sock_opt;
typedef int /*<<< orphan*/ hostnamebuf;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int /*<<< orphan*/ AI_PASSIVE;
scalar_t__ PF_UNSPEC;
int SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, scalar_t__, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, void *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, unsigned int);
int socket(scalar_t__, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int SK_getsock(const char *node, unsigned port, int socket_type, int backlog) {
  struct addrinfo hints, *res, *ai_iter;
  int error, sock = -1, sock_opt, flags;
  char portbuf[16], hostnamebuf[256];
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = PF_UNSPEC;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_socktype = socket_type;
  snprintf(portbuf, 16, "%u", port);
  error = getaddrinfo(node, portbuf, &hints, &res);
  if (error != 0) {
    fprintf(stderr, "SK_getsock(%s, %d): getaddrinfo(): %s", node, port,
            gai_strerror(error));
    return -1;
  }
  for (ai_iter = res; ai_iter != NULL; ai_iter = ai_iter->ai_next) {
    if (ai_iter->ai_family == AF_INET6) {
      inet_ntop(ai_iter->ai_family,
                &((struct sockaddr_in6 *)(ai_iter->ai_addr))->sin6_addr,
                hostnamebuf, sizeof(hostnamebuf));
      fprintf(stderr, "Trying to bind on v6 address '%s' ... ", hostnamebuf);
      sock = socket(ai_iter->ai_family, ai_iter->ai_socktype,
                    ai_iter->ai_protocol);
      if (sock >= 0) {
        fprintf(stderr, "succeed.\n");
        break;
      }
      fprintf(stderr, "failed.\n");
    }
  }
  if (sock < 0) {
    for (ai_iter = res; ai_iter != NULL; ai_iter = ai_iter->ai_next) {
      if (ai_iter->ai_family == AF_INET) {
        inet_ntop(ai_iter->ai_family,
                  &((struct sockaddr_in *)(ai_iter->ai_addr))->sin_addr,
                  hostnamebuf, sizeof(hostnamebuf));
        fprintf(stderr, "Trying to bind on v4 address '%s' ... ", hostnamebuf);
        sock = socket(ai_iter->ai_family, ai_iter->ai_socktype,
                      ai_iter->ai_protocol);
        if (sock >= 0) {
          fprintf(stderr, "succeed.\n");
          break;
        }
        fprintf(stderr, "failed.\n");
      }
    }
  }
  if (sock < 0) {
    fprintf(stderr,
            "SK_getsock(%s, %d): No v6 nor v4 address found or supported", node,
            port);
    return -1;
  }
  sock_opt = 1;
  if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&sock_opt,
                 sizeof(sock_opt)) == -1) {
    fprintf(stderr, "SK_getsock(%s, %d): setsockopt(): %d (%s)", node, port,
            errno, strerror(errno));
    return -1;
  }
  if ((bind(sock, ai_iter->ai_addr, ai_iter->ai_addrlen)) == -1) {
    fprintf(stderr, "SK_getsock(%s, %d): bind(): %d (%s)", node, port, errno,
            strerror(errno));
    return -1;
  }
  if (socket_type == SOCK_STREAM) {
    if (listen(sock, backlog) == -1) {
      fprintf(stderr, "SK_getsock(%s, %d): listen(): %d (%s)", node, port,
              errno, strerror(errno));
      return -1;
    }
  }
  freeaddrinfo(res);
  return sock;
}


x86 assembly (clang, -O0):
<SK_getsock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1e0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movl   $0xffffffff,-0x68(%rbp)
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x48(%rbp)
lea    -0x80(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xdde(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x80(%rbp),%rsi
lea    -0x50(%rbp),%rdx
lea    -0x58(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
je     12a4 <SK_getsock+0xe4>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x194(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x190(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x184(%rbp)
mov    -0x64(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x194(%rbp),%edi
mov    -0x190(%rbp),%rdx
mov    -0x184(%rbp),%ecx
mov    %rax,%r8
lea    0xd72(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    168a <SK_getsock+0x4ca>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     137c <SK_getsock+0x1bc>
mov    -0x60(%rbp),%rax
mov    (%rax),%rax
mov    0x2d03(%rip),%rcx
cmp    (%rcx),%rax
jne    1366 <SK_getsock+0x1a6>
mov    -0x60(%rbp),%rax
mov    (%rax),%rdi
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x180(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    0x2cc3(%rip),%rax
mov    (%rax),%edi
lea    -0x180(%rbp),%rdx
lea    0xd24(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rax
mov    (%rax),%rdi
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x60(%rbp),%rax
mov    0x18(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     134f <SK_getsock+0x18f>
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
lea    0xd0d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    137c <SK_getsock+0x1bc>
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
lea    0xcfb(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    136b <SK_getsock+0x1ab>
mov    -0x60(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    12ac <SK_getsock+0xec>
cmpl   $0x0,-0x68(%rbp)
jge    1463 <SK_getsock+0x2a3>
mov    -0x58(%rbp),%rax
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     145e <SK_getsock+0x29e>
mov    -0x60(%rbp),%rax
mov    (%rax),%rax
mov    0x2c29(%rip),%rcx
cmp    (%rcx),%rax
jne    1448 <SK_getsock+0x288>
mov    -0x60(%rbp),%rax
mov    (%rax),%rdi
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x180(%rbp),%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    0x2be1(%rip),%rax
mov    (%rax),%edi
lea    -0x180(%rbp),%rdx
lea    0xc7c(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%rax
mov    (%rax),%rdi
mov    -0x60(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x60(%rbp),%rax
mov    0x18(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jl     1431 <SK_getsock+0x271>
mov    0x2b9c(%rip),%rax
mov    (%rax),%edi
lea    0xc2b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    145e <SK_getsock+0x29e>
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
lea    0xc19(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    144d <SK_getsock+0x28d>
mov    -0x60(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x60(%rbp)
jmp    138e <SK_getsock+0x1ce>
jmp    1463 <SK_getsock+0x2a3>
cmpl   $0x0,-0x68(%rbp)
jge    1497 <SK_getsock+0x2d7>
mov    0x2b44(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
lea    0xc06(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    168a <SK_getsock+0x4ca>
movl   $0x1,-0x6c(%rbp)
mov    -0x68(%rbp),%edi
mov    0x2b40(%rip),%rax
mov    (%rax),%esi
mov    0x2aef(%rip),%rax
mov    (%rax),%edx
lea    -0x6c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1542 <SK_getsock+0x382>
mov    0x2ae6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1a8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x19c(%rbp)
mov    0x2ab3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x198(%rbp)
mov    0x2aa4(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x1ac(%rbp),%edi
mov    -0x1a8(%rbp),%rdx
mov    -0x19c(%rbp),%ecx
mov    -0x198(%rbp),%r8d
mov    %rax,%r9
lea    0xb97(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    168a <SK_getsock+0x4ca>
mov    -0x68(%rbp),%edi
mov    -0x60(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x60(%rbp),%rax
mov    0xc(%rax),%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    15d9 <SK_getsock+0x419>
mov    0x2a4f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c4(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1c0(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
mov    0x2a1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1b0(%rbp)
mov    0x2a0d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x1c4(%rbp),%edi
mov    -0x1c0(%rbp),%rdx
mov    -0x1b4(%rbp),%ecx
mov    -0x1b0(%rbp),%r8d
mov    %rax,%r9
lea    0xb2a(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    168a <SK_getsock+0x4ca>
mov    -0x18(%rbp),%eax
mov    0x29cd(%rip),%rcx
cmp    (%rcx),%eax
jne    167b <SK_getsock+0x4bb>
mov    -0x68(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1676 <SK_getsock+0x4b6>
mov    0x29b2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1dc(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x1d8(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1cc(%rbp)
mov    0x297f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c8(%rbp)
mov    0x2970(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x1dc(%rbp),%edi
mov    -0x1d8(%rbp),%rdx
mov    -0x1cc(%rbp),%ecx
mov    -0x1c8(%rbp),%r8d
mov    %rax,%r9
lea    0xab1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    168a <SK_getsock+0x4ca>
jmp    167b <SK_getsock+0x4bb>
mov    -0x58(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1e0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SK_getsock>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x178,%rsp
mov    %ecx,%r12d
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
lea    0x30(%rsp),%r13
mov    %r13,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1070 <memset@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x30(%rsp)
mov    0x2dd2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x58(%rsp)
mov    %ebx,0x38(%rsp)
lea    0xde9(%rip),%rdx
lea    0x60(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x10,%esi
mov    %r14d,%ecx
call   1050 <snprintf@plt>
lea    0x18(%rsp),%rcx
mov    %r15,%rdi
mov    %rbp,%rsi
mov    %r13,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
je     1271 <SK_getsock+0xb1>
mov    0x2d6e(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <gai_strerror@plt>
lea    0xda9(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %rax,%r8
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    151f <SK_getsock+0x35f>
mov    %ebx,0x28(%rsp)
mov    %r12d,0x24(%rsp)
mov    0x18(%rsp),%r13
test   %r13,%r13
je     14d2 <SK_getsock+0x312>
mov    %r15,0x10(%rsp)
mov    %r14d,0xc(%rsp)
mov    0x2d2f(%rip),%rax
mov    (%rax),%rdi
mov    $0xffffffff,%ebp
lea    0x70(%rsp),%rbx
lea    0xd7c(%rip),%r14
lea    0xda6(%rip),%r15
jmp    12c9 <SK_getsock+0x109>
cs nopw 0x0(%rax,%rax,1)
mov    0x20(%r13),%r13
test   %r13,%r13
je     132d <SK_getsock+0x16d>
cmp    %rdi,0x0(%r13)
jne    12c0 <SK_getsock+0x100>
mov    0x10(%r13),%rsi
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    0x2cd1(%rip),%r12
mov    (%r12),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%rdi
mov    0x8(%r13),%esi
mov    0x18(%r13),%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jns    13e7 <SK_getsock+0x227>
mov    (%r12),%edi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%rdi
jmp    12c0 <SK_getsock+0x100>
test   %ebp,%ebp
js     134a <SK_getsock+0x18a>
xor    %r13d,%r13d
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15
mov    0x2c73(%rip),%rbx
jmp    1408 <SK_getsock+0x248>
mov    0x18(%rsp),%r13
test   %r13,%r13
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15
je     14d2 <SK_getsock+0x312>
mov    0x2c67(%rip),%r12
mov    (%r12),%rdi
lea    0x70(%rsp),%rbx
lea    0xcea(%rip),%r14
jmp    13a2 <SK_getsock+0x1e2>
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
lea    0xcd0(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    (%r12),%rdi
mov    0x20(%r13),%r13
test   %r13,%r13
je     14b5 <SK_getsock+0x2f5>
cmp    %rdi,0x0(%r13)
jne    1395 <SK_getsock+0x1d5>
mov    0x10(%r13),%rsi
mov    %rbx,%rdx
mov    $0x100,%ecx
call   1030 <inet_ntop@plt>
mov    0x2bf8(%rip),%r15
mov    (%r15),%edi
mov    %r14,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0x0(%r13),%rdi
mov    0x8(%r13),%esi
mov    0x18(%r13),%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     1380 <SK_getsock+0x1c0>
mov    0x2bca(%rip),%rbx
mov    (%rbx),%edi
lea    0xc59(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15
movl   $0x1,0x2c(%rsp)
mov    0x2bd1(%rip),%rax
mov    (%rax),%esi
mov    0x2b80(%rip),%rax
mov    (%rax),%edx
lea    0x2c(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     147f <SK_getsock+0x2bf>
mov    0x10(%r13),%rsi
mov    0xc(%r13),%edx
mov    %ebp,%edi
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     149a <SK_getsock+0x2da>
mov    0x2b5c(%rip),%rax
mov    0x28(%rsp),%ecx
cmp    %ecx,(%rax)
jne    1470 <SK_getsock+0x2b0>
mov    %ebp,%edi
mov    0x24(%rsp),%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
je     14f1 <SK_getsock+0x331>
mov    0x18(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
jmp    1524 <SK_getsock+0x364>
mov    (%rbx),%ebx
mov    0x2b20(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xc2e(%rip),%rsi
jmp    150a <SK_getsock+0x34a>
mov    (%rbx),%ebx
mov    0x2b05(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xc3d(%rip),%rsi
jmp    150a <SK_getsock+0x34a>
test   %ebp,%ebp
mov    0xc(%rsp),%r14d
mov    0x10(%rsp),%r15
js     14d2 <SK_getsock+0x312>
xor    %r13d,%r13d
mov    0x2aeb(%rip),%rbx
jmp    1408 <SK_getsock+0x248>
mov    0x2adf(%rip),%rax
mov    (%rax),%edi
lea    0xba8(%rip),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    151f <SK_getsock+0x35f>
mov    (%rbx),%ebx
mov    0x2aae(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xc0a(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
mov    %rax,%r9
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x178,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i64, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@PF_UNSPEC = global i64 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"SK_getsock(%s, %d): getaddrinfo(): %s\00"
@AF_INET6 = global i64 0
@.str.2 = [39 x i8] c"Trying to bind on v6 address '%s' ... \00"
@.str.3 = [10 x i8] c"succeed.\0A\00"
@.str.4 = [9 x i8] c"failed.\0A\00"
@AF_INET = global i64 0
@.str.5 = [39 x i8] c"Trying to bind on v4 address '%s' ... \00"
@.str.6 = [60 x i8] c"SK_getsock(%s, %d): No v6 nor v4 address found or supported\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.7 = [42 x i8] c"SK_getsock(%s, %d): setsockopt(): %d (%s)\00"
@errno = global i32 0
@.str.8 = [36 x i8] c"SK_getsock(%s, %d): bind(): %d (%s)\00"
@SOCK_STREAM = global i32 0
@.str.9 = [38 x i8] c"SK_getsock(%s, %d): listen(): %d (%s)\00"
define i32 @SK_getsock(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.addrinfo
%11 = alloca %struct.addrinfo*
%12 = alloca %struct.addrinfo*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca [16 x i8]
%18 = alloca [256 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 -1, i32* %14
%19 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 48)
%20 = load i64, i64* @PF_UNSPEC
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i64 %20, i64* %21
%22 = load i32, i32* @AI_PASSIVE
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %22, i32* %23
%24 = load i32, i32* %8
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 1
store i32 %24, i32* %25
%26 = getelementptr inbounds [16 x i8], [16 x i8]* %17, i64 0, i64 0
%27 = load i32, i32* %7
%28 = call i32 @snprintf(i8* %26, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %27)
%29 = load i8*, i8** %6
%30 = getelementptr inbounds [16 x i8], [16 x i8]* %17, i64 0, i64 0
%31 = call i32 @getaddrinfo(i8* %29, i8* %30, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %31, i32* %13
%32 = load i32, i32* %13
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %41
34: ; preds = %4
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = load i32, i32* %13
%39 = call i8* @gai_strerror(i32 %38)
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %36, i32 %37, i8* %39)
store i32 -1, i32* %5
br label %204
41: ; preds = %4
%42 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %42, %struct.addrinfo** %12
br label %43
43: ; preds = %85, %41
%44 = load %struct.addrinfo*, %struct.addrinfo** %12
%45 = icmp ne %struct.addrinfo* %44, null
br i1 %45, label %46, label %89
46: ; preds = %43
%47 = load %struct.addrinfo*, %struct.addrinfo** %12
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = load i64, i64* @AF_INET6
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %84
52: ; preds = %46
%53 = load %struct.addrinfo*, %struct.addrinfo** %12
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 0
%55 = load i64, i64* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %12
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 3
%58 = load i64, i64* %57
%59 = inttoptr i64 %58 to %struct.sockaddr_in6*
%60 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %59, i32 0, i32 0
%61 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%62 = call i32 @inet_ntop(i64 %55, i32* %60, i8* %61, i32 256)
%63 = load i32, i32* @stderr
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %64)
%66 = load %struct.addrinfo*, %struct.addrinfo** %12
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 0
%68 = load i64, i64* %67
%69 = load %struct.addrinfo*, %struct.addrinfo** %12
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 1
%71 = load i32, i32* %70
%72 = load %struct.addrinfo*, %struct.addrinfo** %12
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %72, i32 0, i32 4
%74 = load i32, i32* %73
%75 = call i32 @socket(i64 %68, i32 %71, i32 %74)
store i32 %75, i32* %14
%76 = load i32, i32* %14
%77 = icmp sge i32 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %52
%79 = load i32, i32* @stderr
%80 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %89
81: ; preds = %52
%82 = load i32, i32* @stderr
%83 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %84
84: ; preds = %81, %46
br label %85
85: ; preds = %84
%86 = load %struct.addrinfo*, %struct.addrinfo** %12
%87 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %86, i32 0, i32 5
%88 = load %struct.addrinfo*, %struct.addrinfo** %87
store %struct.addrinfo* %88, %struct.addrinfo** %12
br label %43
89: ; preds = %78, %43
%90 = load i32, i32* %14
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %141
92: ; preds = %89
%93 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %93, %struct.addrinfo** %12
br label %94
94: ; preds = %136, %92
%95 = load %struct.addrinfo*, %struct.addrinfo** %12
%96 = icmp ne %struct.addrinfo* %95, null
br i1 %96, label %97, label %140
97: ; preds = %94
%98 = load %struct.addrinfo*, %struct.addrinfo** %12
%99 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %98, i32 0, i32 0
%100 = load i64, i64* %99
%101 = load i64, i64* @AF_INET
%102 = icmp eq i64 %100, %101
br i1 %102, label %103, label %135
103: ; preds = %97
%104 = load %struct.addrinfo*, %struct.addrinfo** %12
%105 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %104, i32 0, i32 0
%106 = load i64, i64* %105
%107 = load %struct.addrinfo*, %struct.addrinfo** %12
%108 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %107, i32 0, i32 3
%109 = load i64, i64* %108
%110 = inttoptr i64 %109 to %struct.sockaddr_in*
%111 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %110, i32 0, i32 0
%112 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%113 = call i32 @inet_ntop(i64 %106, i32* %111, i8* %112, i32 256)
%114 = load i32, i32* @stderr
%115 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%116 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %115)
%117 = load %struct.addrinfo*, %struct.addrinfo** %12
%118 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %117, i32 0, i32 0
%119 = load i64, i64* %118
%120 = load %struct.addrinfo*, %struct.addrinfo** %12
%121 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %120, i32 0, i32 1
%122 = load i32, i32* %121
%123 = load %struct.addrinfo*, %struct.addrinfo** %12
%124 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %123, i32 0, i32 4
%125 = load i32, i32* %124
%126 = call i32 @socket(i64 %119, i32 %122, i32 %125)
store i32 %126, i32* %14
%127 = load i32, i32* %14
%128 = icmp sge i32 %127, 0
br i1 %128, label %129, label %132
129: ; preds = %103
%130 = load i32, i32* @stderr
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %140
132: ; preds = %103
%133 = load i32, i32* @stderr
%134 = call i32 (i32, i8*, ...) @fprintf(i32 %133, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
br label %135
135: ; preds = %132, %97
br label %136
136: ; preds = %135
%137 = load %struct.addrinfo*, %struct.addrinfo** %12
%138 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %137, i32 0, i32 5
%139 = load %struct.addrinfo*, %struct.addrinfo** %138
store %struct.addrinfo* %139, %struct.addrinfo** %12
br label %94
140: ; preds = %129, %94
br label %141
141: ; preds = %140, %89
%142 = load i32, i32* %14
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %149
144: ; preds = %141
%145 = load i32, i32* @stderr
%146 = load i8*, i8** %6
%147 = load i32, i32* %7
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i8* %146, i32 %147)
store i32 -1, i32* %5
br label %204
149: ; preds = %141
store i32 1, i32* %15
%150 = load i32, i32* %14
%151 = load i32, i32* @SOL_SOCKET
%152 = load i32, i32* @SO_REUSEADDR
%153 = bitcast i32* %15 to i8*
%154 = call i32 @setsockopt(i32 %150, i32 %151, i32 %152, i8* %153, i32 4)
%155 = icmp eq i32 %154, -1
br i1 %155, label %156, label %164
156: ; preds = %149
%157 = load i32, i32* @stderr
%158 = load i8*, i8** %6
%159 = load i32, i32* %7
%160 = load i32, i32* @errno
%161 = load i32, i32* @errno
%162 = call i8* @strerror(i32 %161)
%163 = call i32 (i32, i8*, ...) @fprintf(i32 %157, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %158, i32 %159, i32 %160, i8* %162)
store i32 -1, i32* %5
br label %204
164: ; preds = %149
%165 = load i32, i32* %14
%166 = load %struct.addrinfo*, %struct.addrinfo** %12
%167 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %166, i32 0, i32 3
%168 = load i64, i64* %167
%169 = load %struct.addrinfo*, %struct.addrinfo** %12
%170 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %169, i32 0, i32 2
%171 = load i32, i32* %170
%172 = call i32 @bind(i32 %165, i64 %168, i32 %171)
%173 = icmp eq i32 %172, -1
br i1 %173, label %174, label %182
174: ; preds = %164
%175 = load i32, i32* @stderr
%176 = load i8*, i8** %6
%177 = load i32, i32* %7
%178 = load i32, i32* @errno
%179 = load i32, i32* @errno
%180 = call i8* @strerror(i32 %179)
%181 = call i32 (i32, i8*, ...) @fprintf(i32 %175, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %176, i32 %177, i32 %178, i8* %180)
store i32 -1, i32* %5
br label %204
182: ; preds = %164
%183 = load i32, i32* %8
%184 = load i32, i32* @SOCK_STREAM
%185 = icmp eq i32 %183, %184
br i1 %185, label %186, label %200
186: ; preds = %182
%187 = load i32, i32* %14
%188 = load i32, i32* %9
%189 = call i32 @listen(i32 %187, i32 %188)
%190 = icmp eq i32 %189, -1
br i1 %190, label %191, label %199
191: ; preds = %186
%192 = load i32, i32* @stderr
%193 = load i8*, i8** %6
%194 = load i32, i32* %7
%195 = load i32, i32* @errno
%196 = load i32, i32* @errno
%197 = call i8* @strerror(i32 %196)
%198 = call i32 (i32, i8*, ...) @fprintf(i32 %192, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %193, i32 %194, i32 %195, i8* %197)
store i32 -1, i32* %5
br label %204
199: ; preds = %186
br label %200
200: ; preds = %199, %182
%201 = load %struct.addrinfo*, %struct.addrinfo** %11
%202 = call i32 @freeaddrinfo(%struct.addrinfo* %201)
%203 = load i32, i32* %14
store i32 %203, i32* %5
br label %204
204: ; preds = %200, %191, %174, %156, %144, %34
%205 = load i32, i32* %5
ret i32 %205
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i64, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@PF_UNSPEC = global i64 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%u\00"
@stderr = global i32 0
@.str.1 = [38 x i8] c"SK_getsock(%s, %d): getaddrinfo(): %s\00"
@AF_INET6 = global i64 0
@.str.2 = [39 x i8] c"Trying to bind on v6 address '%s' ... \00"
@.str.3 = [10 x i8] c"succeed.\0A\00"
@.str.4 = [9 x i8] c"failed.\0A\00"
@AF_INET = global i64 0
@.str.5 = [39 x i8] c"Trying to bind on v4 address '%s' ... \00"
@.str.6 = [60 x i8] c"SK_getsock(%s, %d): No v6 nor v4 address found or supported\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.7 = [42 x i8] c"SK_getsock(%s, %d): setsockopt(): %d (%s)\00"
@errno = global i32 0
@.str.8 = [36 x i8] c"SK_getsock(%s, %d): bind(): %d (%s)\00"
@SOCK_STREAM = global i32 0
@.str.9 = [38 x i8] c"SK_getsock(%s, %d): listen(): %d (%s)\00"
define i32 @SK_getsock(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = alloca [16 x i8]
%9 = alloca [256 x i8]
%10 = bitcast %struct.addrinfo* %5 to i8*
%11 = bitcast %struct.addrinfo** %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %8, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%15 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 48)
%16 = load i64, i64* @PF_UNSPEC
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i64 %16, i64* %17
%18 = load i32, i32* @AI_PASSIVE
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
store i32 %2, i32* %20
%21 = call i32 @snprintf(i8* %13, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %1)
%22 = call i32 @getaddrinfo(i8* %0, i8* %13, %struct.addrinfo* %5, %struct.addrinfo** %6)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %4
%25 = load %struct.addrinfo*, %struct.addrinfo** %6
%26 = icmp eq %struct.addrinfo* %25, null
br i1 %26, label %106, label %27
27: ; preds = %24
%28 = load i64, i64* @AF_INET6
br label %33
29: ; preds = %4
%30 = load i32, i32* @stderr
%31 = call i8* @gai_strerror(i32 %22)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %1, i8* %31)
br label %152
33: ; preds = %27, %59
%34 = phi i64 [ %60, %59 ], [ %28, %27 ]
%35 = phi %struct.addrinfo* [ %63, %59 ], [ %25, %27 ]
%36 = phi i32 [ %61, %59 ], [ -1, %27 ]
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%38 = load i64, i64* %37
%39 = icmp eq i64 %38, %34
br i1 %39, label %40, label %59
40: ; preds = %33
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 3
%42 = load i64, i64* %41
%43 = inttoptr i64 %42 to %struct.sockaddr_in6*
%44 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %43, i64 0, i32 0
%45 = call i32 @inet_ntop(i64 %34, i32* %44, i8* %14, i32 256)
%46 = load i32, i32* @stderr
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%48 = load i64, i64* %37
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%50 = load i32, i32* %49
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 4
%52 = load i32, i32* %51
%53 = call i32 @socket(i64 %48, i32 %50, i32 %52)
%54 = icmp sgt i32 %53, -1
br i1 %54, label %109, label %55
55: ; preds = %40
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%58 = load i64, i64* @AF_INET6
br label %59
59: ; preds = %33, %55
%60 = phi i64 [ %58, %55 ], [ %34, %33 ]
%61 = phi i32 [ %53, %55 ], [ %36, %33 ]
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 5
%63 = load %struct.addrinfo*, %struct.addrinfo** %62
%64 = icmp eq %struct.addrinfo* %63, null
br i1 %64, label %65, label %33
65: ; preds = %59
%66 = icmp slt i32 %61, 0
br i1 %66, label %67, label %114
67: ; preds = %65
%68 = load %struct.addrinfo*, %struct.addrinfo** %6
%69 = icmp eq %struct.addrinfo* %68, null
br i1 %69, label %106, label %70
70: ; preds = %67
%71 = load i64, i64* @AF_INET
br label %72
72: ; preds = %70, %98
%73 = phi i64 [ %99, %98 ], [ %71, %70 ]
%74 = phi %struct.addrinfo* [ %102, %98 ], [ %68, %70 ]
%75 = phi i32 [ %100, %98 ], [ %61, %70 ]
%76 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i64 0, i32 0
%77 = load i64, i64* %76
%78 = icmp eq i64 %77, %73
br i1 %78, label %79, label %98
79: ; preds = %72
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i64 0, i32 3
%81 = load i64, i64* %80
%82 = inttoptr i64 %81 to %struct.sockaddr_in*
%83 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %82, i64 0, i32 0
%84 = call i32 @inet_ntop(i64 %73, i32* %83, i8* %14, i32 256)
%85 = load i32, i32* @stderr
%86 = call i32 (i32, i8*, ...) @fprintf(i32 %85, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* %14)
%87 = load i64, i64* %76
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i64 0, i32 1
%89 = load i32, i32* %88
%90 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i64 0, i32 4
%91 = load i32, i32* %90
%92 = call i32 @socket(i64 %87, i32 %89, i32 %91)
%93 = icmp sgt i32 %92, -1
br i1 %93, label %109, label %94
94: ; preds = %79
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%97 = load i64, i64* @AF_INET
br label %98
98: ; preds = %72, %94
%99 = phi i64 [ %97, %94 ], [ %73, %72 ]
%100 = phi i32 [ %92, %94 ], [ %75, %72 ]
%101 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i64 0, i32 5
%102 = load %struct.addrinfo*, %struct.addrinfo** %101
%103 = icmp eq %struct.addrinfo* %102, null
br i1 %103, label %104, label %72
104: ; preds = %98
%105 = icmp slt i32 %100, 0
br i1 %105, label %106, label %114
106: ; preds = %24, %67, %104
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 %1)
br label %152
109: ; preds = %40, %79
%110 = phi i32 [ %92, %79 ], [ %53, %40 ]
%111 = phi %struct.addrinfo* [ %74, %79 ], [ %35, %40 ]
%112 = load i32, i32* @stderr
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %112, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
br label %114
114: ; preds = %109, %65, %104
%115 = phi i32 [ %100, %104 ], [ %61, %65 ], [ %110, %109 ]
%116 = phi %struct.addrinfo* [ null, %104 ], [ null, %65 ], [ %111, %109 ]
store i32 1, i32* %7
%117 = load i32, i32* @SOL_SOCKET
%118 = load i32, i32* @SO_REUSEADDR
%119 = call i32 @setsockopt(i32 %115, i32 %117, i32 %118, i8* %12, i32 4)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %126
121: ; preds = %114
%122 = load i32, i32* @stderr
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.7, i64 0, i64 0), i8* %0, i32 %1, i32 %123, i8* %124)
br label %152
126: ; preds = %114
%127 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %116, i64 0, i32 3
%128 = load i64, i64* %127
%129 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %116, i64 0, i32 2
%130 = load i32, i32* %129
%131 = call i32 @bind(i32 %115, i64 %128, i32 %130)
%132 = icmp eq i32 %131, -1
br i1 %132, label %133, label %138
133: ; preds = %126
%134 = load i32, i32* @stderr
%135 = load i32, i32* @errno
%136 = call i8* @strerror(i32 %135)
%137 = call i32 (i32, i8*, ...) @fprintf(i32 %134, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.8, i64 0, i64 0), i8* %0, i32 %1, i32 %135, i8* %136)
br label %152
138: ; preds = %126
%139 = load i32, i32* @SOCK_STREAM
%140 = icmp eq i32 %139, %2
br i1 %140, label %141, label %149
141: ; preds = %138
%142 = call i32 @listen(i32 %115, i32 %3)
%143 = icmp eq i32 %142, -1
br i1 %143, label %144, label %149
144: ; preds = %141
%145 = load i32, i32* @stderr
%146 = load i32, i32* @errno
%147 = call i8* @strerror(i32 %146)
%148 = call i32 (i32, i8*, ...) @fprintf(i32 %145, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.9, i64 0, i64 0), i8* %0, i32 %1, i32 %146, i8* %147)
br label %152
149: ; preds = %141, %138
%150 = load %struct.addrinfo*, %struct.addrinfo** %6
%151 = call i32 @freeaddrinfo(%struct.addrinfo* %150)
br label %152
152: ; preds = %149, %144, %133, %121, %106, %29
%153 = phi i32 [ -1, %29 ], [ -1, %106 ], [ -1, %121 ], [ -1, %133 ], [ -1, %144 ], [ %115, %149 ]
ret i32 %153
}