// File: ALSchwalm[P]entrospy/entrospy/graph.cpp
// Function: operator<<(std::ostream&, EntropyGraph const&)
std::ostream& operator<<(std::ostream& out, const EntropyGraph& graph) {
    out << boost::format("set term qt noenhanced size 1024, 768\n"
                         "set title '%1%'\n"
                         "set grid\n"
                         "set xlabel 'address'\n"
                         "set ylabel 'entropy'\n"
                         "set xtics rotate by -30\n"
                         "set format x '%%.0f'\n"
                         "set style line 1 lc rgb '#A0A0A0' lt 0 lw 2\n"
                         "set grid back ls 1\n") %
               graph.m_title;

    std::vector<std::string> points_cfg;
    uint64_t max_file_size = 0;
    for (const auto& pv : graph.m_scores) {
        const auto& path = pv.first;
        auto file_size = boost::filesystem::file_size(path);
        if (file_size > max_file_size) {
            max_file_size = file_size;
        }

        std::string p =
            boost::str(boost::format("'-' title '%1%' with points") % path);
        points_cfg.emplace_back(p);
    }

    out << boost::format("plot [0:%1%] [0:1] %2%") % max_file_size %
               boost::algorithm::join(points_cfg, ", ");
    out << "\n";

    for (const auto& pv : graph.m_scores) {
        const auto& scores = pv.second;
        for (const auto& score : scores) {
            auto position = score.first;
            double value = score.second;

            out << position << " " << value << "\n";
        }
        out << "e\n";
    }
    out << "quit\n";
    return out;
}

// Assembly:
subq $0x448, %rsp            # imm = 0x448
movq %rdi, 0x440(%rsp)
movq %rsi, 0x438(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0x99ba(%rip), %rsi      # 0x382b5
leaq 0x358(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xd940
movq 0x68(%rsp), %rdi
movq 0x438(%rsp), %rsi
callq 0xdaf0
movq %rax, 0x70(%rsp)
jmp 0x2e926
movq 0x70(%rsp), %rsi
movq 0x60(%rsp), %rdi
callq 0x2f0c0
jmp 0x2e937
leaq 0x358(%rsp), %rdi
callq 0xdea0
leaq 0x330(%rsp), %rdi
callq 0xd380
movq $0x0, 0x328(%rsp)
movq 0x438(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x320(%rsp)
movq 0x320(%rsp), %rdi
callq 0x2f290
movq %rax, 0x318(%rsp)
movq 0x320(%rsp), %rdi
callq 0x2f2c0
movq %rax, 0x310(%rsp)
leaq 0x318(%rsp), %rdi
leaq 0x310(%rsp), %rsi
callq 0x2f2f0
testb $0x1, %al
jne 0x2e9b9
jmp 0x2eb81
leaq 0x318(%rsp), %rdi
callq 0x2f310
movq %rax, 0x308(%rsp)
movq 0x308(%rsp), %rax
movq %rax, 0x300(%rsp)
movq 0x300(%rsp), %rsi
leaq 0x2d8(%rsp), %rdi
callq 0xe010
jmp 0x2e9f5
leaq 0x2d8(%rsp), %rdi
callq 0x2f330
movq %rax, 0x58(%rsp)
jmp 0x2ea09
leaq 0x2d8(%rsp), %rdi
callq 0xd290
movq 0x58(%rsp), %rax
movq %rax, 0x2f8(%rsp)
movq 0x2f8(%rsp), %rax
cmpq 0x328(%rsp), %rax
jbe 0x2eaac
movq 0x2f8(%rsp), %rax
movq %rax, 0x328(%rsp)
jmp 0x2eaac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x358(%rsp), %rdi
callq 0xdea0
jmp 0x2ee97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x2ee8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x2d8(%rsp), %rdi
callq 0xd290
jmp 0x2ee8a
leaq 0x98d8(%rip), %rsi      # 0x3838b
leaq 0x1d8(%rsp), %rdi
callq 0xd940
jmp 0x2eac2
movq 0x300(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
callq 0xdaf0
movq %rax, 0x50(%rsp)
jmp 0x2eade
movq 0x50(%rsp), %rsi
leaq 0x2b8(%rsp), %rdi
callq 0xdf00
jmp 0x2eaf2
leaq 0x1d8(%rsp), %rdi
callq 0xdea0
leaq 0x330(%rsp), %rdi
leaq 0x2b8(%rsp), %rsi
callq 0x2f350
jmp 0x2eb16
leaq 0x2b8(%rsp), %rdi
callq 0xab18
leaq 0x318(%rsp), %rdi
callq 0x2f3c0
jmp 0x2e99b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0xdea0
jmp 0x2ee8a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0x2b8(%rsp), %rdi
callq 0xab18
jmp 0x2ee8a
movq 0x440(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x9812(%rip), %rsi      # 0x383a7
leaq 0xf8(%rsp), %rdi
callq 0xd940
jmp 0x2eba4
leaq 0xf8(%rsp), %rdi
leaq 0x328(%rsp), %rsi
callq 0xdd10
movq %rax, 0x40(%rsp)
jmp 0x2ebc0
leaq 0x7c58(%rip), %rdx      # 0x3681f
leaq 0xd8(%rsp), %rdi
leaq 0x330(%rsp), %rsi
callq 0xdb20
jmp 0x2ebde
movq 0x40(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0xdaf0
movq %rax, 0x38(%rsp)
jmp 0x2ebf7
movq 0x38(%rsp), %rsi
movq 0x48(%rsp), %rdi
callq 0x2f0c0
jmp 0x2ec08
leaq 0xd8(%rsp), %rdi
callq 0xab18
leaq 0xf8(%rsp), %rdi
callq 0xdea0
movq 0x440(%rsp), %rdi
leaq 0x9758(%rip), %rsi      # 0x38389
callq 0xa510
jmp 0x2ec38
movq 0x438(%rsp), %rax
addq $0x48, %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x2f290
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x2f2c0
movq %rax, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x2f2f0
testb $0x1, %al
jne 0x2ec94
jmp 0x2ee4d
leaq 0xc8(%rsp), %rdi
callq 0x2f310
movq %rax, 0xb8(%rsp)
movq 0xb8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x2f3f0
movq %rax, 0xa0(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x2f420
movq %rax, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x2f450
testb $0x1, %al
jne 0x2ed15
jmp 0x2ee23
leaq 0xa0(%rsp), %rdi
callq 0x2f490
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rax
movups (%rax), %xmm0
movaps %xmm0, 0x80(%rsp)
movq 0x90(%rsp), %rax
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x11b70
movq %rax, 0x30(%rsp)
jmp 0x2ed71
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0xaa10
movq %rax, 0x20(%rsp)
jmp 0x2ed87
movq 0x20(%rsp), %rdi
leaq 0x9857(%rip), %rsi      # 0x385ea
callq 0xa510
movq %rax, 0x18(%rsp)
jmp 0x2ed9f
movq 0x18(%rsp), %rdi
movsd 0x78(%rsp), %xmm0
callq 0xaa90
movq %rax, 0x10(%rsp)
jmp 0x2edb6
movq 0x10(%rsp), %rdi
leaq 0x95c7(%rip), %rsi      # 0x38389
callq 0xa510
jmp 0x2edc9
jmp 0x2edcb
leaq 0xa0(%rsp), %rdi
callq 0x2f4a0
jmp 0x2ecf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
jmp 0x2ee14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x350(%rsp)
movl %eax, 0x34c(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0xab18
leaq 0xf8(%rsp), %rdi
callq 0xdea0
jmp 0x2ee8a
movq 0x440(%rsp), %rdi
leaq 0x958c(%rip), %rsi      # 0x383be
callq 0xa510
jmp 0x2ee39
jmp 0x2ee3b
leaq 0xc8(%rsp), %rdi
callq 0x2f3c0
jmp 0x2ec76
movq 0x440(%rsp), %rdi
leaq 0x9565(%rip), %rsi      # 0x383c1
callq 0xa510
jmp 0x2ee63
movq 0x440(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x330(%rsp), %rdi
callq 0xe280
movq 0x8(%rsp), %rax
addq $0x448, %rsp            # imm = 0x448
retq
leaq 0x330(%rsp), %rdi
callq 0xe280
movq 0x350(%rsp), %rdi
callq 0xa9b0
nopw %cs:(%rax,%rax)