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

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


x86 assembly (clang, -O0):
<setUpServSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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   10a0 <getaddrinfo@plt>
mov    %eax,-0x30(%rbp)
cmp    $0x0,%eax
je     1256 <setUpServSocket+0xb6>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1050 <getservbyname@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    1222 <setUpServSocket+0x82>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
jmp    124a <setUpServSocket+0xaa>
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x2c(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x44(%rbp),%edi
mov    %rax,%rdx
lea    0xded(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d3 <setUpServSocket+0x233>
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   10c0 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    12b6 <setUpServSocket+0x116>
mov    0x2d55(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x48(%rbp),%edi
mov    %rax,%rdx
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d3 <setUpServSocket+0x233>
mov    -0x38(%rbp),%edi
mov    0x2d28(%rip),%rax
mov    (%rax),%esi
mov    0x2cff(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    131d <setUpServSocket+0x17d>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xd43(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d3 <setUpServSocket+0x233>
mov    -0x38(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
jne    137d <setUpServSocket+0x1dd>
mov    -0x38(%rbp),%edi
call   1060 <close@plt>
mov    0x2c8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%rdx
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d3 <setUpServSocket+0x233>
mov    -0x38(%rbp),%edi
mov    $0x14,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    13cd <setUpServSocket+0x22d>
mov    0x2c3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    %rax,%rdx
lea    0xcad(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d3 <setUpServSocket+0x233>
mov    -0x38(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setUpServSocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%rdx
movl   $0x1,0x4(%rsp)
lea    0x8(%rsp),%rcx
xor    %edi,%edi
call   10a0 <getaddrinfo@plt>
test   %eax,%eax
je     1207 <setUpServSocket+0x67>
mov    0x2e03(%rip),%rax
mov    (%rax),%r14d
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1050 <getservbyname@plt>
mov    0x2df2(%rip),%rcx
mov    (%rcx),%ebp
test   %rax,%rax
je     129d <setUpServSocket+0xfd>
mov    %r14d,%edi
call   1040 <gai_strerror@plt>
lea    0xe30(%rip),%rsi
mov    %ebp,%edi
jmp    1312 <setUpServSocket+0x172>
mov    0x8(%rsp),%rax
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ab <setUpServSocket+0x10b>
mov    %eax,%ebx
mov    0x2dbc(%rip),%rax
mov    (%rax),%esi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     12cb <setUpServSocket+0x12b>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebx,%edi
call   1090 <bind@plt>
cmp    $0xffffffff,%eax
je     12eb <setUpServSocket+0x14b>
mov    %ebx,%edi
mov    $0x14,%esi
call   1080 <listen@plt>
cmp    $0xffffffff,%eax
jne    1321 <setUpServSocket+0x181>
mov    0x2d54(%rip),%rax
mov    (%rax),%ebx
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xdcc(%rip),%rsi
jmp    1310 <setUpServSocket+0x170>
lea    0xd60(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
jmp    1315 <setUpServSocket+0x175>
mov    0x2d26(%rip),%rax
mov    (%rax),%ebx
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd78(%rip),%rsi
jmp    1310 <setUpServSocket+0x170>
mov    0x2d06(%rip),%rax
mov    (%rax),%ebx
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd64(%rip),%rsi
jmp    1310 <setUpServSocket+0x170>
mov    %ebx,%edi
call   1060 <close@plt>
mov    0x2cdf(%rip),%rax
mov    (%rax),%ebx
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd4d(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
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"
@stderr = global i32 0
@.str.1 = [44 x i8] c"getservbyname: failed to find service \22%s\22\0A\00"
@.str.2 = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.3 = [12 x i8] c"socket: %s\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [16 x i8] c"setsockopt: %s\0A\00"
@.str.5 = [10 x i8] c"bind: %s\0A\00"
@.str.6 = [12 x i8] c"listen: %s\0A\00"
@stdout = global i32 0
define i32 @setUpServSocket(%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 %struct.servent*
store %struct.addrinfo* %0, %struct.addrinfo** %4
store i8* %1, i8** %5
store i32 1, i32* %10
%13 = load i8*, i8** %5
%14 = load %struct.addrinfo*, %struct.addrinfo** %4
%15 = call i32 @getaddrinfo(i32* null, i8* %13, %struct.addrinfo* %14, %struct.addrinfo** %6)
store i32 %15, i32* %9
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %2
%18 = load i32, i32* @errno
store i32 %18, i32* %8
%19 = load i8*, i8** %5
%20 = call %struct.servent* @getservbyname(i8* %19, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store %struct.servent* %20, %struct.servent** %12
%21 = icmp eq %struct.servent* %20, null
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %5
%25 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %31
26: ; preds = %17
%27 = load i32, i32* @stderr
%28 = load i32, i32* %8
%29 = call i8* @gai_strerror(i32 %28)
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %26, %22
store i32 -1, i32* %3
br label %88
32: ; preds = %2
%33 = load %struct.addrinfo*, %struct.addrinfo** %6
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 4
%35 = load i32, i32* %34
%36 = load %struct.addrinfo*, %struct.addrinfo** %6
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 3
%38 = load i32, i32* %37
%39 = load %struct.addrinfo*, %struct.addrinfo** %6
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %39, i32 0, i32 2
%41 = load i32, i32* %40
%42 = call i32 @socket(i32 %35, i32 %38, i32 %41)
store i32 %42, i32* %11
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %49
44: ; preds = %32
%45 = load i32, i32* @stderr
%46 = load i32, i32* @errno
%47 = call i8* @strerror(i32 %46)
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %47)
store i32 -1, i32* %3
br label %88
49: ; preds = %32
%50 = load i32, i32* %11
%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 %60
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 ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %58)
store i32 -1, i32* %3
br label %88
60: ; preds = %49
%61 = load i32, i32* %11
%62 = load %struct.addrinfo*, %struct.addrinfo** %6
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %62, i32 0, i32 1
%64 = load i32, i32* %63
%65 = load %struct.addrinfo*, %struct.addrinfo** %6
%66 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i32 @bind(i32 %61, i32 %64, i32 %67)
%69 = icmp eq i32 %68, -1
br i1 %69, label %70, label %77
70: ; preds = %60
%71 = load i32, i32* %11
%72 = call i32 @close(i32 %71)
%73 = load i32, i32* @stderr
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i8* %75)
store i32 -1, i32* %3
br label %88
77: ; preds = %60
%78 = load i32, i32* %11
%79 = call i32 @listen(i32 %78, i32 20)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %86
81: ; preds = %77
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i8* %84)
store i32 -1, i32* %3
br label %88
86: ; preds = %77
%87 = load i32, i32* %11
store i32 %87, i32* %3
br label %88
88: ; preds = %86, %81, %70, %55, %44, %31
%89 = load i32, i32* %3
ret i32 %89
}

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