// File: /workspace/github_cpp_makefile_star2_O3/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 0x3298
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 0x3a3b
movl $0x2, %r12d
cmpl $0x64, %r14d
jb 0x3a3b
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 0x400c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x407e
movq -0x3a0(%rbp), %rdi
cmpq %r13, %rdi
je 0x3a80
callq 0x21c0
incl %r14d
cmpl $0xcb2, %r14d           # imm = 0xCB2
jne 0x3a12
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq %rax, %r14
je 0x3b43
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 0x387a
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 0x2500
movl %eax, %ebx
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x3b05
callq 0x21c0
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x3b1d
callq 0x21c0
cmpl %r13d, %ebx
cmovbl %ebx, %r13d
addq $0x20, %r14
cmpq -0x60(%rbp), %r14
leaq -0x70(%rbp), %r12
movq %r15, %rbx
jne 0x3ab2
movl $0x1f4, %esi            # imm = 0x1F4
subl %r13d, %esi
jmp 0x3b45
xorl %esi, %esi
leaq 0x1805(%rip), %rdi      # 0x5351
xorl %eax, %eax
callq 0x2040
leaq -0x3a0(%rbp), %rdi
callq 0x2270
leaq 0x1804(%rip), %rsi      # 0x536a
leaq -0x3a0(%rbp), %rdi
movl $0x4, %edx
callq 0x2050
leaq -0x330(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x3ba7
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 0x3c61
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 0x387a
movq %r12, -0x100(%rbp)
movq $0x0, -0xf8(%rbp)
movb $0x0, -0xf0(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0x100(%rbp), %rdx
callq 0x2fbe
movl %eax, %r13d
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x3c26
callq 0x21c0
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x3c3e
callq 0x21c0
testb %r13b, %r13b
jne 0x3c54
movq (%r14), %rsi
leaq 0x1728(%rip), %rdi      # 0x5375
xorl %eax, %eax
callq 0x2040
addq $0x20, %r14
cmpq %r15, %r14
jne 0x3bc6
leaq -0x170(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1722(%rip), %rsi      # 0x5395
leaq 0x1721(%rip), %rdx      # 0x539b
leaq -0x180(%rbp), %rdi
callq 0x3918
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 0x2fbe
movl %eax, %ebx
movq -0x1a0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3cc7
callq 0x21c0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
je 0x3cd8
callq 0x21c0
testb %bl, %bl
je 0x3ce8
leaq 0x16f5(%rip), %rdi      # 0x53d8
callq 0x2230
movq -0x40(%rbp), %r13
movq -0x38(%rbp), %r14
cmpq %r14, %r13
je 0x3e39
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 0x387a
movq %r15, -0xe0(%rbp)
movq $0x0, -0xd8(%rbp)
movb $0x0, -0xd0(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0xe0(%rbp), %rdx
callq 0x2d08
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3d65
callq 0x21c0
movq -0x160(%rbp), %rdi
cmpq %r12, %rdi
je 0x3d76
callq 0x21c0
addq $0x20, %r13
cmpq %r14, %r13
jne 0x3d0e
movq -0x40(%rbp), %r14
movq -0x38(%rbp), %r15
cmpq %r15, %r14
je 0x3e39
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 0x387a
movq %r12, -0xa0(%rbp)
movq $0x0, -0x98(%rbp)
movb $0x0, -0x90(%rbp)
leaq -0x58(%rbp), %rdi
movq %rbx, %rsi
leaq -0xa0(%rbp), %rdx
callq 0x2fbe
movl %eax, %r13d
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3dfe
callq 0x21c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x3e16
callq 0x21c0
testb %r13b, %r13b
je 0x3e2c
movq (%r14), %rsi
leaq 0x1577(%rip), %rdi      # 0x539c
xorl %eax, %eax
callq 0x2040
addq $0x20, %r14
cmpq %r15, %r14
jne 0x3d9e
movq 0x31a0(%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 0x3fb4
leaq -0x58(%rbp), %rdi
callq 0x24f2
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 0x3ea9
callq 0x21c0
movq -0x180(%rbp), %rdi
cmpq %r14, %rdi
jne 0x3f45
jmp 0x3f4a
jmp 0x3f19
jmp 0x3f80
movq %rax, %rbx
jmp 0x3fa2
jmp 0x3f19
jmp 0x3f19
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3ee5
callq 0x21c0
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
jmp 0x3f40
jmp 0x3f19
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3f0b
callq 0x21c0
movq -0x160(%rbp), %rdi
cmpq %r12, %rdi
jne 0x3f45
jmp 0x3f4a
movq %rax, %rbx
jmp 0x3f4a
movq %rax, %rbx
movq -0x100(%rbp), %rdi
cmpq %r12, %rdi
je 0x3f32
callq 0x21c0
movq -0x120(%rbp), %rdi
leaq -0x110(%rbp), %rax
cmpq %rax, %rdi
je 0x3f4a
callq 0x21c0
leaq -0x3a0(%rbp), %rdi
callq 0x2220
jmp 0x3f99
jmp 0x3f80
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r12, %rdi
je 0x3f6b
callq 0x21c0
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
jne 0x3f94
jmp 0x3f99
movq %rax, %rbx
jmp 0x3f99
movq %rax, %rbx
movq -0x3a0(%rbp), %rdi
cmpq %r13, %rdi
je 0x3f99
callq 0x21c0
leaq -0x40(%rbp), %rdi
callq 0x3fb4
leaq -0x58(%rbp), %rdi
callq 0x24f2
movq %rbx, %rdi
callq 0x2280
nop