#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;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ asprintf(char **, char *, int);
int /*<<< orphan*/ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int sock_daemon_connect(int port) {
  struct addrinfo *res, *t;
  struct addrinfo hints = {.ai_flags = AI_PASSIVE,
                           .ai_family = AF_UNSPEC,
                           .ai_socktype = SOCK_STREAM};
  char *service;
  int n;
  int sockfd = -1, connfd;
  if (asprintf(&service, "%d", port) < 0) {
    fprintf(stderr, "asprintf failed\n");
    return -1;
  }
  n = getaddrinfo(NULL, service, &hints, &res);
  if (n < 0) {
    fprintf(stderr, "%s for port %d\n", gai_strerror(n), port);
    free(service);
    return -1;
  }
  for (t = res; t; t = t->ai_next) {
    sockfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol);
    if (sockfd >= 0) {
      n = 1;
      setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &n, sizeof n);
      if (!bind(sockfd, t->ai_addr, t->ai_addrlen))
        break;
      close(sockfd);
      sockfd = -1;
    }
  }
  freeaddrinfo(res);
  free(service);
  if (sockfd < 0) {
    fprintf(stderr, "couldn't listen to port %d\n", port);
    return -1;
  }
  listen(sockfd, 1);
  connfd = accept(sockfd, NULL, 0);
  close(sockfd);
  if (connfd < 0) {
    fprintf(stderr, "accept() failed\n");
    return -1;
  }
  return connfd;
}


x86 assembly (clang, -O0):
<sock_daemon_connect>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x38(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2dd9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x50(%rbp)
mov    -0x8(%rbp),%edx
lea    -0x48(%rbp),%rdi
lea    0xddf(%rip),%rsi
call   1090 <asprintf@plt>
cmp    $0x0,%rax
jge    1253 <sock_daemon_connect+0x93>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdc3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fd <sock_daemon_connect+0x23d>
mov    -0x48(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x40(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
jge    12b5 <sock_daemon_connect+0xf5>
mov    0x2d4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    -0x4c(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x58(%rbp),%edi
mov    %rax,%rdx
mov    -0x8(%rbp),%ecx
lea    0xd7b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fd <sock_daemon_connect+0x23d>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1362 <sock_daemon_connect+0x1a2>
mov    -0x18(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jl     134c <sock_daemon_connect+0x18c>
movl   $0x1,-0x4c(%rbp)
mov    -0x50(%rbp),%edi
mov    0x2ce8(%rip),%rax
mov    (%rax),%esi
mov    0x2caf(%rip),%rax
mov    (%rax),%edx
lea    -0x4c(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    -0x50(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
call   10a0 <bind@plt>
cmp    $0x0,%eax
jne    133d <sock_daemon_connect+0x17d>
jmp    1362 <sock_daemon_connect+0x1a2>
mov    -0x50(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x50(%rbp)
jmp    1351 <sock_daemon_connect+0x191>
mov    -0x18(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12bd <sock_daemon_connect+0xfd>
mov    -0x10(%rbp),%rdi
call   10d0 <freeaddrinfo@plt>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x50(%rbp)
jge    13a4 <sock_daemon_connect+0x1e4>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
lea    0xc93(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fd <sock_daemon_connect+0x23d>
mov    -0x50(%rbp),%edi
mov    $0x1,%esi
call   1080 <listen@plt>
mov    -0x50(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,-0x54(%rbp)
mov    -0x50(%rbp),%edi
call   1060 <close@plt>
cmpl   $0x0,-0x54(%rbp)
jge    13f7 <sock_daemon_connect+0x237>
mov    0x2bed(%rip),%rax
mov    (%rax),%edi
lea    0xc5c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fd <sock_daemon_connect+0x23d>
mov    -0x54(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_daemon_connect>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edi,%r14d
movq   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    0x2de2(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x40(%rsp)
lea    0xde7(%rip),%rsi
lea    0x10(%rsp),%rdi
mov    %r14d,%edx
call   1090 <asprintf@plt>
test   %rax,%rax
js     12e0 <sock_daemon_connect+0x120>
mov    0x10(%rsp),%rsi
lea    0x20(%rsp),%rdx
lea    0x18(%rsp),%rcx
xor    %edi,%edi
call   10c0 <getaddrinfo@plt>
mov    %eax,0xc(%rsp)
test   %eax,%eax
js     12f5 <sock_daemon_connect+0x135>
mov    0x18(%rsp),%rbx
test   %rbx,%rbx
je     1327 <sock_daemon_connect+0x167>
mov    0x2d82(%rip),%r12
mov    0x2d4b(%rip),%r13
lea    0xc(%rsp),%r15
jmp    1295 <sock_daemon_connect+0xd5>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
call   1060 <close@plt>
mov    $0xffffffff,%ebp
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     12d9 <sock_daemon_connect+0x119>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10e0 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
js     128c <sock_daemon_connect+0xcc>
movl   $0x1,0xc(%rsp)
mov    (%r12),%esi
mov    0x0(%r13),%edx
mov    %ebp,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   10a0 <bind@plt>
test   %eax,%eax
jne    1280 <sock_daemon_connect+0xc0>
mov    0x18(%rsp),%rdi
jmp    132e <sock_daemon_connect+0x16e>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd13(%rip),%rsi
jmp    1375 <sock_daemon_connect+0x1b5>
mov    0x2ccc(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1050 <gai_strerror@plt>
lea    0xd08(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
mov    %r14d,%ecx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
jmp    1398 <sock_daemon_connect+0x1d8>
mov    $0xffffffff,%ebp
xor    %edi,%edi
call   10d0 <freeaddrinfo@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
test   %ebp,%ebp
js     137e <sock_daemon_connect+0x1be>
mov    %ebp,%edi
mov    $0x1,%esi
call   1080 <listen@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <accept@plt>
mov    %eax,%ebx
mov    %ebp,%edi
call   1060 <close@plt>
test   %ebx,%ebx
jns    139d <sock_daemon_connect+0x1dd>
mov    0x2c5c(%rip),%rax
mov    (%rax),%edi
lea    0xccb(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1398 <sock_daemon_connect+0x1d8>
mov    0x2c43(%rip),%rax
mov    (%rax),%edi
lea    0xc96(%rip),%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"asprintf failed\0A\00"
@.str.2 = [16 x i8] c"%s for port %d\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [28 x i8] c"couldn't listen to port %d\0A\00"
@.str.4 = [17 x i8] c"accept() failed\0A\00"
define i32 @sock_daemon_connect(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo*
%6 = alloca %struct.addrinfo
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %3
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 0
store i32 0, i32* %11
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 1
store i32 0, i32* %12
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 2
store i32 0, i32* %13
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 3
%15 = load i32, i32* @SOCK_STREAM
store i32 %15, i32* %14
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 4
%17 = load i32, i32* @AF_UNSPEC
store i32 %17, i32* %16
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i32 0, i32 6
%20 = load i32, i32* @AI_PASSIVE
store i32 %20, i32* %19
store i32 -1, i32* %9
%21 = load i32, i32* %3
%22 = call i64 @asprintf(i8** %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %1
%25 = load i32, i32* @stderr
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %106
27: ; preds = %1
%28 = load i8*, i8** %7
%29 = call i32 @getaddrinfo(i32* null, i8* %28, %struct.addrinfo* %6, %struct.addrinfo** %4)
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %40
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = load i32, i32* %8
%35 = call i8* @gai_strerror(i32 %34)
%36 = load i32, i32* %3
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 %36)
%38 = load i8*, i8** %7
%39 = call i32 @free(i8* %38)
store i32 -1, i32* %2
br label %106
40: ; preds = %27
%41 = load %struct.addrinfo*, %struct.addrinfo** %4
store %struct.addrinfo* %41, %struct.addrinfo** %5
br label %42
42: ; preds = %77, %40
%43 = load %struct.addrinfo*, %struct.addrinfo** %5
%44 = icmp ne %struct.addrinfo* %43, null
br i1 %44, label %45, label %81
45: ; preds = %42
%46 = load %struct.addrinfo*, %struct.addrinfo** %5
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 4
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %5
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 3
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %5
%53 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %52, i32 0, i32 2
%54 = load i32, i32* %53
%55 = call i32 @socket(i32 %48, i32 %51, i32 %54)
store i32 %55, i32* %9
%56 = load i32, i32* %9
%57 = icmp sge i32 %56, 0
br i1 %57, label %58, label %76
58: ; preds = %45
store i32 1, i32* %8
%59 = load i32, i32* %9
%60 = load i32, i32* @SOL_SOCKET
%61 = load i32, i32* @SO_REUSEADDR
%62 = call i32 @setsockopt(i32 %59, i32 %60, i32 %61, i32* %8, i32 4)
%63 = load i32, i32* %9
%64 = load %struct.addrinfo*, %struct.addrinfo** %5
%65 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %64, i32 0, i32 1
%66 = load i32, i32* %65
%67 = load %struct.addrinfo*, %struct.addrinfo** %5
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @bind(i32 %63, i32 %66, i32 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %73, label %72
72: ; preds = %58
br label %81
73: ; preds = %58
%74 = load i32, i32* %9
%75 = call i32 @close(i32 %74)
store i32 -1, i32* %9
br label %76
76: ; preds = %73, %45
br label %77
77: ; preds = %76
%78 = load %struct.addrinfo*, %struct.addrinfo** %5
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i32 0, i32 5
%80 = load %struct.addrinfo*, %struct.addrinfo** %79
store %struct.addrinfo* %80, %struct.addrinfo** %5
br label %42
81: ; preds = %72, %42
%82 = load %struct.addrinfo*, %struct.addrinfo** %4
%83 = call i32 @freeaddrinfo(%struct.addrinfo* %82)
%84 = load i8*, i8** %7
%85 = call i32 @free(i8* %84)
%86 = load i32, i32* %9
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %92
88: ; preds = %81
%89 = load i32, i32* @stderr
%90 = load i32, i32* %3
%91 = call i32 (i32, i8*, ...) @fprintf(i32 %89, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %90)
store i32 -1, i32* %2
br label %106
92: ; preds = %81
%93 = load i32, i32* %9
%94 = call i32 @listen(i32 %93, i32 1)
%95 = load i32, i32* %9
%96 = call i32 @accept(i32 %95, i32* null, i32 0)
store i32 %96, i32* %10
%97 = load i32, i32* %9
%98 = call i32 @close(i32 %97)
%99 = load i32, i32* %10
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %104
101: ; preds = %92
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %106
104: ; preds = %92
%105 = load i32, i32* %10
store i32 %105, i32* %2
br label %106
106: ; preds = %104, %101, %88, %32, %24
%107 = load i32, i32* %2
ret i32 %107
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i32 0
@AI_PASSIVE = global i32 0
@.str = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.1 = [17 x i8] c"asprintf failed\0A\00"
@.str.2 = [16 x i8] c"%s for port %d\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [28 x i8] c"couldn't listen to port %d\0A\00"
@.str.4 = [17 x i8] c"accept() failed\0A\00"
define i32 @sock_daemon_connect(i32 %0) {
%2 = alloca %struct.addrinfo*
%3 = alloca %struct.addrinfo
%4 = alloca i8*
%5 = alloca i32
%6 = bitcast %struct.addrinfo** %2 to i8*
%7 = bitcast %struct.addrinfo* %3 to i8*
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 0
store i32 0, i32* %8
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 1
store i32 0, i32* %9
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
%12 = load i32, i32* @SOCK_STREAM
store i32 %12, i32* %11
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
%14 = load i32, i32* @AF_UNSPEC
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store %struct.addrinfo* null, %struct.addrinfo** %15
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 6
%17 = load i32, i32* @AI_PASSIVE
store i32 %17, i32* %16
%18 = bitcast i8** %4 to i8*
%19 = bitcast i32* %5 to i8*
%20 = call i64 @asprintf(i8** %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %1
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
br label %86
25: ; preds = %1
%26 = load i8*, i8** %4
%27 = call i32 @getaddrinfo(i32* null, i8* %26, %struct.addrinfo* %3, %struct.addrinfo** %2)
store i32 %27, i32* %5
%28 = icmp slt i32 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = load %struct.addrinfo*, %struct.addrinfo** %2
%31 = icmp eq %struct.addrinfo* %30, null
br i1 %31, label %68, label %38
32: ; preds = %25
%33 = load i32, i32* @stderr
%34 = call i8* @gai_strerror(i32 %27)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %34, i32 %0)
%36 = load i8*, i8** %4
%37 = call i32 @free(i8* %36)
br label %86
38: ; preds = %29, %60
%39 = phi %struct.addrinfo* [ %63, %60 ], [ %30, %29 ]
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 4
%41 = load i32, i32* %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 3
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 2
%45 = load i32, i32* %44
%46 = call i32 @socket(i32 %41, i32 %43, i32 %45)
%47 = icmp sgt i32 %46, -1
br i1 %47, label %48, label %60
48: ; preds = %38
store i32 1, i32* %5
%49 = load i32, i32* @SOL_SOCKET
%50 = load i32, i32* @SO_REUSEADDR
%51 = call i32 @setsockopt(i32 %46, i32 %49, i32 %50, i32* %5, i32 4)
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 1
%53 = load i32, i32* %52
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @bind(i32 %46, i32 %53, i32 %55)
%57 = icmp eq i32 %56, 0
br i1 %57, label %65, label %58
58: ; preds = %48
%59 = call i32 @close(i32 %46)
br label %60
60: ; preds = %38, %58
%61 = phi i32 [ -1, %58 ], [ %46, %38 ]
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i64 0, i32 5
%63 = load %struct.addrinfo*, %struct.addrinfo** %62
%64 = icmp eq %struct.addrinfo* %63, null
br i1 %64, label %65, label %38
65: ; preds = %48, %60
%66 = phi i32 [ %61, %60 ], [ %46, %48 ]
%67 = load %struct.addrinfo*, %struct.addrinfo** %2
br label %68
68: ; preds = %65, %29
%69 = phi %struct.addrinfo* [ null, %29 ], [ %67, %65 ]
%70 = phi i32 [ -1, %29 ], [ %66, %65 ]
%71 = call i32 @freeaddrinfo(%struct.addrinfo* %69)
%72 = load i8*, i8** %4
%73 = call i32 @free(i8* %72)
%74 = icmp slt i32 %70, 0
br i1 %74, label %75, label %78
75: ; preds = %68
%76 = load i32, i32* @stderr
%77 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %86
78: ; preds = %68
%79 = call i32 @listen(i32 %70, i32 1)
%80 = call i32 @accept(i32 %70, i32* null, i32 0)
%81 = call i32 @close(i32 %70)
%82 = icmp slt i32 %80, 0
br i1 %82, label %83, label %86
83: ; preds = %78
%84 = load i32, i32* @stderr
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %84, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %86
86: ; preds = %78, %83, %75, %32, %22
%87 = phi i32 [ -1, %22 ], [ -1, %32 ], [ -1, %75 ], [ -1, %83 ], [ %80, %78 ]
ret i32 %87
}