// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %r12
movq %r12, %rdi
callq 0x4ebc
leaq 0x1be7(%rip), %rsi      # 0x63ad
movq %r12, %rdi
callq 0x2310
leaq -0x40(%rbp), %r12
movq %r12, -0x10(%r12)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rdi
callq 0x4ebc
leaq 0x1bc4(%rip), %rsi      # 0x63b5
leaq -0x50(%rbp), %rdi
callq 0x2310
movq -0x50(%rbp), %rdi
movq %r15, %rsi
callq 0x4555
movq %rax, %r14
movq -0x90(%rbp), %rsi
leaq -0x70(%rbp), %rdi
movq %r15, %rdx
callq 0x4de8
xorl %r13d, %r13d
leaq -0x29(%rbp), %r15
movslq -0x60(%rbp), %rdx
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rax
leaq (%rsi,%rdx), %rcx
addq %rsi, %rdx
decq %rdx
movl -0x58(%rbp), %esi
movl -0x5c(%rbp), %r8d
movq %r14, %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
cmpq %rcx, %rax
jae 0x489a
cmpq %rdx, %rax
jne 0x485d
leal (%rsi,%r8), %r10d
cmpl $0x7, %r10d
jg 0x489a
movzbl (%rax), %r11d
leal 0x1(%r8), %r10d
movl %r10d, -0x5c(%rbp)
movb $0x7, %r9b
subb %r8b, %r9b
movzbl %r9b, %r12d
xorl %r9d, %r9d
btl %r12d, %r11d
setb %r9b
cmpl $0x7, %r8d
jge 0x4889
movl %r10d, %r8d
jmp 0x489a
movl $0x0, -0x5c(%rbp)
incq %rax
movq %rax, -0x68(%rbp)
xorl %r8d, %r8d
testl %r9d, %r9d
je 0x48a9
cmpl $0x1, %r9d
jne 0x48cd
addq $0x8, %rdi
movq (%rdi), %rdi
movl 0x10(%rdi), %r9d
cmpl $-0x1, %r9d
je 0x4843
movb %r9b, -0x29(%rbp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4f56
incl %r13d
jmp 0x4823
testq %r14, %r14
je 0x48e7
movq %r14, %rdi
callq 0x4e6e
movl $0x18, %esi
movq %r14, %rdi
callq 0x21b0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x48fa
movl $0x1, %esi
callq 0x21b0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x4913
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x21b0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x492f
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21b0
movl %r13d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4943
movq %rax, %rbx
jmp 0x4982
movq %rax, %rbx
movq -0x50(%rbp), %rdi
cmpq %r12, %rdi
jne 0x498f
jmp 0x499b
movq %rax, %rbx
jmp 0x499b
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
jne 0x49ab
jmp 0x49b7
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x4982
movl $0x1, %esi
callq 0x21b0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x499b
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x21b0
movq -0x90(%rbp), %rdi
leaq -0x80(%rbp), %rax
cmpq %rax, %rdi
je 0x49b7
movq -0x80(%rbp), %rsi
incq %rsi
callq 0x21b0
movq %rbx, %rdi
callq 0x22e0