#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_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
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 socklen_t;
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ peer_ip;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char const *, struct addrinfo *,
                       struct addrinfo **);
int /*<<< orphan*/ inet_ntop(int /*<<< orphan*/, int /*<<< orphan*/ *, char *,
                             int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int peer_listen(int sockfd, const char *port) {
  int lsockfd;
  socklen_t sockaddr_size = sizeof(struct sockaddr);
  struct addrinfo server, *servinfo, *p;
  struct sockaddr_in peer;
  char peer_ip[INET_ADDRSTRLEN];
  memset(&server, 0, sizeof(server));
  server.ai_family = AF_UNSPEC;
  server.ai_socktype = SOCK_STREAM;
  server.ai_flags = AI_PASSIVE;
  if ((getaddrinfo(NULL, port, &server, &servinfo)) != 0) {
    fprintf(stderr, "Error: Unable to prepare addrinfo\n");
    return 0;
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((lsockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) < 0) {
      fprintf(stderr, "Error: Unable to create socket\n");
      return 0;
    }
    if (bind(lsockfd, p->ai_addr, p->ai_addrlen) < 0) {
      fprintf(stderr, "Error: Bind\n");
      close(sockfd);
      continue;
    }
    break;
  }
  if (p == NULL) {
    fprintf(stderr, "Error: Failed to bind to port %s\n", port);
  }
  freeaddrinfo(servinfo);
  if (listen(sockfd, 2) < 0) {
    fprintf(stderr, "Error: Unable to listen on port %s\n", port);
    return 0;
  }
  while (1) {
    if ((sockfd = accept(sockfd, (struct sockaddr *)&peer, &sockaddr_size)) <
        0) {
      fprintf(stderr, "Error: could not accept connection from peer\n");
      return 0;
    }
    inet_ntop(peer.sin_family, &peer.sin_addr, peer_ip, sizeof(peer_ip));
    printf("Connected to peer: %s\n", peer_ip);
    close(sockfd);
    break;
  }
  return 1;
}


x86 assembly (clang, -O0):
<peer_listen>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x18(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x80(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   10b0 <getaddrinfo@plt>
cmp    $0x0,%rax
je     1276 <peer_listen+0xc6>
mov    0x2d7d(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1432 <peer_listen+0x282>
mov    -0x48(%rbp),%rax
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
je     1332 <peer_listen+0x182>
mov    -0x50(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x50(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x50(%rbp),%rax
mov    0x8(%rax),%edx
call   10d0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    12d9 <peer_listen+0x129>
mov    0x2d1a(%rip),%rax
mov    (%rax),%edi
lea    0xd64(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1432 <peer_listen+0x282>
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x50(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
cmp    $0x0,%rax
jge    131c <peer_listen+0x16c>
mov    0x2cd1(%rip),%rax
mov    (%rax),%edi
lea    0xd3b(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    1321 <peer_listen+0x171>
jmp    1332 <peer_listen+0x182>
mov    -0x50(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x50(%rbp)
jmp    127e <peer_listen+0xce>
cmpq   $0x0,-0x50(%rbp)
jne    1358 <peer_listen+0x1a8>
mov    0x2c8c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x48(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    -0x8(%rbp),%edi
mov    $0x2,%esi
call   1080 <listen@plt>
cmp    $0x0,%rax
jge    13a6 <peer_listen+0x1f6>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xce6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1432 <peer_listen+0x282>
jmp    13ab <peer_listen+0x1fb>
jmp    13b0 <peer_listen+0x200>
mov    -0x8(%rbp),%edi
lea    -0x58(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    13f6 <peer_listen+0x246>
mov    0x2bfd(%rip),%rax
mov    (%rax),%edi
lea    0xcba(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
jmp    1432 <peer_listen+0x282>
mov    -0x78(%rbp),%rdx
mov    -0x80(%rbp),%rax
mov    -0x54(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0x78(%rbp),%rsi
lea    0xcad(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x6c(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<peer_listen>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r12
mov    %edi,-0x34(%rbp)
mov    %rsp,%r15
movl   $0x4,-0x38(%rbp)
mov    0x2de8(%rip),%rax
mov    (%rax),%r13d
mov    %rsp,%rbx
lea    0xf(%r13),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x88(%rbp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1050 <memset@plt>
mov    0x2dd7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x7c(%rbp)
mov    0x2dc7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
lea    -0x50(%rbp),%rcx
xor    %edi,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   10b0 <getaddrinfo@plt>
test   %rax,%rax
je     125a <peer_listen+0xaa>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdb4(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
xor    %ebx,%ebx
jmp    139f <peer_listen+0x1ef>
mov    %rbx,-0x58(%rbp)
mov    %r12,-0x40(%rbp)
mov    %r13,-0x60(%rbp)
mov    %r15,-0x30(%rbp)
mov    -0x50(%rbp),%rbx
test   %rbx,%rbx
mov    -0x34(%rbp),%r12d
je     12d5 <peer_listen+0x125>
mov    0x2d52(%rip),%r14
lea    0xdbe(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10d0 <socket@plt>
test   %eax,%eax
js     1376 <peer_listen+0x1c6>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1090 <bind@plt>
test   %rax,%rax
jns    12f0 <peer_listen+0x140>
mov    (%r14),%edi
mov    %r13,%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r12d,%edi
call   1060 <close@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
jne    1290 <peer_listen+0xe0>
mov    0x2cf4(%rip),%rax
mov    (%rax),%edi
lea    0xd6b(%rip),%rsi
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    -0x50(%rbp),%rdi
call   10c0 <freeaddrinfo@plt>
mov    %r12d,%edi
mov    $0x2,%esi
call   1080 <listen@plt>
test   %rax,%rax
js     1357 <peer_listen+0x1a7>
lea    -0x48(%rbp),%rsi
lea    -0x38(%rbp),%rdx
mov    %r12d,%edi
call   10a0 <accept@plt>
test   %eax,%eax
js     1382 <peer_listen+0x1d2>
mov    %eax,%r14d
mov    -0x44(%rbp),%edi
lea    -0x48(%rbp),%rsi
mov    -0x58(%rbp),%rbx
mov    %rbx,%rdx
mov    -0x60(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xd84(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %r14d,%edi
call   1060 <close@plt>
mov    $0x1,%ebx
jmp    139b <peer_listen+0x1eb>
mov    0x2c72(%rip),%rax
mov    (%rax),%edi
lea    0xd0b(%rip),%rsi
xor    %ebx,%ebx
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    139b <peer_listen+0x1eb>
mov    (%r14),%edi
lea    0xca3(%rip),%rsi
jmp    1392 <peer_listen+0x1e2>
mov    0x2c47(%rip),%rax
mov    (%rax),%edi
lea    0xd04(%rip),%rsi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%r15
mov    %r15,%rsp
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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