// File: 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 %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x68(%rbp)
movq 0x3b371(%rip), %rax     # 0x5a480
movq -0x18(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x20, %esi
callq *%rax
movq -0x68(%rbp), %rcx
movq %rax, -0x20(%rbp)
movq 0x3b35b(%rip), %rax     # 0x5a488
movq -0x18(%rbp), %rdi
movq 0x8(%rcx), %rdx
movl $0x20, %esi
callq *%rax
movq %rax, -0x28(%rbp)
jmp 0x1f142
movq -0x68(%rbp), %rax
cmpl $0x0, 0xc8(%rax)
je 0x1f152
nop
jmp 0x1f142
movq -0x68(%rbp), %rcx
movq -0x20(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq %rdx, -0x30(%rbp)
movq -0x28(%rbp), %rax
xorl %edx, %edx
divq 0x30(%rcx)
movq %rdx, -0x38(%rbp)
movq 0xd0(%rcx), %rsi
movq -0x30(%rbp), %rax
movslq 0xdc(%rcx), %rcx
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rax
addq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x1dd90
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rdi
imulq $0x28, -0x30(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movl $0x20, %edx
callq 0x6190
cmpl $0x0, %eax
jne 0x1f204
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x28, -0x30(%rbp), %rcx
addq %rcx, %rax
movq 0x3bacd(%rip), %rcx     # 0x5aca0
movq %rcx, (%rax)
movq 0x3bacb(%rip), %rcx     # 0x5aca8
movq %rcx, 0x8(%rax)
movq 0x3bac8(%rip), %rcx     # 0x5acb0
movq %rcx, 0x10(%rax)
movq 0x3bac5(%rip), %rcx     # 0x5acb8
movq %rcx, 0x18(%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x1f20b
movl $0x0, -0x4c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x1ddd0
movl -0x4c(%rbp), %eax
testl %eax, %eax
je 0x1f222
jmp 0x1f21d
jmp 0x1f2d7
movq -0x68(%rbp), %rcx
movq 0xd0(%rcx), %rsi
movq -0x38(%rbp), %rax
movslq 0xdc(%rcx), %rcx
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rax
addq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x1dd90
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rdi
imulq $0x28, -0x38(%rbp), %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
movl $0x20, %edx
callq 0x6190
cmpl $0x0, %eax
jne 0x1f2b8
movq -0x68(%rbp), %rax
movq 0x38(%rax), %rax
imulq $0x28, -0x38(%rbp), %rcx
addq %rcx, %rax
movq 0x3ba19(%rip), %rcx     # 0x5aca0
movq %rcx, (%rax)
movq 0x3ba17(%rip), %rcx     # 0x5aca8
movq %rcx, 0x8(%rax)
movq 0x3ba14(%rip), %rcx     # 0x5acb0
movq %rcx, 0x10(%rax)
movq 0x3ba11(%rip), %rcx     # 0x5acb8
movq %rcx, 0x18(%rax)
movb $0x1, -0x1(%rbp)
movl $0x1, -0x4c(%rbp)
jmp 0x1f2bf
movl $0x0, -0x4c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x1ddd0
movl -0x4c(%rbp), %eax
testl %eax, %eax
je 0x1f2d3
jmp 0x1f2d1
jmp 0x1f2d7
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)