#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int /*<<< orphan*/ opt;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ FIONBIO;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int ioctl(int, int /*<<< orphan*/, int *);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int setup_tcp_server_socket(const char *host, const char *port, int backlog,
                            int nonblock) {
  struct addrinfo hints, *ais, *ai;
  int err, soc, opt;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE, err = getaddrinfo(host, port, &hints, &ais);
  if (err) {
    fprintf(stderr,
            "%s: "
            "getaddrinfo: %s, host=%s, port=%s"
            " (%s:%d)\n",
            "warning", gai_strerror(err), (host ? host : "(null)"),
            (port ? port : "(null)"),
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
            "common.c",
            338);
    ;
    ;
    return -1;
  }
  for (ai = ais; ai; ai = ai->ai_next) {
    soc = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
    if (soc == -1) {
      fprintf(stderr,
              "%s: "
              "socket: %s"
              " (%s:%d)\n",
              "warning", strerror(errno),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              344);
      ;
      ;
      continue;
    }
    if (nonblock) {
      opt = 1;
      if (ioctl(soc, FIONBIO, &opt) == -1) {
        fprintf(stderr,
                "%s: "
                "ioctl [FIONBIO]: %s"
                " (%s:%d)\n",
                "warning", strerror(errno),
                "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                "outputs/2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/"
                "master/src/common.c",
                350);
        ;
        ;
        close(soc);
        continue;
      }
    }
    opt = 1;
    if (setsockopt(soc, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) == -1) {
      fprintf(stderr,
              "%s: "
              "setsockopt [SO_REUSEADDR]: %s"
              " (%s:%d)\n",
              "warning", strerror(errno),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              357);
      ;
      ;
      close(soc);
      continue;
    }
    if (bind(soc, ai->ai_addr, ai->ai_addrlen) == -1) {
      fprintf(stderr,
              "%s: "
              "bind: %s"
              " (%s:%d)\n",
              "warning", strerror(errno),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              372);
      ;
      ;
      close(soc);
      continue;
    }
    if (listen(soc, backlog) == -1) {
      fprintf(stderr,
              "%s: "
              "listen: %s"
              " (%s:%d)\n",
              "warning", strerror(errno),
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
              "common.c",
              377);
      ;
      ;
      close(soc);
      continue;
    }
    freeaddrinfo(ais);
    return soc;
  }
  freeaddrinfo(ais);
  fprintf(stderr,
          "%s: "
          "Can't create any server sockets"
          " (%s:%d)\n",
          "warning",
          "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
          "2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/"
          "common.c",
          385);
  ;
  ;
  return -1;
}


x86 assembly (clang, -O0):
<setup_tcp_server_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x48(%rbp),%rdx
lea    -0x50(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
je     12f1 <setup_tcp_server_socket+0x131>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x5c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     125f <setup_tcp_server_socket+0x9f>
mov    -0x10(%rbp),%rax
mov    %rax,-0x80(%rbp)
jmp    126f <setup_tcp_server_socket+0xaf>
lea    0xdd1(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    126f <setup_tcp_server_socket+0xaf>
mov    -0x80(%rbp),%rax
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1295 <setup_tcp_server_socket+0xd5>
mov    -0x18(%rbp),%rax
mov    %rax,-0x90(%rbp)
jmp    12a8 <setup_tcp_server_socket+0xe8>
lea    0xd9b(%rip),%rax
mov    %rax,-0x90(%rbp)
jmp    12a8 <setup_tcp_server_socket+0xe8>
mov    -0x88(%rbp),%r8
mov    -0x70(%rbp),%rcx
mov    -0x74(%rbp),%edi
mov    -0x90(%rbp),%r9
lea    0xd3c(%rip),%rsi
lea    0xd64(%rip),%rdx
lea    0xd6c(%rip),%rax
mov    %rax,(%rsp)
movl   $0x152,0x8(%rsp)
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15c6 <setup_tcp_server_socket+0x406>
mov    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     158b <setup_tcp_server_socket+0x3cb>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x58(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x60(%rbp)
cmpl   $0xffffffff,-0x60(%rbp)
jne    1378 <setup_tcp_server_socket+0x1b8>
mov    0x2c96(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    0x2c77(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rcx
lea    0xd6f(%rip),%rsi
lea    0xcd0(%rip),%rdx
lea    0xcd8(%rip),%r8
mov    $0x158,%r9d
mov    $0x0,%al
call   1080 <fprintf@plt>
jmp    157a <setup_tcp_server_socket+0x3ba>
cmpl   $0x0,-0x20(%rbp)
je     1401 <setup_tcp_server_socket+0x241>
movl   $0x1,-0x64(%rbp)
mov    -0x60(%rbp),%edi
mov    0x2c1d(%rip),%rax
mov    (%rax),%esi
lea    -0x64(%rbp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    13fc <setup_tcp_server_socket+0x23c>
mov    0x2c1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x98(%rbp)
mov    0x2bfb(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x98(%rbp),%edi
mov    %rax,%rcx
lea    0xd0b(%rip),%rsi
lea    0xc54(%rip),%rdx
lea    0xc5c(%rip),%r8
mov    $0x15e,%r9d
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
jmp    157a <setup_tcp_server_socket+0x3ba>
jmp    1401 <setup_tcp_server_socket+0x241>
movl   $0x1,-0x64(%rbp)
mov    -0x60(%rbp),%edi
mov    0x2bd6(%rip),%rax
mov    (%rax),%esi
mov    0x2b8d(%rip),%rax
mov    (%rax),%edx
lea    -0x64(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    148a <setup_tcp_server_socket+0x2ca>
mov    0x2b8c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    0x2b6d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x9c(%rbp),%edi
mov    %rax,%rcx
lea    0xc9e(%rip),%rsi
lea    0xbc6(%rip),%rdx
lea    0xbce(%rip),%r8
mov    $0x165,%r9d
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
jmp    157a <setup_tcp_server_socket+0x3ba>
mov    -0x60(%rbp),%edi
mov    -0x58(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x58(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    14fd <setup_tcp_server_socket+0x33d>
mov    0x2b19(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa0(%rbp)
mov    0x2afa(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xa0(%rbp),%edi
mov    %rax,%rcx
lea    0xc56(%rip),%rsi
lea    0xb53(%rip),%rdx
lea    0xb5b(%rip),%r8
mov    $0x174,%r9d
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
jmp    157a <setup_tcp_server_socket+0x3ba>
mov    -0x60(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1566 <setup_tcp_server_socket+0x3a6>
mov    0x2ab0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xa4(%rbp)
mov    0x2a91(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0xa4(%rbp),%edi
mov    %rax,%rcx
lea    0xc03(%rip),%rsi
lea    0xaea(%rip),%rdx
lea    0xaf2(%rip),%r8
mov    $0x179,%r9d
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x60(%rbp),%edi
call   1070 <close@plt>
jmp    157a <setup_tcp_server_socket+0x3ba>
mov    -0x50(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    -0x60(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    15c6 <setup_tcp_server_socket+0x406>
mov    -0x58(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x58(%rbp)
jmp    12f9 <setup_tcp_server_socket+0x139>
mov    -0x50(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    0x2a2d(%rip),%rax
mov    (%rax),%edi
lea    0xbb5(%rip),%rsi
lea    0xa84(%rip),%rdx
lea    0xa8c(%rip),%rcx
mov    $0x181,%r8d
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setup_tcp_server_socket>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %ecx,%r15d
mov    %edx,%r12d
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14,%rdx
call   10b0 <getaddrinfo@plt>
test   %eax,%eax
je     128a <setup_tcp_server_socket+0xca>
mov    0x2d95(%rip),%rcx
mov    (%rcx),%r14d
mov    %eax,%edi
call   1040 <gai_strerror@plt>
test   %rbx,%rbx
lea    0xdf0(%rip),%rcx
cmove  %rcx,%rbx
test   %rbp,%rbp
cmove  %rcx,%rbp
lea    0xde5(%rip),%r10
lea    0xda0(%rip),%rsi
lea    0xdc8(%rip),%rdx
mov    %r14d,%edi
mov    %rax,%rcx
mov    %rbx,%r8
mov    %rbp,%r9
xor    %eax,%eax
push   $0x152
push   %r10
call   1080 <fprintf@plt>
add    $0x10,%rsp
jmp    14bc <setup_tcp_server_socket+0x2fc>
mov    0x10(%rsp),%r13
test   %r13,%r13
je     148a <setup_tcp_server_socket+0x2ca>
mov    %r12d,0x1c(%rsp)
lea    0xd8b(%rip),%r12
lea    0xd93(%rip),%rbp
jmp    12f8 <setup_tcp_server_socket+0x138>
mov    0x2d14(%rip),%rax
mov    (%rax),%ebx
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %ebx,%edi
lea    0xe33(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbp,%r8
mov    $0x165,%r9d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r14d,%edi
call   1070 <close@plt>
mov    0x18(%r13),%r13
test   %r13,%r13
je     1483 <setup_tcp_server_socket+0x2c3>
mov    0x10(%r13),%edi
mov    0x8(%r13),%edx
mov    0xc(%r13),%esi
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     13e0 <setup_tcp_server_socket+0x220>
mov    %eax,%r14d
test   %r15d,%r15d
je     1341 <setup_tcp_server_socket+0x181>
movl   $0x1,0xc(%rsp)
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
mov    %r14d,%edi
lea    0xc(%rsp),%rdx
call   1060 <ioctl@plt>
cmp    $0xffffffff,%eax
je     141b <setup_tcp_server_socket+0x25b>
movl   $0x1,0xc(%rsp)
mov    0x2c98(%rip),%rax
mov    (%rax),%esi
mov    0x2c4f(%rip),%rax
mov    (%rax),%edx
mov    %r14d,%edi
lea    0xc(%rsp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     12ad <setup_tcp_server_socket+0xed>
mov    0x0(%r13),%edx
mov    0x4(%r13),%esi
mov    %r14d,%edi
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
je     144f <setup_tcp_server_socket+0x28f>
mov    %r14d,%edi
mov    0x1c(%rsp),%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    14d4 <setup_tcp_server_socket+0x314>
mov    0x2c1c(%rip),%rax
mov    (%rax),%ebx
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %ebx,%edi
lea    0xd7c(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbp,%r8
mov    $0x179,%r9d
jmp    12dc <setup_tcp_server_socket+0x11c>
nopl   0x0(%rax)
mov    0x2be1(%rip),%rax
mov    (%rax),%ebx
mov    0x2bc8(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %ebx,%edi
lea    0xcc7(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbp,%r8
mov    $0x158,%r9d
xor    %eax,%eax
call   1080 <fprintf@plt>
jmp    12eb <setup_tcp_server_socket+0x12b>
mov    0x2ba6(%rip),%rax
mov    (%rax),%ebx
mov    0x2b8d(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %ebx,%edi
lea    0xca4(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbp,%r8
mov    $0x15e,%r9d
jmp    12dc <setup_tcp_server_socket+0x11c>
mov    0x2b72(%rip),%rax
mov    (%rax),%ebx
mov    0x2b59(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    %ebx,%edi
lea    0xcbc(%rip),%rsi
mov    %r12,%rdx
mov    %rax,%rcx
mov    %rbp,%r8
mov    $0x174,%r9d
jmp    12dc <setup_tcp_server_socket+0x11c>
mov    0x10(%rsp),%rdi
jmp    148c <setup_tcp_server_socket+0x2cc>
xor    %edi,%edi
call   10d0 <freeaddrinfo@plt>
mov    0x2b30(%rip),%rax
mov    (%rax),%edi
lea    0xcb8(%rip),%rsi
lea    0xb87(%rip),%rdx
lea    0xb8f(%rip),%rcx
mov    $0x181,%r8d
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x10(%rsp),%rdi
call   10d0 <freeaddrinfo@plt>
jmp    14c2 <setup_tcp_server_socket+0x302>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"%s: getaddrinfo: %s, host=%s, port=%s (%s:%d)\0A\00"
@.str.1 = [8 x i8] c"warning\00"
@.str.2 = [7 x i8] c"(null)\00"
@.str.3 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/common.c\00"
@.str.4 = [24 x i8] c"%s: socket: %s (%s:%d)\0A\00"
@errno = global i32 0
@FIONBIO = global i32 0
@.str.5 = [33 x i8] c"%s: ioctl [FIONBIO]: %s (%s:%d)\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.6 = [43 x i8] c"%s: setsockopt [SO_REUSEADDR]: %s (%s:%d)\0A\00"
@.str.7 = [22 x i8] c"%s: bind: %s (%s:%d)\0A\00"
@.str.8 = [24 x i8] c"%s: listen: %s (%s:%d)\0A\00"
@.str.9 = [45 x i8] c"%s: Can't create any server sockets (%s:%d)\0A\00"
define i32 @setup_tcp_server_socket(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%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
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
%16 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 40)
%17 = load i32, i32* @AF_UNSPEC
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %17, i32* %18
%19 = load i32, i32* @SOCK_STREAM
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %19, i32* %20
%21 = load i32, i32* @AI_PASSIVE
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %21, i32* %22
%23 = load i8*, i8** %6
%24 = load i8*, i8** %7
%25 = call i32 @getaddrinfo(i8* %23, i8* %24, %struct.addrinfo* %10, %struct.addrinfo** %11)
store i32 %25, i32* %13
%26 = load i32, i32* %13
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %47
28: ; preds = %4
%29 = load i32, i32* @stderr
%30 = load i32, i32* %13
%31 = call i8* @gai_strerror(i32 %30)
%32 = load i8*, i8** %6
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %36
34: ; preds = %28
%35 = load i8*, i8** %6
br label %37
36: ; preds = %28
br label %37
37: ; preds = %36, %34
%38 = phi i8* [ %35, %34 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %36 ]
%39 = load i8*, i8** %7
%40 = icmp ne i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = load i8*, i8** %7
br label %44
43: ; preds = %37
br label %44
44: ; preds = %43, %41
%45 = phi i8* [ %42, %41 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %43 ]
%46 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %31, i8* %38, i8* %45, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 338)
store i32 -1, i32* %5
br label %141
47: ; preds = %4
%48 = load %struct.addrinfo*, %struct.addrinfo** %11
store %struct.addrinfo* %48, %struct.addrinfo** %12
br label %49
49: ; preds = %132, %47
%50 = load %struct.addrinfo*, %struct.addrinfo** %12
%51 = icmp ne %struct.addrinfo* %50, null
br i1 %51, label %52, label %136
52: ; preds = %49
%53 = load %struct.addrinfo*, %struct.addrinfo** %12
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 4
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %12
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 3
%58 = load i32, i32* %57
%59 = load %struct.addrinfo*, %struct.addrinfo** %12
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 2
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %55, i32 %58, i32 %61)
store i32 %62, i32* %14
%63 = load i32, i32* %14
%64 = icmp eq i32 %63, -1
br i1 %64, label %65, label %70
65: ; preds = %52
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = call i8* @strerror(i32 %67)
%69 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %68, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 344)
br label %132
70: ; preds = %52
%71 = load i32, i32* %9
%72 = icmp ne i32 %71, 0
br i1 %72, label %73, label %86
73: ; preds = %70
store i32 1, i32* %15
%74 = load i32, i32* %14
%75 = load i32, i32* @FIONBIO
%76 = call i32 @ioctl(i32 %74, i32 %75, i32* %15)
%77 = icmp eq i32 %76, -1
br i1 %77, label %78, label %85
78: ; preds = %73
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i8* @strerror(i32 %80)
%82 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %81, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 350)
%83 = load i32, i32* %14
%84 = call i32 @close(i32 %83)
br label %132
85: ; preds = %73
br label %86
86: ; preds = %85, %70
store i32 1, i32* %15
%87 = load i32, i32* %14
%88 = load i32, i32* @SOL_SOCKET
%89 = load i32, i32* @SO_REUSEADDR
%90 = call i32 @setsockopt(i32 %87, i32 %88, i32 %89, i32* %15, i32 4)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %99
92: ; preds = %86
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %95, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 357)
%97 = load i32, i32* %14
%98 = call i32 @close(i32 %97)
br label %132
99: ; preds = %86
%100 = load i32, i32* %14
%101 = load %struct.addrinfo*, %struct.addrinfo** %12
%102 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %101, i32 0, i32 1
%103 = load i32, i32* %102
%104 = load %struct.addrinfo*, %struct.addrinfo** %12
%105 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %104, i32 0, i32 0
%106 = load i32, i32* %105
%107 = call i32 @bind(i32 %100, i32 %103, i32 %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %116
109: ; preds = %99
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %112, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 372)
%114 = load i32, i32* %14
%115 = call i32 @close(i32 %114)
br label %132
116: ; preds = %99
%117 = load i32, i32* %14
%118 = load i32, i32* %8
%119 = call i32 @listen(i32 %117, i32 %118)
%120 = icmp eq i32 %119, -1
br i1 %120, label %121, label %128
121: ; preds = %116
%122 = load i32, i32* @stderr
%123 = load i32, i32* @errno
%124 = call i8* @strerror(i32 %123)
%125 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %122, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %124, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 377)
%126 = load i32, i32* %14
%127 = call i32 @close(i32 %126)
br label %132
128: ; preds = %116
%129 = load %struct.addrinfo*, %struct.addrinfo** %11
%130 = call i32 @freeaddrinfo(%struct.addrinfo* %129)
%131 = load i32, i32* %14
store i32 %131, i32* %5
br label %141
132: ; preds = %121, %109, %92, %78, %65
%133 = load %struct.addrinfo*, %struct.addrinfo** %12
%134 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %133, i32 0, i32 5
%135 = load %struct.addrinfo*, %struct.addrinfo** %134
store %struct.addrinfo* %135, %struct.addrinfo** %12
br label %49
136: ; preds = %49
%137 = load %struct.addrinfo*, %struct.addrinfo** %11
%138 = call i32 @freeaddrinfo(%struct.addrinfo* %137)
%139 = load i32, i32* @stderr
%140 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %139, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 385)
store i32 -1, i32* %5
br label %141
141: ; preds = %136, %128, %44
%142 = load i32, i32* %5
ret i32 %142
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [47 x i8] c"%s: getaddrinfo: %s, host=%s, port=%s (%s:%d)\0A\00"
@.str.1 = [8 x i8] c"warning\00"
@.str.2 = [7 x i8] c"(null)\00"
@.str.3 = [137 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/pandax381/rlogd/refs/heads/master/src/common.c\00"
@.str.4 = [24 x i8] c"%s: socket: %s (%s:%d)\0A\00"
@errno = global i32 0
@FIONBIO = global i32 0
@.str.5 = [33 x i8] c"%s: ioctl [FIONBIO]: %s (%s:%d)\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.6 = [43 x i8] c"%s: setsockopt [SO_REUSEADDR]: %s (%s:%d)\0A\00"
@.str.7 = [22 x i8] c"%s: bind: %s (%s:%d)\0A\00"
@.str.8 = [24 x i8] c"%s: listen: %s (%s:%d)\0A\00"
@.str.9 = [45 x i8] c"%s: Can't create any server sockets (%s:%d)\0A\00"
define i32 @setup_tcp_server_socket(i8* %0, i8* %1, i32 %2, i32 %3) {
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %5 to i8*
%9 = bitcast %struct.addrinfo** %6 to i8*
%10 = bitcast i32* %7 to i8*
%11 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 40)
%12 = load i32, i32* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %12, i32* %13
%14 = load i32, i32* @SOCK_STREAM
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
store i32 %14, i32* %15
%16 = load i32, i32* @AI_PASSIVE
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 6
store i32 %16, i32* %17
%18 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %5, %struct.addrinfo** %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %4
%21 = load %struct.addrinfo*, %struct.addrinfo** %6
%22 = icmp eq %struct.addrinfo* %21, null
br i1 %22, label %101, label %23
23: ; preds = %20
%24 = icmp eq i32 %3, 0
br label %33
25: ; preds = %4
%26 = load i32, i32* @stderr
%27 = call i8* @gai_strerror(i32 %18)
%28 = icmp eq i8* %0, null
%29 = select i1 %28, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %0
%30 = icmp eq i8* %1, null
%31 = select i1 %30, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %1
%32 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %27, i8* %29, i8* %31, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 338)
br label %106
33: ; preds = %23, %95
%34 = phi %struct.addrinfo* [ %21, %23 ], [ %97, %95 ]
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 4
%36 = load i32, i32* %35
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 3
%38 = load i32, i32* %37
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 2
%40 = load i32, i32* %39
%41 = call i32 @socket(i32 %36, i32 %38, i32 %40)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %48
43: ; preds = %33
%44 = load i32, i32* @stderr
%45 = load i32, i32* @errno
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 344)
br label %95
48: ; preds = %33
br i1 %24, label %59, label %49
49: ; preds = %48
store i32 1, i32* %7
%50 = load i32, i32* @FIONBIO
%51 = call i32 @ioctl(i32 %41, i32 %50, i32* %7)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %59
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = load i32, i32* @errno
%56 = call i8* @strerror(i32 %55)
%57 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %56, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 350)
%58 = call i32 @close(i32 %41)
br label %95
59: ; preds = %49, %48
store i32 1, i32* %7
%60 = load i32, i32* @SOL_SOCKET
%61 = load i32, i32* @SO_REUSEADDR
%62 = call i32 @setsockopt(i32 %41, i32 %60, i32 %61, i32* %7, i32 4)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %70
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %67, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 357)
%69 = call i32 @close(i32 %41)
br label %95
70: ; preds = %59
%71 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 1
%72 = load i32, i32* %71
%73 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 0
%74 = load i32, i32* %73
%75 = call i32 @bind(i32 %41, i32 %72, i32 %74)
%76 = icmp eq i32 %75, -1
br i1 %76, label %77, label %83
77: ; preds = %70
%78 = load i32, i32* @stderr
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %80, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 372)
%82 = call i32 @close(i32 %41)
br label %95
83: ; preds = %70
%84 = call i32 @listen(i32 %41, i32 %2)
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %92
86: ; preds = %83
%87 = load i32, i32* @stderr
%88 = load i32, i32* @errno
%89 = call i8* @strerror(i32 %88)
%90 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %87, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %89, i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 377)
%91 = call i32 @close(i32 %41)
br label %95
92: ; preds = %83
%93 = load %struct.addrinfo*, %struct.addrinfo** %6
%94 = call i32 @freeaddrinfo(%struct.addrinfo* %93)
br label %106
95: ; preds = %86, %77, %64, %53, %43
%96 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i64 0, i32 5
%97 = load %struct.addrinfo*, %struct.addrinfo** %96
%98 = icmp eq %struct.addrinfo* %97, null
br i1 %98, label %99, label %33
99: ; preds = %95
%100 = load %struct.addrinfo*, %struct.addrinfo** %6
br label %101
101: ; preds = %99, %20
%102 = phi %struct.addrinfo* [ %100, %99 ], [ null, %20 ]
%103 = call i32 @freeaddrinfo(%struct.addrinfo* %102)
%104 = load i32, i32* @stderr
%105 = call i32 (i32, i8*, i8*, i8*, ...) @fprintf(i32 %104, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([137 x i8], [137 x i8]* @.str.3, i64 0, i64 0), i32 385)
br label %106
106: ; preds = %101, %92, %25
%107 = phi i32 [ -1, %25 ], [ %41, %92 ], [ -1, %101 ]
ret i32 %107
}