// File: /workspace/github_c_makefile_star2_O3/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 0xcb9f8
leaq 0x79c69(%rip), %rdi     # 0x145647
leaq 0x79aff(%rip), %rsi     # 0x1454e4
movl $0xc59, %edx            # imm = 0xC59
leaq 0x79b2f(%rip), %rcx     # 0x145520
xorl %eax, %eax
callq 0xbe592
cmpq $0x0, 0x8(%r14)
jne 0xcba20
leaq 0x79c41(%rip), %rdi     # 0x145647
leaq 0x79ad7(%rip), %rsi     # 0x1454e4
movl $0xc5a, %edx            # imm = 0xC5A
leaq 0x79c46(%rip), %rcx     # 0x14565f
xorl %eax, %eax
callq 0xbe592
movq %r14, %rdi
movq %r15, %rsi
callq 0xcb77f
cmpq 0x20(%r14), %rax
jb 0xcbae9
movl $0x1, %ecx
movq %r14, %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0xcb407
cmpq 0x20(%r14), %rax
jb 0xcbbb0
movq 0x18(%r14), %rsi
movl $0x1, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbe7d5
movq %rax, 0x18(%r14)
movq 0x10(%r14), %rbp
movq 0x20(%r14), %r12
testq %r12, %r12
je 0xcbab5
incq 0x28(%r14)
leaq (%r12,%r12), %rdx
movq %rdx, 0x20(%r14)
movl $0x10, %edi
xorl %esi, %esi
callq 0xbe825
movq %rax, 0x10(%r14)
leaq 0x8(%rbp), %r13
movq -0x8(%r13), %rsi
testq %rsi, %rsi
je 0xcbaaa
movq (%r13), %rdx
movq %r14, %rdi
callq 0xcb9be
addq $0x10, %r13
decq %r12
jne 0xcba95
jmp 0xcbada
movq $0x4, 0x28(%r14)
movq $0x8, 0x20(%r14)
movl $0x10, %edi
movl $0x8, %edx
xorl %esi, %esi
callq 0xbe825
movq %rax, 0x10(%r14)
movq %rbp, %rdi
xorl %esi, %esi
callq 0xbe7b1
jmp 0xcb9d2
movq %rax, %rbp
movq 0x10(%r14), %rax
shlq $0x4, %rbp
movq 0x8(%rax,%rbp), %r15
testq %r15, %r15
je 0xcbba4
movq 0x8(%r14), %r12
leaq 0xd095b(%rip), %rax     # 0x19c468
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 0xcbb63
movq 0x10(%rax), %rdx
movl $0x18, %ecx
cmpq %r12, %rdx
je 0xcbb63
movq 0x20(%rax), %rdx
movl $0x28, %ecx
cmpq %r12, %rdx
je 0xcbb63
movq 0x30(%rax), %rdx
movl $0x38, %ecx
cmpq %r12, %rdx
jne 0xcbb6c
movq (%rax,%rcx), %r13
testq %r13, %r13
jne 0xcbb93
movabsq $0x782b96602f424981, %rdi # imm = 0x782B96602F424981
movq %r12, %rsi
callq 0xe9bc5
movq %rax, %r13
leaq 0xd08e0(%rip), %rdi     # 0x19c468
movq %r12, %rsi
movq %rax, %rdx
callq 0x115fac
movq %r13, %rdi
movq %r15, %rsi
callq *0xb8(%r13)
movq 0x10(%r14), %rax
addq %rbp, %rax
addq $0x8, %rax
movq %rbx, (%rax)
jmp 0xcbbbf
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