// File: /workspace/github_cpp_makefile_star2_O2/chahk0129[P]hash_bench/./index/cuckoo_hash.h
// Function: CuckooHash<char [32]>::Delete(char (&) [32])
bool CuckooHash<Key_t>::Delete(Key_t& key) {
    size_t f_hash, s_hash;
    if constexpr(sizeof(Key_t) > 8){
        f_hash = hash_funcs[0](key, sizeof(Key_t), _seed);
        s_hash = hash_funcs[1](key, sizeof(Key_t), _seed);
    }
    else{
        f_hash = hash_funcs[0](&key, sizeof(Key_t), _seed);
        s_hash = hash_funcs[1](&key, sizeof(Key_t), _seed);
    }

RETRY:
    while(resizing_lock){
        asm("nop");
    }

    auto f_idx = f_hash % capacity;
    auto s_idx = s_hash % capacity;

    { // try first hashing
        unique_lock<shared_mutex> lock(mutex[f_idx/locksize]);
        if constexpr(sizeof(Key_t) > 8){
            if(memcmp(table[f_idx].key, key, sizeof(Key_t)) == 0){
                memcpy(table[f_idx].key, INVALID<Key_t>, sizeof(Key_t));
                return true;
            }
        }
        else{
            if(memcmp(&table[f_idx].key, &key, sizeof(Key_t)) == 0){
                memcpy(&table[f_idx].key, &INVALID<Key_t>, sizeof(Key_t));
                return true;
            }
        }
    }

    { // try second hashing
        unique_lock<shared_mutex> lock(mutex[s_idx/locksize]);
        if constexpr(sizeof(Key_t) > 8){
            if(memcmp(table[s_idx].key, key, sizeof(Key_t)) == 0){
                memcpy(table[s_idx].key, INVALID<Key_t>, sizeof(Key_t));
                return true;
            }
        }
        else{
            if(memcmp(&table[s_idx].key, &key, sizeof(Key_t)) == 0){
                memcpy(&table[s_idx].key, &INVALID<Key_t>, sizeof(Key_t));
                return true;
            }
        }
    }
                                                                           
  return false;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x8(%rdi), %rdx
pushq $0x20
popq %r15
movq %rsi, %rdi
movq %r15, %rsi
callq 0x2040
movq %rax, %r12
movq 0x8(%r14), %rdx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x82f2
movq %rax, %r15
cmpl $0x0, 0xc8(%r14)
je 0x94e2
nop
jmp 0x94d5
movq 0x30(%r14), %r13
movq %r12, %rax
xorl %edx, %edx
divq %r13
movq %rdx, %r12
movslq 0xdc(%r14), %rcx
movq %rdx, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rsi
addq 0xd0(%r14), %rsi
movq %rsp, %rdi
callq 0x8a0c
imulq $0x28, %r12, %r12
addq 0x38(%r14), %r12
pushq $0x20
popq %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x2200
testl %eax, %eax
je 0x95a0
movq %r15, %rax
xorl %edx, %edx
divq %r13
movq %rdx, %r15
movq %rsp, %rdi
callq 0x8a22
movslq 0xdc(%r14), %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rsi
addq 0xd0(%r14), %rsi
movq %rsp, %rdi
callq 0x8a0c
imulq $0x28, %r15, %r15
addq 0x38(%r14), %r15
pushq $0x20
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x2200
testl %eax, %eax
sete %bl
jne 0x9596
movaps 0xad6a(%rip), %xmm0     # 0x142f0
movups %xmm0, 0x10(%r15)
movaps 0xad4e(%rip), %xmm0     # 0x142e0
movups %xmm0, (%r15)
movq %rsp, %rdi
callq 0x8a22
jmp 0x95c3
movaps 0xad49(%rip), %xmm0     # 0x142f0
movups %xmm0, 0x10(%r12)
movaps 0xad2c(%rip), %xmm0     # 0x142e0
movups %xmm0, (%r12)
movq %rsp, %rdi
callq 0x8a22
movb $0x1, %bl
movl %ebx, %eax
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
nop