// File: nachogoro[P]wordcrack-herminia/src/main.cpp
// Function: writeResultsToOutputFiles(std::map<Word, int, std::less<Word>, std::allocator<std::pair<Word const, int>>>&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void writeResultsToOutputFiles(
        std::map<Word,int>& foundWords,
        const std::string& outFileWords,
        const std::string& outFileCoords)
{
    // Sort results by score
    std::vector<std::pair<Word, int> > pairs;
    for (auto itr = foundWords.begin(); itr != foundWords.end(); ++itr) {
        pairs.push_back(*itr);
    }

    sort(pairs.begin(), pairs.end(), [=](const std::pair<Word, int>& a, const std::pair<Word, int>& b)
            {
            return a.second > b.second;
            }
        );

    std::ofstream wordOutput(outFileWords);
    std::ofstream coordOutput(outFileCoords);
    for (auto it = pairs.begin(); it != pairs.end(); ++it) {
        wordOutput << it->first.currentWord() << " " << it->second << std::endl;
        coordOutput << it->first.generateScreenCoords() << std::endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5d0, %rsp            # imm = 0x5D0
movq %rdi, -0x5a8(%rbp)
movq %rsi, -0x5a0(%rbp)
movq %rdx, -0x598(%rbp)
callq 0x31c0
movq -0x5a8(%rbp), %rdi
movq -0x5a0(%rbp), %rsi
movq -0x598(%rbp), %rdx
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x11720
movq -0x8(%rbp), %rdi
callq 0x11220
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
callq 0x11290
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x11250
testb $0x1, %al
jne 0xea9c
jmp 0xeb19
leaq -0x38(%rbp), %rdi
callq 0x11790
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x117c0
jmp 0xeab6
leaq -0x30(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x11750
jmp 0xeac8
leaq -0x118(%rbp), %rdi
callq 0x11470
leaq -0x38(%rbp), %rdi
callq 0x112f0
jmp 0xea7c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0xed77
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x11470
jmp 0xed77
leaq -0x30(%rbp), %rdi
movq %rdi, -0x5b0(%rbp)
callq 0x11810
movq -0x5b0(%rbp), %rdi
movq %rax, -0x130(%rbp)
callq 0x11840
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0xf810
jmp 0xeb58
movq -0x10(%rbp), %rsi
leaq -0x340(%rbp), %rdi
movl $0x10, %edx
callq 0x3450
jmp 0xeb6f
movq -0x18(%rbp), %rsi
leaq -0x540(%rbp), %rdi
movl $0x10, %edx
callq 0x3450
jmp 0xeb86
leaq -0x30(%rbp), %rdi
callq 0x11810
movq %rax, -0x548(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x11840
movq %rax, -0x550(%rbp)
leaq -0x548(%rbp), %rdi
leaq -0x550(%rbp), %rsi
callq 0x11880
testb $0x1, %al
jne 0xebc2
jmp 0xed35
leaq -0x548(%rbp), %rdi
callq 0x118e0
movq %rax, %rsi
leaq -0x570(%rbp), %rdi
callq 0x5490
jmp 0xebdf
leaq -0x340(%rbp), %rdi
leaq -0x570(%rbp), %rsi
callq 0x31f0
movq %rax, -0x5b8(%rbp)
jmp 0xebfb
movq -0x5b8(%rbp), %rdi
leaq 0x85e2(%rip), %rsi      # 0x171eb
callq 0x3220
movq %rax, -0x5c0(%rbp)
jmp 0xec17
leaq -0x548(%rbp), %rdi
callq 0x118e0
movq -0x5c0(%rbp), %rdi
movl 0xd0(%rax), %esi
callq 0x33e0
movq %rax, -0x5c8(%rbp)
jmp 0xec3e
movq -0x5c8(%rbp), %rdi
movq 0x11364(%rip), %rsi     # 0x1ffb0
callq 0x3260
jmp 0xec53
leaq -0x570(%rbp), %rdi
callq 0x3150
leaq -0x548(%rbp), %rdi
callq 0x118e0
movq %rax, %rsi
leaq -0x590(%rbp), %rdi
callq 0x3f40
jmp 0xec7c
leaq -0x540(%rbp), %rdi
leaq -0x590(%rbp), %rsi
callq 0x31f0
movq %rax, -0x5d0(%rbp)
jmp 0xec98
movq -0x5d0(%rbp), %rdi
movq 0x1130a(%rip), %rsi     # 0x1ffb0
callq 0x3260
jmp 0xecad
leaq -0x590(%rbp), %rdi
callq 0x3150
leaq -0x548(%rbp), %rdi
callq 0x11910
jmp 0xeb96
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0xed6b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
jmp 0xed5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x570(%rbp), %rdi
callq 0x3150
jmp 0xed5f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x120(%rbp)
movl %eax, -0x124(%rbp)
leaq -0x590(%rbp), %rdi
callq 0x3150
jmp 0xed5f
leaq -0x540(%rbp), %rdi
callq 0x3330
leaq -0x340(%rbp), %rdi
callq 0x3330
leaq -0x30(%rbp), %rdi
callq 0x11940
addq $0x5d0, %rsp            # imm = 0x5D0
popq %rbp
retq
leaq -0x540(%rbp), %rdi
callq 0x3330
leaq -0x340(%rbp), %rdi
callq 0x3330
leaq -0x30(%rbp), %rdi
callq 0x11940
movq -0x120(%rbp), %rdi
callq 0x33f0
nopl (%rax)