// File: /workspace/github_cpp_makefile_star2_O2/night-shift[P]Srl/include/Srl/Hash.hpp
// Function: std::pair<bool, std::shared_ptr<void>*> Srl::Lib::HTable<unsigned long, std::shared_ptr<void>, Srl::Lib::HashSrl<unsigned long, void>>::insert_hash<unsigned long&, std::shared_ptr<void>>(unsigned long, bool, unsigned long&, std::shared_ptr<void>&&)
std::pair<bool, V*> HTable<K, V, H>::insert_hash(uint64_t hash, bool update_on_dup,
                                                     KV&& key, Args&&... args)
    {
        if(this->limit < 1 || this->elements >= this->limit) {
            this->redistribute();
        }

        auto bucket  = get_bucket(hash);
        Entry* entry = table[bucket];
        Entry* prev  = nullptr;

        while(entry) {

            if(entry->hash == hash && entry->key == key) {

                if(update_on_dup) {

                    this->destroy_item(entry->val);
                    new (&entry->val) V(std::forward<Args>(args)...);
                }

                return { true, &entry->val };
            }

            prev  = entry;
            entry = entry->next;
        }

        Entry* mem = nullptr;

        if(this->mem_cache.size() > 0) {
            mem = this->mem_cache.back();
            this->mem_cache.pop_back();

        } else {
            mem = this->heap.template get_mem<Entry>(1);
        }

        auto* new_entry = new (mem) Entry (
            hash, std::forward<KV>(key), std::forward<Args>(args)...
        );

        if(prev) {
            prev->next = new_entry;
        } else {
            table[bucket] = new_entry;
        }

        this->elements++;

        return { false, &(new_entry->val) };
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rcx, %r15
movl %edx, %r9d
movq %rsi, %r12
movq %rdi, %r14
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0x195bc
cmpq %rax, 0x18(%r14)
jb 0x195d0
movq %r14, %rdi
movq %r8, %rbx
movl %r9d, %ebp
callq 0x12130
movl %ebp, %r9d
movq %rbx, %r8
movq 0x8(%r14), %rcx
movq %rcx, %rdx
shrq $0x20, %rdx
movq %r12, %rax
shrq $0x20, %rax
xorl %ebx, %ebx
testq %rdx, %rdx
cmovneq %rbx, %rax
xorq %r12, %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rbp
shlq $0x3, %rbp
movq 0x20(%r14), %rcx
addq %rbp, %rcx
movq (%r15), %rax
movq (%rcx), %r13
testq %r13, %r13
je 0x19621
cmpq %r12, (%r13)
jne 0x19618
cmpq %rax, 0x10(%r13)
je 0x19639
leaq 0x8(%r13), %rcx
movq %r13, %rbx
jmp 0x19604
movq 0x30(%r14), %rax
cmpq 0x28(%r14), %rax
je 0x19665
movq -0x8(%rax), %r13
addq $-0x8, %rax
movq %rax, 0x30(%r14)
jmp 0x1967a
movb $0x1, %bpl
testb %r9b, %r9b
je 0x196a3
leaq 0x20(%r13), %rdi
movq %r8, %rbx
callq 0x11ef0
andq $0x0, 0x20(%r13)
movups (%rbx), %xmm0
andq $0x0, 0x8(%rbx)
movups %xmm0, 0x18(%r13)
andq $0x0, (%rbx)
jmp 0x196a3
leaq 0x48(%r14), %rdi
pushq $0x1
popq %rsi
movq %r8, %r13
callq 0x11380
movq %r13, %r8
movq %rax, %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq %r8, %rcx
callq 0x12490
addq 0x20(%r14), %rbp
leaq 0x8(%rbx), %rax
testq %rbx, %rbx
cmoveq %rbp, %rax
movq %r13, (%rax)
incq 0x18(%r14)
xorl %ebp, %ebp
addq $0x18, %r13
movl %ebp, %eax
movq %r13, %rdx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop