// File: /workspace/github_c_makefile_star2_O2/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, (%rsp)
movq %rsi, %r15
movq %rdi, %r14
pushq $0x1
popq %rbp
testq %r15, %r15
jne 0x6996c
leaq 0x59b95(%rip), %rdi     # 0xc34e7
leaq 0x59a2b(%rip), %rsi     # 0xc3384
movl $0xc59, %edx            # imm = 0xC59
leaq 0x59a5b(%rip), %rcx     # 0xc33c0
xorl %eax, %eax
callq 0x60031
cmpq $0x0, 0x8(%r14)
jne 0x69994
leaq 0x59b6d(%rip), %rdi     # 0xc34e7
leaq 0x59a03(%rip), %rsi     # 0xc3384
movl $0xc5a, %edx            # imm = 0xC5A
leaq 0x59b72(%rip), %rcx     # 0xc34ff
xorl %eax, %eax
callq 0x60031
movq %r14, %rdi
movq %r15, %rsi
callq 0x697f9
cmpq 0x20(%r14), %rax
jb 0x69a47
movq %r14, %rdi
movq %r15, %rsi
movq (%rsp), %rdx
movq %rbp, %rcx
callq 0x695cd
cmpq 0x20(%r14), %rax
jb 0x69a79
movq 0x18(%r14), %rsi
movq %rbp, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6025e
movq %rax, 0x18(%r14)
movq 0x20(%r14), %r12
pushq $0x4
popq %rax
testq %r12, %r12
je 0x699ec
movq 0x28(%r14), %rax
incq %rax
movq 0x10(%r14), %r13
leaq (%r12,%r12), %rdx
testq %r12, %r12
movq %rax, 0x28(%r14)
pushq $0x8
popq %rax
cmoveq %rax, %rdx
movq %rdx, 0x20(%r14)
pushq $0x10
popq %rdi
xorl %esi, %esi
callq 0x602ac
movq %rax, 0x10(%r14)
leaq 0x8(%r13), %rbx
subq $0x1, %r12
jb 0x69a38
movq -0x8(%rbx), %rsi
testq %rsi, %rsi
je 0x69a32
movq (%rbx), %rdx
movq %r14, %rdi
callq 0x6992e
addq $0x10, %rbx
jmp 0x69a18
movq %r13, %rdi
xorl %esi, %esi
callq 0x6023e
jmp 0x69946
movq %rax, %r13
movq 0x10(%r14), %rax
shlq $0x4, %r13
movq 0x8(%rax,%r13), %rsi
testq %rsi, %rsi
je 0x69a69
movq 0x8(%r14), %rdi
callq 0x69915
movq 0x10(%r14), %rax
addq %r13, %rax
addq $0x8, %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
jmp 0x69a88
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