// File: /workspace/github_cpp_makefile_star2_O2/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 $0x388, %rsp            # imm = 0x388
leaq -0x68(%rbp), %rbx
pushq $0x8
popq %rsi
movq %rbx, %rdi
movl $0x3fd, %edx            # imm = 0x3FD
movl $0x1f4, %ecx            # imm = 0x1F4
callq 0x23ec
movq %rbx, %rdi
callq 0x3004
leaq -0x50(%rbp), %rbx
andq $0x0, 0x10(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rbx)
xorl %r14d, %r14d
leaq -0x3b0(%rbp), %r15
cmpl $0xcb2, %r14d           # imm = 0xCB2
je 0x355a
movq %r15, %rdi
movl %r14d, %esi
callq 0x3916
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3a90
movq %r15, %rdi
callq 0x2120
incl %r14d
jmp 0x352e
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movl $0x1f4, %r15d           # imm = 0x1F4
leaq -0x1b0(%rbp), %r14
leaq -0xf0(%rbp), %r12
cmpq -0x70(%rbp), %rbx
je 0x35d7
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2220
leaq -0xe0(%rbp), %rax
movq %rax, -0xf0(%rbp)
andq $0x0, -0xe8(%rbp)
movb $0x0, -0xe0(%rbp)
leaq -0x68(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x24ec
movl %eax, %r13d
movq %r12, %rdi
callq 0x2120
movq %r14, %rdi
callq 0x2120
cmpl %r15d, %r13d
cmovbl %r13d, %r15d
addq $0x20, %rbx
jmp 0x357a
movl $0x1f4, %esi            # imm = 0x1F4
subl %r15d, %esi
leaq 0xd2b(%rip), %rdi       # 0x4311
xorl %eax, %eax
callq 0x2040
leaq -0x3b0(%rbp), %rdi
callq 0x2280
leaq 0xd2a(%rip), %rsi       # 0x432a
leaq -0x3b0(%rbp), %rdi
pushq $0x4
popq %rdx
callq 0x2050
leaq -0x340(%rbp), %rdi
callq 0x2090
testb %al, %al
je 0x363f
movq -0x68(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x3b0(%rbp), %rdi
callq 0x2210
leaq -0x3b0(%rbp), %rdi
callq 0x2230
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r15
leaq -0x190(%rbp), %r14
leaq -0xd0(%rbp), %r12
cmpq %r15, %rbx
je 0x36c0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2220
leaq -0xc0(%rbp), %rax
movq %rax, -0xd0(%rbp)
andq $0x0, -0xc8(%rbp)
movb $0x0, -0xc0(%rbp)
leaq -0x68(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2dbe
movl %eax, %r13d
movq %r12, %rdi
callq 0x2120
movq %r14, %rdi
callq 0x2120
testb %r13b, %r13b
jne 0x36ba
movq (%rbx), %rsi
leaq 0xc82(%rip), %rdi       # 0x4335
xorl %eax, %eax
callq 0x2040
addq $0x20, %rbx
jmp 0x3655
leaq 0xc8e(%rip), %rsi       # 0x4355
leaq -0x130(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x20f0
leaq -0x100(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq -0x68(%rbp), %rdi
leaq -0x130(%rbp), %rsi
leaq -0x110(%rbp), %rdx
callq 0x2dbe
movl %eax, %ebx
leaq -0x110(%rbp), %rdi
callq 0x2120
leaq -0x130(%rbp), %rdi
callq 0x2120
testb %bl, %bl
je 0x372b
leaq 0xc72(%rip), %rdi       # 0x4398
callq 0x2250
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r13
leaq -0x170(%rbp), %r14
leaq -0x68(%rbp), %r15
leaq -0xb0(%rbp), %r12
cmpq %r13, %rbx
je 0x3796
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2220
leaq -0xa0(%rbp), %rax
movq %rax, -0xb0(%rbp)
andq $0x0, -0xa8(%rbp)
movb $0x0, -0xa0(%rbp)
movq %r15, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2b80
movq %r12, %rdi
callq 0x2120
movq %r14, %rdi
callq 0x2120
addq $0x20, %rbx
jmp 0x3745
movq -0x50(%rbp), %rbx
movq -0x48(%rbp), %r15
leaq -0x150(%rbp), %r14
leaq -0x90(%rbp), %r12
cmpq %r15, %rbx
je 0x3811
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2220
leaq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movb $0x0, -0x80(%rbp)
leaq -0x68(%rbp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x2dbe
movl %eax, %r13d
movq %r12, %rdi
callq 0x2120
movq %r14, %rdi
callq 0x2120
testb %r13b, %r13b
je 0x380b
movq (%rbx), %rsi
leaq 0xb58(%rip), %rdi       # 0x435c
xorl %eax, %eax
callq 0x2040
addq $0x20, %rbx
jmp 0x37ac
leaq -0x3b0(%rbp), %rdi
callq 0x2240
leaq -0x50(%rbp), %rdi
callq 0x3976
leaq -0x68(%rbp), %rdi
callq 0x24de
xorl %eax, %eax
addq $0x388, %rsp            # imm = 0x388
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0x2120
leaq -0x130(%rbp), %rdi
jmp 0x38bb
jmp 0x38a0
jmp 0x38e8
movq %rax, %rbx
jmp 0x3905
jmp 0x38a0
jmp 0x38a0
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2120
leaq -0x150(%rbp), %rdi
jmp 0x38bb
jmp 0x38a0
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x2120
leaq -0x170(%rbp), %rdi
jmp 0x38bb
movq %rax, %rbx
jmp 0x38c0
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2120
leaq -0x190(%rbp), %rdi
callq 0x2120
leaq -0x3b0(%rbp), %rdi
callq 0x2240
jmp 0x38fc
jmp 0x38e8
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x2120
leaq -0x1b0(%rbp), %rdi
jmp 0x38f7
movq %rax, %rbx
jmp 0x38fc
movq %rax, %rbx
leaq -0x3b0(%rbp), %rdi
callq 0x2120
leaq -0x50(%rbp), %rdi
callq 0x3976
leaq -0x68(%rbp), %rdi
callq 0x24de
movq %rbx, %rdi
callq 0x2290