// File: /workspace/github_cpp_makefile_star2_O3/chahk0129[P]hash_bench/./index/cuckoo_hash.h
// Function: CuckooHash<char [32]>::Update(char (&) [32], long)
bool CuckooHash<Key_t>::Update(Key_t& key, Value_t value) {
    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].value, &value, sizeof(Value_t));
                return true;
            }
        }
        else{
            if(memcmp(&table[f_idx].key, &key, sizeof(Key_t)) == 0){
		memcpy(&table[f_idx].value, &value, sizeof(Value_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].value, &value, sizeof(Value_t));
                return true;
            }
        }
        else{
            if(memcmp(&table[s_idx].key, &key, sizeof(Key_t)) == 0){
		memcpy(&table[s_idx].value, &value, sizeof(Value_t));
                return true;
            }
        }
    }
                                                                           
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, (%rsp)
movq %rsi, %r14
movq %rdi, %r15
movq 0x8(%rdi), %rdx
movl $0x20, %esi
movq %r14, %rdi
callq 0x2050
movl 0x8(%r15), %ebp
xorl $0x20, %ebp
xorl %ecx, %ecx
imull $0x5bd1e995, (%r14,%rcx), %edx # imm = 0x5BD1E995
movl %edx, %esi
shrl $0x18, %esi
xorl %edx, %esi
imull $0x5bd1e995, %esi, %edx # imm = 0x5BD1E995
imull $0x5bd1e995, %ebp, %ebp # imm = 0x5BD1E995
xorl %edx, %ebp
addq $0x4, %rcx
cmpq $0x20, %rcx
jne 0xb5e4
jmp 0xb60e
nop
cmpl $0x0, 0xc8(%r15)
jne 0xb60d
movq 0x30(%r15), %rbx
xorl %edx, %edx
divq %rbx
movq %rdx, %r12
movslq 0xdc(%r15), %rcx
movq %rdx, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rax
addq 0xd0(%r15), %rax
leaq 0x8(%rsp), %r13
movq %rax, (%r13)
movb $0x0, 0x8(%r13)
movq %r13, %rdi
callq 0xad3c
movb $0x1, 0x8(%r13)
movq 0x38(%r15), %rax
leaq (%r12,%r12,4), %rcx
movdqu (%rax,%rcx,8), %xmm0
movdqu 0x10(%rax,%rcx,8), %xmm1
movdqu (%r14), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu 0x10(%r14), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %edx
cmpl $0xffff, %edx           # imm = 0xFFFF
je 0xb743
movl %ebp, %eax
shrl $0xd, %eax
xorl %ebp, %eax
imull $0x5bd1e995, %eax, %ecx # imm = 0x5BD1E995
movl %ecx, %eax
shrl $0xf, %eax
xorl %ecx, %eax
xorl %edx, %edx
divq %rbx
movq %rdx, %r12
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0xaa52
movslq 0xdc(%r15), %rcx
movq %r12, %rax
xorl %edx, %edx
divq %rcx
imulq $0x38, %rax, %rax
addq 0xd0(%r15), %rax
movq %rax, (%r13)
movb $0x0, 0x8(%r13)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
callq 0xad3c
movb $0x1, 0x8(%r13)
movq 0x38(%r15), %rax
leaq (%r12,%r12,4), %rcx
movdqu (%rax,%rcx,8), %xmm0
movdqu 0x10(%rax,%rcx,8), %xmm1
movdqu (%r14), %xmm2
pcmpeqb %xmm0, %xmm2
movdqu 0x10(%r14), %xmm0
pcmpeqb %xmm1, %xmm0
pand %xmm2, %xmm0
pmovmskb %xmm0, %edx
cmpl $0xffff, %edx           # imm = 0xFFFF
sete %bpl
jne 0xb737
leaq (%rax,%rcx,8), %rax
movq (%rsp), %rcx
movq %rcx, 0x20(%rax)
leaq 0x8(%rsp), %rdi
callq 0xaa52
jmp 0xb75c
leaq (%rax,%rcx,8), %rax
movq (%rsp), %rcx
movq %rcx, 0x20(%rax)
leaq 0x8(%rsp), %rdi
callq 0xaa52
movb $0x1, %bpl
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop