// File: /workspace/github_cpp_makefile_star2_O3/OpenFodder[P]SOS_Unpacker/SOS_Unpacker.cpp
// Function: main
int main(int argc, char* argv[]) {
    std::cout << "SOS Unpacker\n";
    std::cout << "https://github.com/OpenFodder\n\n";

    if (CAPSInit()) {
        std::cout << "CAPSImg.dll not found\n";
    } else {

        system("mkdir out");

        for (auto& extension : { ".raw", ".ipf" } ) {
            std::cout << "Finding " << extension << " files\n";
            auto Files = local_DirectoryList(".", extension);

            if (!Files.size())
                std::cout << "No " << extension << " files found\n";

            //local_DirectoryList
            for (auto& File : Files) {
                std::cout << "\nLoading " << File << "\n";
                auto Tracks = GetSOSTracks(File);

                if (!Tracks.size()) {
                    std::cout << "No Tracks found in file: " << File << "\n";
                    continue;
                }


                std::cout << "Extracting to .\\out\\...\n";
                ExtractFiles(Tracks, "out");
            }
        }
    }

    std::cout << "Press enter to finish\n";
    std::cin.get();

    CAPSExit();
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq 0x8908(%rip), %rbx      # 0x18fd0
leaq 0x1efd(%rip), %rsi      # 0x125cc
movl $0xd, %edx
movq %rbx, %rdi
callq 0x4240
leaq 0x1ef7(%rip), %rsi      # 0x125da
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x4240
callq 0x5acc
testl %eax, %eax
je 0x10716
movq 0x88d0(%rip), %rdi      # 0x18fd0
leaq 0x1ef3(%rip), %rsi      # 0x125fa
movl $0x16, %edx
callq 0x4240
jmp 0x109da
leaq 0x1ef4(%rip), %rdi      # 0x12611
callq 0x41b0
leaq 0x1ef2(%rip), %rax      # 0x1261b
movq %rax, 0x70(%rsp)
leaq 0x1eeb(%rip), %rax      # 0x12620
movq %rax, 0x78(%rsp)
xorl %eax, %eax
leaq 0x30(%rsp), %r14
leaq 0x80(%rsp), %r12
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x1ecd(%rip), %rsi      # 0x12625
movq %rax, %r13
callq 0x4240
movq %r13, 0x68(%rsp)
movq 0x70(%rsp,%r13), %r15
testq %r15, %r15
je 0x10787
movq %r15, %rdi
callq 0x40f0
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x4240
jmp 0x1079e
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x4360
movl $0x7, %edx
movq %rbx, %rdi
leaq 0x1e81(%rip), %rsi      # 0x1262e
callq 0x4240
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x1c5e(%rip), %rsi      # 0x12426
leaq 0x1c58(%rip), %rdx      # 0x12427
callq 0x10bd4
movq %r14, %rdi
movq %r15, %rsi
leaq 0xf(%rsp), %rdx
callq 0x40d0
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %r14, %rdx
callq 0x11228
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x10812
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1082e
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %rbp
cmpq %r13, %rbp
jne 0x109b4
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x1de6(%rip), %rsi      # 0x12636
callq 0x4240
testq %r15, %r15
je 0x10872
movq %r15, %rdi
callq 0x40f0
movq %rbx, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x4240
jmp 0x10889
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x4360
movl $0xd, %edx
movq %rbx, %rdi
leaq 0x1da2(%rip), %rsi      # 0x1263a
callq 0x4240
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %rbp
jmp 0x109b4
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x1d8d(%rip), %rsi      # 0x12648
callq 0x4240
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x4240
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1ce8(%rip), %rsi      # 0x125c7
callq 0x4240
movq %r14, %rdi
movq %r13, %rsi
callq 0xfc60
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x10970
movl $0x18, %edx
movq %rbx, %rdi
leaq 0x1d62(%rip), %rsi      # 0x1266c
callq 0x4240
movq %r12, %rdi
movq %r14, %rsi
callq 0x10b4a
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x1ce4(%rip), %rsi      # 0x12617
leaq 0x1ce0(%rip), %rdx      # 0x1261a
callq 0x10bd4
movq %r12, %rdi
movq %r15, %rsi
callq 0x101ab
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x10966
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
movq %r12, %rdi
callq 0x10aec
jmp 0x109a8
movl $0x19, %edx
movq %rbx, %rdi
leaq 0x1cd3(%rip), %rsi      # 0x12652
callq 0x4240
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x4240
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1c24(%rip), %rsi      # 0x125c7
callq 0x4240
movq %r14, %rdi
callq 0x10aec
addq $0x20, %r13
cmpq %rbp, %r13
jne 0x108ac
leaq 0x50(%rsp), %rdi
callq 0x10aec
movq 0x68(%rsp), %rax
addq $0x8, %rax
cmpq $0x10, %rax
jne 0x10749
movq 0x85ef(%rip), %rdi      # 0x18fd0
leaq 0x1c9d(%rip), %rsi      # 0x12685
movl $0x16, %edx
callq 0x4240
movq 0x85e7(%rip), %rdi      # 0x18fe0
callq 0x4260
callq 0x5acf
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x10ab4
movq %rax, %rbx
jmp 0x10a43
movq %rax, %rbx
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x10a43
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x10ab4
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
jmp 0x10ab4
jmp 0x10aa7
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x10a87
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
jmp 0x10a87
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x10aec
jmp 0x10a9b
jmp 0x10aa7
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x10aec
jmp 0x10aaa
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x10aec
movq %rbx, %rdi
callq 0x43a0