// File: /workspace/github_cpp_makefile_star2_O2/nachogoro[P]wordcrack-herminia/src/main.cpp
// Function: main
int main(int argc, char** argv)
{
    std::string programName(argv[0]);
    if (argc != 9) {
        printUsage(programName);
        return 0;
    }

    std::string dictFileName;
    std::string boardFileName;
    std::string outFileWords;
    std::string outFileCoords;

    // Get the configuration parameters
    for (int i = 1; i <= 7; i+=2)
    {
        std::string config(argv[i]);
        if (config == "--dict") {
            dictFileName = argv[i+1];
        } else if (config == "--board") {
            boardFileName = argv[i+1];
        } else if (config == "--outwords") {
            outFileWords = argv[i+1];
        } else if (config == "--outcoords") {
            outFileCoords = argv[i+1];
        } else {
            printUsage(programName);
            return 0;
        }
    }

    // Validate the configuration parameters
    validateConfig(dictFileName, boardFileName, outFileWords, outFileCoords);

    std::chrono::high_resolution_clock::time_point dictStart =
        std::chrono::high_resolution_clock::now();

    Dictionary dict(dictFileName);

    std::chrono::high_resolution_clock::time_point dictEnd =
        std::chrono::high_resolution_clock::now();
    auto dictDuration = std::chrono::duration_cast<std::chrono::seconds>(dictEnd - dictStart).count();

    std::cout << "Dictionary loaded in " << dictDuration << " seconds" << std::endl;

    Board board(boardFileName);
    std::map<Word, int> foundWords;

    std::chrono::high_resolution_clock::time_point start =
        std::chrono::high_resolution_clock::now();

    findAllWords(board,dict,foundWords);

    std::chrono::high_resolution_clock::time_point end =
        std::chrono::high_resolution_clock::now();

    auto duration = std::chrono::duration_cast<std::chrono::seconds>(end - start).count();
    std::cout << "All words found in " << duration << " seconds" << std::endl;


    writeResultsToOutputFiles(foundWords, outFileWords, outFileCoords);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7d8, %rsp            # imm = 0x7D8
movq %rsi, %rbx
movl %edi, %r14d
callq 0x2180
movq (%rbx), %rsi
leaq -0xd0(%rbp), %rdi
leaq -0x480(%rbp), %rdx
callq 0x20c0
cmpl $0x9, %r14d
jne 0x534f
leaq -0xa0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
leaq -0x80(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
leaq -0x60(%rbp), %rsi
movq %rsi, -0x10(%rsi)
andq $0x0, -0x8(%rsi)
movb %cl, (%rax)
movb %cl, (%rdx)
movb %cl, (%rsi)
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
pushq $0x1
popq %r13
leaq -0x480(%rbp), %r14
leaq 0x2ece(%rip), %r12      # 0x8180
leaq -0xb0(%rbp), %r15
cmpq $0x7, %r13
ja 0x5360
movq (%rbx,%r13,8), %rsi
movq %r14, %rdi
leaq -0x100(%rbp), %rdx
callq 0x20c0
movq %r14, %rdi
movq %r12, %rsi
callq 0x3485
movq %r15, %rdi
testb %al, %al
jne 0x5334
movq %r14, %rdi
leaq 0x2e95(%rip), %rsi      # 0x8187
callq 0x3485
leaq -0x90(%rbp), %rdi
testb %al, %al
jne 0x5334
movq %r14, %rdi
leaq 0x2e83(%rip), %rsi      # 0x818f
callq 0x3485
leaq -0x70(%rbp), %rdi
testb %al, %al
jne 0x5334
movq %r14, %rdi
leaq 0x2e77(%rip), %rsi      # 0x819a
callq 0x3485
leaq -0x50(%rbp), %rdi
testb %al, %al
je 0x5519
movq 0x8(%rbx,%r13,8), %rsi
callq 0x2370
movq %r14, %rdi
callq 0x20f0
addq $0x2, %r13
jmp 0x52b9
leaq -0xd0(%rbp), %rdi
callq 0x55d0
jmp 0x54f9
leaq -0xb0(%rbp), %rdi
leaq -0x90(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x50(%rbp), %rcx
callq 0x5738
callq 0x2040
movq %rax, %rbx
leaq -0x30(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x4644
callq 0x2040
movq %rax, %r14
movq 0x7c26(%rip), %rdi      # 0xcfc8
leaq 0x2dfd(%rip), %rsi      # 0x81a6
callq 0x21d0
movq %rax, %rdi
subq %rbx, %r14
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
movq %r14, %rax
cqto
idivq %rcx
movq %rax, %rsi
callq 0x21c0
leaq 0x2dec(%rip), %rsi      # 0x81bc
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq -0x480(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x2c04
leaq -0xf8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
callq 0x2040
movq %rax, %rbx
leaq -0x800(%rbp), %rdi
leaq -0x480(%rbp), %rsi
callq 0x6722
leaq -0x800(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x59a6
leaq -0x800(%rbp), %rdi
callq 0x67b6
callq 0x2040
movq %rax, %r14
movq 0x7b6c(%rip), %rdi      # 0xcfc8
leaq 0x2d62(%rip), %rsi      # 0x81c5
callq 0x21d0
movq %rax, %rdi
subq %rbx, %r14
movl $0x3b9aca00, %ecx       # imm = 0x3B9ACA00
movq %r14, %rax
cqto
idivq %rcx
movq %rax, %rsi
callq 0x21c0
leaq 0x2d32(%rip), %rsi      # 0x81bc
movq %rax, %rdi
callq 0x21d0
movq %rax, %rdi
callq 0x2100
leaq -0x100(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x5a8f
leaq -0x100(%rbp), %rdi
callq 0x6976
leaq -0x480(%rbp), %rdi
callq 0x67b6
leaq -0x30(%rbp), %rdi
callq 0x474e
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0x70(%rbp), %rdi
callq 0x20f0
leaq -0x90(%rbp), %rdi
callq 0x20f0
leaq -0xb0(%rbp), %rdi
callq 0x20f0
leaq -0xd0(%rbp), %rdi
callq 0x20f0
xorl %eax, %eax
addq $0x7d8, %rsp            # imm = 0x7D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0xd0(%rbp), %rdi
callq 0x55d0
leaq -0x480(%rbp), %rdi
callq 0x20f0
jmp 0x54cf
jmp 0x557e
movq %rax, %rbx
leaq -0x800(%rbp), %rdi
callq 0x67b6
jmp 0x555b
jmp 0x5558
jmp 0x5553
jmp 0x558f
jmp 0x558f
movq %rax, %rbx
jmp 0x55bc
movq %rax, %rbx
jmp 0x5573
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
callq 0x6976
leaq -0x480(%rbp), %rdi
callq 0x67b6
leaq -0x30(%rbp), %rdi
callq 0x474e
jmp 0x5592
movq %rax, %rbx
leaq -0x480(%rbp), %rdi
callq 0x20f0
jmp 0x5592
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x20f0
leaq -0x70(%rbp), %rdi
callq 0x20f0
leaq -0x90(%rbp), %rdi
callq 0x20f0
leaq -0xb0(%rbp), %rdi
callq 0x20f0
leaq -0xd0(%rbp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2330