#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct sockaddr_in {
  int dummy;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  int ai_flags;
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ *ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
  int /*<<< orphan*/ *ai_canonname;
};
typedef int /*<<< orphan*/ optval;
typedef int /*<<< orphan*/ client_address;
typedef int /*<<< orphan*/ available;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int AI_NUMERICSERV;
int AI_PASSIVE;
int /*<<< orphan*/ EXIT_FAILURE;
int NI_MAXHOST;
int NI_MAXSERV;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int accept(int, struct sockaddr *, int *);
scalar_t__ bind(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ close(int);
int /*<<< orphan*/ closeWithError(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
scalar_t__ getaddrinfo(int /*<<< orphan*/ *, char *, struct addrinfo *,
                       struct addrinfo **);
scalar_t__ getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                       int /*<<< orphan*/);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ read(int, char **, int);
scalar_t__ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ write(int, char **, int);
int main() {
  int server_socktfd, client_socktfd;
  int server_length, client_length;
  struct sockaddr_in client_address;
  char caracter[32];
  struct addrinfo available;
  struct addrinfo *availablePorts, *aprp;
  int optval;
  char addrStr[(NI_MAXHOST + NI_MAXSERV + 10)];
  char host[NI_MAXHOST];
  char service[NI_MAXSERV];
  const char *readError = "read() error , keep going!!!";
  int minutos = 10;
  memset(&available, 0, sizeof(available));
  available.ai_canonname = NULL;
  available.ai_addr = NULL;
  available.ai_next = NULL;
  available.ai_socktype = SOCK_STREAM;
  available.ai_family = AF_INET;
  available.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
  if (getaddrinfo(NULL, "5000", &available, &availablePorts) < 0) {
    closeWithError("getaddrinfo() failed");
  }
  optval = 1;
  for (aprp = availablePorts; aprp != NULL; aprp = aprp->ai_next) {
    if ((server_socktfd = socket(aprp->ai_family, aprp->ai_socktype,
                                 aprp->ai_protocol)) < 0) {
      continue;
    }
    if (setsockopt(server_socktfd, SOL_SOCKET, SO_REUSEADDR, &optval,
                   sizeof(optval)) < 0) {
      closeWithError("setsockopt() failed");
    }
    if (bind(server_socktfd, aprp->ai_addr, aprp->ai_addrlen) == 0) {
      break;
    }
    close(server_socktfd);
  }
  if (aprp == NULL) {
    printf("%s\n", "No se pudo conectar a ningún puerto");
    exit(EXIT_FAILURE);
  }
  if (listen(server_socktfd, 5) < 0) {
    closeWithError("listen() failed");
  }
  freeaddrinfo(availablePorts);
  printf("%s\n", "Server initialized and waiting...");
  while (1) {
    if ((client_socktfd =
             accept(server_socktfd, (struct sockaddr *)&client_address,
                    &client_length)) == -1) {
      perror("accept() failed");
    }
    client_length = sizeof(client_address);
    printf("%s\n", "New Connection Created");
    if (getnameinfo((struct sockaddr *)&client_address, client_length, host,
                    NI_MAXHOST, service, NI_MAXSERV, 0) == 0)
      snprintf(addrStr, (NI_MAXHOST + NI_MAXSERV + 10), "(%s, %s)", host,
               service);
    else
      snprintf(addrStr, (NI_MAXHOST + NI_MAXSERV + 10), "(?UNKNOWN?)");
    printf("Connection from %s\n", addrStr);
    while (1) {
      if (read(client_socktfd, &caracter, 32) < 0) {
        perror("read() failed");
        strcpy(caracter, readError);
      }
      if (write(client_socktfd, &caracter, 32) < 0) {
        close(client_socktfd);
        closeWithError("write() failed");
      }
    }
    if (close(client_socktfd)) {
      perror("close() failed");
      continue;
    }
  }
  if (client_socktfd == -1) {
    closeWithError("accept() failed");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d67(%rip),%rcx
mov    (%rcx),%edi
mov    0x2d86(%rip),%rax
mov    (%rax),%edx
mov    %edx,%esi
mov    %edi,%edx
lea    0xa(%rdx,%rsi,1),%edx
mov    %rsp,%rsi
mov    %rsi,-0x90(%rbp)
mov    %rdx,%rdi
add    $0xf,%rdi
and    $0xfffffffffffffff0,%rdi
mov    %rsp,%rsi
sub    %rdi,%rsi
mov    %rsi,-0xd0(%rbp)
mov    %rsi,%rsp
mov    %rdx,-0x98(%rbp)
mov    (%rcx),%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0xc8(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0xa0(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xc0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0xa8(%rbp)
lea    0xd39(%rip),%rax
mov    %rax,-0xb0(%rbp)
movl   $0xa,-0xb4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
movq   $0x0,-0x48(%rbp)
movq   $0x0,-0x68(%rbp)
movq   $0x0,-0x50(%rbp)
mov    0x2cb1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    0x2cbd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x58(%rbp)
mov    0x2cb9(%rip),%rax
mov    (%rax),%eax
mov    0x2cd0(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x70(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xce5(%rip),%rsi
lea    -0x70(%rbp),%rdx
lea    -0x78(%rbp),%rcx
call   1120 <getaddrinfo@plt>
cmp    $0x0,%rax
jge    135b <main+0x13b>
lea    0xccc(%rip),%rdi
call   1060 <closeWithError@plt>
movl   $0x1,-0x84(%rbp)
mov    -0x78(%rbp),%rax
mov    %rax,-0x80(%rbp)
cmpq   $0x0,-0x80(%rbp)
je     141f <main+0x1ff>
mov    -0x80(%rbp),%rax
mov    0x18(%rax),%edi
mov    -0x80(%rbp),%rax
mov    0x14(%rax),%esi
mov    -0x80(%rbp),%rax
mov    0x10(%rax),%edx
call   1140 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    13a3 <main+0x183>
jmp    140e <main+0x1ee>
mov    -0x8(%rbp),%edi
mov    0x2c33(%rip),%rax
mov    (%rax),%esi
mov    0x2bf2(%rip),%rax
mov    (%rax),%edx
lea    -0x84(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0x0,%rax
jge    13e0 <main+0x1c0>
lea    0xc5c(%rip),%rdi
call   1060 <closeWithError@plt>
mov    -0x8(%rbp),%edi
mov    -0x80(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x80(%rbp),%rax
mov    0x4(%rax),%edx
call   10e0 <bind@plt>
cmp    $0x0,%rax
jne    1406 <main+0x1e6>
jmp    141f <main+0x1ff>
mov    -0x8(%rbp),%edi
call   10a0 <close@plt>
mov    -0x80(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x80(%rbp)
jmp    136d <main+0x14d>
cmpq   $0x0,-0x80(%rbp)
jne    144b <main+0x22b>
lea    0xcbd(%rip),%rdi
lea    0xc13(%rip),%rsi
call   1070 <printf@plt>
mov    0x2b6c(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
cmp    $0x0,%rax
jge    146e <main+0x24e>
lea    0xc07(%rip),%rdi
call   1060 <closeWithError@plt>
mov    -0x78(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
lea    0xc70(%rip),%rdi
lea    0xbfb(%rip),%rsi
call   1070 <printf@plt>
jmp    148f <main+0x26f>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x14(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    14b7 <main+0x297>
lea    0xbf0(%rip),%rdi
call   10f0 <perror@plt>
movl   $0x4,-0x14(%rbp)
lea    0xc29(%rip),%rdi
lea    0xbe6(%rip),%rsi
call   1070 <printf@plt>
mov    -0xc8(%rbp),%rdx
mov    -0xc0(%rbp),%r8
lea    -0x18(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    0x2ab3(%rip),%rax
mov    (%rax),%ecx
mov    0x2ad2(%rip),%rax
mov    (%rax),%r9d
xor    %eax,%eax
sub    $0x10,%rsp
movl   $0x0,(%rsp)
call   10b0 <getnameinfo@plt>
add    $0x10,%rsp
cmp    $0x0,%rax
jne    1556 <main+0x336>
mov    -0xc0(%rbp),%r8
mov    -0xc8(%rbp),%rcx
mov    -0xd0(%rbp),%rdi
mov    0x2a6b(%rip),%rax
mov    (%rax),%esi
mov    0x2a8a(%rip),%rax
add    (%rax),%esi
add    $0xa,%esi
lea    0xb7f(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
jmp    1580 <main+0x360>
mov    -0xd0(%rbp),%rdi
mov    0x2a3c(%rip),%rax
mov    (%rax),%esi
mov    0x2a5b(%rip),%rax
add    (%rax),%esi
add    $0xa,%esi
lea    0xb59(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0xd0(%rbp),%rsi
lea    0xb50(%rip),%rdi
call   1070 <printf@plt>
jmp    1598 <main+0x378>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   10c0 <read@plt>
cmp    $0x0,%rax
jge    15cf <main+0x3af>
lea    0xb38(%rip),%rdi
call   10f0 <perror@plt>
lea    -0x40(%rbp),%rdi
mov    -0xb0(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0xc(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x20,%edx
call   1050 <write@plt>
cmp    $0x0,%rax
jge    15fe <main+0x3de>
mov    -0xc(%rbp),%edi
call   10a0 <close@plt>
lea    0xb07(%rip),%rdi
call   1060 <closeWithError@plt>
jmp    1593 <main+0x373>

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    0x2d65(%rip),%rax
mov    (%rax),%ecx
mov    0x2d84(%rip),%rax
mov    (%rax),%eax
lea    (%rcx,%rax,1),%edx
add    $0xa,%edx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rsi
sub    %rdx,%rsi
mov    %rsi,-0x58(%rbp)
mov    %rsi,%rsp
mov    %rsp,%rdx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%rdx
mov    %rdx,-0x50(%rbp)
mov    %rdx,%rsp
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
lea    -0x88(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x30,%edx
call   1090 <memset@plt>
movq   $0x0,-0x80(%rbp)
xorps  %xmm0,%xmm0
movups %xmm0,-0x68(%rbp)
mov    0x2d01(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2d0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2d09(%rip),%rax
mov    0x2d22(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,-0x88(%rbp)
lea    0xd36(%rip),%rsi
lea    -0x40(%rbp),%rcx
xor    %edi,%edi
mov    %rbx,%rdx
call   1120 <getaddrinfo@plt>
test   %rax,%rax
jns    1306 <main+0xe6>
lea    0xd21(%rip),%rdi
call   1060 <closeWithError@plt>
movl   $0x1,-0x34(%rbp)
mov    -0x40(%rbp),%r15
test   %r15,%r15
je     1510 <main+0x2f0>
mov    0x2cbf(%rip),%r12
mov    0x2c80(%rip),%r14
lea    -0x34(%rbp),%r13
jmp    1358 <main+0x138>
xchg   %ax,%ax
mov    0x8(%r15),%rsi
mov    0x4(%r15),%edx
mov    %ebx,%edi
call   10e0 <bind@plt>
test   %rax,%rax
je     1399 <main+0x179>
mov    %ebx,%edi
call   10a0 <close@plt>
mov    0x20(%r15),%r15
test   %r15,%r15
je     1510 <main+0x2f0>
mov    0x18(%r15),%edi
mov    0x10(%r15),%edx
mov    0x14(%r15),%esi
call   1140 <socket@plt>
test   %eax,%eax
js     134b <main+0x12b>
mov    %eax,%ebx
mov    (%r12),%esi
mov    (%r14),%edx
mov    %eax,%edi
mov    %r13,%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
test   %rax,%rax
jns    1330 <main+0x110>
lea    0xca5(%rip),%rdi
call   1060 <closeWithError@plt>
jmp    1330 <main+0x110>
mov    %ebx,%edi
mov    $0x5,%esi
call   10d0 <listen@plt>
test   %rax,%rax
jns    13b6 <main+0x196>
lea    0xcbf(%rip),%rdi
call   1060 <closeWithError@plt>
mov    -0x40(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
lea    0xd28(%rip),%rdi
lea    0xcb3(%rip),%rsi
call   1070 <printf@plt>
lea    -0x30(%rbp),%rsi
lea    -0x2c(%rbp),%rdx
mov    %ebx,%edi
call   1100 <accept@plt>
mov    %eax,%r14d
cmp    $0xffffffff,%eax
mov    -0x50(%rbp),%r12
mov    -0x48(%rbp),%r13
je     14ff <main+0x2df>
movl   $0x4,-0x2c(%rbp)
lea    0xceb(%rip),%rdi
lea    0xca8(%rip),%rsi
call   1070 <printf@plt>
mov    -0x2c(%rbp),%esi
mov    0x2b87(%rip),%rbx
mov    (%rbx),%ecx
mov    0x2ba6(%rip),%r15
mov    (%r15),%r9d
sub    $0x8,%rsp
lea    -0x30(%rbp),%rdi
mov    %r12,%rdx
mov    %r13,%r8
push   $0x0
call   10b0 <getnameinfo@plt>
add    $0x10,%rsp
mov    (%rbx),%ecx
mov    (%r15),%edx
lea    (%rcx,%rdx,1),%esi
add    $0xa,%esi
test   %rax,%rax
mov    -0x58(%rbp),%rbx
je     1465 <main+0x245>
lea    0xc79(%rip),%rdx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <snprintf@plt>
jmp    147c <main+0x25c>
lea    0xc5d(%rip),%rdx
mov    %rbx,%rdi
mov    %r12,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1080 <snprintf@plt>
lea    0xc5b(%rip),%rdi
mov    %rbx,%rsi
call   1070 <printf@plt>
lea    -0xb0(%rbp),%rbx
lea    0xc59(%rip),%r15
lea    0xb60(%rip),%r12
lea    0xc59(%rip),%r13
nopw   0x0(%rax,%rax,1)
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   10c0 <read@plt>
test   %rax,%rax
jns    14d8 <main+0x2b8>
mov    %r15,%rdi
call   10f0 <perror@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1050 <write@plt>
test   %rax,%rax
jns    14b0 <main+0x290>
mov    %r14d,%edi
call   10a0 <close@plt>
mov    %r13,%rdi
call   1060 <closeWithError@plt>
jmp    14b0 <main+0x290>
lea    0xb9c(%rip),%rdi
call   10f0 <perror@plt>
jmp    13f5 <main+0x1d5>
lea    0xbd7(%rip),%rdi
lea    0xb2d(%rip),%rsi
call   1070 <printf@plt>
mov    0x2a86(%rip),%rax
mov    (%rax),%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i32, i32, i32*, i32, i32, i32, %struct.addrinfo*, i32* }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [29 x i8] c"read() error , keep going!!!\00"
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@AI_PASSIVE = global i32 0
@AI_NUMERICSERV = global i32 0
@.str.1 = [5 x i8] c"5000\00"
@.str.2 = [21 x i8] c"getaddrinfo() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [37 x i8] c"No se pudo conectar a ning\C3\BAn puerto\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [16 x i8] c"listen() failed\00"
@.str.7 = [34 x i8] c"Server initialized and waiting...\00"
@.str.8 = [16 x i8] c"accept() failed\00"
@.str.9 = [23 x i8] c"New Connection Created\00"
@.str.10 = [9 x i8] c"(%s, %s)\00"
@.str.11 = [12 x i8] c"(?UNKNOWN?)\00"
@.str.12 = [20 x i8] c"Connection from %s\0A\00"
@.str.13 = [14 x i8] c"read() failed\00"
@.str.14 = [15 x i8] c"write() failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
%7 = alloca [32 x i8]
%8 = alloca %struct.addrinfo
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo*
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i64
%15 = alloca i64
%16 = alloca i8*
%17 = alloca i32
store i32 0, i32* %1
%18 = load i32, i32* @NI_MAXHOST
%19 = load i32, i32* @NI_MAXSERV
%20 = add nsw i32 %18, %19
%21 = add nsw i32 %20, 10
%22 = zext i32 %21 to i64
%23 = call i8* @llvm.stacksave()
store i8* %23, i8** %12
%24 = alloca i8, i64 %22
store i64 %22, i64* %13
%25 = load i32, i32* @NI_MAXHOST
%26 = zext i32 %25 to i64
%27 = alloca i8, i64 %26
store i64 %26, i64* %14
%28 = load i32, i32* @NI_MAXSERV
%29 = zext i32 %28 to i64
%30 = alloca i8, i64 %29
store i64 %29, i64* %15
store i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8** %16
store i32 10, i32* %17
%31 = call i32 @memset(%struct.addrinfo* %8, i32 0, i32 48)
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 7
store i32* null, i32** %32
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 2
store i32* null, i32** %33
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 6
store %struct.addrinfo* null, %struct.addrinfo** %34
%35 = load i32, i32* @SOCK_STREAM
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 4
store i32 %35, i32* %36
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 5
store i32 %37, i32* %38
%39 = load i32, i32* @AI_PASSIVE
%40 = load i32, i32* @AI_NUMERICSERV
%41 = or i32 %39, %40
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %8, i32 0, i32 0
store i32 %41, i32* %42
%43 = call i64 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %8, %struct.addrinfo** %9)
%44 = icmp slt i64 %43, 0
br i1 %44, label %45, label %47
45: ; preds = %0
%46 = call i32 @closeWithError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %45, %0
store i32 1, i32* %11
%48 = load %struct.addrinfo*, %struct.addrinfo** %9
store %struct.addrinfo* %48, %struct.addrinfo** %10
br label %49
49: ; preds = %87, %47
%50 = load %struct.addrinfo*, %struct.addrinfo** %10
%51 = icmp ne %struct.addrinfo* %50, null
br i1 %51, label %52, label %91
52: ; preds = %49
%53 = load %struct.addrinfo*, %struct.addrinfo** %10
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 5
%55 = load i32, i32* %54
%56 = load %struct.addrinfo*, %struct.addrinfo** %10
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %56, i32 0, i32 4
%58 = load i32, i32* %57
%59 = load %struct.addrinfo*, %struct.addrinfo** %10
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %59, i32 0, i32 3
%61 = load i32, i32* %60
%62 = call i32 @socket(i32 %55, i32 %58, i32 %61)
store i32 %62, i32* %2
%63 = icmp slt i32 %62, 0
br i1 %63, label %64, label %65
64: ; preds = %52
br label %87
65: ; preds = %52
%66 = load i32, i32* %2
%67 = load i32, i32* @SOL_SOCKET
%68 = load i32, i32* @SO_REUSEADDR
%69 = call i64 @setsockopt(i32 %66, i32 %67, i32 %68, i32* %11, i32 4)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %73
71: ; preds = %65
%72 = call i32 @closeWithError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %73
73: ; preds = %71, %65
%74 = load i32, i32* %2
%75 = load %struct.addrinfo*, %struct.addrinfo** %10
%76 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %75, i32 0, i32 2
%77 = load i32*, i32** %76
%78 = load %struct.addrinfo*, %struct.addrinfo** %10
%79 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %78, i32 0, i32 1
%80 = load i32, i32* %79
%81 = call i64 @bind(i32 %74, i32* %77, i32 %80)
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %73
br label %91
84: ; preds = %73
%85 = load i32, i32* %2
%86 = call i64 @close(i32 %85)
br label %87
87: ; preds = %84, %64
%88 = load %struct.addrinfo*, %struct.addrinfo** %10
%89 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %88, i32 0, i32 6
%90 = load %struct.addrinfo*, %struct.addrinfo** %89
store %struct.addrinfo* %90, %struct.addrinfo** %10
br label %49
91: ; preds = %83, %49
%92 = load %struct.addrinfo*, %struct.addrinfo** %10
%93 = icmp eq %struct.addrinfo* %92, null
br i1 %93, label %94, label %98
94: ; preds = %91
%95 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%96 = load i32, i32* @EXIT_FAILURE
%97 = call i32 @exit(i32 %96)
unreachable
98: ; preds = %91
%99 = load i32, i32* %2
%100 = call i64 @listen(i32 %99, i32 5)
%101 = icmp slt i64 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @closeWithError(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %104
104: ; preds = %102, %98
%105 = load %struct.addrinfo*, %struct.addrinfo** %9
%106 = call i32 @freeaddrinfo(%struct.addrinfo* %105)
%107 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
br label %108
108: ; preds = %104
br label %109
109: ; preds = %108
%110 = load i32, i32* %2
%111 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%112 = call i32 @accept(i32 %110, %struct.sockaddr* %111, i32* %5)
store i32 %112, i32* %3
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %116
114: ; preds = %109
%115 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %116
116: ; preds = %114, %109
store i32 4, i32* %5
%117 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%118 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%119 = load i32, i32* %5
%120 = load i32, i32* @NI_MAXHOST
%121 = load i32, i32* @NI_MAXSERV
%122 = call i64 @getnameinfo(%struct.sockaddr* %118, i32 %119, i8* %27, i32 %120, i8* %30, i32 %121, i32 0)
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %130
124: ; preds = %116
%125 = load i32, i32* @NI_MAXHOST
%126 = load i32, i32* @NI_MAXSERV
%127 = add nsw i32 %125, %126
%128 = add nsw i32 %127, 10
%129 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 %128, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %27, i8* %30)
br label %136
130: ; preds = %116
%131 = load i32, i32* @NI_MAXHOST
%132 = load i32, i32* @NI_MAXSERV
%133 = add nsw i32 %131, %132
%134 = add nsw i32 %133, 10
%135 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 %134, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
br label %136
136: ; preds = %130, %124
%137 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %24)
br label %138
138: ; preds = %158, %136
br label %139
139: ; preds = %138
%140 = load i32, i32* %3
%141 = bitcast [32 x i8]* %7 to i8**
%142 = call i64 @read(i32 %140, i8** %141, i32 32)
%143 = icmp slt i64 %142, 0
br i1 %143, label %144, label %149
144: ; preds = %139
%145 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%146 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%147 = load i8*, i8** %16
%148 = call i32 @strcpy(i8* %146, i8* %147)
br label %149
149: ; preds = %144, %139
%150 = load i32, i32* %3
%151 = bitcast [32 x i8]* %7 to i8**
%152 = call i64 @write(i32 %150, i8** %151, i32 32)
%153 = icmp slt i64 %152, 0
br i1 %153, label %154, label %158
154: ; preds = %149
%155 = load i32, i32* %3
%156 = call i64 @close(i32 %155)
%157 = call i32 @closeWithError(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
br label %158
158: ; preds = %154, %149
br label %138
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i32, i32, i32*, i32, i32, i32, %struct.addrinfo*, i32* }
%struct.sockaddr = type { i32 }
@NI_MAXHOST = global i32 0
@NI_MAXSERV = global i32 0
@.str = [29 x i8] c"read() error , keep going!!!\00"
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@AI_PASSIVE = global i32 0
@AI_NUMERICSERV = global i32 0
@.str.1 = [5 x i8] c"5000\00"
@.str.2 = [21 x i8] c"getaddrinfo() failed\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [20 x i8] c"setsockopt() failed\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [37 x i8] c"No se pudo conectar a ning\C3\BAn puerto\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [16 x i8] c"listen() failed\00"
@.str.7 = [34 x i8] c"Server initialized and waiting...\00"
@.str.8 = [16 x i8] c"accept() failed\00"
@.str.9 = [23 x i8] c"New Connection Created\00"
@.str.10 = [9 x i8] c"(%s, %s)\00"
@.str.11 = [12 x i8] c"(?UNKNOWN?)\00"
@.str.12 = [20 x i8] c"Connection from %s\0A\00"
@.str.13 = [14 x i8] c"read() failed\00"
@.str.14 = [15 x i8] c"write() failed\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_in
%3 = alloca [32 x i8]
%4 = alloca %struct.addrinfo
%5 = alloca %struct.addrinfo*
%6 = alloca i32
%7 = bitcast i32* %1 to i8*
%8 = bitcast %struct.sockaddr_in* %2 to i8*
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%10 = bitcast %struct.addrinfo* %4 to i8*
%11 = bitcast %struct.addrinfo** %5 to i8*
%12 = bitcast i32* %6 to i8*
%13 = load i32, i32* @NI_MAXHOST
%14 = load i32, i32* @NI_MAXSERV
%15 = add i32 %13, 10
%16 = add i32 %15, %14
%17 = zext i32 %16 to i64
%18 = alloca i8, i64 %17
%19 = zext i32 %13 to i64
%20 = alloca i8, i64 %19
%21 = zext i32 %14 to i64
%22 = alloca i8, i64 %21
%23 = call i32 @memset(%struct.addrinfo* %4, i32 0, i32 48)
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 2
store i32* null, i32** %24
%25 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 6
%26 = bitcast %struct.addrinfo** %25 to i8*
%27 = load i32, i32* @SOCK_STREAM
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 4
store i32 %27, i32* %28
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 5
store i32 %29, i32* %30
%31 = load i32, i32* @AI_PASSIVE
%32 = load i32, i32* @AI_NUMERICSERV
%33 = or i32 %32, %31
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %4, i64 0, i32 0
store i32 %33, i32* %34
%35 = call i64 @getaddrinfo(i32* null, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), %struct.addrinfo* %4, %struct.addrinfo** %5)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %0
%38 = call i32 @closeWithError(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %39
39: ; preds = %37, %0
store i32 1, i32* %6
%40 = load %struct.addrinfo*, %struct.addrinfo** %5
%41 = icmp eq %struct.addrinfo* %40, null
br i1 %41, label %72, label %42
42: ; preds = %39, %68
%43 = phi %struct.addrinfo* [ %70, %68 ], [ %40, %39 ]
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 5
%45 = load i32, i32* %44
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 4
%47 = load i32, i32* %46
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 3
%49 = load i32, i32* %48
%50 = call i32 @socket(i32 %45, i32 %47, i32 %49)
%51 = icmp slt i32 %50, 0
br i1 %51, label %68, label %52
52: ; preds = %42
%53 = load i32, i32* @SOL_SOCKET
%54 = load i32, i32* @SO_REUSEADDR
%55 = call i64 @setsockopt(i32 %50, i32 %53, i32 %54, i32* %6, i32 4)
%56 = icmp slt i64 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = call i32 @closeWithError(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
br label %59
59: ; preds = %57, %52
%60 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 2
%61 = load i32*, i32** %60
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 1
%63 = load i32, i32* %62
%64 = call i64 @bind(i32 %50, i32* %61, i32 %63)
%65 = icmp eq i64 %64, 0
br i1 %65, label %76, label %66
66: ; preds = %59
%67 = call i64 @close(i32 %50)
br label %68
68: ; preds = %42, %66
%69 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %43, i64 0, i32 6
%70 = load %struct.addrinfo*, %struct.addrinfo** %69
%71 = icmp eq %struct.addrinfo* %70, null
br i1 %71, label %72, label %42
72: ; preds = %68, %39
%73 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0))
%74 = load i32, i32* @EXIT_FAILURE
%75 = call i32 @exit(i32 %74)
unreachable
76: ; preds = %59
%77 = call i64 @listen(i32 %50, i32 5)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = call i32 @closeWithError(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
br label %81
81: ; preds = %79, %76
%82 = load %struct.addrinfo*, %struct.addrinfo** %5
%83 = call i32 @freeaddrinfo(%struct.addrinfo* %82)
%84 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0))
%85 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%86 = call i32 @accept(i32 %50, %struct.sockaddr* %85, i32* %1)
%87 = icmp eq i32 %86, -1
br i1 %87, label %88, label %90
88: ; preds = %81
%89 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.8, i64 0, i64 0))
br label %90
90: ; preds = %88, %81
store i32 4, i32* %1
%91 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%92 = load i32, i32* %1
%93 = load i32, i32* @NI_MAXHOST
%94 = load i32, i32* @NI_MAXSERV
%95 = call i64 @getnameinfo(%struct.sockaddr* %85, i32 %92, i8* %20, i32 %93, i8* %22, i32 %94, i32 0)
%96 = icmp eq i64 %95, 0
%97 = load i32, i32* @NI_MAXHOST
%98 = load i32, i32* @NI_MAXSERV
%99 = add i32 %97, 10
%100 = add i32 %99, %98
br i1 %96, label %101, label %103
101: ; preds = %90
%102 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 %100, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.10, i64 0, i64 0), i8* %20, i8* %22)
br label %105
103: ; preds = %90
%104 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %18, i32 %100, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.11, i64 0, i64 0))
br label %105
105: ; preds = %103, %101
%106 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.12, i64 0, i64 0), i8* %18)
%107 = bitcast [32 x i8]* %3 to i8**
br label %108
108: ; preds = %120, %105
%109 = call i64 @read(i32 %86, i8** %107, i32 32)
%110 = icmp slt i64 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %108
%112 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.13, i64 0, i64 0))
%113 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %114
114: ; preds = %111, %108
%115 = call i64 @write(i32 %86, i8** %107, i32 32)
%116 = icmp slt i64 %115, 0
br i1 %116, label %117, label %120
117: ; preds = %114
%118 = call i64 @close(i32 %86)
%119 = call i32 @closeWithError(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
br label %120
120: ; preds = %117, %114
br label %108
}