// File: /workspace/github_cpp_makefile_star2_O3/yoavweiss[P]cache-digests-cuckoo/cuckoo.cpp
// Function: Cuckoo::remove(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Cuckoo::remove(std::string URL, std::string ETag) {
    // Given the following inputs:
    //
    // * `URL` a string corresponding to the Effective Request URI ({{RFC7230}}, Section 5.5) of a cached
    // response {{RFC7234}}
    // * `ETag` a string corresponding to the entity-tag {{RFC7232}} of a cached response {{RFC7234}} (if
    // the ETag is available; otherwise, null);
    // * `digest-value`
    unsigned char* digest = m_digest;
    size_t digestSize = m_digestSize;

    // 1. Let `f` be the value of the first byte of `digest-value`.
    unsigned fingerprintSize = digest[0];
    // 3. Let `N` be the value of the second to fifth bytes of `digest-value` in big endian form.
    unsigned long entries = bigEndianRead(digest, 1, 4);
    // 4. Let `key` be the return value of {{key}} with `URL` and `ETag` as inputs.
    std::string keyStr = key(URL, ETag);
    // 5. Let `h1` be the return value of {{hash}} with `key` and `N` as inputs.
    unsigned long h1 = hash(keyStr, entries);
    // 6. Let `fingerprint` be the return value of {{fingerprint}} with `key` and `f` as inputs.
    unsigned long destinationFingerprintValue = fingerprint(keyStr, fingerprintSize);
    // 7. Let `h2` be the return value of {{hash2}} with `h1`, `fingerprint` and `N` as inputs.
    unsigned long h2 = alternateHash(h1, destinationFingerprintValue, entries);
    // 8. Let `hashes` be an array containing `h1` and `h2`.
    unsigned long hashes[2];
    hashes[0] = h1;
    hashes[1] = h2;
    // 9. For each `h` in `hashes`:
    for (int i = 0; i < 2; ++i) {
        unsigned long h = hashes[i];
        // 1. Let `position_start` be 40 + `h` \* `f` \* `b`.
        unsigned positionStart = 40 + h * fingerprintSize * BucketSize;
        // 2. Let `position_end` be `position_start` + `f` \* `b`.
        unsigned positionEnd = positionStart + fingerprintSize * BucketSize;
        unsigned long fingerprintValue;
        // Make sure we're not reading outside the table.
        assert(ceil(positionStart / 8) <= digestSize);
        // 3. While `position_start` < `position_end`:
        while (positionStart < positionEnd) {
            // 1. Let `bits` be `f` bits from `digest_value` starting at `position_start`.
            fingerprintValue = readFingerprint(digest, positionStart, fingerprintSize);
            // 2. If `bits` is `fingerprint`, set `bits` to all zeros and terminate these steps.
            if (fingerprintValue == destinationFingerprintValue) {
                writeFingerprint(digest, positionStart, fingerprintSize, 0);
                return;
            }
            // 3. Add `f` to `position_start`.
            positionStart += fingerprintSize;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdx, %r12
movq (%rdi), %rbx
movq 0x8(%rdi), %rax
movq %rax, -0x30(%rbp)
movzbl (%rbx), %r14d
xorl %r15d, %r15d
movl $0x1, %eax
movl %r15d, %ecx
shll $0x8, %ecx
movzbl (%rbx,%rax), %r15d
orl %ecx, %r15d
incq %rax
cmpq $0x5, %rax
jne 0x2d36
leaq -0x68(%rbp), %rax
movq %rax, -0x10(%rax)
movq (%rsi), %rax
movq 0x8(%rsi), %rdx
addq %rax, %rdx
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x387a
leaq -0xc8(%rbp), %r13
movq %r13, -0x10(%r13)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq -0xd8(%rbp), %rdi
callq 0x387a
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0xd8(%rbp), %rdx
callq 0x2850
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0x2db6
callq 0x21c0
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2dc8
callq 0x21c0
leaq -0xa8(%rbp), %r13
movq %r13, -0x10(%r13)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rdi
callq 0x387a
leaq -0xb8(%rbp), %rdi
movl %r15d, %esi
callq 0x296e
movl %eax, %r12d
movq -0xb8(%rbp), %rdi
cmpq %r13, %rdi
je 0x2e13
callq 0x21c0
leaq -0x48(%rbp), %rax
movq %rax, -0x10(%rax)
movq -0x98(%rbp), %rsi
movq -0x90(%rbp), %rdx
addq %rsi, %rdx
leaq -0x58(%rbp), %rdi
callq 0x387a
leaq -0x58(%rbp), %rdi
movl %r14d, %esi
callq 0x29e4
movq %rax, %r13
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x2e56
callq 0x21c0
movl %r12d, %edi
movq %r13, %rsi
movl %r15d, %edx
callq 0x2a8e
movl %eax, -0x34(%rbp)
movsd -0x30(%rbp), %xmm0
unpcklps 0x21ad(%rip), %xmm0     # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x21b5(%rip), %xmm0     # 0x5030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, -0xf0(%rbp)
movb $0x1, %al
movl %eax, -0x30(%rbp)
imull %r14d, %r12d
leal 0x28(,%r12,4), %r15d
movl %r15d, %eax
shrl $0x3, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movapd -0xf0(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jb 0x2f2d
addl %r14d, %r12d
leal 0x28(,%r12,4), %r12d
cmpl %r12d, %r15d
jae 0x2ee3
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
callq 0x2b2c
cmpq %r13, %rax
je 0x2ef6
addl %r14d, %r15d
jmp 0x2ec6
movl -0x34(%rbp), %eax
movl %eax, %r12d
testb $0x1, -0x30(%rbp)
movl $0x0, %eax
jne 0x2e91
jmp 0x2f06
movq %rbx, %rdi
movl %r15d, %esi
movl %r14d, %edx
xorl %ecx, %ecx
callq 0x2bfe
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f1b
callq 0x21c0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21b8(%rip), %rdi      # 0x50ec
leaq 0x211f(%rip), %rsi      # 0x505a
leaq 0x21d0(%rip), %rcx      # 0x5112
movl $0xa7, %edx
callq 0x2160
jmp 0x2f7a
jmp 0x2f7a
movq %rax, %rbx
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
jne 0x2f73
jmp 0x2f7d
jmp 0x2f7a
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
cmpq %r13, %rdi
je 0x2f7d
callq 0x21c0
jmp 0x2f7d
movq %rax, %rbx
leaq -0x88(%rbp), %rax
movq -0x10(%rax), %rdi
jmp 0x2fab
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
cmpq %r13, %rdi
je 0x2fa3
callq 0x21c0
jmp 0x2fa3
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2fb5
callq 0x21c0
movq %rbx, %rdi
callq 0x2280
nop