// File: /workspace/github_cpp_makefile_star2_O3/hey-yahei[P]ConvNet/src/helper.cpp
// Function: LoadFromHuffmanFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<unsigned char, std::allocator<unsigned char>>&, TarFile*)
unsigned long LoadFromHuffmanFile(string prefix, vector<unsigned char> &dst, TarFile* tarfile) {
	string data = prefix + ".hf.dat";
	string codebook = prefix + ".hfcb.dat";
	int cnt = 0;

	Tree* huffman_tree = DecodeHuffmanCodebook(codebook.c_str(), tarfile);
	Tree* ptr = huffman_tree;
	Bit accessor(data.c_str(), tarfile);
	int bit;
	while ((bit = accessor.Next()) != -1) {
		if (0 == bit) {
			ptr = ptr->left;
		} else if (1 == bit) {
			ptr = ptr->right;
		} else {
			cerr << "LoadFromHuffmanFile: unknown bit" << endl;
			exit(1);
		}

		if (-1 != ptr->value) {
			dst.push_back(ptr->value);
			cnt++;
			ptr = huffman_tree;
		}
	}

	delete huffman_tree;
	return cnt;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r12
movq %r12, %rdi
callq 0x4e84
leaq 0x1be0(%rip), %rsi      # 0x63ad
movq %r12, %rdi
callq 0x2310
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %rdi
callq 0x4e84
leaq 0x1bbb(%rip), %rsi      # 0x63b5
leaq -0x90(%rbp), %rdi
callq 0x2310
movq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0x4569
movq %rax, %r15
movq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movq %r14, %rdx
callq 0x4db4
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movslq -0x40(%rbp), %rdx
leaq (%rax,%rdx), %rdi
xorl %r14d, %r14d
cmpq %rdi, %rcx
jae 0x48c9
leaq -0x29(%rbp), %r12
movq %r15, %rsi
decq %rdi
movl -0x3c(%rbp), %r8d
cmpq %rdi, %rcx
jne 0x4862
movl -0x38(%rbp), %edi
addl %r8d, %edi
cmpl $0x7, %edi
jg 0x48c6
leal 0x1(%r8), %r9d
movzbl (%rcx), %edi
movl %r9d, -0x3c(%rbp)
subl $0x7, %r8d
jl 0x4881
movl $0x0, -0x3c(%rbp)
incq %rcx
movq %rcx, -0x48(%rbp)
negl %r8d
xorl %r9d, %r9d
btl %r8d, %edi
setb %r9b
movq (%rsi,%r9,8), %rsi
movl 0x10(%rsi), %edi
cmpl $-0x1, %edi
je 0x48bb
movb %dil, -0x29(%rbp)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4f22
incl %r14d
movq -0x50(%rbp), %rax
movq -0x48(%rbp), %rcx
movl -0x40(%rbp), %edx
movq %r15, %rsi
movslq %edx, %rdi
addq %rax, %rdi
cmpq %rdi, %rcx
jb 0x484b
movslq %r14d, %r14
testq %r15, %r15
je 0x48d6
movq %r15, %rdi
callq 0x4e3a
movl $0x18, %esi
movq %r15, %rdi
callq 0x21b0
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x21b0
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x4909
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21b0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x4922
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21b0
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4938
jmp 0x4938
movq %rax, %rbx
jmp 0x4955
jmp 0x493f
movq %rax, %rbx
jmp 0x496d
movq %rax, %rbx
movq -0x50(%rbp), %rdi
movl $0x1, %esi
callq 0x21b0
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x496d
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21b0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x4986
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22e0