// File: /workspace/github_cpp_makefile_star2_O1/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 0x8950(%rip), %rbx      # 0x18fd0
leaq 0x1e1b(%rip), %rsi      # 0x124a2
movl $0xd, %edx
movq %rbx, %rdi
callq 0x4240
leaq 0x1e15(%rip), %rsi      # 0x124b0
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x4240
callq 0x5aac
testl %eax, %eax
je 0x106ce
movq 0x8918(%rip), %rdi      # 0x18fd0
leaq 0x1e11(%rip), %rsi      # 0x124d0
movl $0x16, %edx
callq 0x4240
jmp 0x1099b
leaq 0x1e12(%rip), %rdi      # 0x124e7
callq 0x41b0
leaq 0x1e10(%rip), %rax      # 0x124f1
movq %rax, 0x58(%rsp)
leaq 0x1e09(%rip), %rax      # 0x124f6
movq %rax, 0x60(%rsp)
xorl %r13d, %r13d
leaq 0x38(%rsp), %r14
leaq 0x80(%rsp), %r12
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x1dea(%rip), %rsi      # 0x124fb
callq 0x4240
movq %r13, 0x30(%rsp)
movq 0x58(%rsp,%r13), %r13
testq %r13, %r13
je 0x1073d
movq %r13, %rdi
callq 0x40f0
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x4240
jmp 0x10754
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 0x1da1(%rip), %rsi      # 0x12504
callq 0x4240
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %r13
movq %r13, %rdi
leaq 0x1b91(%rip), %rsi      # 0x12312
leaq 0x1b8b(%rip), %rdx      # 0x12313
callq 0x10b94
movq 0x30(%rsp), %rax
movq 0x58(%rsp,%rax), %rsi
movq %r14, %rdi
leaq 0xf(%rsp), %rdx
callq 0x40d0
leaq 0x68(%rsp), %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x111e0
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x107d0
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x107ec
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x70(%rsp), %rax
cmpq 0x68(%rsp), %rax
jne 0x1085e
movl $0x3, %edx
movq %rbx, %rdi
leaq 0x1d05(%rip), %rsi      # 0x1250c
callq 0x4240
movq 0x30(%rsp), %rax
movq 0x58(%rsp,%rax), %r13
testq %r13, %r13
je 0x10833
movq %r13, %rdi
callq 0x40f0
movq %rbx, %rdi
movq %r13, %rsi
movq %rax, %rdx
callq 0x4240
jmp 0x1084a
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 0x1cb7(%rip), %rsi      # 0x12510
callq 0x4240
movq 0x68(%rsp), %r13
movq 0x70(%rsp), %rbp
cmpq %rbp, %r13
je 0x1097e
movl $0x9, %edx
movq %rbx, %rdi
leaq 0x1c9e(%rip), %rsi      # 0x1251e
callq 0x4240
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x4240
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1bf9(%rip), %rsi      # 0x1249d
callq 0x4240
movq %r14, %rdi
movq %r13, %rsi
callq 0xfc7f
movq 0x40(%rsp), %rax
cmpq 0x38(%rsp), %rax
je 0x10935
movl $0x18, %edx
movq %rbx, %rdi
leaq 0x1c73(%rip), %rsi      # 0x12542
callq 0x4240
movq %r12, %rdi
movq %r14, %rsi
callq 0x10b0a
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rsp), %r15
movq %r15, %rdi
leaq 0x1bf5(%rip), %rsi      # 0x124ed
leaq 0x1bf1(%rip), %rdx      # 0x124f0
callq 0x10b94
movq %r12, %rdi
movq %r15, %rsi
callq 0x101be
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x1092b
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
movq %r12, %rdi
callq 0x10aae
jmp 0x1096d
movl $0x19, %edx
movq %rbx, %rdi
leaq 0x1be4(%rip), %rsi      # 0x12528
callq 0x4240
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq %rbx, %rdi
callq 0x4240
movl $0x1, %edx
movq %rax, %rdi
leaq 0x1b35(%rip), %rsi      # 0x1249d
callq 0x4240
movq %r14, %rdi
callq 0x10aae
addq $0x20, %r13
jmp 0x10868
leaq 0x68(%rsp), %rdi
callq 0x10aae
movq 0x30(%rsp), %r13
addq $0x8, %r13
cmpq $0x10, %r13
jne 0x10702
movq 0x862e(%rip), %rdi      # 0x18fd0
leaq 0x1bb2(%rip), %rsi      # 0x1255b
movl $0x16, %edx
callq 0x4240
movq 0x8626(%rip), %rdi      # 0x18fe0
callq 0x4260
callq 0x5aaf
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x10a75
movq %rax, %rbx
jmp 0x10a04
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0x10a04
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x4210
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x10a75
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
jmp 0x10a75
jmp 0x10a68
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x10a48
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x4210
jmp 0x10a48
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x10aae
jmp 0x10a5c
jmp 0x10a68
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x10aae
jmp 0x10a6b
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x10aae
movq %rbx, %rdi
callq 0x43a0
nop