// File: /workspace/github_cpp_makefile_star2_O3/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 -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1f0b(%rip), %rsi      # 0x51c7
leaq 0x1f0b(%rip), %rdx      # 0x51ce
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x3918
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 0x32d9
cmpq $0x32333435, %rsi       # imm = 0x32333435
je 0x3308
leaq 0x1ece(%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)
shrl $0x8, %eax
decq %rcx
jne 0x3316
movb $0x0, -0x45(%rbp)
leaq -0x80(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1eaf(%rip), %rsi      # 0x51e5
leaq 0x1ead(%rip), %rdx      # 0x51ea
leaq -0x90(%rbp), %rdi
callq 0x3918
leaq -0x90(%rbp), %r14
leaq -0x4a(%rbp), %rsi
movq %r14, %rdi
callq 0x20b0
movl %eax, %ebx
movq (%r14), %rdi
cmpq %r12, %rdi
je 0x336b
callq 0x21c0
testl %ebx, %ebx
je 0x3381
leaq 0x1e75(%rip), %rdi      # 0x51eb
leaq -0x4a(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq -0xb0(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x1e76(%rip), %rcx      # 0x5209
movl $0x10, %r8d
xorl %esi, %esi
callq 0x2240
leaq -0x40(%rbp), %rbx
movb $0x0, 0x10(%rbx)
movq -0xb0(%rbp), %rsi
movl $0x10, %edx
movq %rbx, %rdi
callq 0x2110
movzbl 0xf(%rbx), %eax
movl %eax, %esi
andl $0x7f, %esi
cmpq $0x66, %rsi
je 0x33dc
leaq 0x1e48(%rip), %rdi      # 0x521a
xorl %eax, %eax
callq 0x2040
movb -0x31(%rbp), %al
movzbl -0x32(%rbp), %ecx
shll $0x8, %ecx
movzbl %al, %esi
orl %ecx, %esi
shrl $0x4, %esi
andl $0x7f, %esi
cmpl $0x56, %esi
je 0x3401
leaq 0x1e20(%rip), %rdi      # 0x521a
xorl %eax, %eax
callq 0x2040
xorl %eax, %eax
leaq 0x1f06(%rip), %rcx      # 0x5310
xorl %edx, %edx
movb (%rcx,%rdx,2), %dil
leal -0x30(%rdi), %esi
cmpb $0xa, %sil
jb 0x343c
leal -0x61(%rdi), %esi
cmpb $0x5, %sil
ja 0x342a
addb $-0x57, %dil
movl %edi, %esi
jmp 0x343c
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 0x3472
leal -0x61(%rdi), %r8d
cmpb $0x5, %r8b
ja 0x345e
addb $-0x57, %dil
movl %edi, %r8d
jmp 0x3472
leal -0x41(%rdi), %r8d
addb $-0x37, %dil
cmpb $0x6, %r8b
movzbl %dil, %r8d
cmovael %eax, %r8d
shlb $0x4, %sil
addb %r8b, %sil
movb %sil, -0x90(%rbp,%rdx)
incq %rdx
cmpq $0x20, %rdx
jne 0x340c
movzbl -0x72(%rbp), %esi
movzbl -0x71(%rbp), %eax
andl $0x1, %esi
shll $0x8, %esi
orq %rax, %rsi
cmpq $0x108, %rsi            # imm = 0x108
je 0x34b2
leaq 0x1d6f(%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 0x1b33(%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 0x3525
leaq 0x1d2d(%rip), %rdi      # 0x5247
leaq -0x40(%rbp), %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x160(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1d2c(%rip), %rsi      # 0x5263
leaq 0x1d40(%rip), %rdx      # 0x527e
leaq -0x170(%rbp), %rdi
callq 0x3918
leaq -0x140(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1d22(%rip), %rsi      # 0x527f
leaq 0x1d21(%rip), %rdx      # 0x5285
leaq -0x150(%rbp), %rdi
callq 0x3918
leaq -0x70(%rbp), %rdi
leaq -0x170(%rbp), %rsi
leaq -0x150(%rbp), %rdx
callq 0x2850
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0x3598
callq 0x21c0
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
je 0x35a9
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 0x387a
leaq -0x130(%rbp), %rdi
movl $0x9d1, %esi            # imm = 0x9D1
callq 0x296e
movl %eax, %ebx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x35ef
callq 0x21c0
cmpl $0x4d1, %ebx            # imm = 0x4D1
je 0x3607
movl %ebx, %esi
leaq 0x1c86(%rip), %rdi      # 0x5286
xorl %eax, %eax
callq 0x2040
leaq -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1c4a(%rip), %rsi      # 0x5263
leaq 0x1c5e(%rip), %rdx      # 0x527e
leaq -0x110(%rbp), %rdi
callq 0x3918
leaq -0xe0(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x1c40(%rip), %rsi      # 0x527f
leaq 0x1c3f(%rip), %rdx      # 0x5285
leaq -0xf0(%rbp), %rdi
callq 0x3918
leaq -0x190(%rbp), %rdi
leaq -0x110(%rbp), %rsi
leaq -0xf0(%rbp), %rdx
callq 0x2850
leaq -0x70(%rbp), %rdi
leaq -0x190(%rbp), %rbx
movq %rbx, %rsi
callq 0x21f0
movq (%rbx), %rdi
leaq -0x180(%rbp), %rax
cmpq %rax, %rdi
je 0x3693
callq 0x21c0
movq -0xf0(%rbp), %rdi
cmpq %r12, %rdi
je 0x36a4
callq 0x21c0
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x36b5
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 0x387a
leaq -0xd0(%rbp), %rdi
movl $0x9, %esi
callq 0x29e4
movq %rax, %rbx
movq -0xd0(%rbp), %rdi
cmpq %r14, %rdi
je 0x36fc
callq 0x21c0
cmpq $0x108, %rbx            # imm = 0x108
je 0x3716
leaq 0x1b97(%rip), %rdi      # 0x52a3
movq %rbx, %rsi
xorl %eax, %eax
callq 0x2040
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3728
callq 0x21c0
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x3739
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 0x3783
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
cmpq %r12, %rdi
je 0x376e
callq 0x21c0
jmp 0x376e
movq %rax, %rbx
movq -0x110(%rbp), %rdi
jmp 0x3783
jmp 0x37bc
movq %rax, %rbx
movq -0x130(%rbp), %rdi
cmpq %r14, %rdi
je 0x37bf
callq 0x21c0
jmp 0x37bf
movq %rax, %rbx
movq -0x150(%rbp), %rdi
cmpq %r12, %rdi
je 0x37a8
callq 0x21c0
jmp 0x37a8
movq %rax, %rbx
movq -0x170(%rbp), %rdi
cmpq %r14, %rdi
jne 0x37cc
jmp 0x37d6
jmp 0x37d3
jmp 0x37d3
jmp 0x37d3
movq %rax, %rbx
leaq -0x60(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x37d6
callq 0x21c0
jmp 0x37d6
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x37e7
callq 0x21c0
movq %rbx, %rdi
callq 0x2280