#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 servent {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};
typedef int /*<<< orphan*/ logString;

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
scalar_t__ fprintf(int /*<<< orphan*/, char *, ...);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
struct servent *getservbyname(char *, char *);
int listen(int, int);
int /*<<< orphan*/ logaroo(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int);
int setUpListeningSocket(struct addrinfo *hints, char *PortString) {
  struct addrinfo *servInfo, *p;
  int savError;
  int status;
  int yes = 1;
  int sockListen;
  char logString[8192];
  struct servent *sstatus;
  0 && fprintf(stderr, "Entering setUpListeningSocket\n");
  if ((status = getaddrinfo(NULL, PortString, hints, &servInfo)) != 0) {
    savError = errno;
    if ((sstatus = getservbyname(PortString, "tcp")) == NULL) {
      snprintf(logString, sizeof(logString),
               "getservbyname: failed to find service \"%s\"", PortString);
      logaroo(logString);
      1 && fprintf(stderr, "%s\n", logString);
    } else {
      snprintf(logString, sizeof(logString), "getaddrinfo: %s",
               gai_strerror(savError));
      logaroo(logString);
      1 && fprintf(stderr, "%s\n", logString);
    }
    return (-1);
  }
  if ((sockListen = socket(servInfo->ai_family, servInfo->ai_socktype,
                           servInfo->ai_protocol)) == -1) {
    snprintf(logString, sizeof(logString), "socket: %s", strerror(errno));
    logaroo(logString);
    1 && fprintf(stderr, "%s\n", logString);
    return (-1);
  }
  if ((setsockopt(sockListen, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int))) ==
      -1) {
    snprintf(logString, sizeof(logString), "setsockopt: %s", strerror(errno));
    logaroo(logString);
    1 && fprintf(stderr, "%s\n", logString);
    return (-1);
  }
  if ((bind(sockListen, servInfo->ai_addr, servInfo->ai_addrlen)) == -1) {
    close(sockListen);
    snprintf(logString, sizeof(logString), "bind: %s", strerror(errno));
    logaroo(logString);
    1 && fprintf(stderr, "%s\n", logString);
    return (-1);
  }
  if ((listen(sockListen, 20) == -1)) {
    snprintf(logString, sizeof(logString), "listen: %s\n", strerror(errno));
    logaroo(logString);
    1 && fprintf(stderr, "%s\n", logString);
    return (-1);
  }
  0 && fprintf(stderr, "Exiting setUpListeningSocket\n");
  return (sockListen);
}


x86 assembly (clang, -O0):
<setUpListeningSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    -0x20(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     12da <setUpListeningSocket+0x11a>
mov    0x2dce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xdee(%rip),%rsi
call   1070 <getservbyname@plt>
mov    %rax,-0x2048(%rbp)
cmp    $0x0,%rax
jne    1273 <setUpListeningSocket+0xb3>
lea    -0x2040(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    $0x2000,%esi
lea    0xdc5(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2d81(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xe03(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    12ce <setUpListeningSocket+0x10e>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x2050(%rbp)
mov    -0x2c(%rbp),%edi
call   1060 <gai_strerror@plt>
mov    -0x2050(%rbp),%rdi
mov    %rax,%rcx
mov    $0x2000,%esi
lea    0xd90(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2d21(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xda3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <setUpListeningSocket+0x363>
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edx
call   10e0 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    136d <setUpListeningSocket+0x1ad>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x2058(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2058(%rbp),%rdi
mov    %rax,%rcx
mov    $0x2000,%esi
lea    0xd0d(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xd10(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <setUpListeningSocket+0x363>
mov    -0x38(%rbp),%edi
mov    0x2c71(%rip),%rax
mov    (%rax),%esi
mov    0x2c48(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1407 <setUpListeningSocket+0x247>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x2060(%rbp)
mov    0x2c21(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2060(%rbp),%rdi
mov    %rax,%rcx
mov    $0x2000,%esi
lea    0xc7e(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2bf4(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xc76(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <setUpListeningSocket+0x363>
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
jne    149a <setUpListeningSocket+0x2da>
mov    -0x38(%rbp),%edi
call   1080 <close@plt>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x2068(%rbp)
mov    0x2b8e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2068(%rbp),%rdi
mov    %rax,%rcx
mov    $0x2000,%esi
lea    0xbfa(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2b61(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xbe3(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <setUpListeningSocket+0x363>
mov    -0x38(%rbp),%edi
mov    $0x14,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    151d <setUpListeningSocket+0x35d>
lea    -0x2040(%rbp),%rax
mov    %rax,-0x2070(%rbp)
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x2070(%rbp),%rdi
mov    %rax,%rcx
mov    $0x2000,%esi
lea    0xb80(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x2040(%rbp),%rdi
call   1030 <logaroo@plt>
mov    0x2ade(%rip),%rax
mov    (%rax),%edi
lea    -0x2040(%rbp),%rdx
lea    0xb60(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1523 <setUpListeningSocket+0x363>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setUpListeningSocket>:
push   %rbp
push   %rbx
sub    $0x2018,%rsp
mov    %rsi,%rbx
mov    %rdi,%rdx
movl   $0x1,0x4(%rsp)
lea    0x8(%rsp),%rcx
xor    %edi,%edi
call   10c0 <getaddrinfo@plt>
test   %eax,%eax
je     121b <setUpListeningSocket+0x5b>
mov    0x2de2(%rip),%rax
mov    (%rax),%ebp
lea    0xe09(%rip),%rsi
mov    %rbx,%rdi
call   1070 <getservbyname@plt>
test   %rax,%rax
je     12a4 <setUpListeningSocket+0xe4>
mov    %ebp,%edi
call   1060 <gai_strerror@plt>
lea    0xe19(%rip),%rdx
jmp    1304 <setUpListeningSocket+0x144>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10e0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ba <setUpListeningSocket+0xfa>
mov    %eax,%ebx
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     12d1 <setUpListeningSocket+0x111>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebx,%edi
call   10b0 <bind@plt>
cmp    $0xffffffff,%eax
je     12e8 <setUpListeningSocket+0x128>
mov    %ebx,%edi
mov    $0x14,%esi
call   10a0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1342 <setUpListeningSocket+0x182>
mov    0x2d3c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xdc0(%rip),%rdx
jmp    1304 <setUpListeningSocket+0x144>
lea    0xd59(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x2000,%esi
mov    %rbx,%rcx
jmp    1311 <setUpListeningSocket+0x151>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd70(%rip),%rdx
jmp    1304 <setUpListeningSocket+0x144>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd64(%rip),%rdx
jmp    1304 <setUpListeningSocket+0x144>
mov    %ebx,%edi
call   1080 <close@plt>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd55(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x2000,%esi
mov    %rax,%rcx
call   1050 <snprintf@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <logaroo@plt>
mov    0x2cae(%rip),%rax
mov    (%rax),%edi
lea    0xd37(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x2018,%rsp
pop    %rbx
pop    %rbp
ret

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

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