#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 scalar_t__ pid_t;
typedef int /*<<< orphan*/ cli;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int EXIT_FAILURE;
int EXIT_SUCCESS;
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);
scalar_t__ fork();
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, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
char *strerror(int);
int /*<<< orphan*/ wait(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");
  while (1) {
    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);
    }
    pid_t pid = fork();
    if (pid < 0) {
      errn = errno;
      printf("fork: %s\n", strerror(errn));
      exit(EXIT_FAILURE);
    } else if (pid == 0) {
      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 (buff[0] == 'q') {
          send(cli_sd, '\0', 1, 80);
          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);
      exit(EXIT_SUCCESS);
    } else if (pid > 0) {
      close(cli_sd);
    }
  }
  wait(&stat);
  close(sd);
  exit(stat);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x100,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2da7(%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,-0xf8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x58(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xf0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x60(%rbp)
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d60(%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     12e7 <main+0x107>
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    0x2cd0(%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   1100 <socket@plt>
mov    %eax,-0xcc(%rbp)
cmpl   $0xffffffff,-0xcc(%rbp)
jne    1351 <main+0x171>
mov    0x2ca2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    0x2c66(%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     13bf <main+0x1df>
mov    0x2c34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc7c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    0x2bf8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x40(%rbp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    -0xcc(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
mov    %eax,-0xc8(%rbp)
cmpl   $0x0,-0xc8(%rbp)
je     1424 <main+0x244>
mov    0x2bc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc18(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b93(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xcc(%rbp),%edi
mov    $0x5,%esi
call   1080 <listen@plt>
lea    0xbf8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1447 <main+0x267>
movl   $0x4,-0xd0(%rbp)
mov    -0xcc(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
call   10a0 <accept@plt>
mov    %eax,-0xd4(%rbp)
cmpl   $0xffffffff,-0xd4(%rbp)
jne    14b3 <main+0x2d3>
mov    0x2b37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xba0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2b04(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    $0x0,%al
call   10e0 <fork@plt>
mov    %rax,-0xe0(%rbp)
cmpq   $0x0,-0xe0(%rbp)
jge    1508 <main+0x328>
mov    0x2ae2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xb57(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2aaf(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0xe0(%rbp)
jne    16eb <main+0x50b>
mov    -0xf0(%rbp),%r8
mov    -0xf8(%rbp),%rdx
lea    -0x48(%rbp),%rdi
mov    -0xd0(%rbp),%esi
mov    0x2a6b(%rip),%rax
mov    (%rax),%ecx
mov    0x2a9a(%rip),%rax
mov    (%rax),%r9d
mov    0x2a78(%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     15a6 <main+0x3c6>
mov    0x2a44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
mov    -0xc4(%rbp),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xac3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2a11(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0xf0(%rbp),%rdx
mov    -0xf8(%rbp),%rsi
lea    0xaaa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0xe4(%rbp)
cmpl   $0x0,-0xe4(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    15e5 <main+0x405>
jmp    16b6 <main+0x4d6>
mov    -0xd4(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xe8(%rbp)
cmpl   $0x0,-0xe8(%rbp)
jne    161b <main+0x43b>
movl   $0x1,-0xe4(%rbp)
movsbl -0xc0(%rbp),%eax
cmp    $0x71,%eax
jne    164e <main+0x46e>
mov    -0xd4(%rbp),%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x50,%ecx
mov    $0x0,%al
call   1040 <send@plt>
movl   $0x1,-0xe4(%rbp)
cmpl   $0x0,-0xe4(%rbp)
jne    16a3 <main+0x4c3>
movslq -0xe8(%rbp),%rax
movb   $0x0,-0xc0(%rbp,%rax,1)
lea    -0xc0(%rbp),%rsi
lea    0xa01(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xd4(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    -0xe8(%rbp),%edx
mov    $0x50,%ecx
mov    $0x0,%al
call   1040 <send@plt>
jmp    16b1 <main+0x4d1>
lea    0x9dd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    15cc <main+0x3ec>
mov    -0xd4(%rbp),%edi
call   1060 <close@plt>
mov    -0xf8(%rbp),%rsi
mov    -0xf0(%rbp),%rdx
lea    0x9c1(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x28c4(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0xe0(%rbp)
jle    1704 <main+0x524>
mov    -0xd4(%rbp),%edi
call   1060 <close@plt>
jmp    1709 <main+0x529>
jmp    170e <main+0x52e>
jmp    1442 <main+0x262>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    0x2db3(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
mov    0x2da9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x60(%rbp)
movq   $0x0,-0x58(%rbp)
mov    0x8(%rsi),%rdi
mov    0x10(%rsi),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
test   %eax,%eax
jne    12aa <main+0xba>
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%esi
mov    0x14(%rax),%edi
xor    %edx,%edx
call   1110 <socket@plt>
cmp    $0xffffffff,%eax
jne    12e0 <main+0xf0>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd69(%rip),%rdi
jmp    12bf <main+0xcf>
mov    0x2d07(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xd41(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    %eax,%r12d
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %r12d,%edi
call   10a0 <bind@plt>
test   %eax,%eax
jne    13ac <main+0x1bc>
mov    -0x38(%rbp),%rdi
call   1100 <freeaddrinfo@plt>
mov    %r12d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
test   %eax,%eax
jne    13c6 <main+0x1d6>
mov    %rbx,-0x48(%rbp)
mov    %r12d,%edi
mov    $0x5,%esi
call   1090 <listen@plt>
lea    0xd62(%rip),%rdi
call   1040 <puts@plt>
movl   $0x4,-0x2c(%rbp)
lea    -0x40(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %r12d,%edi
call   10b0 <accept@plt>
cmp    $0xffffffff,%eax
je     1395 <main+0x1a5>
mov    %eax,%ebx
lea    -0x40(%rbp),%r13
lea    -0x2c(%rbp),%r14
xchg   %ax,%ax
xor    %eax,%eax
call   10f0 <fork@plt>
test   %rax,%rax
js     13ea <main+0x1fa>
je     1401 <main+0x211>
mov    %ebx,%edi
call   1070 <close@plt>
movl   $0x4,-0x2c(%rbp)
mov    %r12d,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   10b0 <accept@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1360 <main+0x170>
mov    0x2c1c(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc89(%rip),%rdi
jmp    13db <main+0x1eb>
mov    0x2c05(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc5c(%rip),%rdi
jmp    12bf <main+0xcf>
mov    0x2beb(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc4c(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    12d2 <main+0xe2>
mov    0x2bc7(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc40(%rip),%rdi
jmp    13db <main+0x1eb>
mov    -0x2c(%rbp),%esi
mov    0x2b95(%rip),%rax
mov    (%rax),%ecx
mov    0x2bc4(%rip),%rax
mov    (%rax),%r9d
mov    0x2ba2(%rip),%rax
mov    (%rax),%eax
sub    $0x8,%rsp
lea    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%r14
mov    %r14,%rdx
mov    %r15,%r8
push   %rax
call   1080 <getnameinfo@plt>
add    $0x10,%rsp
test   %eax,%eax
jne    1529 <main+0x339>
lea    0xc0f(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%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>
cmpb   $0x71,-0xd0(%rbp)
je     14de <main+0x2ee>
mov    %eax,%r14d
lea    0xbee(%rip),%r12
lea    -0xd0(%rbp),%r13
nopw   0x0(%rax,%rax,1)
test   %r14d,%r14d
je     14f3 <main+0x303>
movslq %r14d,%rax
movb   $0x0,-0xd0(%rbp,%rax,1)
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r14d,%edx
mov    $0x50,%ecx
xor    %eax,%eax
call   1050 <send@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r14d
cmpb   $0x71,-0xd0(%rbp)
jne    1490 <main+0x2a0>
mov    %ebx,%edi
xor    %esi,%esi
mov    $0x1,%edx
mov    $0x50,%ecx
xor    %eax,%eax
call   1050 <send@plt>
lea    0xba5(%rip),%rdi
call   1040 <puts@plt>
mov    %ebx,%edi
call   1070 <close@plt>
lea    0xb6f(%rip),%rdi
mov    -0x48(%rbp),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xb0b(%rip),%rdi
jmp    13db <main+0x1eb>

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"
@.str.6 = [10 x i8] c"fork: %s\0A\00"
@NI_NUMERICHOST = global i32 0
@.str.7 = [17 x i8] c"getnameinfo: %s\0A\00"
@.str.8 = [20 x i8] c"host: %s, port: %s\0A\00"
@.str.9 = [14 x i8] c"recieved: %s\0A\00"
@.str.10 = [16 x i8] c"Client aborted\0A\00"
@.str.11 = [25 x i8] c"host: %s, port: %s gone\0A\00"
@EXIT_SUCCESS = global i32 0
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 i64
%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))
br label %110
110: ; preds = %205, %106
br label %111
111: ; preds = %110
store i32 4, i32* %15
%112 = load i32, i32* %14
%113 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%114 = call i32 @accept(i32 %112, %struct.sockaddr* %113, i32* %15)
store i32 %114, i32* %16
%115 = load i32, i32* %16
%116 = icmp eq i32 %115, -1
br i1 %116, label %117, label %124
117: ; preds = %111
%118 = load i32, i32* @errno
store i32 %118, i32* %12
%119 = load i32, i32* %12
%120 = call i8* @strerror(i32 %119)
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0), i8* %120)
%122 = load i32, i32* @EXIT_FAILURE
%123 = call i32 @exit(i32 %122)
unreachable
124: ; preds = %111
%125 = call i64 (...) @fork()
store i64 %125, i64* %17
%126 = load i64, i64* %17
%127 = icmp slt i64 %126, 0
br i1 %127, label %128, label %135
128: ; preds = %124
%129 = load i32, i32* @errno
store i32 %129, i32* %12
%130 = load i32, i32* %12
%131 = call i8* @strerror(i32 %130)
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* %131)
%133 = load i32, i32* @EXIT_FAILURE
%134 = call i32 @exit(i32 %133)
unreachable
135: ; preds = %124
%136 = load i64, i64* %17
%137 = icmp eq i64 %136, 0
br i1 %137, label %138, label %197
138: ; preds = %135
%139 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%140 = load i32, i32* %15
%141 = load i32, i32* @NI_MAXHOST
%142 = load i32, i32* @NI_MAXSERV
%143 = load i32, i32* @NI_NUMERICHOST
%144 = call i32 @getnameinfo(%struct.sockaddr* %139, i32 %140, i8* %23, i32 %141, i8* %26, i32 %142, i32 %143)
store i32 %144, i32* %13
%145 = load i32, i32* %13
%146 = icmp ne i32 %145, 0
br i1 %146, label %147, label %154
147: ; preds = %138
%148 = load i32, i32* @errno
store i32 %148, i32* %12
%149 = load i32, i32* %12
%150 = call i8* @strerror(i32 %149)
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i8* %150)
%152 = load i32, i32* @EXIT_FAILURE
%153 = call i32 @exit(i32 %152)
unreachable
154: ; preds = %138
%155 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %23, i8* %26)
store i32 0, i32* %18
br label %156
156: ; preds = %190, %154
%157 = load i32, i32* %18
%158 = icmp ne i32 %157, 0
%159 = xor i1 %158, true
br i1 %159, label %160, label %191
160: ; preds = %156
%161 = load i32, i32* %16
%162 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%163 = call i32 @recv(i32 %161, i8* %162, i32 80, i32 0)
store i32 %163, i32* %19
%164 = load i32, i32* %19
%165 = icmp eq i32 %164, 0
br i1 %165, label %166, label %167
166: ; preds = %160
store i32 1, i32* %18
br label %167
167: ; preds = %166, %160
%168 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%169 = load i8, i8* %168
%170 = sext i8 %169 to i32
%171 = icmp eq i32 %170, 113
br i1 %171, label %172, label %175
172: ; preds = %167
%173 = load i32, i32* %16
%174 = call i32 (i32, ...) @send(i32 %173, i32 0, i32 1, i32 80)
store i32 1, i32* %18
br label %175
175: ; preds = %172, %167
%176 = load i32, i32* %18
%177 = icmp ne i32 %176, 0
br i1 %177, label %188, label %178
178: ; preds = %175
%179 = load i32, i32* %19
%180 = sext i32 %179 to i64
%181 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 %180
store i8 0, i8* %181
%182 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%183 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0), i8* %182)
%184 = load i32, i32* %16
%185 = getelementptr inbounds [81 x i8], [81 x i8]* %11, i64 0, i64 0
%186 = load i32, i32* %19
%187 = call i32 (i32, ...) @send(i32 %184, i8* %185, i32 %186, i32 80)
br label %190
188: ; preds = %175
%189 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %190
190: ; preds = %188, %178
br label %156
191: ; preds = %156
%192 = load i32, i32* %16
%193 = call i32 @close(i32 %192)
%194 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.11, i64 0, i64 0), i8* %23, i8* %26)
%195 = load i32, i32* @EXIT_SUCCESS
%196 = call i32 @exit(i32 %195)
unreachable
197: ; preds = %135
%198 = load i64, i64* %17
%199 = icmp sgt i64 %198, 0
br i1 %199, label %200, label %203
200: ; preds = %197
%201 = load i32, i32* %16
%202 = call i32 @close(i32 %201)
br label %203
203: ; preds = %200, %197
br label %204
204: ; preds = %203
br label %205
205: ; preds = %204
br label %110
}

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