#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 {
  scalar_t__ 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*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ IPPROTO_TCP;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOMAXCONN;
int bind(int, int /*<<< orphan*/, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int socket_listen(const char *hostname, const char *port, int *out_sock) {
  int rv;
  struct addrinfo *addrs = NULL, *addr = NULL, hints;
  int local_sock = -1;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_INET;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = IPPROTO_TCP;
  hints.ai_flags = AI_PASSIVE;
  rv = getaddrinfo(hostname, port, &hints, &addrs);
  if (rv != 0) {
    fprintf(stderr, "Failed to get address info for %s:%s. Error: %d\n",
            hostname, port, rv);
    goto out;
  }
  if (addrs == NULL) {
    fprintf(stderr, "Failed to get any addreses for %s:%s\n", hostname, port);
    rv = -1;
    goto out;
  }
  for (addr = addrs; addr != NULL; addr = addr->ai_next) {
    local_sock = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
    if (local_sock == -1) {
      fprintf(stderr, "Failed to create socket.\n");
      continue;
    }
    rv = bind(local_sock, addr->ai_addr, (int)addr->ai_addrlen);
    if (rv < 0) {
      fprintf(stderr, "Failed to bind. Error: %d\n", rv);
      close(local_sock);
      local_sock = -1;
      continue;
    }
    rv = listen(local_sock, SOMAXCONN);
    if (rv < 0) {
      fprintf(stderr, "Failed to listen.\n");
      close(local_sock);
      local_sock = -1;
      continue;
    }
    break;
  }
  if (local_sock == -1) {
    fprintf(stderr, "Failed to listen to any address.\n");
    rv = -1;
    goto out;
  }
out:
  if (addrs != NULL) {
    freeaddrinfo(addrs);
  }
  if (rv != 0) {
    if (local_sock != -1) {
      close(local_sock);
    }
    *out_sock = -1;
  } else {
    *out_sock = local_sock;
  }
  return rv;
}


x86 assembly (clang, -O0):
<socket_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0xffffffff,-0x5c(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2e02(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1080 <getaddrinfo@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1235 <socket_listen+0xb5>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    13a5 <socket_listen+0x225>
cmpq   $0x0,-0x28(%rbp)
jne    126b <socket_listen+0xeb>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    13a5 <socket_listen+0x225>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1373 <socket_listen+0x1f3>
mov    -0x30(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%edx
call   10a0 <socket@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0xffffffff,-0x5c(%rbp)
jne    12c1 <socket_listen+0x141>
mov    0x2d1c(%rip),%rax
mov    (%rax),%edi
lea    0xda2(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1362 <socket_listen+0x1e2>
mov    -0x5c(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %eax,%edx
call   1070 <bind@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1314 <socket_listen+0x194>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
lea    0xd78(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x5c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x5c(%rbp)
jmp    1362 <socket_listen+0x1e2>
mov    -0x5c(%rbp),%edi
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
call   1060 <listen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    135d <socket_listen+0x1dd>
mov    0x2c8f(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x5c(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x5c(%rbp)
jmp    1362 <socket_listen+0x1e2>
jmp    1373 <socket_listen+0x1f3>
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    1273 <socket_listen+0xf3>
cmpl   $0xffffffff,-0x5c(%rbp)
jne    13a0 <socket_listen+0x220>
mov    0x2c44(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    13a5 <socket_listen+0x225>
jmp    13a5 <socket_listen+0x225>
cmpq   $0x0,-0x28(%rbp)
je     13b9 <socket_listen+0x239>
mov    -0x28(%rbp),%rdi
call   1090 <freeaddrinfo@plt>
cmpl   $0x0,-0x1c(%rbp)
je     13e4 <socket_listen+0x264>
cmpl   $0xffffffff,-0x5c(%rbp)
je     13d5 <socket_listen+0x255>
mov    -0x5c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%rax
movl   $0xffffffff,(%rax)
jmp    13ed <socket_listen+0x26d>
mov    -0x5c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<socket_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbp
movq   $0x0,(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1030 <memset@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2e04(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    0x2e07(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1080 <getaddrinfo@plt>
test   %eax,%eax
je     1228 <socket_listen+0xa8>
mov    %eax,%ebx
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
lea    0xdf2(%rip),%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
mov    %ebx,%r8d
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    1339 <socket_listen+0x1b9>
mov    (%rsp),%r14
test   %r14,%r14
je     1309 <socket_listen+0x189>
mov    %r12,0x8(%rsp)
mov    0x2d87(%rip),%r15
mov    0x2d78(%rip),%r12
lea    0xe3d(%rip),%r13
jmp    127a <socket_listen+0xfa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%r15),%edi
lea    0xded(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x18(%r14),%r14
test   %r14,%r14
je     12ec <socket_listen+0x16c>
mov    0x14(%r14),%edi
mov    0xc(%r14),%edx
mov    0x10(%r14),%esi
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     1260 <socket_listen+0xe0>
mov    %eax,%ebp
mov    (%r14),%edx
mov    0x8(%r14),%esi
mov    %eax,%edi
call   1070 <bind@plt>
test   %eax,%eax
js     12d0 <socket_listen+0x150>
mov    (%r12),%esi
mov    %ebp,%edi
call   1060 <listen@plt>
test   %eax,%eax
jns    1332 <socket_listen+0x1b2>
mov    (%r15),%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    12e3 <socket_listen+0x163>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%r15),%edi
lea    0xd97(%rip),%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1271 <socket_listen+0xf1>
mov    (%r15),%edi
lea    0xda9(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    $0xffffffff,%ebp
jmp    1334 <socket_listen+0x1b4>
mov    0x2cb8(%rip),%rax
mov    (%rax),%edi
lea    0xd18(%rip),%rsi
mov    %rbp,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    $0xffffffff,%ebp
jmp    1339 <socket_listen+0x1b9>
mov    %eax,%ebx
mov    0x8(%rsp),%r12
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1347 <socket_listen+0x1c7>
call   1090 <freeaddrinfo@plt>
test   %ebx,%ebx
je     135f <socket_listen+0x1df>
mov    $0xffffffff,%r14d
cmp    $0xffffffff,%ebp
je     1362 <socket_listen+0x1e2>
mov    %ebp,%edi
call   1040 <close@plt>
jmp    1362 <socket_listen+0x1e2>
mov    %ebp,%r14d
mov    %r14d,(%r12)
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i32, i32, %struct.addrinfo*, i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@IPPROTO_TCP = global i32 0
@AI_PASSIVE = global i32 0
@stderr = global i32 0
@.str = [49 x i8] c"Failed to get address info for %s:%s. Error: %d\0A\00"
@.str.1 = [38 x i8] c"Failed to get any addreses for %s:%s\0A\00"
@.str.2 = [26 x i8] c"Failed to create socket.\0A\00"
@.str.3 = [27 x i8] c"Failed to bind. Error: %d\0A\00"
@SOMAXCONN = global i32 0
@.str.4 = [19 x i8] c"Failed to listen.\0A\00"
@.str.5 = [34 x i8] c"Failed to listen to any address.\0A\00"
define i32 @socket_listen(i8* %0, i8* %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo
%11 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32* %2, i32** %6
store %struct.addrinfo* null, %struct.addrinfo** %8
store %struct.addrinfo* null, %struct.addrinfo** %9
store i32 -1, i32* %11
%12 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 40)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %13, i32* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 3
store i32 %15, i32* %16
%17 = load i32, i32* @IPPROTO_TCP
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 2
store i32 %17, i32* %18
%19 = load i32, i32* @AI_PASSIVE
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %19, i32* %20
%21 = load i8*, i8** %4
%22 = load i8*, i8** %5
%23 = call i32 @getaddrinfo(i8* %21, i8* %22, %struct.addrinfo* %10, %struct.addrinfo** %8)
store i32 %23, i32* %7
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %3
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %4
%29 = load i8*, i8** %5
%30 = load i32, i32* %7
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8* %28, i8* %29, i32 %30)
br label %102
32: ; preds = %3
%33 = load %struct.addrinfo*, %struct.addrinfo** %8
%34 = icmp eq %struct.addrinfo* %33, null
br i1 %34, label %35, label %40
35: ; preds = %32
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %4
%38 = load i8*, i8** %5
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38)
store i32 -1, i32* %7
br label %102
40: ; preds = %32
%41 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %41, %struct.addrinfo** %9
br label %42
42: ; preds = %91, %40
%43 = load %struct.addrinfo*, %struct.addrinfo** %9
%44 = icmp ne %struct.addrinfo* %43, null
br i1 %44, label %45, label %95
45: ; preds = %42
%46 = load %struct.addrinfo*, %struct.addrinfo** %9
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 4
%48 = load i32, i32* %47
%49 = load %struct.addrinfo*, %struct.addrinfo** %9
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %49, i32 0, i32 3
%51 = load i32, i32* %50
%52 = load %struct.addrinfo*, %struct.addrinfo** %9
%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* %11
%56 = load i32, i32* %11
%57 = icmp eq i32 %56, -1
br i1 %57, label %58, label %61
58: ; preds = %45
%59 = load i32, i32* @stderr
%60 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %91
61: ; preds = %45
%62 = load i32, i32* %11
%63 = load %struct.addrinfo*, %struct.addrinfo** %9
%64 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %63, i32 0, i32 1
%65 = load i32, i32* %64
%66 = load %struct.addrinfo*, %struct.addrinfo** %9
%67 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %66, i32 0, i32 0
%68 = load i64, i64* %67
%69 = trunc i64 %68 to i32
%70 = call i32 @bind(i32 %62, i32 %65, i32 %69)
store i32 %70, i32* %7
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %79
73: ; preds = %61
%74 = load i32, i32* @stderr
%75 = load i32, i32* %7
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %74, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i32 %75)
%77 = load i32, i32* %11
%78 = call i32 @close(i32 %77)
store i32 -1, i32* %11
br label %91
79: ; preds = %61
%80 = load i32, i32* %11
%81 = load i32, i32* @SOMAXCONN
%82 = call i32 @listen(i32 %80, i32 %81)
store i32 %82, i32* %7
%83 = load i32, i32* %7
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %90
85: ; preds = %79
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%88 = load i32, i32* %11
%89 = call i32 @close(i32 %88)
store i32 -1, i32* %11
br label %91
90: ; preds = %79
br label %95
91: ; preds = %85, %73, %58
%92 = load %struct.addrinfo*, %struct.addrinfo** %9
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 5
%94 = load %struct.addrinfo*, %struct.addrinfo** %93
store %struct.addrinfo* %94, %struct.addrinfo** %9
br label %42
95: ; preds = %90, %42
%96 = load i32, i32* %11
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %7
br label %102
101: ; preds = %95
br label %102
102: ; preds = %101, %98, %35, %26
%103 = load %struct.addrinfo*, %struct.addrinfo** %8
%104 = icmp ne %struct.addrinfo* %103, null
br i1 %104, label %105, label %108
105: ; preds = %102
%106 = load %struct.addrinfo*, %struct.addrinfo** %8
%107 = call i32 @freeaddrinfo(%struct.addrinfo* %106)
br label %108
108: ; preds = %105, %102
%109 = load i32, i32* %7
%110 = icmp ne i32 %109, 0
br i1 %110, label %111, label %119
111: ; preds = %108
%112 = load i32, i32* %11
%113 = icmp ne i32 %112, -1
br i1 %113, label %114, label %117
114: ; preds = %111
%115 = load i32, i32* %11
%116 = call i32 @close(i32 %115)
br label %117
117: ; preds = %114, %111
%118 = load i32*, i32** %6
store i32 -1, i32* %118
br label %122
119: ; preds = %108
%120 = load i32, i32* %11
%121 = load i32*, i32** %6
store i32 %120, i32* %121
br label %122
122: ; preds = %119, %117
%123 = load i32, i32* %7
ret i32 %123
}

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