// File: hey-yahei[P]ConvNet/src/helper.cpp
// Function: LoadFromSparseHuffmanFile(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, char*, TarFile*)
unsigned long LoadFromSparseHuffmanFile(string prefix, char* dst, TarFile* tarfile) {
	string data_path = prefix + ".data";
	string index_path = prefix + ".index";

	vector<unsigned char> index, data;
	LoadFromHuffmanFile(index_path, index, tarfile);
	LoadFromHuffmanFile(data_path, data, tarfile);
	unsigned long size = index.size();
	if (size != data.size()) {
		cerr << "LoadFromSparseHuffmanFile: size not match" << endl;
		exit(1);
	}

	index[0]--;
	for (int i = 0; i < size; i++) {
		dst += index[i];
		*dst = data[i];
	}
	return size;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rsi, %rax
movq %rdi, %rsi
movq %rsi, -0xf0(%rbp)
movq %rsi, -0x8(%rbp)
movq %rax, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq 0x4565(%rip), %rdx      # 0xc3e0
leaq -0x38(%rbp), %rdi
callq 0x8430
movq -0xf0(%rbp), %rsi
leaq 0x4554(%rip), %rdx      # 0xc3e6
leaq -0x58(%rbp), %rdi
callq 0x8430
jmp 0x7e9d
leaq -0x80(%rbp), %rdi
callq 0x8550
leaq -0x98(%rbp), %rdi
callq 0x8550
leaq -0xb8(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x20c0
jmp 0x7ec4
movq -0x18(%rbp), %rdx
leaq -0xb8(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7c00
jmp 0x7eda
leaq -0xb8(%rbp), %rdi
callq 0x2130
leaq -0xd8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x20c0
jmp 0x7ef8
movq -0x18(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x7c00
jmp 0x7f11
leaq -0xd8(%rbp), %rdi
callq 0x2130
leaq -0x80(%rbp), %rdi
callq 0x8570
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x8570
movq %rax, %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
je 0x7ff1
movq 0xa08f(%rip), %rdi      # 0x11ff0
leaq 0x4485(%rip), %rsi      # 0xc3ed
callq 0x21c0
movq %rax, -0x100(%rbp)
jmp 0x7f76
movq -0x100(%rbp), %rdi
movq 0xa03c(%rip), %rsi      # 0x11fc0
callq 0x2200
jmp 0x7f8b
movl $0x1, %edi
callq 0x2290
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x80cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x80b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x2130
jmp 0x80b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x2130
jmp 0x80b1
leaq -0x80(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x8590
movb (%rax), %cl
addb $-0x1, %cl
movb %cl, (%rax)
movl $0x0, -0xe4(%rbp)
movslq -0xe4(%rbp), %rax
cmpq -0xe0(%rbp), %rax
jae 0x806c
movslq -0xe4(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x8590
movzbl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movslq -0xe4(%rbp), %rsi
leaq -0x98(%rbp), %rdi
callq 0x8590
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0xe4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe4(%rbp)
jmp 0x800f
movq -0xe0(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x85b0
leaq -0x80(%rbp), %rdi
callq 0x85b0
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq -0x108(%rbp), %rax
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x98(%rbp), %rdi
callq 0x85b0
leaq -0x80(%rbp), %rdi
callq 0x85b0
leaq -0x58(%rbp), %rdi
callq 0x2130
leaq -0x38(%rbp), %rdi
callq 0x2130
movq -0x60(%rbp), %rdi
callq 0x2370
nopw %cs:(%rax,%rax)