#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 {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ cli;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ NI_NUMERICHOST;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
void main(int args, char *argv[]) {
  struct addrinfo hints, *res;
  struct sockaddr_storage cli;
  char host[NI_MAXHOST], serv[NI_MAXSERV];
  char buff[81];
  int errn;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  int stat = getaddrinfo(argv[1], argv[2], &hints, &res);
  if (stat != 0) {
    errn = errno;
    printf("getaddrinfo: %s\n", strerror(errn));
    freeaddrinfo(res);
    exit(EXIT_FAILURE);
  }
  int sd = socket(res->ai_family, res->ai_socktype, 0);
  if (sd == -1) {
    errn = errno;
    printf("socket: %s\n", strerror(errn));
    freeaddrinfo(res);
    exit(EXIT_FAILURE);
  }
  stat = bind(sd, (struct sockaddr *)res->ai_addr, res->ai_addrlen);
  if (stat != 0) {
    errn = errno;
    printf("bind: %s\n", strerror(errn));
    freeaddrinfo(res);
    exit(EXIT_FAILURE);
  }
  freeaddrinfo(res);
  stat = listen(sd, 5);
  if (stat != 0) {
    errn = errno;
    printf("listen: %s\n", strerror(errn));
    exit(EXIT_FAILURE);
  }
  listen(sd, 5);
  printf("listening\n");
  int finished = 0;
  while (!finished) {
    socklen_t clen = sizeof(cli);
    int cli_sd = accept(sd, (struct sockaddr *)&cli, &clen);
    if (cli_sd == -1) {
      errn = errno;
      printf("accept: %s\n", strerror(errn));
      exit(EXIT_FAILURE);
    }
    stat = getnameinfo((struct sockaddr *)&cli, clen, host, NI_MAXHOST, serv,
                       NI_MAXSERV, NI_NUMERICHOST);
    if (stat != 0) {
      errn = errno;
      printf("getnameinfo: %s\n", strerror(errn));
      exit(EXIT_FAILURE);
    }
    printf("host: %s, port: %s\n", host, serv);
    int stop = 0;
    while (!stop) {
      int c = recv(cli_sd, buff, 80, 0);
      if (c == 0)
        stop = 1;
      if (!stop) {
        buff[c] = '\0';
        printf("recieved: %s\n", buff);
        send(cli_sd, buff, c, 80);
      } else
        printf("Client aborted\n");
    }
    close(cli_sd);
    printf("host: %s, port: %s gone\n", host, serv);
    finished = 1;
  }
  close(sd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    0x2dc0(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d94(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10c0 <getaddrinfo@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
je     12d7 <main+0x107>
mov    0x2d1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0xcc(%rbp)
cmpl   $0xffffffff,-0xcc(%rbp)
jne    1341 <main+0x171>
mov    0x2cb2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xcee(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xcc(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1090 <bind@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
je     13af <main+0x1df>
mov    0x2c44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    0x2c08(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0xcc(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
je     1414 <main+0x244>
mov    0x2bd6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2ba3(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xcc(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
lea    0xc08(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xd0(%rbp)
cmpl   $0x0,-0xd0(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1455 <main+0x285>
jmp    1662 <main+0x492>
movl   $0x4,-0xd4(%rbp)
mov    -0xcc(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0xd4(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0xd8(%rbp)
cmpl   $0xffffffff,-0xd8(%rbp)
jne    14c1 <main+0x2f1>
mov    0x2b29(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2af6(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xe8(%rbp),%r8
mov    -0xf0(%rbp),%rdx
lea    -0x48(%rbp),%rdi
mov    -0xd4(%rbp),%esi
mov    0x2ac8(%rip),%rax
mov    (%rax),%ecx
mov    0x2aef(%rip),%rax
mov    (%rax),%r9d
mov    0x2acd(%rip),%rax
mov    (%rax),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1070 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
je     1551 <main+0x381>
mov    0x2a99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xb0e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a66(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xe8(%rbp),%rdx
mov    -0xf0(%rbp),%rsi
lea    0xaf5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xdc(%rbp)
cmpl   $0x0,-0xdc(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1590 <main+0x3c0>
jmp    162c <main+0x45c>
mov    -0xd8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xe0(%rbp)
cmpl   $0x0,-0xe0(%rbp)
jne    15c6 <main+0x3f6>
movl   $0x1,-0xdc(%rbp)
cmpl   $0x0,-0xdc(%rbp)
jne    1619 <main+0x449>
movslq -0xe0(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    -0xc0(%rbp),%rsi
lea    0xa7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xd8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    -0xe0(%rbp),%edx
mov    $0x50,%ecx
call   1040 <send@plt>
jmp    1627 <main+0x457>
lea    0xa5d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1577 <main+0x3a7>
mov    -0xd8(%rbp),%edi
call   1060 <close@plt>
mov    -0xf0(%rbp),%rsi
mov    -0xe8(%rbp),%rdx
lea    0xa41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x1,-0xd0(%rbp)
jmp    143c <main+0x26c>
mov    -0xcc(%rbp),%edi
call   1060 <close@plt>
mov    -0x50(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsp,%rbx
mov    0x2daa(%rip),%r14
mov    (%r14),%eax
mov    %rsp,%r13
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
mov    0x2dbf(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2d9c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
movq   $0x0,-0x60(%rbp)
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
lea    -0x78(%rbp),%rdx
lea    -0x30(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    1414 <main+0x234>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%esi
mov    0x14(%rax),%edi
xor    %edx,%edx
call   1100 <socket@plt>
cmp    $0xffffffff,%eax
je     142b <main+0x24b>
mov    %eax,%r12d
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %r12d,%edi
call   10a0 <bind@plt>
test   %eax,%eax
jne    1442 <main+0x262>
mov    -0x30(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %eax,%eax
jne    146c <main+0x28c>
mov    %rbx,-0x50(%rbp)
mov    %r12d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xda4(%rip),%rdi
call   1040 <puts@plt>
movl   $0x4,-0x34(%rbp)
lea    -0x38(%rbp),%rsi
lea    -0x34(%rbp),%rdx
mov    %r12d,%edi
call   10b0 <accept@plt>
cmp    $0xffffffff,%eax
je     1483 <main+0x2a3>
mov    %eax,%ebx
mov    -0x34(%rbp),%esi
mov    (%r14),%ecx
mov    (%r15),%r9d
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    -0x38(%rbp),%rdi
mov    %r13,%rdx
mov    -0x40(%rbp),%r14
mov    %r14,%r8
push   %rax
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    149a <main+0x2ba>
lea    0xd05(%rip),%rdi
mov    %r13,-0x48(%rbp)
mov    %r13,%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
lea    -0xd0(%rbp),%rsi
mov    %ebx,%edi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
je     13d0 <main+0x1f0>
lea    0xce8(%rip),%r13
lea    -0xd0(%rbp),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %eax,%r15
movb   $0x0,-0xd0(%rbp,%r15,1)
mov    %r13,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %r15d,%edx
mov    $0x50,%ecx
call   1050 <send@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jne    1390 <main+0x1b0>
lea    0xcbe(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xc88(%rip),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x40(%rbp),%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
call   1070 <close@plt>
mov    -0x50(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbd7(%rip),%rdi
jmp    1457 <main+0x277>
mov    0x2b86(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbd1(%rip),%rdi
jmp    1457 <main+0x277>
mov    0x2b6f(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xbc6(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x30(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
jmp    14b9 <main+0x2d9>
mov    0x2b45(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xba6(%rip),%rdi
jmp    14af <main+0x2cf>
mov    0x2b2e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xb9b(%rip),%rdi
jmp    14af <main+0x2cf>
mov    0x2b17(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xb90(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2af0(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i32, i32, i64, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"socket: %s\0A\00"
@.str.2 = [10 x i8] c"bind: %s\0A\00"
@.str.3 = [12 x i8] c"listen: %s\0A\00"
@.str.4 = [11 x i8] c"listening\0A\00"
@.str.5 = [12 x i8] c"accept: %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.6 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.7 = [20 x i8] c"host: %s, port: %s\0A\00"
@.str.8 = [14 x i8] c"recieved: %s\0A\00"
@.str.9 = [16 x i8] c"Client aborted\0A\00"
@.str.10 = [25 x i8] c"host: %s, port: %s gone\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.sockaddr_storage
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca [81 x i8]
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%20 = load i32, i32* @NI_MAXHOST
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %8
%23 = alloca i8, i64 %21
store i64 %21, i64* %9
%24 = load i32, i32* @NI_MAXSERV
%25 = zext i32 %24 to i64
%26 = alloca i8, i64 %25
store i64 %25, i64* %10
%27 = load i32, i32* @AI_PASSIVE
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 5
store i32 %27, i32* %28
%29 = load i32, i32* @AF_UNSPEC
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 3
store i32 %29, i32* %30
%31 = load i32, i32* @SOCK_STREAM
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 4
store i64 0, i64* %33
%34 = load i8**, i8*** %4
%35 = getelementptr inbounds i8*, i8** %34, i64 1
%36 = load i8*, i8** %35
%37 = load i8**, i8*** %4
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @getaddrinfo(i8* %36, i8* %39, %struct.addrinfo* %5, %struct.addrinfo** %6)
store i32 %40, i32* %13
%41 = load i32, i32* %13
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %52
43: ; preds = %2
%44 = load i32, i32* @errno
store i32 %44, i32* %12
%45 = load i32, i32* %12
%46 = call i8* @strerror(i32 %45)
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %46)
%48 = load %struct.addrinfo*, %struct.addrinfo** %6
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %48)
%50 = load i32, i32* @EXIT_FAILURE
%51 = call i32 @exit(i32 %50)
unreachable
52: ; preds = %2
%53 = load %struct.addrinfo*, %struct.addrinfo** %6
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 3
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %6
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 2
%58 = load i32, i32* %57
%59 = call i32 @socket(i32 %55, i32 %58, i32 0)
store i32 %59, i32* %14
%60 = load i32, i32* %14
%61 = icmp eq i32 %60, -1
br i1 %61, label %62, label %71
62: ; preds = %52
%63 = load i32, i32* @errno
store i32 %63, i32* %12
%64 = load i32, i32* %12
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %65)
%67 = load %struct.addrinfo*, %struct.addrinfo** %6
%68 = call i32 @freeaddrinfo(%struct.addrinfo* %67)
%69 = load i32, i32* @EXIT_FAILURE
%70 = call i32 @exit(i32 %69)
unreachable
71: ; preds = %52
%72 = load i32, i32* %14
%73 = load %struct.addrinfo*, %struct.addrinfo** %6
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %73, i32 0, i32 1
%75 = load i64, i64* %74
%76 = inttoptr i64 %75 to %struct.sockaddr*
%77 = load %struct.addrinfo*, %struct.addrinfo** %6
%78 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @bind(i32 %72, %struct.sockaddr* %76, i32 %79)
store i32 %80, i32* %13
%81 = load i32, i32* %13
%82 = icmp ne i32 %81, 0
br i1 %82, label %83, label %92
83: ; preds = %71
%84 = load i32, i32* @errno
store i32 %84, i32* %12
%85 = load i32, i32* %12
%86 = call i8* @strerror(i32 %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %86)
%88 = load %struct.addrinfo*, %struct.addrinfo** %6
%89 = call i32 @freeaddrinfo(%struct.addrinfo* %88)
%90 = load i32, i32* @EXIT_FAILURE
%91 = call i32 @exit(i32 %90)
unreachable
92: ; preds = %71
%93 = load %struct.addrinfo*, %struct.addrinfo** %6
%94 = call i32 @freeaddrinfo(%struct.addrinfo* %93)
%95 = load i32, i32* %14
%96 = call i32 @listen(i32 %95, i32 5)
store i32 %96, i32* %13
%97 = load i32, i32* %13
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %106
99: ; preds = %92
%100 = load i32, i32* @errno
store i32 %100, i32* %12
%101 = load i32, i32* %12
%102 = call i8* @strerror(i32 %101)
%103 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %102)
%104 = load i32, i32* @EXIT_FAILURE
%105 = call i32 @exit(i32 %104)
unreachable
106: ; preds = %92
%107 = load i32, i32* %14
%108 = call i32 @listen(i32 %107, i32 5)
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
store i32 0, i32* %15
br label %110
110: ; preds = %172, %106
%111 = load i32, i32* %15
%112 = icmp ne i32 %111, 0
%113 = xor i1 %112, true
br i1 %113, label %114, label %176
114: ; preds = %110
store i32 4, i32* %16
%115 = load i32, i32* %14
%116 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%117 = call i32 @accept(i32 %115, %struct.sockaddr* %116, i32* %16)
store i32 %117, i32* %17
%118 = load i32, i32* %17
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %127
120: ; preds = %114
%121 = load i32, i32* @errno
store i32 %121, i32* %12
%122 = load i32, i32* %12
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %123)
%125 = load i32, i32* @EXIT_FAILURE
%126 = call i32 @exit(i32 %125)
unreachable
127: ; preds = %114
%128 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%129 = load i32, i32* %16
%130 = load i32, i32* @NI_MAXHOST
%131 = load i32, i32* @NI_MAXSERV
%132 = load i32, i32* @NI_NUMERICHOST
%133 = call i32 @getnameinfo(%struct.sockaddr* %128, i32 %129, i8* %23, i32 %130, i8* %26, i32 %131, i32 %132)
store i32 %133, i32* %13
%134 = load i32, i32* %13
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %143
136: ; preds = %127
%137 = load i32, i32* @errno
store i32 %137, i32* %12
%138 = load i32, i32* %12
%139 = call i8* @strerror(i32 %138)
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %139)
%141 = load i32, i32* @EXIT_FAILURE
%142 = call i32 @exit(i32 %141)
unreachable
143: ; preds = %127
%144 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %23, i8* %26)
store i32 0, i32* %18
br label %145
145: ; preds = %171, %143
%146 = load i32, i32* %18
%147 = icmp ne i32 %146, 0
%148 = xor i1 %147, true
br i1 %148, label %149, label %172
149: ; preds = %145
%150 = load i32, i32* %17
%151 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%152 = call i32 @recv(i32 %150, i8* %151, i32 80, i32 0)
store i32 %152, i32* %19
%153 = load i32, i32* %19
%154 = icmp eq i32 %153, 0
br i1 %154, label %155, label %156
155: ; preds = %149
store i32 1, i32* %18
br label %156
156: ; preds = %155, %149
%157 = load i32, i32* %18
%158 = icmp ne i32 %157, 0
br i1 %158, label %169, label %159
159: ; preds = %156
%160 = load i32, i32* %19
%161 = sext i32 %160 to i64
%162 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 %161
store i8 0, i8* %162
%163 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%164 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %163)
%165 = load i32, i32* %17
%166 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%167 = load i32, i32* %19
%168 = call i32 @send(i32 %165, i8* %166, i32 %167, i32 80)
br label %171
169: ; preds = %156
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.9, i64 0, i64 0))
br label %171
171: ; preds = %169, %159
br label %145
172: ; preds = %145
%173 = load i32, i32* %17
%174 = call i32 @close(i32 %173)
%175 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %23, i8* %26)
store i32 1, i32* %15
br label %110
176: ; preds = %110
%177 = load i32, i32* %14
%178 = call i32 @close(i32 %177)
%179 = load i8*, i8** %8
ret void
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i32, i32, i64, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@errno = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [12 x i8] c"socket: %s\0A\00"
@.str.2 = [10 x i8] c"bind: %s\0A\00"
@.str.3 = [12 x i8] c"listen: %s\0A\00"
@.str.5 = [12 x i8] c"accept: %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.6 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.7 = [20 x i8] c"host: %s, port: %s\0A\00"
@.str.8 = [14 x i8] c"recieved: %s\0A\00"
@.str.10 = [25 x i8] c"host: %s, port: %s gone\0A\00"
@str = [10 x i8] c"listening\00"
@str.11 = [15 x i8] c"Client aborted\00"
define void @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.sockaddr_storage
%6 = alloca [81 x i8]
%7 = alloca i32
%8 = bitcast %struct.addrinfo* %3 to i8*
%9 = bitcast %struct.addrinfo** %4 to i8*
%10 = bitcast %struct.sockaddr_storage* %5 to i8*
%11 = load i32, i32* @NI_MAXHOST
%12 = zext i32 %11 to i64
%13 = tail call i8* @llvm.stacksave()
%14 = alloca i8, i64 %12
%15 = load i32, i32* @NI_MAXSERV
%16 = zext i32 %15 to i64
%17 = alloca i8, i64 %16
%18 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* @AI_PASSIVE
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %19, i32* %20
%21 = load i32, i32* @AF_UNSPEC
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %21, i32* %22
%23 = load i32, i32* @SOCK_STREAM
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i64 0, i64* %25
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @getaddrinfo(i8* %27, i8* %29, %struct.addrinfo* %3, %struct.addrinfo** %4)
%31 = icmp eq i32 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %2
%33 = load i32, i32* @errno
%34 = call i8* @strerror(i32 %33)
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = load %struct.addrinfo*, %struct.addrinfo** %4
%37 = call i32 @freeaddrinfo(%struct.addrinfo* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %2
%41 = load %struct.addrinfo*, %struct.addrinfo** %4
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 3
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i64 0, i32 2
%45 = load i32, i32* %44
%46 = call i32 @socket(i32 %43, i32 %45, i32 0)
%47 = icmp eq i32 %46, -1
br i1 %47, label %48, label %56
48: ; preds = %40
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = load %struct.addrinfo*, %struct.addrinfo** %4
%53 = call i32 @freeaddrinfo(%struct.addrinfo* %52)
%54 = load i32, i32* @EXIT_FAILURE
%55 = call i32 @exit(i32 %54)
unreachable
56: ; preds = %40
%57 = load %struct.addrinfo*, %struct.addrinfo** %4
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 1
%59 = load i64, i64* %58
%60 = inttoptr i64 %59 to %struct.sockaddr*
%61 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i64 0, i32 0
%62 = load i32, i32* %61
%63 = call i32 @bind(i32 %46, %struct.sockaddr* %60, i32 %62)
%64 = icmp eq i32 %63, 0
br i1 %64, label %73, label %65
65: ; preds = %56
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = load %struct.addrinfo*, %struct.addrinfo** %4
%70 = call i32 @freeaddrinfo(%struct.addrinfo* %69)
%71 = load i32, i32* @EXIT_FAILURE
%72 = call i32 @exit(i32 %71)
unreachable
73: ; preds = %56
%74 = load %struct.addrinfo*, %struct.addrinfo** %4
%75 = call i32 @freeaddrinfo(%struct.addrinfo* %74)
%76 = call i32 @listen(i32 %46, i32 5)
%77 = icmp eq i32 %76, 0
br i1 %77, label %84, label %78
78: ; preds = %73
%79 = load i32, i32* @errno
%80 = call i8* @strerror(i32 %79)
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* %80)
%82 = load i32, i32* @EXIT_FAILURE
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %73
%85 = call i32 @listen(i32 %46, i32 5)
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str, i64 0, i64 0))
%87 = bitcast i32* %7 to i8*
store i32 4, i32* %7
%88 = bitcast %struct.sockaddr_storage* %5 to %struct.sockaddr*
%89 = call i32 @accept(i32 %46, %struct.sockaddr* %88, i32* %7)
%90 = icmp eq i32 %89, -1
br i1 %90, label %91, label %97
91: ; preds = %84
%92 = load i32, i32* @errno
%93 = call i8* @strerror(i32 %92)
%94 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %93)
%95 = load i32, i32* @EXIT_FAILURE
%96 = call i32 @exit(i32 %95)
unreachable
97: ; preds = %84
%98 = load i32, i32* %7
%99 = load i32, i32* @NI_MAXHOST
%100 = load i32, i32* @NI_MAXSERV
%101 = load i32, i32* @NI_NUMERICHOST
%102 = call i32 @getnameinfo(%struct.sockaddr* %88, i32 %98, i8* %14, i32 %99, i8* %17, i32 %100, i32 %101)
%103 = icmp eq i32 %102, 0
br i1 %103, label %110, label %104
104: ; preds = %97
%105 = load i32, i32* @errno
%106 = call i8* @strerror(i32 %105)
%107 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i8* %106)
%108 = load i32, i32* @EXIT_FAILURE
%109 = call i32 @exit(i32 %108)
unreachable
110: ; preds = %97
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0), i8* %14, i8* %17)
%112 = call i32 @recv(i32 %89, i8* %18, i32 80, i32 0)
%113 = icmp eq i32 %112, 0
br i1 %113, label %122, label %114
114: ; preds = %110, %114
%115 = phi i32 [ %120, %114 ], [ %112, %110 ]
%116 = sext i32 %115 to i64
%117 = getelementptr inbounds [81 x i8], [81 x i8]* %6, i64 0, i64 %116
store i8 0, i8* %117
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %18)
%119 = call i32 @send(i32 %89, i8* %18, i32 %115, i32 80)
%120 = call i32 @recv(i32 %89, i8* %18, i32 80, i32 0)
%121 = icmp eq i32 %120, 0
br i1 %121, label %122, label %114
122: ; preds = %114, %110
%123 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.11, i64 0, i64 0))
%124 = call i32 @close(i32 %89)
%125 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i8* %14, i8* %17)
%126 = call i32 @close(i32 %46)
ret void
}