// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x3458, %rsp           # imm = 0x3458
movq %rsi, %rbx
movq %rdi, %r14
leaq 0x48(%rsp), %r15
movq %r15, %rdi
callq 0x1120
pushq $0x4
popq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x10d0
leaq 0x250(%rsp), %rdi
callq 0x1190
leaq 0x250(%rsp), %rdi
pushq $0x10
popq %rdx
movq %rbx, %rsi
callq 0x1030
andq $0x0, 0x8(%rsp)
andl $0x0, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
andl $0x0, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
andq $0x0, 0x40(%rsp)
leaq 0x450(%rsp), %rbx
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10c0
leaq 0x48(%rsp), %rdi
movl $0x400, %edx            # imm = 0x400
movq %rbx, %rsi
callq 0x1130
leaq 0x48(%rsp), %rdi
leaq 0x4(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x1130
leaq 0x48(%rsp), %rbx
leaq 0x3(%rsp), %r14
pushq $0x1
popq %r15
leaq 0x8(%rsp), %r12
movq %rbx, %rdi
callq 0x1080
cmpl $-0x1, %eax
je 0x17b3
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1130
movzbl 0x3(%rsp), %edi
movq %r12, %rsi
callq 0x1696
jmp 0x1789
movq 0x8(%rsp), %rax
movq 0x18(%rsp), %rcx
movslq 0x4(%rsp), %rdx
movl 0x20(%rsp), %edi
pushq $0x3f
popq %rsi
movq %rcx, %r8
subq %rax, %r8
shlq $0x3, %r8
movl %edi, %r9d
addq %r8, %r9
cmpq %rdx, %r9
jbe 0x17fc
addl $-0x1, %edi
movl %edi, 0x20(%rsp)
jb 0x17d3
movl $0x3f, 0x20(%rsp)
addq $-0x8, %rcx
movq %rcx, 0x18(%rsp)
movl %esi, %edi
jmp 0x17c9
leaq 0x850(%rsp), %rdi
leaq 0x450(%rsp), %rsi
callq 0x203c
leaq 0x850(%rsp), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq 0x24a2
xorl %r15d, %r15d
leaq 0x250(%rsp), %rbx
pushq $0x1
popq %r14
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rax
subq %rsi, %rax
cmpq %r15, %rax
jbe 0x185c
addq %r15, %rsi
movq %rbx, %rdi
movq %r14, %rdx
callq 0x1140
incq %r15
jmp 0x1837
leaq 0x48(%rsp), %rdi
callq 0x1040
leaq 0x250(%rsp), %rdi
callq 0x1150
leaq 0x850(%rsp), %rdi
callq 0x23d4
leaq 0x30(%rsp), %rdi
callq 0x19e4
leaq 0x8(%rsp), %rdi
callq 0x19c8
leaq 0x250(%rsp), %rdi
callq 0x1160
leaq 0x48(%rsp), %rdi
callq 0x1050
addq $0x3458, %rsp           # imm = 0x3458
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x18e0
jmp 0x18e0
jmp 0x18e0
movq %rax, %rbx
jmp 0x18f7
jmp 0x18c7
movq %rax, %rbx
jmp 0x1904
jmp 0x18ce
movq %rax, %rbx
leaq 0x850(%rsp), %rdi
callq 0x23d4
jmp 0x18e3
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x19e4
leaq 0x8(%rsp), %rdi
callq 0x19c8
leaq 0x250(%rsp), %rdi
callq 0x1160
leaq 0x48(%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x11b0