// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
leaq -0x80(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1e2e(%rip), %rsi      # 0x51c7
leaq 0x1e2e(%rip), %rdx      # 0x51ce
leaq -0x90(%rbp), %rbx
movq %rbx, %rdi
callq 0x3a1a
xorl %eax, %eax
movq (%rbx), %rcx
xorl %esi, %esi
movq %rsi, %rdx
shlq $0x8, %rdx
movzbl 0x1(%rcx,%rax), %esi
incq %rax
orq %rdx, %rsi
cmpq $0x4, %rax
jne 0x33b6
cmpq $0x32333435, %rsi       # imm = 0x32333435
je 0x33e5
leaq 0x1df1(%rip), %rdi      # 0x51cf
xorl %eax, %eax
callq 0x2040
movb $0x31, -0x4a(%rbp)
movl $0x32333435, %eax       # imm = 0x32333435
movl $0x4, %ecx
movb %al, -0x4a(%rbp,%rcx)
shrq $0x8, %rax
decq %rcx
jne 0x33f3
movb $0x0, -0x45(%rbp)
leaq -0xa0(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1dce(%rip), %rsi      # 0x51e5
leaq 0x1dcc(%rip), %rdx      # 0x51ea
leaq -0xb0(%rbp), %rdi
callq 0x3a1a
leaq -0xb0(%rbp), %r14
leaq -0x4a(%rbp), %rsi
movq %r14, %rdi
callq 0x20b0
movl %eax, %ebx
movq (%r14), %rdi
cmpq %r12, %rdi
je 0x344c
callq 0x21c0
testl %ebx, %ebx
je 0x3462
leaq 0x1d94(%rip), %rdi      # 0x51eb
leaq -0x4a(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x90(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x1d95(%rip), %rcx      # 0x5209
movl $0x10, %r8d
xorl %esi, %esi
callq 0x2240
leaq -0x40(%rbp), %rbx
movb $0x0, 0x10(%rbx)
movq -0x90(%rbp), %rsi
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2110
movzbl 0xf(%rbx), %esi
andl $0x7f, %esi
cmpq $0x66, %rsi
je 0x34b8
leaq 0x1d69(%rip), %rdi      # 0x521a
xorl %eax, %eax
callq 0x2040
movl $0xe, %eax
xorl %esi, %esi
movq %rsi, %rcx
shlq $0x8, %rcx
movzbl -0x40(%rbp,%rax), %esi
orq %rcx, %rsi
incq %rax
cmpq $0x10, %rax
jne 0x34bf
shrl $0x4, %esi
andl $0x7f, %esi
cmpl $0x56, %esi
je 0x34f0
leaq 0x1d31(%rip), %rdi      # 0x521a
xorl %eax, %eax
callq 0x2040
xorl %eax, %eax
leaq 0x1e17(%rip), %rcx      # 0x5310
xorl %edx, %edx
movb (%rcx,%rdx,2), %dil
leal -0x30(%rdi), %esi
cmpb $0xa, %sil
jb 0x352b
leal -0x61(%rdi), %esi
cmpb $0x5, %sil
ja 0x3519
addb $-0x57, %dil
movl %edi, %esi
jmp 0x352b
leal -0x41(%rdi), %esi
addb $-0x37, %dil
cmpb $0x6, %sil
movzbl %dil, %esi
cmovael %eax, %esi
movb 0x1(%rcx,%rdx,2), %dil
leal -0x30(%rdi), %r8d
cmpb $0xa, %r8b
jb 0x3561
leal -0x61(%rdi), %r8d
cmpb $0x5, %r8b
ja 0x354d
addb $-0x57, %dil
movl %edi, %r8d
jmp 0x3561
leal -0x41(%rdi), %r8d
addb $-0x37, %dil
cmpb $0x6, %r8b
movzbl %dil, %r8d
cmovael %eax, %r8d
shlb $0x4, %sil
addb %r8b, %sil
movb %sil, -0xb0(%rbp,%rdx)
incq %rdx
cmpq $0x20, %rdx
jne 0x34fb
movl $0x1e, %eax
xorl %esi, %esi
movq %rsi, %rcx
shlq $0x8, %rcx
movzbl -0xb0(%rbp,%rax), %esi
orq %rcx, %rsi
incq %rax
cmpq $0x20, %rax
jne 0x3580
andl $0x1ff, %esi            # imm = 0x1FF
cmpq $0x108, %rsi            # imm = 0x108
je 0x35b8
leaq 0x1c69(%rip), %rdi      # 0x521a
xorl %eax, %eax
callq 0x2040
xorps %xmm0, %xmm0
callq 0x21b0
movb $0x5a, -0x3f(%rbp)
movb -0x3e(%rbp), %bl
xorps %xmm0, %xmm0
callq 0x21b0
andb $-0x10, %bl
orb $0x5, %bl
movb %bl, -0x3e(%rbp)
movb -0x3d(%rbp), %bl
movsd 0x1a2d(%rip), %xmm0     # 0x5010
callq 0x21b0
andb $-0xf, %bl
orb $0xc, %bl
movb %bl, -0x3d(%rbp)
movabsq $0x6665646362613938, %rax # imm = 0x6665646362613938
xorq -0x38(%rbp), %rax
movabsq $0x373635343d355a30, %rcx # imm = 0x373635343D355A30
xorq -0x40(%rbp), %rcx
movzbl -0x30(%rbp), %edx
orq %rcx, %rdx
orq %rax, %rdx
je 0x362b
leaq 0x1c27(%rip), %rdi      # 0x5247
leaq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x160(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1c26(%rip), %rsi      # 0x5263
leaq 0x1c3a(%rip), %rdx      # 0x527e
leaq -0x170(%rbp), %rdi
callq 0x3a1a
leaq -0x140(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1c1c(%rip), %rsi      # 0x527f
leaq 0x1c1b(%rip), %rdx      # 0x5285
leaq -0x150(%rbp), %rdi
callq 0x3a1a
leaq -0x70(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x28f4
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0x369e
callq 0x21c0
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
je 0x36af
callq 0x21c0
leaq -0x120(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0x130(%rbp), %rdi
callq 0x3980
leaq -0x130(%rbp), %rdi
movl $0x9d1, %esi            # imm = 0x9D1
callq 0x2a16
movl %eax, %ebx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x36f5
callq 0x21c0
cmpl $0x4d1, %ebx            # imm = 0x4D1
je 0x370d
movl %ebx, %esi
leaq 0x1b80(%rip), %rdi      # 0x5286
xorl %eax, %eax
callq 0x2040
leaq -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b44(%rip), %rsi      # 0x5263
leaq 0x1b58(%rip), %rdx      # 0x527e
leaq -0x110(%rbp), %rdi
callq 0x3a1a
leaq -0xe0(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1b3a(%rip), %rsi      # 0x527f
leaq 0x1b39(%rip), %rdx      # 0x5285
leaq -0xf0(%rbp), %rdi
callq 0x3a1a
leaq -0x190(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x28f4
leaq -0x70(%rbp), %rdi
leaq -0x190(%rbp), %rbx
movq %rbx, %rsi
callq 0x21f0
movq (%rbx), %rdi
leaq -0x180(%rbp), %rax
cmpq %rax, %rdi
je 0x3799
callq 0x21c0
movq -0xf0(%rbp), %rdi
cmpq %r12, %rdi
je 0x37aa
callq 0x21c0
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x37bb
callq 0x21c0
leaq -0xc0(%rbp), %r14
movq %r14, -0x10(%r14)
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rdx
addq %rsi, %rdx
leaq -0xd0(%rbp), %rdi
callq 0x3980
leaq -0xd0(%rbp), %rdi
movl $0x9, %esi
callq 0x2a8c
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r14, %rdi
je 0x3802
callq 0x21c0
cmpq $0x108, %rbx            # imm = 0x108
je 0x381c
leaq 0x1a91(%rip), %rdi      # 0x52a3
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x382e
callq 0x21c0
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x383f
callq 0x21c0
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
jmp 0x3889
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r12, %rdi
je 0x3874
callq 0x21c0
jmp 0x3874
movq %rax, %rbx
movq -0x110(%rbp), %rdi
jmp 0x3889
jmp 0x38c2
movq %rax, %rbx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x38c5
callq 0x21c0
jmp 0x38c5
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0x38ae
callq 0x21c0
jmp 0x38ae
movq %rax, %rbx
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
jne 0x38d2
jmp 0x38dc
jmp 0x38d9
jmp 0x38d9
jmp 0x38d9
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x38dc
callq 0x21c0
jmp 0x38dc
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r15, %rdi
je 0x38ed
callq 0x21c0
movq %rbx, %rdi
callq 0x2280