// File: /workspace/github_cpp_makefile_star2_O2/yoavweiss[P]cache-digests-cuckoo/cuckoo.cpp
// Function: Cuckoo::runTests()
void Cuckoo::runTests() {
    // Test bigEndianRead
    std::string hashStr = "1234567";
    unsigned long hashNumber = bigEndianRead((const unsigned char*)hashStr.c_str(), 1, 4);
    if (hashNumber != 842216501) {
        printf("Fail - hashNumber %lu", hashNumber);
    }
    // Test bigEndianWrite
    unsigned char testDigest[10];
    testDigest[0] = 49;
    bigEndianWrite(testDigest, 1, 4, 842216501);
    testDigest[5] = 0;
    if ((char*)testDigest != std::string("12345")) {
        printf("Fail - bigEndianWrite got %s\n", testDigest);
    }
    // Test readFingerprint
    hashStr = "0123456789abcdef";
    unsigned char fingerprintHash[17];
    fingerprintHash[16] = 0;
    strncpy((char*)fingerprintHash, hashStr.c_str(), 16);
    unsigned long fingerprintValue = readFingerprint(fingerprintHash, 121, 7);
    if (fingerprintValue != 102)
        printf("FAIL - readFingerprint %lu\n", fingerprintValue);
    fingerprintValue = readFingerprint(fingerprintHash, 117, 7);
    if (fingerprintValue!= 86)
        printf("FAIL - readFingerprint %lu\n", fingerprintValue);
    char shaInStr[65] = "2442a9b40768c5ccff9366514374eeca86fd6a3156b11d5f7aaad7b1e3fbbb08";
    unsigned char fingerprintHash2[32];
    for (int i = 0; i < 32; ++i) {
        unsigned char letter = hex(shaInStr[2*i]) * 16 + hex(shaInStr[2*i+1]);
        fingerprintHash2[i] = letter;
    }
    fingerprintValue = readFingerprint(fingerprintHash2, 247, 9);
    if (fingerprintValue!= 264)
        printf("FAIL - readFingerprint %lu\n", fingerprintValue);


    // Test writeFingerprint
    writeFingerprint(fingerprintHash, 8, 8, 90);
    writeFingerprint(fingerprintHash, 20, 4, 5);
    writeFingerprint(fingerprintHash, 28, 3, 6);
    if (strcmp((const char*)fingerprintHash, "0Z5=456789abcdef"))
        printf("FAIL - writeFingerprint %s\n", fingerprintHash);

    // Test hash calculation
    std::string keyStr = key("https://example.com/bla.gif", "34bfac");
    unsigned long hashValue = hash(keyStr, 2513);
    if (hashValue != 1233)
        printf("FAIL - hash calculation %lu\n", hashValue);

    // Test fingerprint
    keyStr = key("https://example.com/bla.gif", "34bfac");
    fingerprintValue = fingerprint(keyStr, 9);
    if (fingerprintValue != 264)
        printf("FAIL - fingerprint calculation %lu\n", fingerprintValue);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
leaq 0x119c(%rip), %rsi      # 0x41b7
leaq -0xa0(%rbp), %rbx
leaq -0x60(%rbp), %rdx
movq %rbx, %rdi
callq 0x20f0
movq (%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
callq 0x2786
cmpq $0x32333435, %rax       # imm = 0x32333435
je 0x3055
leaq 0x1174(%rip), %rdi      # 0x41bf
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x3a(%rbp), %rbx
movb $0x31, (%rbx)
pushq $0x1
popq %rsi
pushq $0x4
popq %rdx
movl $0x32333435, %ecx       # imm = 0x32333435
movq %rbx, %rdi
callq 0x24c6
movb $0x0, 0x5(%rbx)
leaq 0x115b(%rip), %rsi      # 0x41d5
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x20f0
leaq -0x3a(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x34b7
movl %eax, %ebx
leaq -0x60(%rbp), %rdi
callq 0x2120
testb %bl, %bl
je 0x30b5
leaq 0x1131(%rip), %rdi      # 0x41db
leaq -0x3a(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq 0x113d(%rip), %rsi      # 0x41f9
leaq -0xa0(%rbp), %rdi
callq 0x22c0
leaq -0x30(%rbp), %rbx
movb $0x0, 0x10(%rbx)
movq -0xa0(%rbp), %rsi
pushq $0x10
popq %rdx
movq %rbx, %rdi
callq 0x2130
pushq $0x79
popq %rsi
pushq $0x7
popq %rdx
movq %rbx, %rdi
callq 0x29dc
cmpq $0x66, %rax
je 0x3107
leaq 0x110d(%rip), %rdi      # 0x420a
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x30(%rbp), %rdi
pushq $0x75
popq %rsi
pushq $0x7
popq %rdx
callq 0x29dc
cmpq $0x56, %rax
je 0x312d
leaq 0x10e7(%rip), %rdi      # 0x420a
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
xorl %r14d, %r14d
leaq 0x1199(%rip), %r15      # 0x42d0
cmpq $0x20, %r14
je 0x3163
movzbl (%r15,%r14,2), %edi
callq 0x2fd5
movl %eax, %ebx
shlb $0x4, %bl
movzbl 0x1(%r15,%r14,2), %edi
callq 0x2fd5
orb %bl, %al
movb %al, -0x60(%rbp,%r14)
incq %r14
jmp 0x3137
leaq -0x60(%rbp), %rdi
pushq $0x9
popq %rdx
movl $0xf7, %esi
callq 0x29dc
cmpq $0x108, %rax            # imm = 0x108
je 0x318d
leaq 0x1087(%rip), %rdi      # 0x420a
movq %rax, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x30(%rbp), %rdi
pushq $0x8
popq %rdx
pushq $0x5a
popq %rcx
movl %edx, %esi
callq 0x2a9e
leaq -0x30(%rbp), %rdi
pushq $0x14
popq %rsi
pushq $0x4
popq %rdx
pushq $0x5
popq %rcx
callq 0x2a9e
leaq -0x30(%rbp), %rdi
pushq $0x1c
popq %rsi
pushq $0x3
popq %rdx
pushq $0x6
popq %rcx
callq 0x2a9e
leaq 0x105d(%rip), %rsi      # 0x4226
leaq -0x30(%rbp), %rdi
pushq $0x11
popq %rdx
callq 0x21d0
testl %eax, %eax
je 0x31eb
leaq 0x1057(%rip), %rdi      # 0x4237
leaq -0x30(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq 0x1061(%rip), %rsi      # 0x4253
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rdx
callq 0x20f0
leaq 0x1063(%rip), %rsi      # 0x426f
leaq -0x140(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x20f0
leaq -0x80(%rbp), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x140(%rbp), %rdx
callq 0x27ac
leaq -0x140(%rbp), %rdi
callq 0x2120
leaq -0x160(%rbp), %rdi
callq 0x2120
leaq -0x120(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2220
leaq -0x120(%rbp), %rdi
movl $0x9d1, %esi            # imm = 0x9D1
callq 0x284a
movl %eax, %ebx
leaq -0x120(%rbp), %rdi
callq 0x2120
cmpl $0x4d1, %ebx            # imm = 0x4D1
je 0x3292
movl %ebx, %esi
leaq 0xfeb(%rip), %rdi       # 0x4276
xorl %eax, %eax
callq 0x2040
leaq 0xfba(%rip), %rsi       # 0x4253
leaq -0x100(%rbp), %rdi
leaq -0x19(%rbp), %rdx
callq 0x20f0
leaq 0xfbf(%rip), %rsi       # 0x426f
leaq -0xe0(%rbp), %rdi
leaq -0x1a(%rbp), %rdx
callq 0x20f0
leaq -0x180(%rbp), %rdi
leaq -0x100(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x27ac
leaq -0x80(%rbp), %rbx
leaq -0x180(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x21f0
movq %r14, %rdi
callq 0x2120
leaq -0xe0(%rbp), %rdi
callq 0x2120
leaq -0x100(%rbp), %rdi
callq 0x2120
leaq -0xc0(%rbp), %rdi
movq %rbx, %rsi
callq 0x2220
leaq -0xc0(%rbp), %rdi
pushq $0x9
popq %rsi
callq 0x28b2
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0x2120
cmpq $0x108, %rbx            # imm = 0x108
je 0x3357
leaq 0xf46(%rip), %rdi       # 0x4293
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x80(%rbp), %rdi
callq 0x2120
leaq -0xa0(%rbp), %rdi
callq 0x2120
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
jmp 0x33af
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x2120
jmp 0x339a
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x33af
jmp 0x33e2
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x2120
jmp 0x33e5
movq %rax, %rbx
leaq -0x140(%rbp), %rdi
callq 0x2120
jmp 0x33ca
movq %rax, %rbx
leaq -0x160(%rbp), %rdi
jmp 0x33e9
jmp 0x33f0
jmp 0x33f0
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
jmp 0x33e9
jmp 0x33f0
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x2120
jmp 0x33f3
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x2120
movq %rbx, %rdi
callq 0x2290