#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_zero;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, unsigned int *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ free(char *);
long getBytes(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(TYPE_1__);
int listen(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
long read(int, char *, long);
int /*<<< orphan*/ send(int, char *, long, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  struct sockaddr_in cliente, servidor;
  int lensckadd = sizeof(struct sockaddr);
  int recsocket = 0, recsock = 0;
  int conectado = 0, pid = 0;
  unsigned int lens = sizeof(struct sockaddr_in);
  char *mensaje;
  int descriptor;
  long numbytes, bytesread;
  char path[] = "doc.html";
  if (argc != 1) {
    printf("\n[+]Uso: %s\n\n", argv[0]);
    exit(0);
  }
  if ((recsocket = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    printf("\n[!]Error abriendo el socket\n");
    exit(-1);
  }
  servidor.sin_family = AF_INET;
  servidor.sin_port = htons(9999);
  servidor.sin_addr.s_addr = INADDR_ANY;
  memset(servidor.sin_zero, 0, 8);
  if (bind(recsocket, (struct sockaddr *)&servidor, lensckadd) == -1) {
    printf("\n[!]Error en la fase de asociacion\n");
    exit(-1);
  }
  if (listen(recsocket, 2) == -1) {
    printf("\n[!]Error en la fase de escucha\n");
    exit(-1);
  }
  while (!conectado) {
    printf("\n[/]Esperando conexion...\n");
    if ((recsock = accept(recsocket, (struct sockaddr *)&cliente, &lens)) ==
        -1) {
      printf("\n[!]Error en la fase de aceptacion\n");
      exit(-1);
    } else {
      printf("  [*]Se conectó un cliente con IP:%s\n",
             inet_ntoa(cliente.sin_addr));
      pid = fork();
      if (pid == -1) {
        printf("\nError hijo\n");
        exit(-1);
      } else if (pid == 0) {
        numbytes = getBytes(path);
        if (numbytes < 0) {
          printf("\nError al determinar el numero de bytes del archivo %s\n",
                 path);
          exit(-1);
        }
        mensaje = (char *)malloc(1024 / sizeof(char));
        descriptor = open(path, O_RDONLY);
        if (descriptor < 0) {
          printf("\nError al abrir el archivo %s\n", path);
          exit(-1);
        }
        printf("\n[+]Se enviará el archivo %s con %ld bytes de tamaño en %ld "
               "bloques de 1024 bytes\n",
               path, numbytes, (numbytes / 1024));
        printf("\n [~]Enviando [");
        while ((bytesread = read(descriptor, mensaje, (long)1024)) != 0) {
          send(recsock, mensaje, bytesread, 0);
          printf("-");
        }
        printf(">]\t(*)Enviado el archivo completo\n");
        free(mensaje);
        exit(0);
      } else {
        wait(NULL);
        conectado = 1;
      }
    }
    close(recsocket);
    close(recsock);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
movl   $0x10,-0x48(%rbp)
mov    0xd96(%rip),%rax
mov    %rax,-0x71(%rbp)
mov    0xd94(%rip),%al
mov    %al,-0x69(%rbp)
cmpl   $0x1,-0x8(%rbp)
je     129d <main+0x7d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
xor    %edi,%edi
call   1110 <exit@plt>
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
mov    0x2d1b(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
jne    12da <main+0xba>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    0x2d07(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x270f,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2cde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
mov    $0x8,%edx
call   1080 <memset@plt>
mov    -0x38(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    -0x34(%rbp),%edx
call   10d0 <bind@plt>
cmp    $0xffffffff,%eax
jne    133e <main+0x11e>
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%edi
mov    $0x2,%esi
call   10c0 <listen@plt>
cmp    $0xffffffff,%eax
jne    136c <main+0x14c>
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
jmp    1371 <main+0x151>
cmpl   $0x0,-0x40(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1387 <main+0x167>
jmp    1563 <main+0x343>
lea    0xcec(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x48(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x3c(%rbp)
cmp    $0xffffffff,%eax
jne    13c9 <main+0x1a9>
lea    0xcdd(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    -0x20(%rbp),%edi
call   1040 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xcde(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x0,%al
call   1130 <fork@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    140e <main+0x1ee>
lea    0xce3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
cmpl   $0x0,-0x44(%rbp)
jne    1534 <main+0x314>
lea    -0x71(%rbp),%rdi
call   1100 <getBytes@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
jge    144c <main+0x22c>
lea    -0x71(%rbp),%rsi
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    $0x400,%edi
call   10b0 <malloc@plt>
mov    %rax,-0x50(%rbp)
lea    -0x71(%rbp),%rdi
mov    0x2b7b(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    1495 <main+0x275>
lea    -0x71(%rbp),%rsi
lea    0xca1(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    -0x71(%rbp),%rsi
mov    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x60(%rbp),%rax
mov    $0x400,%ecx
cqto
idiv   %rcx
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xc87(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xcce(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
mov    %rax,-0x68(%rbp)
cmp    $0x0,%rax
je     1516 <main+0x2f6>
mov    -0x3c(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x68(%rbp),%rdx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xc9f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    14d2 <main+0x2b2>
lea    0xc8e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1110 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1120 <wait@plt>
movl   $0x1,-0x40(%rbp)
jmp    1549 <main+0x329>
jmp    154e <main+0x32e>
mov    -0x38(%rbp),%edi
call   1090 <close@plt>
mov    -0x3c(%rbp),%edi
call   1090 <close@plt>
jmp    1371 <main+0x151>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
movl   $0x10,0x14(%rsp)
movabs $0x6c6d74682e636f64,%rax
74 6d 6c
mov    %rax,0x8(%rsp)
movb   $0x0,0x10(%rsp)
cmp    $0x1,%edi
jne    1363 <main+0x123>
mov    0x2d72(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d49(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
je     137b <main+0x13b>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x24(%rsp)
mov    $0x270f,%edi
call   1070 <htons@plt>
mov    %eax,0x20(%rsp)
mov    0x2d2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
xor    %esi,%esi
mov    $0x8,%edx
call   10a0 <memset@plt>
lea    0x18(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   10f0 <bind@plt>
cmp    $0xffffffff,%eax
je     1384 <main+0x144>
mov    %ebp,%edi
mov    $0x2,%esi
call   10e0 <listen@plt>
cmp    $0xffffffff,%eax
je     138d <main+0x14d>
lea    0xe04(%rip),%rdi
call   1050 <puts@plt>
lea    0x28(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %ebp,%edi
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
je     1396 <main+0x156>
mov    %eax,%ebx
mov    0x28(%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xcf0(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %eax,%eax
call   1150 <fork@plt>
test   %eax,%eax
je     139f <main+0x15f>
cmp    $0xffffffff,%eax
je     13b7 <main+0x177>
xor    %edi,%edi
call   1140 <wait@plt>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %ebx,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsi),%rsi
lea    0xc9c(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
lea    0xe26(%rip),%rdi
jmp    13be <main+0x17e>
lea    0xdfa(%rip),%rdi
jmp    13be <main+0x17e>
lea    0xdd1(%rip),%rdi
jmp    13be <main+0x17e>
lea    0xda5(%rip),%rdi
jmp    13be <main+0x17e>
lea    0x8(%rsp),%rdi
call   1120 <getBytes@plt>
test   %rax,%rax
jns    13cd <main+0x18d>
lea    0xc89(%rip),%rdi
jmp    13fb <main+0x1bb>
lea    0xd78(%rip),%rdi
call   1050 <puts@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    %rax,%r15
mov    $0x400,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    0x2bfc(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdi
call   1100 <open@plt>
test   %eax,%eax
jns    1411 <main+0x1d1>
lea    0xc7b(%rip),%rdi
lea    0x8(%rsp),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0xffffffff,%edi
call   1130 <exit@plt>
mov    %eax,%r14d
mov    %r15,%rcx
shr    $0xa,%rcx
lea    0xc73(%rip),%rdi
lea    0x8(%rsp),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xcb2(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x400,%edx
mov    %r14d,%edi
mov    %rbp,%rsi
call   10c0 <read@plt>
test   %rax,%rax
je     146f <main+0x22f>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %rax,%rdx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    $0x2d,%edi
call   1040 <putchar@plt>
jmp    143f <main+0x1ff>
lea    0xc9e(%rip),%rdi
call   1050 <puts@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.path = [9 x i8] c"doc.html\00"
@.str = [14 x i8] c"\0A[+]Uso: %s\0A\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [30 x i8] c"\0A[!]Error abriendo el socket\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [36 x i8] c"\0A[!]Error en la fase de asociacion\0A\00"
@.str.3 = [33 x i8] c"\0A[!]Error en la fase de escucha\0A\00"
@.str.4 = [27 x i8] c"\0A[/]Esperando conexion...\0A\00"
@.str.5 = [36 x i8] c"\0A[!]Error en la fase de aceptacion\0A\00"
@.str.6 = [39 x i8] c" [*]Se conect\C3\B3 un cliente con IP:%s\0A\00"
@.str.7 = [13 x i8] c"\0AError hijo\0A\00"
@.str.8 = [56 x i8] c"\0AError al determinar el numero de bytes del archivo %s\0A\00"
@O_RDONLY = global i32 0
@.str.9 = [31 x i8] c"\0AError al abrir el archivo %s\0A\00"
@.str.10 = [85 x i8] c"\0A[+]Se enviar\C3\A1 el archivo %s con %ld bytes de tama\C3\B1o en %ld bloques de 1024 bytes\0A\00"
@.str.11 = [16 x i8] c"\0A [~]Enviando [\00"
@.str.12 = [2 x i8] c"-\00"
@.str.13 = [35 x i8] c">]\09(*)Enviado el archivo completo\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i64
%17 = alloca i64
%18 = alloca [9 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
store i32 16, i32* %13
%19 = bitcast [9 x i8]* %18 to i8*
%20 = load i32, i32* %4
%21 = icmp ne i32 %20, 1
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %2
%29 = load i32, i32* @AF_INET
%30 = load i32, i32* @SOCK_STREAM
%31 = call i32 @socket(i32 %29, i32 %30, i32 0)
store i32 %31, i32* %9
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %28
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @exit(i32 -1)
unreachable
36: ; preds = %28
%37 = load i32, i32* @AF_INET
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 3
store i32 %37, i32* %38
%39 = call i32 @htons(i32 9999)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 2
store i32 %39, i32* %40
%41 = load i32, i32* @INADDR_ANY
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 0
%43 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %42, i32 0, i32 0
store i32 %41, i32* %43
%44 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i32 0, i32 1
%45 = load i32, i32* %44
%46 = call i32 @memset(i32 %45, i32 0, i32 8)
%47 = load i32, i32* %9
%48 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%49 = load i32, i32* %8
%50 = call i32 @bind(i32 %47, %struct.sockaddr* %48, i32 %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %55
52: ; preds = %36
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
%54 = call i32 @exit(i32 -1)
unreachable
55: ; preds = %36
%56 = load i32, i32* %9
%57 = call i32 @listen(i32 %56, i32 2)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
%61 = call i32 @exit(i32 -1)
unreachable
62: ; preds = %55
br label %63
63: ; preds = %139, %62
%64 = load i32, i32* %11
%65 = icmp ne i32 %64, 0
%66 = xor i1 %65, true
br i1 %66, label %67, label %144
67: ; preds = %63
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%69 = load i32, i32* %9
%70 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%71 = call i32 @accept(i32 %69, %struct.sockaddr* %70, i32* %13)
store i32 %71, i32* %10
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %67
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%78 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %77, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i8* @inet_ntoa(i32 %79)
%81 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %80)
%82 = call i32 (...) @fork()
store i32 %82, i32* %12
%83 = load i32, i32* %12
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %88
85: ; preds = %76
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%87 = call i32 @exit(i32 -1)
unreachable
88: ; preds = %76
%89 = load i32, i32* %12
%90 = icmp eq i32 %89, 0
br i1 %90, label %91, label %135
91: ; preds = %88
%92 = getelementptr inbounds [9 x i8], [9 x i8]* %18, i64 0, i64 0
%93 = call i64 @getBytes(i8* %92)
store i64 %93, i64* %16
%94 = load i64, i64* %16
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %91
%97 = getelementptr inbounds [9 x i8], [9 x i8]* %18, i64 0, i64 0
%98 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), i8* %97)
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %91
%101 = call i64 @malloc(i32 1024)
%102 = inttoptr i64 %101 to i8*
store i8* %102, i8** %14
%103 = getelementptr inbounds [9 x i8], [9 x i8]* %18, i64 0, i64 0
%104 = load i32, i32* @O_RDONLY
%105 = call i32 @open(i8* %103, i32 %104)
store i32 %105, i32* %15
%106 = load i32, i32* %15
%107 = icmp slt i32 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %100
%109 = getelementptr inbounds [9 x i8], [9 x i8]* %18, i64 0, i64 0
%110 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %109)
%111 = call i32 @exit(i32 -1)
unreachable
112: ; preds = %100
%113 = getelementptr inbounds [9 x i8], [9 x i8]* %18, i64 0, i64 0
%114 = load i64, i64* %16
%115 = load i64, i64* %16
%116 = sdiv i64 %115, 1024
%117 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.10, i64 0, i64 0), i8* %113, i64 %114, i64 %116)
%118 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
br label %119
119: ; preds = %124, %112
%120 = load i32, i32* %15
%121 = load i8*, i8** %14
%122 = call i64 @read(i32 %120, i8* %121, i64 1024)
store i64 %122, i64* %17
%123 = icmp ne i64 %122, 0
br i1 %123, label %124, label %130
124: ; preds = %119
%125 = load i32, i32* %10
%126 = load i8*, i8** %14
%127 = load i64, i64* %17
%128 = call i32 @send(i32 %125, i8* %126, i64 %127, i32 0)
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
br label %119
130: ; preds = %119
%131 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.13, i64 0, i64 0))
%132 = load i8*, i8** %14
%133 = call i32 @free(i8* %132)
%134 = call i32 @exit(i32 0)
unreachable
135: ; preds = %88
%136 = call i32 @wait(i32* null)
store i32 1, i32* %11
br label %137
137: ; preds = %135
br label %138
138: ; preds = %137
br label %139
139: ; preds = %138
%140 = load i32, i32* %9
%141 = call i32 @close(i32 %140)
%142 = load i32, i32* %10
%143 = call i32 @close(i32 %142)
br label %63
144: ; preds = %63
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.path = [9 x i8] c"doc.html\00"
@.str = [14 x i8] c"\0A[+]Uso: %s\0A\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str.6 = [39 x i8] c" [*]Se conect\C3\B3 un cliente con IP:%s\0A\00"
@.str.8 = [56 x i8] c"\0AError al determinar el numero de bytes del archivo %s\0A\00"
@O_RDONLY = global i32 0
@.str.9 = [31 x i8] c"\0AError al abrir el archivo %s\0A\00"
@.str.10 = [85 x i8] c"\0A[+]Se enviar\C3\A1 el archivo %s con %ld bytes de tama\C3\B1o en %ld bloques de 1024 bytes\0A\00"
@.str.11 = [16 x i8] c"\0A [~]Enviando [\00"
@str = [26 x i8] c"\0A[/]Esperando conexion...\00"
@str.14 = [34 x i8] c">]\09(*)Enviado el archivo completo\00"
@str.15 = [12 x i8] c"\0AError hijo\00"
@str.16 = [35 x i8] c"\0A[!]Error en la fase de aceptacion\00"
@str.17 = [32 x i8] c"\0A[!]Error en la fase de escucha\00"
@str.18 = [35 x i8] c"\0A[!]Error en la fase de asociacion\00"
@str.19 = [29 x i8] c"\0A[!]Error abriendo el socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [9 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast %struct.sockaddr_in* %4 to i8*
%9 = bitcast i32* %5 to i8*
store i32 16, i32* %5
%10 = getelementptr inbounds [9 x i8], [9 x i8]* %6, i64 0, i64 0
%11 = icmp eq i32 %0, 1
br i1 %11, label %16, label %12
12: ; preds = %2
%13 = load i8*, i8** %1
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = tail call i32 @exit(i32 0)
unreachable
16: ; preds = %2
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str.19, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = load i32, i32* @AF_INET
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %25, i32* %26
%27 = tail call i32 @htons(i32 9999)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i32 %29, i32* %30
%31 = tail call i32 @memset(i32 undef, i32 0, i32 8)
%32 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%33 = call i32 @bind(i32 %19, %struct.sockaddr* %32, i32 4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %24
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.18, i64 0, i64 0))
%37 = call i32 @exit(i32 -1)
unreachable
38: ; preds = %24
%39 = call i32 @listen(i32 %19, i32 2)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %44
41: ; preds = %38
%42 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.17, i64 0, i64 0))
%43 = call i32 @exit(i32 -1)
unreachable
44: ; preds = %38
%45 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i32 @accept(i32 %19, %struct.sockaddr* %46, i32* %5)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.16, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %44
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%54 = load i32, i32* %53
%55 = call i8* @inet_ntoa(i32 %54)
%56 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.6, i64 0, i64 0), i8* %55)
%57 = call i32 (...) @fork()
switch i32 %57, label %92 [
i32 -1, label %58
i32 0, label %61
]
58: ; preds = %52
%59 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.15, i64 0, i64 0))
%60 = call i32 @exit(i32 -1)
unreachable
61: ; preds = %52
%62 = call i64 @getBytes(i8* %10)
%63 = icmp slt i64 %62, 0
br i1 %63, label %64, label %67
64: ; preds = %61
%65 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.8, i64 0, i64 0), i8* %10)
%66 = call i32 @exit(i32 -1)
unreachable
67: ; preds = %61
%68 = call i64 @malloc(i32 1024)
%69 = inttoptr i64 %68 to i8*
%70 = load i32, i32* @O_RDONLY
%71 = call i32 @open(i8* %10, i32 %70)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %67
%74 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.9, i64 0, i64 0), i8* %10)
%75 = call i32 @exit(i32 -1)
unreachable
76: ; preds = %67
%77 = lshr i64 %62, 10
%78 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str.10, i64 0, i64 0), i8* %10, i64 %62, i64 %77)
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i64 0, i64 0))
%80 = call i64 @read(i32 %71, i8* %69, i64 1024)
%81 = icmp eq i64 %80, 0
br i1 %81, label %88, label %82
82: ; preds = %76, %82
%83 = phi i64 [ %86, %82 ], [ %80, %76 ]
%84 = call i32 @send(i32 %47, i8* %69, i64 %83, i32 0)
%85 = call i32 @putchar(i32 45)
%86 = call i64 @read(i32 %71, i8* %69, i64 1024)
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %82
88: ; preds = %82, %76
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.14, i64 0, i64 0))
%90 = call i32 @free(i8* %69)
%91 = call i32 @exit(i32 0)
unreachable
92: ; preds = %52
%93 = call i32 @wait(i32* null)
%94 = call i32 @close(i32 %19)
%95 = call i32 @close(i32 %47)
ret i32 0
}