#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 sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ 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 INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int /*<<< orphan*/ get_in_addr(struct sockaddr *);
int getaddrinfo(char const *, char const *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/, char *,
                             int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int listen_socket(const char *hostname, const char *servname, int backlog,
                  int *sockfd) {
  int retv, yes;
  struct addrinfo hints, *servinfo, *p;
  memset(&hints, 0, sizeof hints);
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_flags = AI_PASSIVE;
  if ((retv = getaddrinfo(hostname, servname, &hints, &servinfo))) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(retv));
    return 1;
  }
  for (p = servinfo; p; p = p->ai_next) {
    char s[INET6_ADDRSTRLEN];
    inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s,
              sizeof s);
    printf("binding to %s\n", s);
    if ((*sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
      perror("server: socket");
      continue;
    }
    if (setsockopt(*sockfd, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) < 0) {
      perror("setsockopt");
      return 1;
    }
    if (bind(*sockfd, p->ai_addr, p->ai_addrlen) < 0) {
      close(*sockfd);
      perror("server: bind");
      continue;
    }
    break;
  }
  if (!p) {
    fprintf(stderr, "server: failed to bind\n");
    return 2;
  }
  freeaddrinfo(servinfo);
  if (listen(*sockfd, backlog) == -1) {
    close(*sockfd);
    perror("listen");
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<listen_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1080 <memset@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x48(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2daf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x68(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0x0,%eax
je     1289 <listen_socket+0xa9>
mov    0x2d6a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x88(%rbp)
mov    -0x2c(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0x88(%rbp),%edi
mov    %rax,%rdx
lea    0xd8a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c4 <listen_socket+0x2e4>
mov    -0x68(%rbp),%rax
mov    %rax,-0x70(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     144c <listen_socket+0x26c>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x98(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x90(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x80(%rbp)
mov    -0x70(%rbp),%rax
mov    0x18(%rax),%eax
mov    %eax,-0x9c(%rbp)
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <get_in_addr@plt>
mov    -0x9c(%rbp),%edi
mov    -0x90(%rbp),%rdx
mov    %eax,%esi
mov    -0x98(%rbp),%rax
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x90(%rbp),%rsi
lea    0xcfa(%rip),%rdi
call   1060 <printf@plt>
mov    -0x70(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x70(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x70(%rbp),%rax
mov    0x10(%rax),%edx
call   1100 <socket@plt>
mov    -0x28(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jge    1360 <listen_socket+0x180>
lea    0xcd4(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x4,-0x84(%rbp)
jmp    1406 <listen_socket+0x226>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    0x2c7b(%rip),%rax
mov    (%rax),%esi
mov    0x2c3a(%rip),%rax
mov    (%rax),%edx
lea    -0x30(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
cmp    $0x0,%rax
jge    13b3 <listen_socket+0x1d3>
lea    0xc97(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x84(%rbp)
jmp    1406 <listen_socket+0x226>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x70(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    13fc <listen_socket+0x21c>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1090 <close@plt>
lea    0xc52(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x4,-0x84(%rbp)
jmp    1406 <listen_socket+0x226>
movl   $0x2,-0x84(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,%rsp
mov    -0x84(%rbp),%eax
mov    %eax,-0xa0(%rbp)
sub    $0x1,%eax
je     14c4 <listen_socket+0x2e4>
jmp    1427 <listen_socket+0x247>
mov    -0xa0(%rbp),%eax
sub    $0x2,%eax
je     144c <listen_socket+0x26c>
jmp    143b <listen_socket+0x25b>
mov    -0x70(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x70(%rbp)
jmp    1291 <listen_socket+0xb1>
cmpq   $0x0,-0x70(%rbp)
jne    147a <listen_socket+0x29a>
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
lea    0xbe0(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    14c4 <listen_socket+0x2e4>
mov    -0x68(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    14bd <listen_socket+0x2dd>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1090 <close@plt>
lea    0xbb3(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    14c4 <listen_socket+0x2e4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listen_socket>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rcx,%r13
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    -0x78(%rbp),%r12
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1080 <memset@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
lea    -0x40(%rbp),%rcx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10e0 <getaddrinfo@plt>
test   %eax,%eax
je     1277 <listen_socket+0x97>
mov    0x2d6f(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
lea    0xd9f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x1,%eax
jmp    139b <listen_socket+0x1bb>
mov    %r14d,-0x34(%rbp)
mov    -0x40(%rbp),%r14
test   %r14,%r14
je     135b <listen_socket+0x17b>
mov    %rsp,-0x30(%rbp)
mov    0x2d4d(%rip),%rax
mov    (%rax),%ebx
mov    %rsp,%r12
mov    %rbx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x18(%r14),%r15d
mov    0x8(%r14),%rdi
call   1040 <get_in_addr@plt>
mov    %r15d,%edi
mov    %eax,%esi
mov    %r12,%rdx
mov    %ebx,%ecx
call   1030 <inet_ntop@plt>
lea    0xd45(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    0x18(%r14),%edi
mov    0x10(%r14),%edx
mov    0x14(%r14),%esi
call   1100 <socket@plt>
mov    %eax,0x0(%r13)
lea    0xd30(%rip),%rdi
test   %eax,%eax
js     1345 <listen_socket+0x165>
mov    0x2ced(%rip),%rcx
mov    (%rcx),%esi
mov    0x2cac(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
lea    -0x44(%rbp),%rcx
mov    $0x4,%r8d
call   1050 <setsockopt@plt>
test   %rax,%rax
js     13c4 <listen_socket+0x1e4>
mov    0x0(%r13),%edi
mov    0x8(%r14),%rsi
mov    (%r14),%edx
call   10c0 <bind@plt>
test   %rax,%rax
jns    1379 <listen_socket+0x199>
mov    0x0(%r13),%edi
call   1090 <close@plt>
lea    0xcf5(%rip),%rdi
call   10d0 <perror@plt>
mov    -0x30(%rbp),%rsp
mov    0x20(%r14),%r14
test   %r14,%r14
jne    1288 <listen_socket+0xa8>
mov    0x2c5e(%rip),%rax
mov    (%rax),%edi
lea    0xcdc(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0x2,%eax
jmp    139b <listen_socket+0x1bb>
mov    -0x30(%rbp),%rsp
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    0x0(%r13),%edi
mov    -0x34(%rbp),%esi
call   10b0 <listen@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     13aa <listen_socket+0x1ca>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x0(%r13),%edi
call   1090 <close@plt>
lea    0xca5(%rip),%rdi
call   10d0 <perror@plt>
jmp    126d <listen_socket+0x8d>
lea    0xc64(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%eax
mov    -0x30(%rbp),%rsp
jmp    139b <listen_socket+0x1bb>

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

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