// File: /workspace/github_cpp_makefile_star2_O1/sc0ty[P]CODExtract/src/codfile/codfile.cpp
// Function: CODFile::LoadParent()
bool CODFile::LoadParent()
{
    if (!isOpen) throw "Load file first";

    // parent already loaded
    if (!isChildCOD()) return false;

    /* extract parent filename from cod file */

    // data segment header
    TDATASEGHEADER *dh = (TDATASEGHEADER *)DataSeg;

    // sanity check
    if (dh->exported_string_offset > HeadSeg->data_size)
        throw "Incorrect file format";

    // export names ptr array
    u16 *expn = (u16 *)(DataSeg + sizeof(TDATASEGHEADER) +
                        sizeof(u16)*dh->num_classes +
                        sizeof(u16)*2*dh->num_modules);

    // check if ptr is in data section
    if ( *expn >= HeadSeg->data_size)
        throw "Incorrect file format";

    /* create parent filename */

    string fn = FName;
    fn = &DataSeg[*expn];
	size_t s;

	// find every $ characters
	while ((s = fn.find('$')) != string::npos)
	{
		int c;
		istringstream iss(fn.substr(s+1, 2));
		iss >> hex >> c;
		fn.replace(s, 3, 1, (char)c);
	}

	// extract directory from path
    size_t sz = FName.find_last_of("\\/");
	if (sz != string::npos) fn = FName.substr(0, sz+1) + fn;
    fn += ".cod";

    // load parent cod file
    LoadFile(fn.c_str());

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
cmpb $0x0, 0x48(%rdi)
je 0x376a
movq %rdi, %r12
callq 0x381c
testb %al, %al
je 0x3758
movq 0x28(%r12), %rcx
movq 0x38(%r12), %rdi
movzwl 0x28(%rcx), %ecx
cmpw %cx, 0x6(%rdi)
ja 0x377d
movb %al, -0x29(%rbp)
movzbl 0x5(%rdi), %edx
leaq (%rdi,%rdx,2), %rsi
movzbl 0x4(%rdi), %r14d
cmpw %cx, 0x34(%rsi,%r14,4)
jae 0x377d
leaq (%rdi,%rdx,2), %r15
addq $0x34, %r15
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x3e5c
movzwl (%r15,%r14,4), %r14d
movq %r12, -0x78(%rbp)
addq 0x38(%r12), %r14
movq 0x8(%rbx), %r15
movq %r14, %rdi
callq 0x20f0
movq %rbx, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
movq %rax, %r8
callq 0x22b0
leaq -0x50(%rbp), %rdi
movl $0x24, %esi
xorl %edx, %edx
callq 0x2240
cmpq $-0x1, %rax
je 0x3640
movq %rax, %r14
leaq -0x70(%rbp), %r12
leaq -0x50(%rbp), %r13
leaq -0x1f8(%rbp), %rbx
movq 0x3a45(%rip), %r15      # 0x6fd0
leaq 0x1(%r14), %rdx
movl $0x2, %ecx
movq %r12, %rdi
movq %r13, %rsi
callq 0x21d0
movq %rbx, %rdi
movq %r12, %rsi
movl $0x8, %edx
callq 0x22e0
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x35c8
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21c0
movq -0x1f8(%rbp), %rax
movq -0x18(%rax), %rax
movl -0x1e0(%rbp,%rax), %ecx
andl $-0x4b, %ecx
orl $0x8, %ecx
movl %ecx, -0x1e0(%rbp,%rax)
movq %rbx, %rdi
leaq -0x30(%rbp), %rsi
callq 0x2120
movsbl -0x30(%rbp), %r8d
movl $0x3, %edx
movl $0x1, %ecx
movq %r13, %rdi
movq %r14, %rsi
callq 0x22c0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2280
leaq -0x180(%rbp), %rdi
callq 0x20c0
movq %r13, %rdi
movl $0x24, %esi
xorl %edx, %edx
callq 0x2240
movq %rax, %r14
cmpq $-0x1, %rax
jne 0x358b
movq -0x78(%rbp), %r15
leaq 0x8(%r15), %rbx
leaq 0x1b75(%rip), %rsi      # 0x51c4
movl $0x2, %ecx
movq %rbx, %rdi
movq $-0x1, %rdx
callq 0x2350
cmpq $-0x1, %rax
je 0x3720
incq %rax
leaq -0x70(%rbp), %rdi
movq %rbx, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x21d0
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x20b0
leaq -0x1e8(%rbp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x36bf
movq %rdx, -0x1f8(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x1e8(%rbp)
jmp 0x36c6
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq -0x1f8(%rbp), %rbx
movq %rdx, 0x8(%rbx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq -0x50(%rbp), %rdi
movq %rbx, %rsi
callq 0x2210
movq (%rbx), %rdi
cmpq %r14, %rdi
je 0x3707
movq -0x1e8(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3720
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21c0
leaq 0x1aa0(%rip), %rsi      # 0x51c7
leaq -0x50(%rbp), %rdi
callq 0x2330
movq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x31e8
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3755
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x21c0
movb -0x29(%rbp), %al
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x8, %edi
callq 0x2110
leaq 0x1a39(%rip), %rcx      # 0x51b4
jmp 0x378e
movl $0x8, %edi
callq 0x2110
leaq 0x1a10(%rip), %rcx      # 0x519e
movq %rcx, (%rax)
movq 0x3820(%rip), %rsi      # 0x6fb8
movq %rax, %rdi
xorl %edx, %edx
callq 0x2300
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x37c5
jmp 0x37b5
jmp 0x37b5
jmp 0x37b5
movq %rax, %rbx
jmp 0x37fa
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x37fa
movq -0x60(%rbp), %rsi
incq %rsi
callq 0x21c0
jmp 0x37fa
movq %rax, %rbx
movq 0x37ee(%rip), %rsi      # 0x6fd0
leaq -0x1f8(%rbp), %rdi
callq 0x2280
leaq -0x180(%rbp), %rdi
callq 0x20c0
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3813
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2310
nop