// File: /workspace/github_cpp_makefile_star2_O1/yoavweiss[P]cache-digests-cuckoo/cuckoo_test.cpp
// Function: main
int main() {
    const unsigned MaxCount = 500;
    const unsigned DigestSize = 1021;
    const unsigned URLNumber = 3250;

    // Create a digest
    Cuckoo cuckoo(8, DigestSize, MaxCount);

    // Run a set of sanity tests
    cuckoo.runTests();

    unsigned char* digest = cuckoo.getDigest();
    size_t digestSize = cuckoo.getDigestSize();

    std::vector<std::string> urls;
    for (int i = 0; i < URLNumber; ++i) {
        urls.push_back(std::to_string(i));
    }
    unsigned minmaxcount = 500;
    for (auto& url : urls) {
        unsigned maxcount = cuckoo.add(url, std::string());
        if (maxcount < minmaxcount)
            minmaxcount = maxcount;
    }
    printf("Maximum cucko pushes %u\n", MaxCount - minmaxcount);

    // Write the digest to disk
    std::ofstream outfile;
    outfile.open("digest.bin", std::ios::binary);
    if (outfile.is_open()) {
        outfile.write((const char*)cuckoo.getDigest(), cuckoo.getDigestSize());
        outfile.close();
    }

    // See if the URLs are in the digest
    for (auto& url : urls) {
        if (!cuckoo.query(url, std::string()))
            printf("FAIL - %s is not in the digest\n", url.c_str());
    }
    if (cuckoo.query("blabla", std::string()))
        printf("FAIL - blabla should not be in the digest\n");

    // Remove from the digest
    for (auto& url : urls) {
        cuckoo.remove(url, std::string());
    }
    // Make sure that the URLs are no longer in the digest
    for (auto& url : urls) {
        if (cuckoo.query(url, std::string()))
            printf("FAIL - %s is still in the digest\n", url.c_str());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x378, %rsp            # imm = 0x378
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movl $0x8, %esi
movl $0x3fd, %edx            # imm = 0x3FD
movl $0x1f4, %ecx            # imm = 0x1F4
callq 0x23ec
movq %rbx, %rdi
callq 0x3378
xorps %xmm0, %xmm0
leaq -0x40(%rbp), %rbx
movaps %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
xorl %r14d, %r14d
leaq -0x390(%rbp), %r13
leaq -0x3a0(%rbp), %r15
movl $0x1, %r12d
cmpl $0xa, %r14d
jb 0x3b37
movl $0x2, %r12d
cmpl $0x64, %r14d
jb 0x3b37
cmpl $0x3e8, %r14d           # imm = 0x3E8
movl $0x4, %r12d
sbbl $0x0, %r12d
movl %r12d, %esi
movq %r13, -0x3a0(%rbp)
movq %r15, %rdi
movl $0x2d, %edx
callq 0x21e0
movq -0x3a0(%rbp), %rdi
movl %r12d, %esi
movl %r14d, %edx
callq 0x40fe
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4170
movq -0x3a0(%rbp), %rdi
cmpq %r13, %rdi
je 0x3b7c
callq 0x21c0
incl %r14d
cmpl $0xcb2, %r14d           # imm = 0xCB2
jne 0x3b0e
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq %rax, %r14
je 0x3c3f
movl $0x1f4, %r13d           # imm = 0x1F4
leaq -0x70(%rbp), %r12
leaq -0x140(%rbp), %rbx
leaq -0x130(%rbp), %rax
movq %rax, -0x140(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3980
movq %r12, -0x80(%rbp)
movq $0x0, -0x78(%rbp)
movb $0x0, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %r15
movq %rbx, %rsi
leaq -0x80(%rbp), %rdx
callq 0x250a
movl %eax, %ebx
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c01
callq 0x21c0
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x3c19
callq 0x21c0
cmpl %r13d, %ebx
cmovbl %ebx, %r13d
addq $0x20, %r14
cmpq -0x60(%rbp), %r14
leaq -0x70(%rbp), %r12
movq %r15, %rbx
jne 0x3bae
movl $0x1f4, %esi            # imm = 0x1F4
subl %r13d, %esi
jmp 0x3c41
xorl %esi, %esi
leaq 0x1709(%rip), %rdi      # 0x5351
xorl %eax, %eax
callq 0x2040
leaq -0x3a0(%rbp), %rdi
callq 0x2270
leaq 0x1708(%rip), %rsi      # 0x536a
leaq -0x3a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2050
leaq -0x330(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x3ca3
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
leaq -0x3a0(%rbp), %rdi
callq 0x2200
leaq -0x3a0(%rbp), %rdi
callq 0x2210
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x3d5d
leaq -0xf0(%rbp), %r12
leaq -0x120(%rbp), %rbx
leaq -0x110(%rbp), %rax
movq %rax, -0x120(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3980
movq %r12, -0x100(%rbp)
movq $0x0, -0xf8(%rbp)
movb $0x0, -0xf0(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0x100(%rbp), %rdx
callq 0x307e
movl %eax, %r13d
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x3d22
callq 0x21c0
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x3d3a
callq 0x21c0
testb %r13b, %r13b
jne 0x3d50
movq (%r14), %rsi
leaq 0x162c(%rip), %rdi      # 0x5375
xorl %eax, %eax
callq 0x2040
addq $0x20, %r14
cmpq %r15, %r14
jne 0x3cc2
leaq -0x170(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1626(%rip), %rsi      # 0x5395
leaq 0x1625(%rip), %rdx      # 0x539b
leaq -0x180(%rbp), %rdi
callq 0x3a1a
leaq -0x190(%rbp), %r15
movq %r15, -0x10(%r15)
movq $0x0, -0x8(%r15)
movb $0x0, (%r15)
leaq -0x58(%rbp), %rdi
leaq -0x180(%rbp), %rsi
leaq -0x1a0(%rbp), %rdx
callq 0x307e
movl %eax, %ebx
movq -0x1a0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3dc3
callq 0x21c0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x3dd4
callq 0x21c0
testb %bl, %bl
je 0x3de4
leaq 0x15f9(%rip), %rdi      # 0x53d8
callq 0x2230
movq -0x40(%rbp), %r13
movq -0x38(%rbp), %r14
cmpq %r14, %r13
je 0x3e7b
leaq -0x150(%rbp), %r12
leaq -0xd0(%rbp), %r15
leaq -0x160(%rbp), %rbx
movq %r12, -0x160(%rbp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3980
movq %r15, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
movb $0x0, -0xd0(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0xe0(%rbp), %rdx
callq 0x2db0
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3e61
callq 0x21c0
movq -0x160(%rbp), %rdi
cmpq %r12, %rdi
je 0x3e72
callq 0x21c0
addq $0x20, %r13
cmpq %r14, %r13
jne 0x3e0a
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x3f35
leaq -0x90(%rbp), %r12
leaq -0xc0(%rbp), %rbx
leaq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq (%r14), %rsi
movq 0x8(%r14), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x3980
movq %r12, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movb $0x0, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0xa0(%rbp), %rdx
callq 0x307e
movl %eax, %r13d
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3efa
callq 0x21c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x3f12
callq 0x21c0
testb %r13b, %r13b
je 0x3f28
movq (%r14), %rsi
leaq 0x147b(%rip), %rdi      # 0x539c
xorl %eax, %eax
callq 0x2040
addq $0x20, %r14
cmpq %r15, %r14
jne 0x3e9a
movq 0x30a4(%rip), %rax      # 0x6fe0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq -0x398(%rbp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, -0x3a0(%rbp,%rcx)
callq 0x21a0
leaq -0x2a8(%rbp), %rdi
callq 0x20d0
leaq -0x40(%rbp), %rdi
callq 0x40b0
leaq -0x58(%rbp), %rdi
callq 0x24f6
xorl %eax, %eax
addq $0x378, %rsp            # imm = 0x378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x1a0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3fa5
callq 0x21c0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
jne 0x4041
jmp 0x4046
jmp 0x4015
jmp 0x407c
movq %rax, %rbx
jmp 0x409e
jmp 0x4015
jmp 0x4015
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3fe1
callq 0x21c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x403c
jmp 0x4015
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4007
callq 0x21c0
movq -0x160(%rbp), %rdi
cmpq %r12, %rdi
jne 0x4041
jmp 0x4046
movq %rax, %rbx
jmp 0x4046
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x402e
callq 0x21c0
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x4046
callq 0x21c0
leaq -0x3a0(%rbp), %rdi
callq 0x2220
jmp 0x4095
jmp 0x407c
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x4067
callq 0x21c0
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
jne 0x4090
jmp 0x4095
movq %rax, %rbx
jmp 0x4095
movq %rax, %rbx
movq -0x3a0(%rbp), %rdi
cmpq %r13, %rdi
je 0x4095
callq 0x21c0
leaq -0x40(%rbp), %rdi
callq 0x40b0
leaq -0x58(%rbp), %rdi
callq 0x24f6
movq %rbx, %rdi
callq 0x2280
nop