int compacta(const char *filename) {
  unsigned char *fileBuffer = readFileToBuffer(filename);
  unsigned int *vec = createfVector(fileBuffer);
  struct listHeader *lista_de_pesos = vectorToListOfTrees(vec);
  free(vec);
  struct tree *raiz_da_arvore = makePathTree(lista_de_pesos);
  unsigned char pathTable[256][9];
  for (int o = 0; o < 256; o++)
    for (int p = 0; p < 9; p++)
      pathTable[o][p] = 0;
  unsigned char v[9];
  for (int o = 0; o < 256; o++)
    v[o] = 0;
  createTable(raiz_da_arvore, pathTable, v, 0);
  for (int o = 0; o < 256; o++) {
    if (pathTable[o][0] != '\0') {
      printf("\n'%03d':", o);
      printf("%s", pathTable[o]);
    }
  }
  printf("\n\n-----> \twriteHeader:\n");
  unsigned char *header = writeHeader(raiz_da_arvore);
  printf("\n\n-----> \twriteBody:\n");
  unsigned char *body = writeBody(pathTable, fileBuffer);
  writeToFile("compressed.hcf", header, body);
  free(fileBuffer);
  freeList(lista_de_pesos);
  freeTree(raiz_da_arvore);
  free(header);
  free(body);
  return 0;
}


x86 assembly (clang, -O0):
<compacta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x960,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   10b0 <readFileToBuffer@plt>
cltq
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1070 <createfVector@plt>
cltq
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x0,%al
call   1090 <vectorToListOfTrees@plt>
cltq
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   10e0 <makePathTree@plt>
cltq
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x934(%rbp)
cmpl   $0x100,-0x934(%rbp)
jge    129a <compacta+0xda>
movl   $0x0,-0x938(%rbp)
cmpl   $0x9,-0x938(%rbp)
jge    1281 <compacta+0xc1>
movslq -0x934(%rbp),%rcx
lea    -0x930(%rbp),%rax
imul   $0x9,%rcx,%rcx
add    %rcx,%rax
movslq -0x938(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x938(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x938(%rbp)
jmp    1240 <compacta+0x80>
jmp    1286 <compacta+0xc6>
mov    -0x934(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x934(%rbp)
jmp    1226 <compacta+0x66>
movl   $0x0,-0x948(%rbp)
cmpl   $0x100,-0x948(%rbp)
jge    12d7 <compacta+0x117>
movslq -0x948(%rbp),%rax
movb   $0x0,-0x941(%rbp,%rax,1)
mov    -0x948(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x948(%rbp)
jmp    12a4 <compacta+0xe4>
mov    -0x28(%rbp),%rdi
lea    -0x930(%rbp),%rsi
lea    -0x941(%rbp),%rdx
xor    %ecx,%ecx
mov    $0x0,%al
call   10d0 <createTable@plt>
movl   $0x0,-0x94c(%rbp)
cmpl   $0x100,-0x94c(%rbp)
jge    137d <compacta+0x1bd>
movslq -0x94c(%rbp),%rcx
lea    -0x930(%rbp),%rax
imul   $0x9,%rcx,%rcx
add    %rcx,%rax
movzbl (%rax),%eax
cmp    $0x0,%eax
je     1364 <compacta+0x1a4>
mov    -0x94c(%rbp),%esi
lea    0xcc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movslq -0x94c(%rbp),%rax
lea    -0x930(%rbp),%rsi
imul   $0x9,%rax,%rax
add    %rax,%rsi
lea    0xcac(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1369 <compacta+0x1a9>
mov    -0x94c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94c(%rbp)
jmp    12fc <compacta+0x13c>
lea    0xc88(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   10a0 <writeHeader@plt>
cltq
mov    %rax,-0x958(%rbp)
lea    0xc7e(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x930(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x0,%al
call   10c0 <writeBody@plt>
cltq
mov    %rax,-0x960(%rbp)
mov    -0x958(%rbp),%rsi
mov    -0x960(%rbp),%rdx
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1040 <writeToFile@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
mov    $0x0,%al
call   1050 <freeList@plt>
mov    -0x28(%rbp),%rdi
mov    $0x0,%al
call   1060 <freeTree@plt>
mov    -0x958(%rbp),%rdi
call   1030 <free@plt>
mov    -0x960(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x960,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<compacta>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x928,%rsp
xor    %eax,%eax
call   10d0 <readFileToBuffer@plt>
movslq %eax,%r15
mov    %r15,%rdi
xor    %eax,%eax
call   1080 <createfVector@plt>
movslq %eax,%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   10b0 <vectorToListOfTrees@plt>
movslq %eax,%rbp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdi
xor    %eax,%eax
call   1100 <makePathTree@plt>
movslq %eax,%r12
lea    0x20(%rsp),%rbx
mov    $0x900,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   10f0 <createTable@plt>
lea    0xd3a(%rip),%r13
lea    0xd3c(%rip),%rbp
xor    %r14d,%r14d
jmp    12f1 <compacta+0x111>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x1,%r14
add    $0x9,%rbx
cmp    $0x100,%r14
je     1312 <compacta+0x132>
cmpb   $0x0,(%rbx)
je     12e0 <compacta+0x100>
mov    %r13,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
jmp    12e0 <compacta+0x100>
lea    0xd02(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   10c0 <writeHeader@plt>
movslq %eax,%rbx
lea    0xd00(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10e0 <writeBody@plt>
movslq %eax,%rbp
lea    0xcbc(%rip),%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1050 <writeToFile@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x18(%rsp),%rdi
xor    %eax,%eax
call   1060 <freeList@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <freeTree@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x928,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.listHeader = type opaque
%struct.tree = type opaque
@.str = [9 x i8] c"\0A'%03d':\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [24 x i8] c"\0A\0A-----> \09writeHeader:\0A\00"
@.str.3 = [22 x i8] c"\0A\0A-----> \09writeBody:\0A\00"
@.str.4 = [15 x i8] c"compressed.hcf\00"
define i32 @compacta(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.listHeader*
%6 = alloca %struct.tree*
%7 = alloca [256 x [9 x i8]]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [9 x i8]
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
store i8* %0, i8** %2
%15 = load i8*, i8** %2
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @readFileToBuffer to i32 (i8*, ...)*)(i8* %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 (i8*, ...) bitcast (i32 (...)* @createfVector to i32 (i8*, ...)*)(i8* %19)
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i32*
store i32* %22, i32** %4
%23 = load i32*, i32** %4
%24 = call i32 (i32*, ...) bitcast (i32 (...)* @vectorToListOfTrees to i32 (i32*, ...)*)(i32* %23)
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to %struct.listHeader*
store %struct.listHeader* %26, %struct.listHeader** %5
%27 = load i32*, i32** %4
%28 = bitcast i32* %27 to i8*
%29 = load %struct.listHeader*, %struct.listHeader** %5
%30 = call i32 (%struct.listHeader*, ...) bitcast (i32 (...)* @makePathTree to i32 (%struct.listHeader*, ...)*)(%struct.listHeader* %29)
%31 = sext i32 %30 to i64
%32 = inttoptr i64 %31 to %struct.tree*
store %struct.tree* %32, %struct.tree** %6
store i32 0, i32* %8
br label %33
33: ; preds = %51, %1
%34 = load i32, i32* %8
%35 = icmp slt i32 %34, 256
br i1 %35, label %36, label %54
36: ; preds = %33
store i32 0, i32* %9
br label %37
37: ; preds = %47, %36
%38 = load i32, i32* %9
%39 = icmp slt i32 %38, 9
br i1 %39, label %40, label %50
40: ; preds = %37
%41 = load i32, i32* %8
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %7, i64 0, i64 %42
%44 = load i32, i32* %9
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [9 x i8], [9 x i8]* %43, i64 0, i64 %45
store i8 0, i8* %46
br label %47
47: ; preds = %40
%48 = load i32, i32* %9
%49 = add nsw i32 %48, 1
store i32 %49, i32* %9
br label %37
50: ; preds = %37
br label %51
51: ; preds = %50
%52 = load i32, i32* %8
%53 = add nsw i32 %52, 1
store i32 %53, i32* %8
br label %33
54: ; preds = %33
store i32 0, i32* %11
br label %55
55: ; preds = %62, %54
%56 = load i32, i32* %11
%57 = icmp slt i32 %56, 256
br i1 %57, label %58, label %65
58: ; preds = %55
%59 = load i32, i32* %11
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 %60
store i8 0, i8* %61
br label %62
62: ; preds = %58
%63 = load i32, i32* %11
%64 = add nsw i32 %63, 1
store i32 %64, i32* %11
br label %55
65: ; preds = %55
%66 = load %struct.tree*, %struct.tree** %6
%67 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %7, i64 0, i64 0
%68 = getelementptr inbounds [9 x i8], [9 x i8]* %10, i64 0, i64 0
%69 = call i32 (%struct.tree*, [9 x i8]*, i8*, i32, ...) bitcast (i32 (...)* @createTable to i32 (%struct.tree*, [9 x i8]*, i8*, i32, ...)*)(%struct.tree* %66, [9 x i8]* %67, i8* %68, i32 0)
store i32 0, i32* %12
br label %70
70: ; preds = %90, %65
%71 = load i32, i32* %12
%72 = icmp slt i32 %71, 256
br i1 %72, label %73, label %93
73: ; preds = %70
%74 = load i32, i32* %12
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %7, i64 0, i64 %75
%77 = getelementptr inbounds [9 x i8], [9 x i8]* %76, i64 0, i64 0
%78 = load i8, i8* %77
%79 = zext i8 %78 to i32
%80 = icmp ne i32 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %73
%82 = load i32, i32* %12
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %82)
%84 = load i32, i32* %12
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %7, i64 0, i64 %85
%87 = getelementptr inbounds [9 x i8], [9 x i8]* %86, i64 0, i64 0
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %87)
br label %89
89: ; preds = %81, %73
br label %90
90: ; preds = %89
%91 = load i32, i32* %12
%92 = add nsw i32 %91, 1
store i32 %92, i32* %12
br label %70
93: ; preds = %70
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%95 = load %struct.tree*, %struct.tree** %6
%96 = call i32 (%struct.tree*, ...) bitcast (i32 (...)* @writeHeader to i32 (%struct.tree*, ...)*)(%struct.tree* %95)
%97 = sext i32 %96 to i64
%98 = inttoptr i64 %97 to i8*
store i8* %98, i8** %13
%99 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%100 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %7, i64 0, i64 0
%101 = load i8*, i8** %3
%102 = call i32 ([9 x i8]*, i8*, ...) bitcast (i32 (...)* @writeBody to i32 ([9 x i8]*, i8*, ...)*)([9 x i8]* %100, i8* %101)
%103 = sext i32 %102 to i64
%104 = inttoptr i64 %103 to i8*
store i8* %104, i8** %14
%105 = load i8*, i8** %13
%106 = load i8*, i8** %14
%107 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @writeToFile to i32 (i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %105, i8* %106)
%108 = load i8*, i8** %3
%109 = load %struct.listHeader*, %struct.listHeader** %5
%110 = call i32 (%struct.listHeader*, ...) bitcast (i32 (...)* @freeList to i32 (%struct.listHeader*, ...)*)(%struct.listHeader* %109)
%111 = load %struct.tree*, %struct.tree** %6
%112 = call i32 (%struct.tree*, ...) bitcast (i32 (...)* @freeTree to i32 (%struct.tree*, ...)*)(%struct.tree* %111)
%113 = load i8*, i8** %13
%114 = load i8*, i8** %14
ret i32 0
}

LLVM IR (-O2):
%struct.listHeader = type opaque
%struct.tree = type opaque
@.str = [9 x i8] c"\0A'%03d':\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.4 = [15 x i8] c"compressed.hcf\00"
@str = [23 x i8] c"\0A\0A-----> \09writeHeader:\00"
@str.5 = [21 x i8] c"\0A\0A-----> \09writeBody:\00"
define i32 @compacta(i8* %0) {
%2 = alloca [256 x [9 x i8]]
%3 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %2, i64 0, i64 0, i64 0
%4 = alloca [9 x i8]
%5 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%6 = tail call i32 (i8*, ...) bitcast (i32 (...)* @readFileToBuffer to i32 (i8*, ...)*)(i8* %0)
%7 = sext i32 %6 to i64
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 (i8*, ...) bitcast (i32 (...)* @createfVector to i32 (i8*, ...)*)(i8* %8)
%10 = sext i32 %9 to i64
%11 = inttoptr i64 %10 to i32*
%12 = tail call i32 (i32*, ...) bitcast (i32 (...)* @vectorToListOfTrees to i32 (i32*, ...)*)(i32* %11)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to %struct.listHeader*
%15 = inttoptr i64 %10 to i8*
tail call void @free(i8* %15)
%16 = tail call i32 (%struct.listHeader*, ...) bitcast (i32 (...)* @makePathTree to i32 (%struct.listHeader*, ...)*)(%struct.listHeader* %14)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %2, i64 0, i64 0, i64 0
%19 = getelementptr inbounds [9 x i8], [9 x i8]* %4, i64 0, i64 0
%20 = inttoptr i64 %17 to %struct.tree*
%21 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %2, i64 0, i64 0
%22 = call i32 (%struct.tree*, [9 x i8]*, i8*, i32, ...) bitcast (i32 (...)* @createTable to i32 (%struct.tree*, [9 x i8]*, i8*, i32, ...)*)(%struct.tree* %20, [9 x i8]* %21, i8* %19, i32 0)
br label %35
23: ; preds = %44
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%25 = call i32 (%struct.tree*, ...) bitcast (i32 (...)* @writeHeader to i32 (%struct.tree*, ...)*)(%struct.tree* %20)
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.5, i64 0, i64 0))
%29 = call i32 ([9 x i8]*, i8*, ...) bitcast (i32 (...)* @writeBody to i32 ([9 x i8]*, i8*, ...)*)([9 x i8]* %21, i8* %8)
%30 = sext i32 %29 to i64
%31 = inttoptr i64 %30 to i8*
%32 = call i32 (i8*, i8*, i8*, ...) bitcast (i32 (...)* @writeToFile to i32 (i8*, i8*, i8*, ...)*)(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8* %27, i8* %31)
%33 = call i32 (%struct.listHeader*, ...) bitcast (i32 (...)* @freeList to i32 (%struct.listHeader*, ...)*)(%struct.listHeader* %14)
%34 = call i32 (%struct.tree*, ...) bitcast (i32 (...)* @freeTree to i32 (%struct.tree*, ...)*)(%struct.tree* %20)
ret i32 0
35: ; preds = %1, %44
%36 = phi i64 [ 0, %1 ], [ %45, %44 ]
%37 = getelementptr inbounds [256 x [9 x i8]], [256 x [9 x i8]]* %2, i64 0, i64 %36, i64 0
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = trunc i64 %36 to i32
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %44
44: ; preds = %35, %40
%45 = add nuw nsw i64 %36, 1
%46 = icmp eq i64 %45, 256
br i1 %46, label %23, label %35
}