#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;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ cliente;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int NI_MAXHOST;
int NI_MAXSERV;
int NI_NUMERICHOST;
int NI_NUMERICSERV;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ _exit(int);
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int fork();
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                               int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ wait(int *);
int main(int argc, char **argv) {
  int sd, info;
  struct addrinfo hints;
  struct addrinfo *res;
  char buffer[80];
  int sdC = 0;
  int r = 0;
  int estado = 0;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  if (argc < 2) {
    perror("Error de argumentos.\n");
  }
  getaddrinfo("::1", argv[1], &hints, &res);
  printf("Creando socket.\n");
  sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  printf("Bind.\n");
  bind(sd, (struct sockaddr *)res->ai_addr, res->ai_addrlen);
  struct sockaddr_storage cliente;
  socklen_t cliente_len = sizeof(cliente);
  char host[NI_MAXHOST];
  char serv[NI_MAXSERV];
  printf("Listen.\n");
  if (listen(sd, 10)) {
    return -1;
  }
  printf("Accept.\n");
  sdC = accept(sd, (struct sockaddr *)&cliente, &cliente_len);
  while (strcmp(buffer, "q") != 0 || strcmp(buffer, "q\n") != 0) {
    printf("Recibiendo.\n");
    r = recv(sdC, buffer, 80, 0);
    buffer[r] = '\0';
    printf("r: %d\n", r);
    int pid;
    pid = fork();
    if (pid == -1) {
      perror("Error de fork.\n");
    } else if (pid == 0) {
      if (strcmp(buffer, "q") == 0 || strcmp(buffer, "q\n") == 0) {
        send(sdC, "ADIÓS..\n", 9, 0);
        freeaddrinfo(res);
        close(sd);
        printf("Conexión terminada\n");
        _exit(0);
      }
      getnameinfo((struct sockaddr *)&cliente, cliente_len, host, NI_MAXHOST,
                  serv, NI_MAXSERV, NI_NUMERICHOST | NI_NUMERICSERV);
      printf("Host: %s, Puerto: %s\n", host, serv);
      printf("Mensaje (%i): %s\n", r, buffer);
      send(sdC, buffer, r, 0);
      sleep(3);
    } else {
      wait(&estado);
      printf("Termino el hijo..\n");
      if (strcmp(buffer, "q") == 0 || strcmp(buffer, "q\n") == 0) {
        freeaddrinfo(res);
        close(sd);
        _exit(1);
      }
    }
  }
  freeaddrinfo(res);
  close(sdC);
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0xa4(%rbp)
movl   $0x0,-0xa8(%rbp)
movl   $0x0,-0xac(%rbp)
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1289 <main+0x79>
lea    0xd7c(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd7e(%rip),%rdi
lea    -0x40(%rbp),%rdx
lea    -0x48(%rbp),%rcx
call   10e0 <getaddrinfo@plt>
lea    0xd6e(%rip),%rdi
xor    %eax,%eax
mov    %al,-0xe9(%rbp)
call   1060 <printf@plt>
mov    -0x48(%rbp),%rax
mov    0x1c(%rax),%edi
mov    0x18(%rax),%esi
mov    0x10(%rax),%rdx
call   1130 <socket@plt>
mov    %eax,%ecx
mov    -0xe9(%rbp),%al
mov    %ecx,-0x14(%rbp)
lea    0xd4d(%rip),%rdi
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x48(%rbp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
call   10b0 <bind@plt>
movl   $0x4,-0xb4(%rbp)
mov    0x2caa(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xc8(%rbp)
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xe0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xd0(%rbp)
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
mov    $0xa,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
je     139a <main+0x18a>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0xd4(%rbp)
jmp    167c <main+0x46c>
lea    0xc9a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0xb0(%rbp),%rsi
lea    -0xb4(%rbp),%rdx
call   10d0 <accept@plt>
mov    %eax,-0xa4(%rbp)
lea    -0xa0(%rbp),%rdi
lea    0xc72(%rip),%rsi
call   1090 <strcmp@plt>
mov    %rax,%rcx
mov    $0x1,%al
cmp    $0x0,%rcx
mov    %al,-0xea(%rbp)
jne    140c <main+0x1fc>
lea    -0xa0(%rbp),%rdi
lea    0xc4c(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0xea(%rbp)
mov    -0xea(%rbp),%al
test   $0x1,%al
jne    141f <main+0x20f>
jmp    164f <main+0x43f>
lea    0xc23(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0xa8(%rbp)
movslq -0xa8(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
mov    -0xa8(%rbp),%esi
lea    0xbee(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x0,%al
call   1110 <fork@plt>
mov    %eax,-0xd8(%rbp)
cmpl   $0xffffffff,-0xd8(%rbp)
jne    149a <main+0x28a>
lea    0xbcd(%rip),%rdi
call   10c0 <perror@plt>
jmp    164a <main+0x43a>
cmpl   $0x0,-0xd8(%rbp)
jne    15d1 <main+0x3c1>
lea    -0xa0(%rbp),%rdi
lea    0xb8f(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     14e1 <main+0x2d1>
lea    -0xa0(%rbp),%rdi
lea    0xb74(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1520 <main+0x310>
mov    -0xa4(%rbp),%edi
lea    0xb7f(%rip),%rsi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
lea    0xb65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1040 <_exit@plt>
mov    -0xe0(%rbp),%r8
mov    -0xe8(%rbp),%rdx
lea    -0xb0(%rbp),%rdi
mov    -0xb4(%rbp),%esi
mov    0x2a6e(%rip),%rax
mov    (%rax),%ecx
mov    0x2a85(%rip),%rax
mov    (%rax),%r9d
mov    0x2a63(%rip),%rax
mov    (%rax),%eax
mov    0x2a8a(%rip),%r10
or     (%r10),%eax
sub    $0x10,%rsp
mov    %eax,(%rsp)
call   1080 <getnameinfo@plt>
mov    -0xe8(%rbp),%rsi
mov    -0xe0(%rbp),%rdx
add    $0x10,%rsp
lea    0xb06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa8(%rbp),%esi
lea    -0xa0(%rbp),%rdx
lea    0xb01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0xa4(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0xa8(%rbp),%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    $0x3,%edi
call   10f0 <sleep@plt>
jmp    1645 <main+0x435>
lea    -0xac(%rbp),%rdi
call   1100 <wait@plt>
lea    0xad0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xa4b(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1625 <main+0x415>
lea    -0xa0(%rbp),%rdi
lea    0xa30(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1640 <main+0x430>
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
jmp    1645 <main+0x435>
jmp    164a <main+0x43a>
jmp    13c4 <main+0x1b4>
mov    -0x48(%rbp),%rdi
call   1120 <freeaddrinfo@plt>
mov    -0xa4(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0xd4(%rbp)
mov    -0xc0(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
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    $0xb8,%rsp
mov    %rsi,%rbx
movl   $0x0,-0x44(%rbp)
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
movq   $0x0,-0x78(%rbp)
cmp    $0x1,%edi
jle    154f <main+0x32f>
mov    0x8(%rbx),%rsi
lea    0xd98(%rip),%rdi
lea    -0x88(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   10f0 <getaddrinfo@plt>
lea    0xdd3(%rip),%rdi
call   1050 <puts@plt>
mov    -0x38(%rbp),%rax
mov    0x1c(%rax),%edi
mov    0x18(%rax),%esi
mov    0x10(%rax),%rdx
call   1140 <socket@plt>
mov    %eax,%r14d
lea    0xdc1(%rip),%rdi
call   1050 <puts@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %r14d,%edi
call   10c0 <bind@plt>
mov    %rsp,%r15
movl   $0x4,-0x3c(%rbp)
mov    0x2cd1(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x2cd7(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xd6b(%rip),%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
mov    %rax,%rcx
mov    $0xffffffff,%eax
test   %rcx,%rcx
jne    153d <main+0x31d>
mov    %rbx,-0x58(%rbp)
mov    %r12,-0x60(%rbp)
mov    %r15,-0x50(%rbp)
lea    0xd3d(%rip),%rdi
call   1050 <puts@plt>
lea    -0x40(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
mov    %r14d,-0x2c(%rbp)
mov    %r14d,%edi
call   10e0 <accept@plt>
mov    %eax,%r14d
lea    0xcae(%rip),%rbx
lea    -0xe0(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xd07(%rip),%r13
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    13af <main+0x18f>
mov    %r12,%rdi
lea    0xc7b(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     151e <main+0x2fe>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%r15d
cltq
movb   $0x0,-0xe0(%rbp,%rax,1)
lea    0xc42(%rip),%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1120 <fork@plt>
test   %eax,%eax
je     1450 <main+0x230>
cmp    $0xffffffff,%eax
je     143d <main+0x21d>
lea    -0x44(%rbp),%rdi
call   1110 <wait@plt>
lea    0xc93(%rip),%rdi
call   1050 <puts@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1560 <main+0x340>
mov    %r12,%rdi
lea    0xbf2(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1387 <main+0x167>
jmp    1560 <main+0x340>
lea    0xbe2(%rip),%rdi
call   10d0 <perror@plt>
jmp    1387 <main+0x167>
xchg   %ax,%ax
mov    %r14d,%r13d
mov    %r12,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     157b <main+0x35b>
mov    %r12,%rdi
lea    0xbab(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     157b <main+0x35b>
mov    -0x3c(%rbp),%esi
mov    0x2b27(%rip),%rax
mov    (%rax),%ecx
mov    0x2b3e(%rip),%rax
mov    (%rax),%r9d
mov    0x2b4c(%rip),%rax
mov    (%rax),%eax
mov    0x2b13(%rip),%rdx
or     (%rdx),%eax
sub    $0x8,%rsp
lea    -0x40(%rbp),%rdi
mov    %r12,%rbx
mov    -0x60(%rbp),%r12
mov    %r12,%rdx
mov    -0x58(%rbp),%r14
mov    %r14,%r8
push   %rax
call   1090 <getnameinfo@plt>
add    $0x10,%rsp
lea    0xb6f(%rip),%rdi
mov    %r12,%rsi
mov    %rbx,%r12
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xb6e(%rip),%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13d,%r14d
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    $0x3,%edi
call   1100 <sleep@plt>
lea    0xb01(%rip),%rbx
jmp    1380 <main+0x160>
mov    -0x38(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
mov    -0x50(%rbp),%r15
mov    %r15,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xaaa(%rip),%rdi
call   10d0 <perror@plt>
jmp    1273 <main+0x53>
mov    -0x38(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
lea    0xab4(%rip),%rsi
mov    %r13d,%edi
mov    $0x9,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x38(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
lea    0xb03(%rip),%rdi
call   1050 <puts@plt>
xor    %edi,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i64, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.1 = [4 x i8] c"::1\00"
@.str.2 = [17 x i8] c"Creando socket.\0A\00"
@.str.3 = [7 x i8] c"Bind.\0A\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str.4 = [9 x i8] c"Listen.\0A\00"
@.str.5 = [9 x i8] c"Accept.\0A\00"
@.str.6 = [2 x i8] c"q\00"
@.str.7 = [3 x i8] c"q\0A\00"
@.str.8 = [13 x i8] c"Recibiendo.\0A\00"
@.str.9 = [7 x i8] c"r: %d\0A\00"
@.str.10 = [16 x i8] c"Error de fork.\0A\00"
@.str.11 = [10 x i8] c"ADI\C3\93S..\0A\00"
@.str.12 = [21 x i8] c"Conexi\C3\B3n terminada\0A\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.13 = [22 x i8] c"Host: %s, Puerto: %s\0A\00"
@.str.14 = [18 x i8] c"Mensaje (%i): %s\0A\00"
@.str.15 = [19 x i8] c"Termino el hijo..\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 [80 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.sockaddr_storage
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %11
store i32 0, i32* %12
store i32 0, i32* %13
%21 = load i32, i32* @AI_PASSIVE
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %21, i32* %22
%23 = load i32, i32* @AF_UNSPEC
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %23, i32* %24
%25 = load i32, i32* @SOCK_STREAM
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 3
store i32 %25, i32* %26
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i64 0, i64* %27
%28 = load i32, i32* %4
%29 = icmp slt i32 %28, 2
br i1 %29, label %30, label %32
30: ; preds = %2
%31 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %32
32: ; preds = %30, %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @getaddrinfo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %35, %struct.addrinfo* %8, %struct.addrinfo** %9)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%38 = load %struct.addrinfo*, %struct.addrinfo** %9
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 4
%40 = load i32, i32* %39
%41 = load %struct.addrinfo*, %struct.addrinfo** %9
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 3
%43 = load i32, i32* %42
%44 = load %struct.addrinfo*, %struct.addrinfo** %9
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 2
%46 = load i64, i64* %45
%47 = call i32 @socket(i32 %40, i32 %43, i64 %46)
store i32 %47, i32* %6
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* %6
%50 = load %struct.addrinfo*, %struct.addrinfo** %9
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i64, i64* %51
%53 = inttoptr i64 %52 to %struct.sockaddr*
%54 = load %struct.addrinfo*, %struct.addrinfo** %9
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @bind(i32 %49, %struct.sockaddr* %53, i32 %56)
store i32 4, i32* %15
%58 = load i32, i32* @NI_MAXHOST
%59 = zext i32 %58 to i64
%60 = call i8* @llvm.stacksave()
store i8* %60, i8** %16
%61 = alloca i8, i64 %59
store i64 %59, i64* %17
%62 = load i32, i32* @NI_MAXSERV
%63 = zext i32 %62 to i64
%64 = alloca i8, i64 %63
store i64 %63, i64* %18
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%66 = load i32, i32* %6
%67 = call i64 @listen(i32 %66, i32 10)
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %70
69: ; preds = %32
store i32 -1, i32* %3
store i32 1, i32* %19
br label %164
70: ; preds = %32
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* %6
%73 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%74 = call i32 @accept(i32 %72, %struct.sockaddr* %73, i32* %15)
store i32 %74, i32* %11
br label %75
75: ; preds = %156, %70
%76 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%78 = icmp ne i64 %77, 0
br i1 %78, label %83, label %79
79: ; preds = %75
%80 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%82 = icmp ne i64 %81, 0
br label %83
83: ; preds = %79, %75
%84 = phi i1 [ true, %75 ], [ %82, %79 ]
br i1 %84, label %85, label %157
85: ; preds = %83
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0))
%87 = load i32, i32* %11
%88 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%89 = call i32 @recv(i32 %87, i8* %88, i32 80, i32 0)
store i32 %89, i32* %12
%90 = load i32, i32* %12
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 %91
store i8 0, i8* %92
%93 = load i32, i32* %12
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %93)
%95 = call i32 (...) @fork()
store i32 %95, i32* %20
%96 = load i32, i32* %20
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %100
98: ; preds = %85
%99 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %156
100: ; preds = %85
%101 = load i32, i32* %20
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %138
103: ; preds = %100
%104 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%105 = call i64 @strcmp(i8* %104, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%106 = icmp eq i64 %105, 0
br i1 %106, label %111, label %107
107: ; preds = %103
%108 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%109 = call i64 @strcmp(i8* %108, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%110 = icmp eq i64 %109, 0
br i1 %110, label %111, label %120
111: ; preds = %107, %103
%112 = load i32, i32* %11
%113 = call i32 @send(i32 %112, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 9, i32 0)
%114 = load %struct.addrinfo*, %struct.addrinfo** %9
%115 = call i32 @freeaddrinfo(%struct.addrinfo* %114)
%116 = load i32, i32* %6
%117 = call i32 @close(i32 %116)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.12, i64 0, i64 0))
%119 = call i32 @_exit(i32 0)
unreachable
120: ; preds = %107
%121 = bitcast %struct.sockaddr_storage* %14 to %struct.sockaddr*
%122 = load i32, i32* %15
%123 = load i32, i32* @NI_MAXHOST
%124 = load i32, i32* @NI_MAXSERV
%125 = load i32, i32* @NI_NUMERICHOST
%126 = load i32, i32* @NI_NUMERICSERV
%127 = or i32 %125, %126
%128 = call i32 @getnameinfo(%struct.sockaddr* %121, i32 %122, i8* %61, i32 %123, i8* %64, i32 %124, i32 %127)
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i8* %61, i8* %64)
%130 = load i32, i32* %12
%131 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %130, i8* %131)
%133 = load i32, i32* %11
%134 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%135 = load i32, i32* %12
%136 = call i32 @send(i32 %133, i8* %134, i32 %135, i32 0)
%137 = call i32 @sleep(i32 3)
br label %155
138: ; preds = %100
%139 = call i32 @wait(i32* %13)
%140 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.15, i64 0, i64 0))
%141 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%142 = call i64 @strcmp(i8* %141, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%143 = icmp eq i64 %142, 0
br i1 %143, label %148, label %144
144: ; preds = %138
%145 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%146 = call i64 @strcmp(i8* %145, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%147 = icmp eq i64 %146, 0
br i1 %147, label %148, label %154
148: ; preds = %144, %138
%149 = load %struct.addrinfo*, %struct.addrinfo** %9
%150 = call i32 @freeaddrinfo(%struct.addrinfo* %149)
%151 = load i32, i32* %6
%152 = call i32 @close(i32 %151)
%153 = call i32 @_exit(i32 1)
unreachable
154: ; preds = %144
br label %155
155: ; preds = %154, %120
br label %156
156: ; preds = %155, %98
br label %75
157: ; preds = %83
%158 = load %struct.addrinfo*, %struct.addrinfo** %9
%159 = call i32 @freeaddrinfo(%struct.addrinfo* %158)
%160 = load i32, i32* %11
%161 = call i32 @close(i32 %160)
%162 = load i32, i32* %6
%163 = call i32 @close(i32 %162)
store i32 0, i32* %3
store i32 1, i32* %19
br label %164
164: ; preds = %157, %69
%165 = load i8*, i8** %16
%166 = load i32, i32* %3
ret i32 %166
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i64, i64, i32, i32, i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.1 = [4 x i8] c"::1\00"
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str.6 = [2 x i8] c"q\00"
@.str.7 = [3 x i8] c"q\0A\00"
@.str.9 = [7 x i8] c"r: %d\0A\00"
@.str.10 = [16 x i8] c"Error de fork.\0A\00"
@.str.11 = [10 x i8] c"ADI\C3\93S..\0A\00"
@NI_NUMERICHOST = global i32 0
@NI_NUMERICSERV = global i32 0
@.str.13 = [22 x i8] c"Host: %s, Puerto: %s\0A\00"
@.str.14 = [18 x i8] c"Mensaje (%i): %s\0A\00"
@str = [16 x i8] c"Creando socket.\00"
@str.16 = [6 x i8] c"Bind.\00"
@str.17 = [8 x i8] c"Listen.\00"
@str.18 = [8 x i8] c"Accept.\00"
@str.19 = [12 x i8] c"Recibiendo.\00"
@str.20 = [18 x i8] c"Termino el hijo..\00"
@str.21 = [20 x i8] c"Conexi\C3\B3n terminada\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [80 x i8]
%6 = alloca i32
%7 = alloca %struct.sockaddr_storage
%8 = alloca i32
%9 = bitcast %struct.addrinfo* %3 to i8*
%10 = bitcast %struct.addrinfo** %4 to i8*
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%12 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%13 = load i32, i32* @AI_PASSIVE
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %13, i32* %14
%15 = load i32, i32* @AF_UNSPEC
%16 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %15, i32* %16
%17 = load i32, i32* @SOCK_STREAM
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %17, i32* %18
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %19
%20 = icmp slt i32 %0, 2
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @getaddrinfo(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %25, %struct.addrinfo* %3, %struct.addrinfo** %4)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%28 = load %struct.addrinfo*, %struct.addrinfo** %4
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 4
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 3
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %28, i64 0, i32 2
%34 = load i64, i64* %33
%35 = call i32 @socket(i32 %30, i32 %32, i64 %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @str.16, i64 0, i64 0))
%37 = load %struct.addrinfo*, %struct.addrinfo** %4
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 1
%39 = load i64, i64* %38
%40 = inttoptr i64 %39 to %struct.sockaddr*
%41 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i64 0, i32 0
%42 = load i32, i32* %41
%43 = call i32 @bind(i32 %35, %struct.sockaddr* %40, i32 %42)
%44 = bitcast %struct.sockaddr_storage* %7 to i8*
%45 = bitcast i32* %8 to i8*
store i32 4, i32* %8
%46 = load i32, i32* @NI_MAXHOST
%47 = zext i32 %46 to i64
%48 = call i8* @llvm.stacksave()
%49 = alloca i8, i64 %47
%50 = load i32, i32* @NI_MAXSERV
%51 = zext i32 %50 to i64
%52 = alloca i8, i64 %51
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.17, i64 0, i64 0))
%54 = call i64 @listen(i32 %35, i32 10)
%55 = icmp eq i64 %54, 0
br i1 %55, label %56, label %119
56: ; preds = %23
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.18, i64 0, i64 0))
%58 = bitcast %struct.sockaddr_storage* %7 to %struct.sockaddr*
%59 = call i32 @accept(i32 %35, %struct.sockaddr* %58, i32* %8)
br label %60
60: ; preds = %100, %56
%61 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%62 = icmp eq i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %60
%64 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%65 = icmp eq i64 %64, 0
br i1 %65, label %114, label %66
66: ; preds = %60, %63
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.19, i64 0, i64 0))
%68 = call i32 @recv(i32 %59, i8* %11, i32 80, i32 0)
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %69
store i8 0, i8* %70
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i32 %68)
%72 = call i32 (...) @fork()
switch i32 %72, label %101 [
i32 -1, label %73
i32 0, label %75
]
73: ; preds = %66
%74 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0))
br label %100
75: ; preds = %66
%76 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%77 = icmp eq i64 %76, 0
br i1 %77, label %81, label %78
78: ; preds = %75
%79 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %88
81: ; preds = %78, %75
%82 = call i32 @send(i32 %59, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0), i32 9, i32 0)
%83 = load %struct.addrinfo*, %struct.addrinfo** %4
%84 = call i32 @freeaddrinfo(%struct.addrinfo* %83)
%85 = call i32 @close(i32 %35)
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.21, i64 0, i64 0))
%87 = call i32 @_exit(i32 0)
unreachable
88: ; preds = %78
%89 = load i32, i32* %8
%90 = load i32, i32* @NI_MAXHOST
%91 = load i32, i32* @NI_MAXSERV
%92 = load i32, i32* @NI_NUMERICHOST
%93 = load i32, i32* @NI_NUMERICSERV
%94 = or i32 %93, %92
%95 = call i32 @getnameinfo(%struct.sockaddr* %58, i32 %89, i8* %49, i32 %90, i8* %52, i32 %91, i32 %94)
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.13, i64 0, i64 0), i8* %49, i8* %52)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.14, i64 0, i64 0), i32 %68, i8* %11)
%98 = call i32 @send(i32 %59, i8* %11, i32 %68, i32 0)
%99 = call i32 @sleep(i32 3)
br label %100
100: ; preds = %88, %106, %73
br label %60
101: ; preds = %66
%102 = call i32 @wait(i32* %6)
%103 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.20, i64 0, i64 0))
%104 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %109, label %106
106: ; preds = %101
%107 = call i64 @strcmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%108 = icmp eq i64 %107, 0
br i1 %108, label %109, label %100
109: ; preds = %106, %101
%110 = load %struct.addrinfo*, %struct.addrinfo** %4
%111 = call i32 @freeaddrinfo(%struct.addrinfo* %110)
%112 = call i32 @close(i32 %35)
%113 = call i32 @_exit(i32 1)
unreachable
114: ; preds = %63
%115 = load %struct.addrinfo*, %struct.addrinfo** %4
%116 = call i32 @freeaddrinfo(%struct.addrinfo* %115)
%117 = call i32 @close(i32 %59)
%118 = call i32 @close(i32 %35)
br label %119
119: ; preds = %23, %114
%120 = phi i32 [ 0, %114 ], [ -1, %23 ]
ret i32 %120
}