// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_hmap.c
// Function: bcore_hmap_tpto_s_set_d
vd_t* bcore_hmap_tpto_s_set_d( bcore_hmap_tpto_s* o, tp_t key, vd_t val )
{
    if( !key ) ERR( "key is zero" );
    if( !o->type ) ERR( "type is not defined" );

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

    idx = tpto_set( o, ( bcore_hnode_tpto_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_tpto_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_tpto_s ), NULL, o->size );
        for( uz_t i = 0; i < buf_size; i++ )
        {
            if( buf_nodes[ i ].key ) bcore_hmap_tpto_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_tpto_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 0xd5928
leaq 0x7ad13(%rip), %rdi     # 0x150621
leaq 0x7aba9(%rip), %rsi     # 0x1504be
movl $0xc59, %edx            # imm = 0xC59
leaq 0x7abd9(%rip), %rcx     # 0x1504fa
xorl %eax, %eax
callq 0xc80f6
cmpq $0x0, 0x8(%r14)
jne 0xd5950
leaq 0x7aceb(%rip), %rdi     # 0x150621
leaq 0x7ab81(%rip), %rsi     # 0x1504be
movl $0xc5a, %edx            # imm = 0xC5A
leaq 0x7acf0(%rip), %rcx     # 0x150639
xorl %eax, %eax
callq 0xc80f6
movq %r14, %rdi
movq %r15, %rsi
callq 0xd56aa
cmpq 0x20(%r14), %rax
jb 0xd5a16
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xd5326
cmpq 0x20(%r14), %rax
jb 0xd5add
movq 0x18(%r14), %rsi
movl $0x1, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xc8339
movq %rax, 0x18(%r14)
movq 0x20(%r14), %r13
testq %r13, %r13
je 0xd59aa
movq 0x28(%r14), %rax
incq %rax
jmp 0xd59af
movl $0x4, %eax
movq 0x10(%r14), %rbp
leaq (,%r13,2), %rdx
testq %r13, %r13
movq %rax, 0x28(%r14)
movl $0x8, %eax
cmoveq %rax, %rdx
movq %rdx, 0x20(%r14)
movl $0x10, %edi
xorl %esi, %esi
callq 0xc8389
movq %rax, 0x10(%r14)
testq %r13, %r13
je 0xd5a07
leaq 0x8(%rbp), %r12
movq -0x8(%r12), %rsi
testq %rsi, %rsi
je 0xd59fe
movq (%r12), %rdx
movq %r14, %rdi
callq 0xd58ee
addq $0x10, %r12
decq %r13
jne 0xd59e8
movq %rbp, %rdi
xorl %esi, %esi
callq 0xc8315
jmp 0xd5902
movq %rax, %rbp
movq 0x10(%r14), %rax
shlq $0x4, %rbp
movq 0x8(%rax,%rbp), %r15
testq %r15, %r15
je 0xd5acd
movq 0x8(%r14), %r12
leaq 0xd3a2e(%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 %r12, %rcx
shlq $0x4, %rcx
leaq (%rdx,%rcx), %rax
movq (%rdx,%rcx), %rdx
movl $0x8, %ecx
cmpq %r12, %rdx
je 0xd5a90
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r12, %rdx
je 0xd5a90
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r12, %rdx
je 0xd5a90
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r12, %rdx
jne 0xd5afb
movq (%rax,%rcx), %r13
testq %r13, %r13
jne 0xd5ac0
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r12, %rsi
callq 0xf3f85
movq %rax, %r13
leaq 0xd39b3(%rip), %rdi     # 0x1a9468
movq %r12, %rsi
movq %rax, %rdx
callq 0x12128c
movq %r13, %rdi
movq %r15, %rsi
callq *0xb8(%r13)
movq 0x10(%r14), %rax
addq %rbp, %rax
addq $0x8, %rax
movq %rbx, (%rax)
jmp 0xd5aec
movq 0x10(%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 %r13d, %r13d
jmp 0xd5a94