#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_storage {
  scalar_t__ ss_family;
};
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_family;
  int ai_protocol;
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
int listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
int /*<<< orphan*/ send(int, char const *, int /*<<< orphan*/,
                        int /*<<< orphan*/);
int socket(scalar_t__, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char const *);
int main(int argc, char **argv) {
  int status, s;
  struct addrinfo *addr, *p;
  struct addrinfo hint;
  char ipstr[INET6_ADDRSTRLEN];
  const char *ty = "Thank you for calling!\n";
  memset(&hint, 0, sizeof(struct addrinfo));
  hint.ai_family = AF_UNSPEC;
  hint.ai_socktype = SOCK_STREAM;
  hint.ai_flags = AI_PASSIVE;
  if (status = getaddrinfo(NULL, "7779", &hint, &addr)) {
    fprintf(stderr, "[Error]%s\n", gai_strerror(status));
    exit(1);
  }
  printf("IP addresses for %s:\n\n", "localhost");
  for (p = addr; p != NULL; p = p->ai_next) {
    void *addr;
    char *ipver;
    if (p->ai_family == AF_INET) {
      struct sockaddr_in *ipv4 = (struct sockaddr_in *)p->ai_addr;
      addr = &(ipv4->sin_addr);
      ipver = "IPv4";
    } else {
      struct sockaddr_in6 *ipv6 = (struct sockaddr_in6 *)p->ai_addr;
      addr = &(ipv6->sin6_addr);
      ipver = "IPv6";
    }
    inet_ntop(p->ai_family, addr, ipstr, sizeof(ipstr));
    printf("  %s: %s | protocol: %d\n", ipver, ipstr, p->ai_protocol);
  }
  s = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
  if (s == -1) {
    perror("Socket:");
    exit(1);
  }
  if (bind(s, addr->ai_addr, addr->ai_addrlen)) {
    perror("Bind:");
    exit(1);
  }
  if (listen(s, 20) == -1) {
    perror("listen:");
    exit(1);
  }
  while (1) {
    struct sockaddr_storage their_addr;
    socklen_t len = sizeof their_addr;
    int newsock = accept(s, (struct sockaddr *)&their_addr, &len);
    if (newsock == -1) {
      perror("Accept:");
      exit(1);
    }
    inet_ntop(
        their_addr.ss_family,
        (their_addr.ss_family == AF_INET
             ? (void *)&(((struct sockaddr_in *)&their_addr)->sin_addr)
             : (void *)&(((struct sockaddr_in6 *)&their_addr)->sin6_addr)),
        ipstr, sizeof(ipstr));
    printf("[Server] accepted new client with address: %s\n", ipstr);
    send(newsock, ty, strlen(ty), 0);
    close(newsock);
  }
  freeaddrinfo(addr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xb0(%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,-0xa8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
lea    0xdba(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1080 <memset@plt>
mov    0x2d6f(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d49(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x40(%rbp)
mov    0x2d65(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd8d(%rip),%rsi
lea    -0x58(%rbp),%rdx
lea    -0x20(%rbp),%rcx
call   1100 <getaddrinfo@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
je     12da <main+0xea>
mov    0x2d15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xb4(%rbp)
mov    -0x14(%rbp),%edi
call   1070 <gai_strerror@plt>
mov    -0xb4(%rbp),%edi
mov    %rax,%rdx
lea    0xd52(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
lea    0xd47(%rip),%rdi
lea    0xd57(%rip),%rsi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     13b9 <main+0x1c9>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2cc8(%rip),%rcx
cmp    (%rcx),%rax
jne    1343 <main+0x153>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xd0f(%rip),%rax
mov    %rax,-0x80(%rbp)
jmp    1368 <main+0x178>
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    0xcea(%rip),%rax
mov    %rax,-0x80(%rbp)
mov    -0xa8(%rbp),%rdx
mov    -0xb0(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa8(%rbp),%rdx
mov    -0x80(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%ecx
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x28(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x28(%rbp)
jmp    12f7 <main+0x107>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edx
call   1110 <socket@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    13f6 <main+0x206>
lea    0xc85(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    -0x20(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x20(%rbp),%rax
mov    0xc(%rax),%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
je     142d <main+0x23d>
lea    0xc56(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    1459 <main+0x269>
lea    0xc30(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    145e <main+0x26e>
jmp    1463 <main+0x273>
movl   $0x8,-0x9c(%rbp)
mov    -0x18(%rbp),%edi
lea    -0x98(%rbp),%rsi
lea    -0x9c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,-0xa0(%rbp)
cmpl   $0xffffffff,-0xa0(%rbp)
jne    14ac <main+0x2bc>
lea    0xbe5(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    -0x98(%rbp),%rax
mov    %rax,-0xc0(%rbp)
mov    -0x98(%rbp),%rax
mov    0x2b10(%rip),%rcx
cmp    (%rcx),%rax
jne    14e4 <main+0x2f4>
lea    -0x98(%rbp),%rax
mov    %rax,-0xc8(%rbp)
jmp    14f2 <main+0x302>
lea    -0x98(%rbp),%rax
mov    %rax,-0xc8(%rbp)
mov    -0xa8(%rbp),%rdx
mov    -0xc0(%rbp),%rdi
mov    -0xb0(%rbp),%rax
mov    -0xc8(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
mov    -0xa8(%rbp),%rsi
lea    0xb67(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa0(%rbp),%eax
mov    %eax,-0xd4(%rbp)
mov    -0x70(%rbp),%rax
mov    %rax,-0xd0(%rbp)
mov    -0x70(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xd4(%rbp),%edi
mov    -0xd0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0xa0(%rbp),%edi
call   1090 <close@plt>
jmp    145e <main+0x26e>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    0x2de0(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%r12
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x78(%rbp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1080 <memset@plt>
mov    0x2d9a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x78(%rbp)
mov    0x2d74(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
lea    0xdbc(%rip),%rsi
lea    -0x38(%rbp),%rcx
xor    %edi,%edi
mov    %r15,%rdx
call   1100 <getaddrinfo@plt>
test   %eax,%eax
jne    130d <main+0x11d>
lea    0xdaf(%rip),%rdi
lea    0xdbf(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x38(%rbp),%rbx
lea    0xdc1(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx),%rdi
mov    0x10(%rbx),%rsi
mov    0x2d2a(%rip),%rax
cmp    (%rax),%rdi
lea    0xd96(%rip),%r13
lea    0xd8a(%rip),%rax
cmove  %rax,%r13
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
mov    0x8(%rbx),%ecx
mov    %r15,%rdi
mov    %r13,%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rbx),%rbx
test   %rbx,%rbx
jne    12a0 <main+0xb0>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    0x18(%rax),%esi
mov    0x8(%rax),%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
jne    1338 <main+0x148>
lea    0xd64(%rip),%rdi
jmp    1417 <main+0x227>
mov    0x2cac(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
lea    0xcf9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>
mov    %eax,%ebx
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rsi
mov    0xc(%rax),%edx
mov    %ebx,%edi
call   10c0 <bind@plt>
test   %rax,%rax
jne    136e <main+0x17e>
mov    %ebx,%edi
mov    $0x14,%esi
call   10b0 <listen@plt>
cmp    $0xffffffff,%eax
jne    137a <main+0x18a>
lea    0xd11(%rip),%rdi
jmp    1417 <main+0x227>
lea    0xcff(%rip),%rdi
jmp    1417 <main+0x227>
movl   $0x8,-0x2c(%rbp)
lea    -0x48(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %ebx,%edi
call   10e0 <accept@plt>
cmp    $0xffffffff,%eax
mov    %ebx,-0x3c(%rbp)
je     1410 <main+0x220>
mov    %eax,%r15d
lea    -0x48(%rbp),%rbx
lea    0xc5a(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
mov    -0x48(%rbp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r14d,%ecx
call   1030 <inet_ntop@plt>
lea    0xcc1(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    %r15d,%edi
mov    %r13,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %r15d,%edi
call   1090 <close@plt>
movl   $0x8,-0x2c(%rbp)
mov    -0x3c(%rbp),%edi
mov    %rbx,%rsi
lea    -0x2c(%rbp),%rdx
call   10e0 <accept@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    13b0 <main+0x1c0>
lea    0xc6b(%rip),%rdi
call   10d0 <perror@plt>
mov    $0x1,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i32, i64, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [24 x i8] c"Thank you for calling!\0A\00"
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [5 x i8] c"7779\00"
@stderr = global i32 0
@.str.2 = [11 x i8] c"[Error]%s\0A\00"
@.str.3 = [23 x i8] c"IP addresses for %s:\0A\0A\00"
@.str.4 = [10 x i8] c"localhost\00"
@AF_INET = global i64 0
@.str.5 = [5 x i8] c"IPv4\00"
@.str.6 = [5 x i8] c"IPv6\00"
@.str.7 = [25 x i8] c" %s: %s | protocol: %d\0A\00"
@.str.8 = [8 x i8] c"Socket:\00"
@.str.9 = [6 x i8] c"Bind:\00"
@.str.10 = [8 x i8] c"listen:\00"
@.str.11 = [8 x i8] c"Accept:\00"
@.str.12 = [47 x i8] c"[Server] accepted new client with address: %s\0A\00"
define i32 @main(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 i8*
%12 = alloca i64
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca %struct.sockaddr_in*
%17 = alloca %struct.sockaddr_in6*
%18 = alloca %struct.sockaddr_storage
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%21 = load i32, i32* @INET6_ADDRSTRLEN
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %11
%24 = alloca i8, i64 %22
store i64 %22, i64* %12
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %13
%25 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 48)
%26 = load i64, i64* @AF_UNSPEC
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i64 %26, i64* %27
%28 = load i32, i32* @SOCK_STREAM
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %28, i32* %29
%30 = load i32, i32* @AI_PASSIVE
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 6
store i32 %30, i32* %31
%32 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %10, %struct.addrinfo** %8)
store i32 %32, i32* %6
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %2
%35 = load i32, i32* @stderr
%36 = load i32, i32* %6
%37 = call i8* @gai_strerror(i32 %36)
%38 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %37)
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %2
%41 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%42 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %42, %struct.addrinfo** %9
br label %43
43: ; preds = %80, %40
%44 = load %struct.addrinfo*, %struct.addrinfo** %9
%45 = icmp ne %struct.addrinfo* %44, null
br i1 %45, label %46, label %84
46: ; preds = %43
%47 = load %struct.addrinfo*, %struct.addrinfo** %9
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = load i64, i64* @AF_INET
%51 = icmp eq i64 %49, %50
br i1 %51, label %52, label %60
52: ; preds = %46
%53 = load %struct.addrinfo*, %struct.addrinfo** %9
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 3
%55 = load i64, i64* %54
%56 = inttoptr i64 %55 to %struct.sockaddr_in*
store %struct.sockaddr_in* %56, %struct.sockaddr_in** %16
%57 = load %struct.sockaddr_in*, %struct.sockaddr_in** %16
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %57, i32 0, i32 0
%59 = bitcast i32* %58 to i8*
store i8* %59, i8** %14
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8** %15
br label %68
60: ; preds = %46
%61 = load %struct.addrinfo*, %struct.addrinfo** %9
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 3
%63 = load i64, i64* %62
%64 = inttoptr i64 %63 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %64, %struct.sockaddr_in6** %17
%65 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %17
%66 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %65, i32 0, i32 0
%67 = bitcast i32* %66 to i8*
store i8* %67, i8** %14
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0), i8** %15
br label %68
68: ; preds = %60, %52
%69 = load %struct.addrinfo*, %struct.addrinfo** %9
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = load i8*, i8** %14
%73 = trunc i64 %22 to i32
%74 = call i32 @inet_ntop(i64 %71, i8* %72, i8* %24, i32 %73)
%75 = load i8*, i8** %15
%76 = load %struct.addrinfo*, %struct.addrinfo** %9
%77 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %76, i32 0, i32 1
%78 = load i32, i32* %77
%79 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %75, i8* %24, i32 %78)
br label %80
80: ; preds = %68
%81 = load %struct.addrinfo*, %struct.addrinfo** %9
%82 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %81, i32 0, i32 5
%83 = load %struct.addrinfo*, %struct.addrinfo** %82
store %struct.addrinfo* %83, %struct.addrinfo** %9
br label %43
84: ; preds = %43
%85 = load %struct.addrinfo*, %struct.addrinfo** %8
%86 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %85, i32 0, i32 0
%87 = load i64, i64* %86
%88 = load %struct.addrinfo*, %struct.addrinfo** %8
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i32 0, i32 4
%90 = load i32, i32* %89
%91 = load %struct.addrinfo*, %struct.addrinfo** %8
%92 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %91, i32 0, i32 1
%93 = load i32, i32* %92
%94 = call i32 @socket(i64 %87, i32 %90, i32 %93)
store i32 %94, i32* %7
%95 = load i32, i32* %7
%96 = icmp eq i32 %95, -1
br i1 %96, label %97, label %100
97: ; preds = %84
%98 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%99 = call i32 @exit(i32 1)
unreachable
100: ; preds = %84
%101 = load i32, i32* %7
%102 = load %struct.addrinfo*, %struct.addrinfo** %8
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %102, i32 0, i32 3
%104 = load i64, i64* %103
%105 = load %struct.addrinfo*, %struct.addrinfo** %8
%106 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %105, i32 0, i32 2
%107 = load i32, i32* %106
%108 = call i64 @bind(i32 %101, i64 %104, i32 %107)
%109 = icmp ne i64 %108, 0
br i1 %109, label %110, label %113
110: ; preds = %100
%111 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %100
%114 = load i32, i32* %7
%115 = call i32 @listen(i32 %114, i32 20)
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %120
117: ; preds = %113
%118 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%119 = call i32 @exit(i32 1)
unreachable
120: ; preds = %113
br label %121
121: ; preds = %146, %120
br label %122
122: ; preds = %121
store i32 8, i32* %19
%123 = load i32, i32* %7
%124 = bitcast %struct.sockaddr_storage* %18 to %struct.sockaddr*
%125 = call i32 @accept(i32 %123, %struct.sockaddr* %124, i32* %19)
store i32 %125, i32* %20
%126 = load i32, i32* %20
%127 = icmp eq i32 %126, -1
br i1 %127, label %128, label %131
128: ; preds = %122
%129 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %122
%132 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %18, i32 0, i32 0
%133 = load i64, i64* %132
%134 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %18, i32 0, i32 0
%135 = load i64, i64* %134
%136 = load i64, i64* @AF_INET
%137 = icmp eq i64 %135, %136
br i1 %137, label %138, label %142
138: ; preds = %131
%139 = bitcast %struct.sockaddr_storage* %18 to %struct.sockaddr_in*
%140 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %139, i32 0, i32 0
%141 = bitcast i32* %140 to i8*
br label %146
142: ; preds = %131
%143 = bitcast %struct.sockaddr_storage* %18 to %struct.sockaddr_in6*
%144 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %143, i32 0, i32 0
%145 = bitcast i32* %144 to i8*
br label %146
146: ; preds = %142, %138
%147 = phi i8* [ %141, %138 ], [ %145, %142 ]
%148 = trunc i64 %22 to i32
%149 = call i32 @inet_ntop(i64 %133, i8* %147, i8* %24, i32 %148)
%150 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i8* %24)
%151 = load i32, i32* %20
%152 = load i8*, i8** %13
%153 = load i8*, i8** %13
%154 = call i32 @strlen(i8* %153)
%155 = call i32 @send(i32 %151, i8* %152, i32 %154, i32 0)
%156 = load i32, i32* %20
%157 = call i32 @close(i32 %156)
br label %121
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i32, i64, i32, %struct.addrinfo*, i32 }
%struct.sockaddr_storage = type { i64 }
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [24 x i8] c"Thank you for calling!\0A\00"
@AF_UNSPEC = global i64 0
@SOCK_STREAM = global i32 0
@AI_PASSIVE = global i32 0
@.str.1 = [5 x i8] c"7779\00"
@stderr = global i32 0
@.str.2 = [11 x i8] c"[Error]%s\0A\00"
@.str.3 = [23 x i8] c"IP addresses for %s:\0A\0A\00"
@.str.4 = [10 x i8] c"localhost\00"
@AF_INET = global i64 0
@.str.5 = [5 x i8] c"IPv4\00"
@.str.6 = [5 x i8] c"IPv6\00"
@.str.7 = [25 x i8] c" %s: %s | protocol: %d\0A\00"
@.str.8 = [8 x i8] c"Socket:\00"
@.str.9 = [6 x i8] c"Bind:\00"
@.str.10 = [8 x i8] c"listen:\00"
@.str.11 = [8 x i8] c"Accept:\00"
@.str.12 = [47 x i8] c"[Server] accepted new client with address: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.addrinfo*
%4 = alloca %struct.addrinfo
%5 = alloca %struct.sockaddr_storage
%6 = alloca i32
%7 = bitcast %struct.addrinfo** %3 to i8*
%8 = bitcast %struct.addrinfo* %4 to i8*
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = alloca i8, i64 %10
%12 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 48)
%13 = load i64, i64* @AF_UNSPEC
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
store i64 %13, i64* %14
%15 = load i32, i32* @SOCK_STREAM
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @AI_PASSIVE
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
store i32 %17, i32* %18
%19 = call i32 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i8* @gai_strerror(i32 %19)
%24 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %23)
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
%28 = load %struct.addrinfo*, %struct.addrinfo** %3
br label %29
29: ; preds = %26, %29
%30 = phi %struct.addrinfo* [ %44, %29 ], [ %28, %26 ]
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @AF_INET
%34 = icmp eq i64 %32, %33
%35 = select i1 %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0)
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 3
%37 = load i64, i64* %36
%38 = inttoptr i64 %37 to i8*
%39 = call i32 @inet_ntop(i64 %32, i8* %38, i8* %11, i32 %9)
%40 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 1
%41 = load i32, i32* %40
%42 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.7, i64 0, i64 0), i8* %35, i8* %11, i32 %41)
%43 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %30, i64 0, i32 5
%44 = load %struct.addrinfo*, %struct.addrinfo** %43
%45 = icmp eq %struct.addrinfo* %44, null
br i1 %45, label %46, label %29
46: ; preds = %29
%47 = load %struct.addrinfo*, %struct.addrinfo** %3
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 0
%49 = load i64, i64* %48
%50 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 4
%51 = load i32, i32* %50
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i64 0, i32 1
%53 = load i32, i32* %52
%54 = call i32 @socket(i64 %49, i32 %51, i32 %53)
%55 = icmp eq i32 %54, -1
br i1 %55, label %56, label %59
56: ; preds = %46
%57 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.8, i64 0, i64 0))
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %46
%60 = load %struct.addrinfo*, %struct.addrinfo** %3
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 3
%62 = load i64, i64* %61
%63 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %60, i64 0, i32 2
%64 = load i32, i32* %63
%65 = call i64 @bind(i32 %54, i64 %62, i32 %64)
%66 = icmp eq i64 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %59
%68 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.9, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %59
%71 = call i32 @listen(i32 %54, i32 20)
%72 = icmp eq i32 %71, -1
br i1 %72, label %81, label %73
73: ; preds = %70
%74 = bitcast %struct.sockaddr_storage* %5 to i8*
%75 = bitcast i32* %6 to i8*
%76 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
store i32 8, i32* %6
%77 = call i32 @accept(i32 %54, %struct.sockaddr* %76, i32* %6)
%78 = icmp eq i32 %77, -1
br i1 %78, label %84, label %79
79: ; preds = %73
%80 = getelementptr inbounds %struct.sockaddr_storage, %struct.sockaddr_storage* %5, i64 0, i32 0
br label %87
81: ; preds = %70
%82 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0))
%83 = call i32 @exit(i32 1)
unreachable
84: ; preds = %87, %73
%85 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i64 0, i64 0))
%86 = call i32 @exit(i32 1)
unreachable
87: ; preds = %79, %87
%88 = phi i32 [ %77, %79 ], [ %95, %87 ]
%89 = load i64, i64* %80
%90 = call i32 @inet_ntop(i64 %89, i8* %74, i8* %11, i32 %9)
%91 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.12, i64 0, i64 0), i8* %11)
%92 = call i32 @strlen(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%93 = call i32 @send(i32 %88, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i32 %92, i32 0)
%94 = call i32 @close(i32 %88)
store i32 8, i32* %6
%95 = call i32 @accept(i32 %54, %struct.sockaddr* %76, i32* %6)
%96 = icmp eq i32 %95, -1
br i1 %96, label %84, label %87
}