// File: dlbeer[P]summary_map/test_sum.cpp
// Function: main
int main(int argc, char **argv)
{
    const char *path = "/usr/share/dict/words";

    if (argc > 1)
	path = argv[1];

    std::cout << "Loading words from " << path << '\n';

    test_vector vec;
    std::vector<int> series;
    std::mt19937 rnd;
    test_map m;

    load_words(path, vec);
    assert(vec.size() >= 1000);
    std::cout << "Working with " << vec.size() << " items\n";

    std::sort(vec.begin(), vec.end());
    rnd.seed(5);

    int all_sum = 0;

    for (unsigned int i = 0; i < vec.size(); i++) {
	all_sum += vec[i].second;
	series.push_back(all_sum);
    }

    std::cout << "Inserting...\n";

    for (unsigned int i = 0; i < vec.size(); i++) {
	m.insert(vec[i]);
	range_test(rnd, m, vec, series, i + 1);
	assert(m.sum().sum == series[i]);
    }

    std::cout << "Sum: " << m.sum().sum << '\n';

    std::cout << "Removing...\n";

    for (int i = vec.size() - 1; i >= 0; i--) {
	assert(m.sum().sum == series[i]);
	m.erase(vec[i].first);
	range_test(rnd, m, vec, series, i);
    }

    assert(m.sum().sum == 0);
    return 0;
}

// Assembly:
subq $0x1518, %rsp           # imm = 0x1518
movl $0x0, 0x1514(%rsp)
movl %edi, 0x1510(%rsp)
movq %rsi, 0x1508(%rsp)
leaq 0x6c5c(%rip), %rax      # 0x9004
movq %rax, 0x1500(%rsp)
cmpl $0x1, 0x1510(%rsp)
jle 0x23ce
movq 0x1508(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x1500(%rsp)
movq 0xac03(%rip), %rdi      # 0xcfd8
leaq 0x6c3e(%rip), %rsi      # 0x901a
callq 0x2130
movq %rax, %rdi
movq 0x1500(%rsp), %rsi
callq 0x2130
movq %rax, %rdi
movl $0xa, %esi
callq 0x2160
leaq 0x14e8(%rsp), %rdi
callq 0x2b80
leaq 0x14d0(%rsp), %rdi
callq 0x2b90
leaq 0x148(%rsp), %rdi
callq 0x2ba0
jmp 0x2427
leaq 0xe0(%rsp), %rdi
callq 0x2bc0
jmp 0x2436
movq 0x1500(%rsp), %rdi
leaq 0x14e8(%rsp), %rsi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x75b0
jmp 0x2452
leaq 0x14e8(%rsp), %rdi
callq 0x2c30
cmpq $0x3e8, %rax            # imm = 0x3E8
jb 0x2469
jmp 0x24ba
leaq 0x6bbe(%rip), %rdi      # 0x902e
leaq 0x6bca(%rip), %rsi      # 0x9041
movl $0x3e, %edx
leaq 0x6bcb(%rip), %rcx      # 0x904e
callq 0x20e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x296c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
jmp 0x295f
movq 0xab17(%rip), %rdi      # 0xcfd8
leaq 0x6b9d(%rip), %rsi      # 0x9065
callq 0x2130
movq %rax, 0x68(%rsp)
jmp 0x24d4
leaq 0x14e8(%rsp), %rdi
callq 0x2c30
movq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x2040
movq %rax, 0x60(%rsp)
jmp 0x24f5
movq 0x60(%rsp), %rdi
leaq 0x6b72(%rip), %rsi      # 0x9073
callq 0x2130
jmp 0x2508
leaq 0x14e8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x2c90
movq 0x58(%rsp), %rdi
movq %rax, 0xd8(%rsp)
callq 0x2cc0
movq %rax, 0xd0(%rsp)
movq 0xd8(%rsp), %rdi
movq 0xd0(%rsp), %rsi
callq 0x2c50
jmp 0x254b
leaq 0x148(%rsp), %rdi
movl $0x5, %esi
callq 0x2cf0
jmp 0x255f
movl $0x0, 0xcc(%rsp)
movl $0x0, 0xc8(%rsp)
movl 0xc8(%rsp), %eax
movq %rax, 0x50(%rsp)
leaq 0x14e8(%rsp), %rdi
callq 0x2c30
movq %rax, %rcx
movq 0x50(%rsp), %rax
cmpq %rcx, %rax
jae 0x25f0
movl 0xc8(%rsp), %eax
movl %eax, %esi
leaq 0x14e8(%rsp), %rdi
callq 0x2dc0
movl 0x20(%rax), %ecx
movl 0xcc(%rsp), %eax
addl %ecx, %eax
movl %eax, 0xcc(%rsp)
leaq 0x14d0(%rsp), %rdi
leaq 0xcc(%rsp), %rsi
callq 0x2de0
jmp 0x25db
jmp 0x25dd
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x2575
movq 0xa9e1(%rip), %rdi      # 0xcfd8
leaq 0x6a7d(%rip), %rsi      # 0x907b
callq 0x2130
jmp 0x2605
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
movq %rax, 0x48(%rsp)
leaq 0x14e8(%rsp), %rdi
callq 0x2c30
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0x2782
movl 0xc4(%rsp), %eax
movl %eax, %esi
leaq 0x14e8(%rsp), %rdi
callq 0x2dc0
movq %rax, %rsi
leaq 0x98(%rsp), %rdi
callq 0x2f00
jmp 0x2662
leaq 0xe0(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x2e50
movb %dl, 0x3f(%rsp)
movq %rax, 0x40(%rsp)
jmp 0x2682
movb 0x3f(%rsp), %al
movq 0x40(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movb %al, 0x90(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x2f40
movl 0xc4(%rsp), %r8d
incl %r8d
leaq 0x148(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x14e8(%rsp), %rdx
leaq 0x14d0(%rsp), %rcx
callq 0x29a0
jmp 0x26d9
leaq 0xe0(%rsp), %rdi
callq 0x2f50
movl %eax, 0x38(%rsp)
jmp 0x26ec
movl 0x38(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x84(%rsp), %eax
movl %eax, 0x34(%rsp)
movl 0xc4(%rsp), %eax
movl %eax, %esi
leaq 0x14d0(%rsp), %rdi
callq 0x2f80
movq %rax, %rcx
movl 0x34(%rsp), %eax
cmpl (%rcx), %eax
jne 0x2725
jmp 0x276a
leaq 0x695d(%rip), %rdi      # 0x9089
leaq 0x690e(%rip), %rsi      # 0x9041
movl $0x50, %edx
leaq 0x690f(%rip), %rcx      # 0x904e
callq 0x20e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x140(%rsp)
movl %eax, 0x13c(%rsp)
leaq 0x98(%rsp), %rdi
callq 0x2f40
jmp 0x295f
jmp 0x276c
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x2610
movq 0xa84f(%rip), %rdi      # 0xcfd8
leaq 0x6912(%rip), %rsi      # 0x90a2
callq 0x2130
movq %rax, 0x28(%rsp)
jmp 0x279c
leaq 0xe0(%rsp), %rdi
callq 0x2f50
movl %eax, 0x24(%rsp)
jmp 0x27af
movq 0x28(%rsp), %rdi
movl 0x24(%rsp), %eax
movl %eax, 0x80(%rsp)
movl 0x80(%rsp), %esi
callq 0x21f0
movq %rax, 0x18(%rsp)
jmp 0x27d2
movq 0x18(%rsp), %rdi
movl $0xa, %esi
callq 0x2160
jmp 0x27e3
movq 0xa7ee(%rip), %rdi      # 0xcfd8
leaq 0x68b7(%rip), %rsi      # 0x90a8
callq 0x2130
jmp 0x27f8
leaq 0x14e8(%rsp), %rdi
callq 0x2c30
subq $0x1, %rax
movl %eax, 0x7c(%rsp)
cmpl $0x0, 0x7c(%rsp)
jl 0x28db
leaq 0xe0(%rsp), %rdi
callq 0x2f50
movl %eax, 0x14(%rsp)
jmp 0x282b
movl 0x14(%rsp), %eax
movl %eax, 0x78(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x10(%rsp)
movslq 0x7c(%rsp), %rsi
leaq 0x14d0(%rsp), %rdi
callq 0x2f80
movq %rax, %rcx
movl 0x10(%rsp), %eax
cmpl (%rcx), %eax
jne 0x285a
jmp 0x2879
leaq 0x6828(%rip), %rdi      # 0x9089
leaq 0x67d9(%rip), %rsi      # 0x9041
movl $0x58, %edx
leaq 0x67da(%rip), %rcx      # 0x904e
callq 0x20e0
movslq 0x7c(%rsp), %rsi
leaq 0x14e8(%rsp), %rdi
callq 0x2dc0
movq %rax, %rsi
leaq 0xe0(%rsp), %rdi
callq 0x2fa0
jmp 0x289d
movl 0x7c(%rsp), %r8d
leaq 0x148(%rsp), %rdi
leaq 0xe0(%rsp), %rsi
leaq 0x14e8(%rsp), %rdx
leaq 0x14d0(%rsp), %rcx
callq 0x29a0
jmp 0x28c9
jmp 0x28cb
movl 0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x7c(%rsp)
jmp 0x280d
leaq 0xe0(%rsp), %rdi
callq 0x2f50
movl %eax, 0xc(%rsp)
jmp 0x28ee
movl 0xc(%rsp), %eax
movl %eax, 0x74(%rsp)
cmpl $0x0, 0x74(%rsp)
jne 0x28ff
jmp 0x291e
leaq 0x67af(%rip), %rdi      # 0x90b5
leaq 0x6734(%rip), %rsi      # 0x9041
movl $0x5d, %edx
leaq 0x6735(%rip), %rcx      # 0x904e
callq 0x20e0
movl $0x0, 0x1514(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x3020
leaq 0x14d0(%rsp), %rdi
callq 0x3070
leaq 0x14e8(%rsp), %rdi
callq 0x30d0
movl 0x1514(%rsp), %eax
addq $0x1518, %rsp           # imm = 0x1518
retq
leaq 0xe0(%rsp), %rdi
callq 0x3020
leaq 0x14d0(%rsp), %rdi
callq 0x3070
leaq 0x14e8(%rsp), %rdi
callq 0x30d0
movq 0x140(%rsp), %rdi
callq 0x2200
nopw %cs:(%rax,%rax)