#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*/ socklen_t;
typedef int /*<<< orphan*/ on;
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
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 *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int tcp_listen(const char *hostname, const char *service, socklen_t *len) {
  int listenfd, n;
  const int on = 1;
  struct addrinfo hints, *res, *rp;
  memset(&hints, 0, sizeof(hints));
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((n = getaddrinfo(hostname, service, &hints, &res)) != 0) {
    fprintf(stderr, "tcp_listen - getaddrinfo() failed: %s\n", gai_strerror(n));
    return -1;
  }
  for (rp = res; rp != NULL; rp = rp->ai_next) {
    listenfd = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol);
    if (listenfd == -1)
      continue;
    if (setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
      fprintf(stderr, "tcp_listen - setsockopt() failed: %s\n",
              strerror(errno));
      close(listenfd);
      freeaddrinfo(res);
      return -1;
    }
    if (bind(listenfd, rp->ai_addr, rp->ai_addrlen) != -1)
      break;
    close(listenfd);
  }
  if (rp == NULL) {
    fprintf(stderr, "tcp_listen failed\n");
    listenfd = -1;
  }
  if (listenfd != -1) {
    if (listen(listenfd, 1024) == -1) {
      fprintf(stderr, "tcp_listen - listen() failed: %s\n", strerror(errno));
      close(listenfd);
      listenfd = -1;
    }
  }
  if (len != NULL)
    *len = res->ai_addrlen;
  freeaddrinfo(res);
  return listenfd;
}


x86 assembly (clang, -O0):
<tcp_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movl   $0x1,-0x2c(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    0x2de7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x60(%rbp),%rcx
call   10a0 <getaddrinfo@plt>
mov    %eax,-0x28(%rbp)
cmp    $0x0,%eax
je     1257 <tcp_listen+0xa7>
mov    0x2d9e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x28(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fb <tcp_listen+0x24b>
mov    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x68(%rbp)
je     134a <tcp_listen+0x19a>
mov    -0x68(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x68(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x68(%rbp),%rax
mov    0x8(%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1296 <tcp_listen+0xe6>
jmp    1339 <tcp_listen+0x189>
mov    -0x24(%rbp),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%esi
mov    0x2d07(%rip),%rax
mov    (%rax),%edx
lea    -0x2c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    130e <tcp_listen+0x15e>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x60(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13fb <tcp_listen+0x24b>
mov    -0x24(%rbp),%edi
mov    -0x68(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x68(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     1331 <tcp_listen+0x181>
jmp    134a <tcp_listen+0x19a>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x68(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x68(%rbp)
jmp    125f <tcp_listen+0xaf>
cmpq   $0x0,-0x68(%rbp)
jne    1373 <tcp_listen+0x1c3>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
je     13d5 <tcp_listen+0x225>
mov    -0x24(%rbp),%edi
mov    $0x400,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    13d0 <tcp_listen+0x220>
mov    0x2c2e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2c12(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xca6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
movl   $0xffffffff,-0x24(%rbp)
jmp    13d5 <tcp_listen+0x225>
cmpq   $0x0,-0x20(%rbp)
je     13ec <tcp_listen+0x23c>
mov    -0x60(%rbp),%rax
mov    (%rax),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x60(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcp_listen>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%rbp
movl   $0x1,0xc(%rsp)
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2df6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x30(%rsp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x1c(%rsp)
mov    %rsp,%rcx
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
je     124c <tcp_listen+0x9c>
mov    0x2da2(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xdca(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
jmp    133e <tcp_listen+0x18e>
mov    (%rsp),%rbx
test   %rbx,%rbx
je     130f <tcp_listen+0x15f>
mov    0x2d88(%rip),%r12
mov    0x2d49(%rip),%r13
lea    0xc(%rsp),%r15
jmp    1284 <tcp_listen+0xd4>
xchg   %ax,%ax
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     130f <tcp_listen+0x15f>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     1277 <tcp_listen+0xc7>
mov    %eax,%ebp
mov    (%r12),%esi
mov    0x0(%r13),%edx
mov    %eax,%edi
mov    %r15,%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     134f <tcp_listen+0x19f>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     1270 <tcp_listen+0xc0>
mov    %ebp,%edi
mov    $0x400,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    132b <tcp_listen+0x17b>
mov    0x2ce5(%rip),%rax
mov    (%rax),%ebx
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd66(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
jmp    1326 <tcp_listen+0x176>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
lea    0xd2e(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    (%rsp),%rdi
test   %r14,%r14
je     1339 <tcp_listen+0x189>
mov    (%rdi),%eax
mov    %eax,(%r14)
call   10c0 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c72(%rip),%rax
mov    (%rax),%ebx
mov    0x2c59(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xcba(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    (%rsp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    $0xffffffff,%ebp
jmp    133e <tcp_listen+0x18e>

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

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