#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 Hoja {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
unsigned char EOF;
int atoi(char *);
int /*<<< orphan*/ comparacion(unsigned char *, struct Hoja *, int);
int /*<<< orphan*/ crearArbolHuffman(struct Hoja **, struct Hoja *,
                                     struct Hoja *, struct Hoja *);
int /*<<< orphan*/ crearLista(struct Hoja *, struct Hoja **, struct Hoja **,
                              struct Hoja **, int);
int /*<<< orphan*/ crearListaVector(float *, struct Hoja **, struct Hoja **,
                                    struct Hoja **, int, int);
struct Hoja *crear_hoja(unsigned char *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(unsigned char *, int, int, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(unsigned char *, unsigned char *, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recorrerArbol(struct Hoja *, int *, int, struct Hoja **,
                                 struct Hoja **, int);
int /*<<< orphan*/ recorrerHuffman(struct Hoja *, char **, int, int *, double *,
                                   double *, int);
int main(int argc, char *argv[]) {
  int n;
  FILE *fichero;
  if (argc != 3) {
    printf("Error: Numero de parametros de entrada incorrectos.\n");
    exit(1);
  }
  n = atoi(argv[2]);
  if (n < 1) {
    printf("Error: Valor de N incorrecto, debe ser mayor que cero.\n");
    exit(1);
  }
  fichero = fopen(argv[1], "rb");
  if (fichero == NULL) {
    printf("Error: El fichero de entrada no existe o esta dañado.\n");
    exit(1);
  }
  int num_lecturas = 0;
  int num_simbolos = 0;
  struct Hoja *inicioLista = NULL;
  struct Hoja *finalLista = NULL;
  struct Hoja *recorreLista = NULL;
  if (n == 1) {
    unsigned char *p_lectura;
    float v_contador[256] = {0};
    p_lectura = (unsigned char *)malloc(n * sizeof(unsigned char));
    while (!feof(fichero)) {
      fread(p_lectura, sizeof(unsigned char), n, fichero);
      int sigue = 1;
      if (feof(fichero)) {
        if (p_lectura[n] != EOF) {
          sigue = 0;
        }
      }
      if (sigue) {
        num_lecturas++;
        v_contador[(int)*p_lectura]++;
      }
    }
    crearListaVector(v_contador, &inicioLista, &finalLista, &recorreLista,
                     num_lecturas, n);
  } else if (n > 1) {
    struct Hoja *raiz;
    raiz = NULL;
    while (!feof(fichero)) {
      unsigned char *p_mem = (unsigned char *)malloc(n * sizeof(unsigned char));
      fread(p_mem, sizeof(unsigned char), n, fichero);
      int sigue = 1;
      if (feof(fichero)) {
        if (p_mem[n] != EOF) {
          sigue = 0;
        }
      }
      if (sigue) {
        unsigned char *lec = (unsigned char *)malloc(n * sizeof(unsigned char));
        memcpy(lec, p_mem, n);
        num_lecturas++;
        if (raiz == NULL) {
          raiz = crear_hoja(p_mem, n);
        } else {
          comparacion(p_mem, raiz, n);
        }
      }
    }
    struct Hoja *RaizProb = NULL;
    struct Hoja *hProb = NULL;
    int *p_cont_hojas = &num_simbolos;
    recorrerArbol(raiz, p_cont_hojas, num_lecturas, &hProb, &RaizProb, n);
    crearLista(RaizProb, &inicioLista, &finalLista, &recorreLista, n);
  }
  recorreLista = inicioLista;
  struct Hoja *raizHuffman = NULL;
  crearArbolHuffman(&raizHuffman, inicioLista, finalLista, recorreLista);
  char *codigoHuffman = (char *)malloc(50 * sizeof(char));
  int *contador = (int *)malloc(1 * sizeof(int));
  double Lhuffman = 0;
  double comprimir = 0;
  int a = 0;
  *contador = 1;
  recorrerHuffman(raizHuffman, &codigoHuffman, 1, contador, &Lhuffman,
                  &comprimir, a);
  printf("Longitud Media: %10.9lf\n", Lhuffman);
  double original = num_lecturas * n;
  comprimir = comprimir / 8;
  if (comprimir - (int)comprimir > 0) {
    comprimir++;
  }
  printf("Bytes de la secuencia comprimida: %d\n", (int)comprimir);
  printf("Bytes del fichero original: %.0lf\n", original);
  printf("Comprimido entre original: %.9lf\n", (int)comprimir / original);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     123b <main+0x3b>
lea    0xdea(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    126d <main+0x6d>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe05(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a8 <main+0xa8>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
cmpl   $0x1,-0x14(%rbp)
jne    13df <main+0x1df>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    131d <main+0x11d>
jmp    13ba <main+0x1ba>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
movl   $0x1,-0x454(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     137c <main+0x17c>
mov    -0x48(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    0x2c86(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     1377 <main+0x177>
movl   $0x0,-0x454(%rbp)
jmp    137c <main+0x17c>
cmpl   $0x0,-0x454(%rbp)
je     13b5 <main+0x1b5>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x48(%rbp),%rax
movzbl (%rax),%eax
cltq
movss  0xc6d(%rip),%xmm0
addss  -0x450(%rbp,%rax,4),%xmm0
ff ff
movss  %xmm0,-0x450(%rbp,%rax,4)
ff ff
jmp    12fe <main+0xfe>
lea    -0x450(%rbp),%rdi
mov    -0x24(%rbp),%r8d
mov    -0x14(%rbp),%r9d
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10e0 <crearListaVector@plt>
jmp    1583 <main+0x383>
cmpl   $0x1,-0x14(%rbp)
jle    157e <main+0x37e>
movq   $0x0,-0x460(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1413 <main+0x213>
jmp    1519 <main+0x319>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x468(%rbp)
mov    -0x468(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1060 <fread@plt>
movl   $0x1,-0x46c(%rbp)
mov    -0x20(%rbp),%rdi
call   10a0 <feof@plt>
cmp    $0x0,%rax
je     148e <main+0x28e>
mov    -0x468(%rbp),%rax
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%eax
mov    0x2b74(%rip),%rcx
movzbl (%rcx),%ecx
cmp    %ecx,%eax
je     1489 <main+0x289>
movl   $0x0,-0x46c(%rbp)
jmp    148e <main+0x28e>
cmpl   $0x0,-0x46c(%rbp)
je     1514 <main+0x314>
movslq -0x14(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x478(%rbp)
mov    -0x478(%rbp),%rdi
mov    -0x468(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   10b0 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x460(%rbp)
jne    14f9 <main+0x2f9>
mov    -0x468(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1090 <crear_hoja@plt>
mov    %rax,-0x460(%rbp)
jmp    150f <main+0x30f>
mov    -0x468(%rbp),%rdi
mov    -0x460(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <comparacion@plt>
jmp    1514 <main+0x314>
jmp    13f4 <main+0x1f4>
movq   $0x0,-0x480(%rbp)
movq   $0x0,-0x488(%rbp)
lea    -0x28(%rbp),%rax
mov    %rax,-0x490(%rbp)
mov    -0x460(%rbp),%rdi
mov    -0x490(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    -0x14(%rbp),%r9d
lea    -0x488(%rbp),%rcx
lea    -0x480(%rbp),%r8
call   10d0 <recorrerArbol@plt>
mov    -0x480(%rbp),%rdi
mov    -0x14(%rbp),%r8d
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   1050 <crearLista@plt>
jmp    1583 <main+0x383>
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x498(%rbp)
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
lea    -0x498(%rbp),%rdi
call   1030 <crearArbolHuffman@plt>
mov    $0x32,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x4a0(%rbp)
mov    $0x4,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x4a8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x4b0(%rbp)
ff
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x4b8(%rbp)
ff
movl   $0x0,-0x4bc(%rbp)
mov    -0x4a8(%rbp),%rax
movl   $0x1,(%rax)
mov    -0x498(%rbp),%rdi
mov    -0x4a8(%rbp),%rcx
mov    -0x4bc(%rbp),%eax
lea    -0x4a0(%rbp),%rsi
mov    $0x1,%edx
lea    -0x4b0(%rbp),%r8
lea    -0x4b8(%rbp),%r9
mov    %eax,(%rsp)
call   1120 <recorrerHuffman@plt>
movsd  -0x4b0(%rbp),%xmm0
ff
lea    0xa7a(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
mov    -0x24(%rbp),%eax
imul   -0x14(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x4c8(%rbp)
ff
movsd  -0x4b8(%rbp),%xmm0
ff
movsd  0x994(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x4b8(%rbp)
ff
movsd  -0x4b8(%rbp),%xmm0
ff
cvttsd2si -0x4b8(%rbp),%eax
ff
cvtsi2sd %eax,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jbe    16b5 <main+0x4b5>
movsd  0x963(%rip),%xmm0
addsd  -0x4b8(%rbp),%xmm0
ff
movsd  %xmm0,-0x4b8(%rbp)
ff
cvttsd2si -0x4b8(%rbp),%esi
ff
lea    0xa11(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movsd  -0x4c8(%rbp),%xmm0
ff
lea    0xa21(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
cvttsd2si -0x4b8(%rbp),%eax
ff
cvtsi2sd %eax,%xmm0
divsd  -0x4c8(%rbp),%xmm0
ff
lea    0xa22(%rip),%rdi
mov    $0x1,%al
call   1070 <printf@plt>
xor    %eax,%eax
add    $0x4d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x458,%rsp
cmp    $0x3,%edi
jne    158d <main+0x37d>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
call   1110 <atoi@plt>
test   %eax,%eax
jle    1596 <main+0x386>
mov    %eax,%r12d
mov    0x8(%rbx),%rdi
lea    0xdcc(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     159f <main+0x38f>
mov    %rax,%rbx
movl   $0x0,0x3c(%rsp)
movq   $0x0,0x30(%rsp)
movq   $0x0,0x28(%rsp)
movq   $0x0,0x20(%rsp)
cmp    $0x1,%r12d
jne    12dc <main+0xcc>
lea    0x50(%rsp),%rdi
xor    %r14d,%r14d
mov    $0x400,%edx
xor    %esi,%esi
call   1090 <memset@plt>
mov    $0x1,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
je     1483 <main+0x273>
lea    0x50(%rsp),%rdi
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %r14d,%r8d
mov    $0x1,%r9d
call   10f0 <crearListaVector@plt>
jmp    133e <main+0x12e>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
je     14ea <main+0x2da>
xor    %r15d,%r15d
xor    %r14d,%r14d
movq   $0x0,0x50(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x3c(%rsp),%rsi
lea    0x18(%rsp),%rcx
lea    0x50(%rsp),%r8
mov    %r15,%rdi
mov    %r14d,%edx
mov    %r12d,%r9d
call   10e0 <recorrerArbol@plt>
mov    0x50(%rsp),%rdi
lea    0x30(%rsp),%rsi
lea    0x28(%rsp),%rdx
lea    0x20(%rsp),%rcx
mov    %r12d,%r8d
call   1050 <crearLista@plt>
mov    0x30(%rsp),%rcx
mov    %rcx,0x20(%rsp)
movq   $0x0,0x50(%rsp)
mov    0x28(%rsp),%rdx
lea    0x50(%rsp),%rdi
mov    %rcx,%rsi
call   1030 <crearArbolHuffman@plt>
mov    $0x32,%edi
call   10d0 <malloc@plt>
mov    %rax,0x18(%rsp)
mov    $0x4,%edi
call   10d0 <malloc@plt>
movq   $0x0,0x48(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x1,(%rax)
mov    0x50(%rsp),%rdi
movl   $0x0,(%rsp)
lea    0x18(%rsp),%rsi
lea    0x48(%rsp),%r8
lea    0x10(%rsp),%r9
mov    $0x1,%edx
mov    %rax,%rcx
call   1130 <recorrerHuffman@plt>
movsd  0x48(%rsp),%xmm0
lea    0xc52(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
imul   %r12d,%r14d
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  0xc18(%rip),%xmm0
cvttpd2dq %xmm0,%xmm1
cvtdq2pd %xmm1,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
movsd  0xc08(%rip),%xmm1
addsd  %xmm0,%xmm1
xorpd  %xmm3,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movlpd %xmm3,0x10(%rsp)
cvttsd2si %xmm3,%esi
lea    0xc02(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0xc1a(%rip),%rdi
movsd  0x40(%rsp),%xmm0
mov    $0x1,%al
call   1080 <printf@plt>
movsd  0x10(%rsp),%xmm0
cvttpd2dq %xmm0,%xmm0
cvtdq2pd %xmm0,%xmm0
divsd  0x40(%rsp),%xmm0
lea    0xc15(%rip),%rdi
mov    $0x1,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x458,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %r14d,%r14d
mov    0x2b5b(%rip),%r15
jmp    14bd <main+0x2ad>
nop
add    $0x1,%r14d
movzbl 0x0(%rbp),%eax
movss  0x50(%rsp,%rax,4),%xmm0
addss  0xb5a(%rip),%xmm0
movss  %xmm0,0x50(%rsp,%rax,4)
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
jne    12b8 <main+0xa8>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1070 <fread@plt>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
je     1490 <main+0x280>
movzbl 0x1(%rbp),%eax
cmp    (%r15),%al
je     1490 <main+0x280>
jmp    14ac <main+0x29c>
mov    %r12d,%r13d
xor    %r14d,%r14d
xor    %r15d,%r15d
jmp    153e <main+0x32e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
call   10d0 <malloc@plt>
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   10c0 <memcpy@plt>
add    $0x1,%r14d
mov    %rbp,%rdi
test   %r15,%r15
je     1580 <main+0x370>
mov    %r15,%rsi
mov    %r12d,%edx
call   1040 <comparacion@plt>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
jne    12f3 <main+0xe3>
mov    %r12d,%edi
call   10d0 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1070 <fread@plt>
mov    %rbx,%rdi
call   10b0 <feof@plt>
test   %rax,%rax
je     1500 <main+0x2f0>
movzbl 0x0(%rbp,%r13,1),%eax
mov    0x2a72(%rip),%rcx
cmp    (%rcx),%al
je     1500 <main+0x2f0>
jmp    152d <main+0x31d>
nopl   0x0(%rax)
mov    %r12d,%esi
call   10a0 <crear_hoja@plt>
mov    %rax,%r15
jmp    152d <main+0x31d>
lea    0xb79(%rip),%rdi
jmp    15a6 <main+0x396>
lea    0xb39(%rip),%rdi
jmp    15a6 <main+0x396>
lea    0xaf9(%rip),%rdi
call   1060 <puts@plt>
mov    $0x1,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.Hoja = type { i32 }
@.str = [53 x i8] c"Error: Numero de parametros de entrada incorrectos.\0A\00"
@.str.1 = [56 x i8] c"Error: Valor de N incorrecto, debe ser mayor que cero.\0A\00"
@.str.2 = [3 x i8] c"rb\00"
@.str.3 = [56 x i8] c"Error: El fichero de entrada no existe o esta da\C3\B1ado.\0A\00"
@EOF = global i8 0
@.str.4 = [25 x i8] c"Longitud Media: %10.9lf\0A\00"
@.str.5 = [38 x i8] c"Bytes de la secuencia comprimida: %d\0A\00"
@.str.6 = [35 x i8] c"Bytes del fichero original: %.0lf\0A\00"
@.str.7 = [34 x i8] c"Comprimido entre original: %.9lf\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 i32
%9 = alloca i32
%10 = alloca %struct.Hoja*
%11 = alloca %struct.Hoja*
%12 = alloca %struct.Hoja*
%13 = alloca i8*
%14 = alloca [256 x float]
%15 = alloca i32
%16 = alloca %struct.Hoja*
%17 = alloca i8*
%18 = alloca i32
%19 = alloca i8*
%20 = alloca %struct.Hoja*
%21 = alloca %struct.Hoja*
%22 = alloca i32*
%23 = alloca %struct.Hoja*
%24 = alloca i8*
%25 = alloca i32*
%26 = alloca double
%27 = alloca double
%28 = alloca i32
%29 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%30 = load i32, i32* %4
%31 = icmp ne i32 %30, 3
br i1 %31, label %32, label %35
32: ; preds = %2
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %2
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 2
%38 = load i8*, i8** %37
%39 = call i32 @atoi(i8* %38)
store i32 %39, i32* %6
%40 = load i32, i32* %6
%41 = icmp slt i32 %40, 1
br i1 %41, label %42, label %45
42: ; preds = %35
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %35
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = load i8*, i8** %47
%49 = call i32* @fopen(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %49, i32** %7
%50 = load i32*, i32** %7
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %45
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %45
store i32 0, i32* %8
store i32 0, i32* %9
store %struct.Hoja* null, %struct.Hoja** %10
store %struct.Hoja* null, %struct.Hoja** %11
store %struct.Hoja* null, %struct.Hoja** %12
%56 = load i32, i32* %6
%57 = icmp eq i32 %56, 1
br i1 %57, label %58, label %110
58: ; preds = %55
%59 = bitcast [256 x float]* %14 to i8*
%60 = load i32, i32* %6
%61 = sext i32 %60 to i64
%62 = mul i64 %61, 1
%63 = trunc i64 %62 to i32
%64 = call i64 @malloc(i32 %63)
%65 = inttoptr i64 %64 to i8*
store i8* %65, i8** %13
br label %66
66: ; preds = %104, %58
%67 = load i32*, i32** %7
%68 = call i64 @feof(i32* %67)
%69 = icmp ne i64 %68, 0
%70 = xor i1 %69, true
br i1 %70, label %71, label %105
71: ; preds = %66
%72 = load i8*, i8** %13
%73 = load i32, i32* %6
%74 = load i32*, i32** %7
%75 = call i32 @fread(i8* %72, i32 1, i32 %73, i32* %74)
store i32 1, i32* %15
%76 = load i32*, i32** %7
%77 = call i64 @feof(i32* %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %91
79: ; preds = %71
%80 = load i8*, i8** %13
%81 = load i32, i32* %6
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
%84 = load i8, i8* %83
%85 = zext i8 %84 to i32
%86 = load i8, i8* @EOF
%87 = zext i8 %86 to i32
%88 = icmp ne i32 %85, %87
br i1 %88, label %89, label %90
89: ; preds = %79
store i32 0, i32* %15
br label %90
90: ; preds = %89, %79
br label %91
91: ; preds = %90, %71
%92 = load i32, i32* %15
%93 = icmp ne i32 %92, 0
br i1 %93, label %94, label %104
94: ; preds = %91
%95 = load i32, i32* %8
%96 = add nsw i32 %95, 1
store i32 %96, i32* %8
%97 = load i8*, i8** %13
%98 = load i8, i8* %97
%99 = zext i8 %98 to i32
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds [256 x float], [256 x float]* %14, i64 0, i64 %100
%102 = load float, float* %101
%103 = fadd float %102, 1.000000e+00
store float %103, float* %101
br label %104
104: ; preds = %94, %91
br label %66
105: ; preds = %66
%106 = getelementptr inbounds [256 x float], [256 x float]* %14, i64 0, i64 0
%107 = load i32, i32* %8
%108 = load i32, i32* %6
%109 = call i32 @crearListaVector(float* %106, %struct.Hoja** %10, %struct.Hoja** %11, %struct.Hoja** %12, i32 %107, i32 %108)
br label %184
110: ; preds = %55
%111 = load i32, i32* %6
%112 = icmp sgt i32 %111, 1
br i1 %112, label %113, label %183
113: ; preds = %110
store %struct.Hoja* null, %struct.Hoja** %16
br label %114
114: ; preds = %173, %113
%115 = load i32*, i32** %7
%116 = call i64 @feof(i32* %115)
%117 = icmp ne i64 %116, 0
%118 = xor i1 %117, true
br i1 %118, label %119, label %174
119: ; preds = %114
%120 = load i32, i32* %6
%121 = sext i32 %120 to i64
%122 = mul i64 %121, 1
%123 = trunc i64 %122 to i32
%124 = call i64 @malloc(i32 %123)
%125 = inttoptr i64 %124 to i8*
store i8* %125, i8** %17
%126 = load i8*, i8** %17
%127 = load i32, i32* %6
%128 = load i32*, i32** %7
%129 = call i32 @fread(i8* %126, i32 1, i32 %127, i32* %128)
store i32 1, i32* %18
%130 = load i32*, i32** %7
%131 = call i64 @feof(i32* %130)
%132 = icmp ne i64 %131, 0
br i1 %132, label %133, label %145
133: ; preds = %119
%134 = load i8*, i8** %17
%135 = load i32, i32* %6
%136 = sext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %134, i64 %136
%138 = load i8, i8* %137
%139 = zext i8 %138 to i32
%140 = load i8, i8* @EOF
%141 = zext i8 %140 to i32
%142 = icmp ne i32 %139, %141
br i1 %142, label %143, label %144
143: ; preds = %133
store i32 0, i32* %18
br label %144
144: ; preds = %143, %133
br label %145
145: ; preds = %144, %119
%146 = load i32, i32* %18
%147 = icmp ne i32 %146, 0
br i1 %147, label %148, label %173
148: ; preds = %145
%149 = load i32, i32* %6
%150 = sext i32 %149 to i64
%151 = mul i64 %150, 1
%152 = trunc i64 %151 to i32
%153 = call i64 @malloc(i32 %152)
%154 = inttoptr i64 %153 to i8*
store i8* %154, i8** %19
%155 = load i8*, i8** %19
%156 = load i8*, i8** %17
%157 = load i32, i32* %6
%158 = call i32 @memcpy(i8* %155, i8* %156, i32 %157)
%159 = load i32, i32* %8
%160 = add nsw i32 %159, 1
store i32 %160, i32* %8
%161 = load %struct.Hoja*, %struct.Hoja** %16
%162 = icmp eq %struct.Hoja* %161, null
br i1 %162, label %163, label %167
163: ; preds = %148
%164 = load i8*, i8** %17
%165 = load i32, i32* %6
%166 = call %struct.Hoja* @crear_hoja(i8* %164, i32 %165)
store %struct.Hoja* %166, %struct.Hoja** %16
br label %172
167: ; preds = %148
%168 = load i8*, i8** %17
%169 = load %struct.Hoja*, %struct.Hoja** %16
%170 = load i32, i32* %6
%171 = call i32 @comparacion(i8* %168, %struct.Hoja* %169, i32 %170)
br label %172
172: ; preds = %167, %163
br label %173
173: ; preds = %172, %145
br label %114
174: ; preds = %114
store %struct.Hoja* null, %struct.Hoja** %20
store %struct.Hoja* null, %struct.Hoja** %21
store i32* %9, i32** %22
%175 = load %struct.Hoja*, %struct.Hoja** %16
%176 = load i32*, i32** %22
%177 = load i32, i32* %8
%178 = load i32, i32* %6
%179 = call i32 @recorrerArbol(%struct.Hoja* %175, i32* %176, i32 %177, %struct.Hoja** %21, %struct.Hoja** %20, i32 %178)
%180 = load %struct.Hoja*, %struct.Hoja** %20
%181 = load i32, i32* %6
%182 = call i32 @crearLista(%struct.Hoja* %180, %struct.Hoja** %10, %struct.Hoja** %11, %struct.Hoja** %12, i32 %181)
br label %183
183: ; preds = %174, %110
br label %184
184: ; preds = %183, %105
%185 = load %struct.Hoja*, %struct.Hoja** %10
store %struct.Hoja* %185, %struct.Hoja** %12
store %struct.Hoja* null, %struct.Hoja** %23
%186 = load %struct.Hoja*, %struct.Hoja** %10
%187 = load %struct.Hoja*, %struct.Hoja** %11
%188 = load %struct.Hoja*, %struct.Hoja** %12
%189 = call i32 @crearArbolHuffman(%struct.Hoja** %23, %struct.Hoja* %186, %struct.Hoja* %187, %struct.Hoja* %188)
%190 = call i64 @malloc(i32 50)
%191 = inttoptr i64 %190 to i8*
store i8* %191, i8** %24
%192 = call i64 @malloc(i32 4)
%193 = inttoptr i64 %192 to i32*
store i32* %193, i32** %25
store double 0.000000e+00, double* %26
store double 0.000000e+00, double* %27
store i32 0, i32* %28
%194 = load i32*, i32** %25
store i32 1, i32* %194
%195 = load %struct.Hoja*, %struct.Hoja** %23
%196 = load i32*, i32** %25
%197 = load i32, i32* %28
%198 = call i32 @recorrerHuffman(%struct.Hoja* %195, i8** %24, i32 1, i32* %196, double* %26, double* %27, i32 %197)
%199 = load double, double* %26
%200 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %199)
%201 = load i32, i32* %8
%202 = load i32, i32* %6
%203 = mul nsw i32 %201, %202
%204 = sitofp i32 %203 to double
store double %204, double* %29
%205 = load double, double* %27
%206 = fdiv double %205, 8.000000e+00
store double %206, double* %27
%207 = load double, double* %27
%208 = load double, double* %27
%209 = fptosi double %208 to i32
%210 = sitofp i32 %209 to double
%211 = fsub double %207, %210
%212 = fcmp ogt double %211, 0.000000e+00
br i1 %212, label %213, label %216
213: ; preds = %184
%214 = load double, double* %27
%215 = fadd double %214, 1.000000e+00
store double %215, double* %27
br label %216
216: ; preds = %213, %184
%217 = load double, double* %27
%218 = fptosi double %217 to i32
%219 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %218)
%220 = load double, double* %29
%221 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), double %220)
%222 = load double, double* %27
%223 = fptosi double %222 to i32
%224 = sitofp i32 %223 to double
%225 = load double, double* %29
%226 = fdiv double %224, %225
%227 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), double %226)
ret i32 0
}

LLVM IR (-O2):
%struct.Hoja = type { i32 }
@.str.2 = [3 x i8] c"rb\00"
@EOF = global i8 0
@.str.4 = [25 x i8] c"Longitud Media: %10.9lf\0A\00"
@.str.5 = [38 x i8] c"Bytes de la secuencia comprimida: %d\0A\00"
@.str.6 = [35 x i8] c"Bytes del fichero original: %.0lf\0A\00"
@.str.7 = [34 x i8] c"Comprimido entre original: %.9lf\0A\00"
@str = [55 x i8] c"Error: El fichero de entrada no existe o esta da\C3\B1ado.\00"
@str.8 = [55 x i8] c"Error: Valor de N incorrecto, debe ser mayor que cero.\00"
@str.9 = [52 x i8] c"Error: Numero de parametros de entrada incorrectos.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.Hoja*
%5 = alloca %struct.Hoja*
%6 = alloca %struct.Hoja*
%7 = alloca [256 x float]
%8 = alloca %struct.Hoja*
%9 = alloca %struct.Hoja*
%10 = alloca %struct.Hoja*
%11 = alloca i8*
%12 = alloca double
%13 = alloca double
%14 = icmp eq i32 %0, 3
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.9, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = tail call i32 @atoi(i8* %20)
%22 = icmp slt i32 %21, 1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str.8, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %18
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32* @fopen(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @str, i64 0, i64 0))
%33 = tail call i32 @exit(i32 1)
unreachable
34: ; preds = %26
%35 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%36 = bitcast %struct.Hoja** %4 to i8*
store %struct.Hoja* null, %struct.Hoja** %4
%37 = bitcast %struct.Hoja** %5 to i8*
store %struct.Hoja* null, %struct.Hoja** %5
%38 = bitcast %struct.Hoja** %6 to i8*
store %struct.Hoja* null, %struct.Hoja** %6
%39 = icmp eq i32 %21, 1
br i1 %39, label %45, label %40
40: ; preds = %34
%41 = tail call i64 @feof(i32* %29)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %105
43: ; preds = %40
%44 = zext i32 %21 to i64
br label %77
45: ; preds = %34
%46 = bitcast [256 x float]* %7 to i8*
%47 = tail call i64 @malloc(i32 1)
%48 = inttoptr i64 %47 to i8*
%49 = tail call i64 @feof(i32* %29)
%50 = icmp eq i64 %49, 0
br i1 %50, label %51, label %73
51: ; preds = %45
%52 = getelementptr inbounds i8, i8* %48, i64 1
br label %53
53: ; preds = %51, %69
%54 = phi i32 [ 0, %51 ], [ %70, %69 ]
%55 = tail call i32 @fread(i8* %48, i32 1, i32 1, i32* %29)
%56 = tail call i64 @feof(i32* %29)
%57 = icmp eq i64 %56, 0
br i1 %57, label %62, label %58
58: ; preds = %53
%59 = load i8, i8* %52
%60 = load i8, i8* @EOF
%61 = icmp eq i8 %59, %60
br i1 %61, label %62, label %69
62: ; preds = %53, %58
%63 = add nsw i32 %54, 1
%64 = load i8, i8* %48
%65 = zext i8 %64 to i64
%66 = getelementptr inbounds [256 x float], [256 x float]* %7, i64 0, i64 %65
%67 = load float, float* %66
%68 = fadd float %67, 1.000000e+00
store float %68, float* %66
br label %69
69: ; preds = %62, %58
%70 = phi i32 [ %63, %62 ], [ %54, %58 ]
%71 = tail call i64 @feof(i32* %29)
%72 = icmp eq i64 %71, 0
br i1 %72, label %53, label %73
73: ; preds = %69, %45
%74 = phi i32 [ 0, %45 ], [ %70, %69 ]
%75 = getelementptr inbounds [256 x float], [256 x float]* %7, i64 0, i64 0
%76 = call i32 @crearListaVector(float* %75, %struct.Hoja** %4, %struct.Hoja** %5, %struct.Hoja** %6, i32 %74, i32 1)
br label %113
77: ; preds = %43, %100
%78 = phi i32 [ 0, %43 ], [ %102, %100 ]
%79 = phi %struct.Hoja* [ null, %43 ], [ %101, %100 ]
%80 = tail call i64 @malloc(i32 %21)
%81 = inttoptr i64 %80 to i8*
%82 = tail call i32 @fread(i8* %81, i32 1, i32 %21, i32* %29)
%83 = tail call i64 @feof(i32* %29)
%84 = icmp eq i64 %83, 0
br i1 %84, label %90, label %85
85: ; preds = %77
%86 = getelementptr inbounds i8, i8* %81, i64 %44
%87 = load i8, i8* %86
%88 = load i8, i8* @EOF
%89 = icmp eq i8 %87, %88
br i1 %89, label %90, label %100
90: ; preds = %77, %85
%91 = tail call i64 @malloc(i32 %21)
%92 = inttoptr i64 %91 to i8*
%93 = tail call i32 @memcpy(i8* %92, i8* %81, i32 %21)
%94 = add nsw i32 %78, 1
%95 = icmp eq %struct.Hoja* %79, null
br i1 %95, label %96, label %98
96: ; preds = %90
%97 = tail call %struct.Hoja* @crear_hoja(i8* %81, i32 %21)
br label %100
98: ; preds = %90
%99 = tail call i32 @comparacion(i8* %81, %struct.Hoja* %79, i32 %21)
br label %100
100: ; preds = %96, %98, %85
%101 = phi %struct.Hoja* [ %79, %85 ], [ %97, %96 ], [ %79, %98 ]
%102 = phi i32 [ %78, %85 ], [ %94, %96 ], [ %94, %98 ]
%103 = tail call i64 @feof(i32* %29)
%104 = icmp eq i64 %103, 0
br i1 %104, label %77, label %105
105: ; preds = %100, %40
%106 = phi %struct.Hoja* [ null, %40 ], [ %101, %100 ]
%107 = phi i32 [ 0, %40 ], [ %102, %100 ]
%108 = bitcast %struct.Hoja** %8 to i8*
store %struct.Hoja* null, %struct.Hoja** %8
%109 = bitcast %struct.Hoja** %9 to i8*
store %struct.Hoja* null, %struct.Hoja** %9
%110 = call i32 @recorrerArbol(%struct.Hoja* %106, i32* %3, i32 %107, %struct.Hoja** %9, %struct.Hoja** %8, i32 %21)
%111 = load %struct.Hoja*, %struct.Hoja** %8
%112 = call i32 @crearLista(%struct.Hoja* %111, %struct.Hoja** %4, %struct.Hoja** %5, %struct.Hoja** %6, i32 %21)
br label %113
113: ; preds = %105, %73
%114 = phi i32 [ %74, %73 ], [ %107, %105 ]
%115 = load %struct.Hoja*, %struct.Hoja** %4
store %struct.Hoja* %115, %struct.Hoja** %6
%116 = bitcast %struct.Hoja** %10 to i8*
store %struct.Hoja* null, %struct.Hoja** %10
%117 = load %struct.Hoja*, %struct.Hoja** %5
%118 = call i32 @crearArbolHuffman(%struct.Hoja** %10, %struct.Hoja* %115, %struct.Hoja* %117, %struct.Hoja* %115)
%119 = bitcast i8** %11 to i8*
%120 = call i64 @malloc(i32 50)
%121 = inttoptr i64 %120 to i8*
store i8* %121, i8** %11
%122 = call i64 @malloc(i32 4)
%123 = inttoptr i64 %122 to i32*
%124 = bitcast double* %12 to i8*
store double 0.000000e+00, double* %12
%125 = bitcast double* %13 to i8*
store double 0.000000e+00, double* %13
store i32 1, i32* %123
%126 = load %struct.Hoja*, %struct.Hoja** %10
%127 = call i32 @recorrerHuffman(%struct.Hoja* %126, i8** %11, i32 1, i32* %123, double* %12, double* %13, i32 0)
%128 = load double, double* %12
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), double %128)
%130 = mul nsw i32 %114, %21
%131 = sitofp i32 %130 to double
%132 = load double, double* %13
%133 = fmul double %132, 1.250000e-01
%134 = fptosi double %133 to i32
%135 = sitofp i32 %134 to double
%136 = fsub double %133, %135
%137 = fcmp ogt double %136, 0.000000e+00
%138 = fadd double %133, 1.000000e+00
%139 = select i1 %137, double %138, double %133
store double %139, double* %13
%140 = fptosi double %139 to i32
%141 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.5, i64 0, i64 0), i32 %140)
%142 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.6, i64 0, i64 0), double %131)
%143 = load double, double* %13
%144 = fptosi double %143 to i32
%145 = sitofp i32 %144 to double
%146 = fdiv double %145, %131
%147 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.7, i64 0, i64 0), double %146)
ret i32 0
}