// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_hmap.c
// Function: bcore_hmap_tpaw_s_set_d
vd_t* bcore_hmap_tpaw_s_set_d( bcore_hmap_tpaw_s* o, tp_t key, vd_t val )
{
    if( !key ) ERR( "key is zero" );

    uz_t idx = tpaw_find( o, key );
    if( idx < o->size )
    {
        if( o->nodes[ idx ].val ) bcore_inst_a_discard( o->nodes[ idx ].val );
        o->nodes[ idx ].val = val;
        return &o->nodes[ idx ].val;
    }

    idx = tpaw_set( o, ( bcore_hnode_tpaw_s ){ .key = key, .val = val }, 1 );
    if( idx < o->size ) return &o->nodes[ idx ].val;

    // rehash
    {
        o->flags = bcore_u_alloc( sizeof( bl_t ), o->flags, 0, NULL );
        bcore_hnode_tpaw_s* buf_nodes = o->nodes;
        uz_t  buf_size = o->size;
        o->depth_limit = ( o->size > 0 ) ? o->depth_limit + 1 : 4;
        o->size        = ( o->size > 0 ) ? o->size * 2        : 8;
        o->nodes = bcore_u_memzero( sizeof( bcore_hnode_tpaw_s ), NULL, o->size );
        for( uz_t i = 0; i < buf_size; i++ )
        {
            if( buf_nodes[ i ].key ) bcore_hmap_tpaw_s_set_d( o, buf_nodes[ i ].key, buf_nodes[ i ].val );
        }
        bcore_alloc( buf_nodes, 0 ); // rehashing does not destroy any object (only rearranges nodes)
    }

    return bcore_hmap_tpaw_s_set_d( o, key, val );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
testq %r15, %r15
jne 0xd650b
leaq 0x7a15c(%rip), %rdi     # 0x15064d
leaq 0x79fc6(%rip), %rsi     # 0x1504be
movl $0xe42, %edx            # imm = 0xE42
leaq 0x79ff6(%rip), %rcx     # 0x1504fa
xorl %eax, %eax
callq 0xc80f6
movq %r14, %rdi
movq %r15, %rsi
callq 0xd63e1
cmpq 0x18(%r14), %rax
jb 0xd65d1
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd619a
cmpq 0x18(%r14), %rax
jb 0xd6696
movq 0x10(%r14), %rsi
movl $0x1, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xc8339
movq %rax, 0x10(%r14)
movq 0x18(%r14), %rbp
testq %rbp, %rbp
je 0xd6565
movq 0x20(%r14), %rax
incq %rax
jmp 0xd656a
movl $0x4, %eax
movq 0x8(%r14), %r12
leaq (,%rbp,2), %rdx
testq %rbp, %rbp
movq %rax, 0x20(%r14)
movl $0x8, %eax
cmoveq %rax, %rdx
movq %rdx, 0x18(%r14)
movl $0x10, %edi
xorl %esi, %esi
callq 0xc8389
movq %rax, 0x8(%r14)
testq %rbp, %rbp
je 0xd65c2
leaq 0x8(%r12), %r13
movq -0x8(%r13), %rsi
testq %rsi, %rsi
je 0xd65b9
movq (%r13), %rdx
movq %r14, %rdi
callq 0xd64d1
addq $0x10, %r13
decq %rbp
jne 0xd65a4
movq %r12, %rdi
xorl %esi, %esi
callq 0xc8315
jmp 0xd64e5
movq %rax, %r12
movq 0x8(%r14), %rax
shlq $0x4, %r12
movq 0x8(%rax,%r12), %r15
testq %r15, %r15
je 0xd6686
movq (%r15), %r13
leaq 0xd2e74(%rip), %rax     # 0x1a9468
movl (%rax), %ecx
movslq %ecx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x20(%rax,%rcx,8), %rdx
movq 0x18(%rax,%rcx,8), %rcx
andq %r13, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r13, %rdx
je 0xd664a
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r13, %rdx
je 0xd664a
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r13, %rdx
je 0xd664a
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r13, %rdx
jne 0xd66b4
movq (%rax,%rcx), %rbp
testq %rbp, %rbp
jne 0xd667a
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r13, %rsi
callq 0xf3f85
movq %rax, %rbp
leaq 0xd2df9(%rip), %rdi     # 0x1a9468
movq %r13, %rsi
movq %rax, %rdx
callq 0x12128c
movq %rbp, %rdi
movq %r15, %rsi
callq *0xb8(%rbp)
movq 0x8(%r14), %rax
addq %r12, %rax
addq $0x8, %rax
movq %rbx, (%rax)
jmp 0xd66a5
movq 0x8(%r14), %rcx
shlq $0x4, %rax
addq %rcx, %rax
addq $0x8, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
jmp 0xd664e