// File: /workspace/github_cpp_makefile_star2_O1/Matheus-Aguilar[P]Huffman/main.cpp
// Function: descompressFile(char*, char*)
void descompressFile(char *in, char *out){
	
	ifstream fin; //Input file
	fin.open(in, ios::binary); 

	ofstream fout; //Output file
	fout.open(out, ofstream::out);

	vector<bool> bits; //Bits of the input file
	vector<char> content; //Decoded content

	int freq[256] = {0}; //Frequency array

	//Getting the frequencies of the huffman encoding
	fin.read(reinterpret_cast<char *>(freq), sizeof(freq));

	//Get the encoding size (to ignore extra bits)
	int HuffmanSize;
	fin.read(reinterpret_cast<char *>(&HuffmanSize), sizeof(int));

	//Reading bytes and conveting to bits
	unsigned char byte;
	while(fin.peek() != -1){
		fin.read(reinterpret_cast<char *>(&byte), sizeof(unsigned char));
		splitByte(byte, bits); //Split byte and append to the end of bits
	}

	//Remove extra bits
	while(bits.size() > HuffmanSize) bits.pop_back(); 

	HuffmanTree tree(freq); //Build the tree
	tree.descompress(content, bits); //Decodes the bits into a string

	for(int i = 0; i < content.size(); ++i)
		fout.write(reinterpret_cast<char *>(&content[i]), sizeof(char)); //Save the decoded content into file

	//Close files
	fin.close();
	fout.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x3470, %rsp           # imm = 0x3470
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x258(%rsp), %r15
movq %r15, %rdi
callq 0x2140
movq %r15, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x20e0
leaq 0x58(%rsp), %rdi
callq 0x21b0
leaq 0x58(%rsp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2030
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq %rax, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
leaq 0x460(%rsp), %rbx
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
xorl %esi, %esi
callq 0x20d0
leaq 0x258(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rsi
callq 0x2150
leaq 0x258(%rsp), %rdi
leaq 0x3c(%rsp), %rsi
movl $0x4, %edx
callq 0x2150
leaq 0x258(%rsp), %rbx
leaq 0xf(%rsp), %r14
leaq 0x10(%rsp), %r15
movq %rbx, %rdi
callq 0x2090
cmpl $-0x1, %eax
je 0x283f
movl $0x1, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2150
movb $-0x80, %r12b
movb 0xf(%rsp), %bpl
xorl %esi, %esi
testb %bpl, %r12b
setne %sil
movq %r15, %rdi
callq 0x2a92
movl %r12d, %eax
shrb %al
cmpb $0x2, %r12b
movl %eax, %r12d
jae 0x281e
jmp 0x27f9
movq 0x10(%rsp), %rax
movq 0x20(%rsp), %rcx
movslq 0x3c(%rsp), %rdx
movl 0x28(%rsp), %esi
movq %rcx, %rdi
subq %rax, %rdi
leaq (%rsi,%rdi,8), %rdi
cmpq %rdx, %rdi
jbe 0x288a
subl $0x1, %esi
jae 0x2874
addq $-0x8, %rcx
movq %rcx, 0x20(%rsp)
movl $0x3f, %esi
movq %rcx, %rdi
subq %rax, %rdi
movl %esi, %r8d
leaq (%r8,%rdi,8), %rdi
cmpq %rdx, %rdi
ja 0x2861
movl %esi, 0x28(%rsp)
leaq 0x868(%rsp), %rdi
leaq 0x460(%rsp), %rsi
callq 0x2fb8
leaq 0x868(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq 0x34f8
movq 0x40(%rsp), %rsi
cmpq %rsi, 0x48(%rsp)
je 0x28ef
xorl %r14d, %r14d
leaq 0x58(%rsp), %rbx
addq %r14, %rsi
movl $0x1, %edx
movq %rbx, %rdi
callq 0x2160
incq %r14
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rax
subq %rsi, %rax
cmpq %r14, %rax
ja 0x28ca
leaq 0x258(%rsp), %rdi
callq 0x2040
leaq 0x58(%rsp), %rdi
callq 0x2170
leaq 0x868(%rsp), %rdi
callq 0x33f6
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x292a
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x295a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq 0x3677(%rip), %rax      # 0x5fd8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x60(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x58(%rsp,%rcx)
callq 0x2100
leaq 0x150(%rsp), %rdi
callq 0x2070
leaq 0x258(%rsp), %rdi
callq 0x2050
addq $0x3470, %rsp           # imm = 0x3470
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29d1
jmp 0x29d1
jmp 0x29d1
movq %rax, %rbx
jmp 0x2a1b
jmp 0x29b6
movq %rax, %rbx
jmp 0x2a25
jmp 0x29bd
movq %rax, %rbx
leaq 0x868(%rsp), %rdi
callq 0x33f6
jmp 0x29d4
jmp 0x29d1
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x29eb
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2a1b
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2130
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movl %eax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x2180
leaq 0x258(%rsp), %rdi
callq 0x2050
movq %rbx, %rdi
callq 0x21d0