// File: 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
subq $0x920, %rsp            # imm = 0x920
movl %edi, -0x89c(%rbp)
movq %rsi, -0x898(%rbp)
callq 0x31c0
movl -0x89c(%rbp), %edi
movq -0x898(%rbp), %rsi
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x890(%rbp)
leaq -0x31(%rbp), %rdi
movq %rdi, -0x888(%rbp)
callq 0x3400
movq -0x890(%rbp), %rsi
movq -0x888(%rbp), %rdx
leaq -0x30(%rbp), %rdi
callq 0x32f0
jmp 0xda8f
leaq -0x31(%rbp), %rdi
callq 0x3270
cmpl $0x9, -0x8(%rbp)
je 0xdae7
leaq -0x30(%rbp), %rdi
callq 0xe0d0
jmp 0xdaa9
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xe012
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x31(%rbp), %rdi
callq 0x3270
jmp 0xe0c3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe0ba
leaq -0x68(%rbp), %rdi
callq 0x3300
leaq -0x88(%rbp), %rdi
callq 0x3300
leaq -0xa8(%rbp), %rdi
callq 0x3300
leaq -0xc8(%rbp), %rdi
callq 0x3300
movl $0x1, -0xcc(%rbp)
cmpl $0x7, -0xcc(%rbp)
jg 0xdd2c
movq -0x10(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x8b0(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x8a8(%rbp)
callq 0x3400
movq -0x8b0(%rbp), %rsi
movq -0x8a8(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x32f0
jmp 0xdb70
leaq -0xf1(%rbp), %rdi
callq 0x3270
leaq 0x9609(%rip), %rsi      # 0x1718c
leaq -0xf0(%rbp), %rdi
callq 0x5580
movb %al, -0x8b1(%rbp)
jmp 0xdb97
movb -0x8b1(%rbp), %al
testb $0x1, %al
jne 0xdba3
jmp 0xdbfd
movq -0x10(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x68(%rbp), %rdi
callq 0x32e0
jmp 0xdbbe
jmp 0xdcf6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf1(%rbp), %rdi
callq 0x3270
jmp 0xe08d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3150
jmp 0xe08d
leaq 0x958f(%rip), %rsi      # 0x17193
leaq -0xf0(%rbp), %rdi
callq 0x5580
movb %al, -0x8b2(%rbp)
jmp 0xdc18
movb -0x8b2(%rbp), %al
testb $0x1, %al
jne 0xdc24
jmp 0xdc47
movq -0x10(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x88(%rbp), %rdi
callq 0x32e0
jmp 0xdc42
jmp 0xdcf4
leaq 0x954d(%rip), %rsi      # 0x1719b
leaq -0xf0(%rbp), %rdi
callq 0x5580
movb %al, -0x8b3(%rbp)
jmp 0xdc62
movb -0x8b3(%rbp), %al
testb $0x1, %al
jne 0xdc6e
jmp 0xdc8e
movq -0x10(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x32e0
jmp 0xdc8c
jmp 0xdcf2
leaq 0x9511(%rip), %rsi      # 0x171a6
leaq -0xf0(%rbp), %rdi
callq 0x5580
movb %al, -0x8b4(%rbp)
jmp 0xdca9
movb -0x8b4(%rbp), %al
testb $0x1, %al
jne 0xdcb5
jmp 0xdcd5
movq -0x10(%rbp), %rax
movslq -0xcc(%rbp), %rcx
movq 0x8(%rax,%rcx,8), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x32e0
jmp 0xdcd3
jmp 0xdcf0
leaq -0x30(%rbp), %rdi
callq 0xe0d0
jmp 0xdce0
movl $0x0, -0x4(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0xdcfd
jmp 0xdcf2
jmp 0xdcf4
jmp 0xdcf6
movl $0x0, -0x48(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x3150
movl -0x48(%rbp), %eax
testl %eax, %eax
jne 0xdfe5
jmp 0xdd16
jmp 0xdd18
movl -0xcc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xcc(%rbp)
jmp 0xdb1e
leaq -0x68(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
leaq -0xc8(%rbp), %rcx
callq 0xe2f0
jmp 0xdd4c
callq 0x3040
movq %rax, -0x100(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xa4e0
jmp 0xdd6a
callq 0x3040
movq %rax, -0x110(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x10de0
movq %rax, -0x8c0(%rbp)
jmp 0xdd92
movq -0x8c0(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x10db0
movq %rax, -0x8c8(%rbp)
jmp 0xddb5
movq -0x8c8(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x10e40
movq %rax, -0x8d0(%rbp)
jmp 0xddd8
movq -0x8d0(%rbp), %rax
movq %rax, -0x118(%rbp)
movq 0x121db(%rip), %rdi     # 0x1ffc8
leaq 0x93be(%rip), %rsi      # 0x171b2
callq 0x3220
movq %rax, -0x8d8(%rbp)
jmp 0xde02
movq -0x8d8(%rbp), %rdi
movq -0x118(%rbp), %rsi
callq 0x3410
movq %rax, -0x8e0(%rbp)
jmp 0xde1e
movq -0x8e0(%rbp), %rdi
leaq 0x939c(%rip), %rsi      # 0x171c8
callq 0x3220
movq %rax, -0x8e8(%rbp)
jmp 0xde3a
movq -0x8e8(%rbp), %rdi
movq 0x12168(%rip), %rsi     # 0x1ffb0
callq 0x3260
jmp 0xde4f
leaq -0x4a8(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x4250
jmp 0xde64
leaq -0x4d8(%rbp), %rdi
callq 0x10e70
callq 0x3040
movq %rax, -0x4e0(%rbp)
leaq -0x860(%rbp), %rdi
leaq -0x4a8(%rbp), %rsi
callq 0x10ea0
jmp 0xde91
leaq -0x860(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x4d8(%rbp), %rdx
callq 0xe870
jmp 0xdead
leaq -0x860(%rbp), %rdi
callq 0x10fb0
callq 0x3040
movq %rax, -0x868(%rbp)
leaq -0x868(%rbp), %rdi
leaq -0x4e0(%rbp), %rsi
callq 0x10de0
movq %rax, -0x8f0(%rbp)
jmp 0xdee1
movq -0x8f0(%rbp), %rax
movq %rax, -0x880(%rbp)
leaq -0x880(%rbp), %rdi
callq 0x10db0
movq %rax, -0x8f8(%rbp)
jmp 0xdf04
movq -0x8f8(%rbp), %rax
movq %rax, -0x878(%rbp)
leaq -0x878(%rbp), %rdi
callq 0x10e40
movq %rax, -0x900(%rbp)
jmp 0xdf27
movq -0x900(%rbp), %rax
movq %rax, -0x870(%rbp)
movq 0x1208c(%rip), %rdi     # 0x1ffc8
leaq 0x928e(%rip), %rsi      # 0x171d1
callq 0x3220
movq %rax, -0x908(%rbp)
jmp 0xdf51
movq -0x908(%rbp), %rdi
movq -0x870(%rbp), %rsi
callq 0x3410
movq %rax, -0x910(%rbp)
jmp 0xdf6d
movq -0x910(%rbp), %rdi
leaq 0x924d(%rip), %rsi      # 0x171c8
callq 0x3220
movq %rax, -0x918(%rbp)
jmp 0xdf89
movq -0x918(%rbp), %rdi
movq 0x12019(%rip), %rsi     # 0x1ffb0
callq 0x3260
jmp 0xdf9e
leaq -0x4d8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0xea20
jmp 0xdfba
leaq -0x4d8(%rbp), %rdi
callq 0x11010
leaq -0x4a8(%rbp), %rdi
callq 0x10fb0
leaq -0x108(%rbp), %rdi
callq 0x11040
movl $0x0, -0x48(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3150
leaq -0xa8(%rbp), %rdi
callq 0x3150
leaq -0x88(%rbp), %rdi
callq 0x3150
leaq -0x68(%rbp), %rdi
callq 0x3150
leaq -0x30(%rbp), %rdi
callq 0x3150
movl -0x4(%rbp), %eax
addq $0x920, %rsp            # imm = 0x920
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe08d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe081
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0xe069
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x860(%rbp), %rdi
callq 0x10fb0
leaq -0x4d8(%rbp), %rdi
callq 0x11010
leaq -0x4a8(%rbp), %rdi
callq 0x10fb0
leaq -0x108(%rbp), %rdi
callq 0x11040
leaq -0xc8(%rbp), %rdi
callq 0x3150
leaq -0xa8(%rbp), %rdi
callq 0x3150
leaq -0x88(%rbp), %rdi
callq 0x3150
leaq -0x68(%rbp), %rdi
callq 0x3150
leaq -0x30(%rbp), %rdi
callq 0x3150
movq -0x40(%rbp), %rdi
callq 0x33f0
nopl (%rax)