// File: /workspace/github_c_makefile_star2_O1/johsteffens[P]beth/lib/bcore/bcore_hmap_tp_sr.c
// Function: bcore_hmap_tp_sr_s_set
sr_s* bcore_hmap_tp_sr_s_set( bcore_hmap_tp_sr_s* o, tp_t key, sr_s val )
{
    if( !key ) ERR( "key is zero" );

    uz_t idx = tp_sr_find( o, key );
    if( idx < o->size ) return bcore_hnode_tp_sr_s_set( &o->nodes[ idx ], val );

    {
        bcore_hnode_tp_sr_s node;
        bcore_hnode_tp_sr_s_init( &node );
        node.key = key;
        idx = tp_sr_set( o, node, 1 );
        if( idx < o->size ) return bcore_hnode_tp_sr_s_set( &o->nodes[ idx ], val );
    }

    // rehash
    {
        o->flags = bcore_u_alloc( sizeof( bl_t ), o->flags, 0, NULL );
        bcore_hnode_tp_sr_s* buf_nodes = o->nodes;
        uz_t  buf_size = o->size;
        if( o->size > 0 )
        {
            o->size *= 2;
            o->depth_limit++;
        }
        else
        {
            o->size = 8;
            o->depth_limit = 4;
        }

        // Note: We can safely reset the memory as long as bcore_hnode_tp_sr_s_init is memzero
        o->nodes = bcore_u_memzero( sizeof( bcore_hnode_tp_sr_s ), NULL, o->size );

        for( uz_t i = 0; i < buf_size; i++ )
        {
            if( buf_nodes[ i ].key ) bcore_hmap_tp_sr_s_set( o, buf_nodes[ i ].key, buf_nodes[ i ].val );
        }

        // ownership of all buffered nodes has been been transferred above by passing sr_s by value -> nodes must not explicitly shut down
        bcore_alloc( buf_nodes, 0 );
    }

    return bcore_hmap_tp_sr_s_set( o, key, val );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq %rdi, %rbx
testq %rsi, %rsi
jne 0xde032
leaq 0x73888(%rip), %rdi     # 0x1518a0
leaq 0x73898(%rip), %rsi     # 0x1518b7
leaq 0x724d4(%rip), %rcx     # 0x1504fa
movl $0xe7, %edx
xorl %eax, %eax
callq 0xc80f6
movq %rbx, %rdi
movq %r14, %rsi
callq 0xddf08
cmpq 0x18(%rbx), %rax
jae 0xde061
shlq $0x5, %rax
addq 0x8(%rbx), %rax
movq %rax, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xddc70
leaq 0x80(%rsp), %r12
leaq 0x28(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
callq 0xc8366
movq %r14, (%r15)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %esi
movq %rbx, %rdi
callq 0xde199
movq %rax, %r15
movq 0x18(%rbx), %r13
cmpq %r13, %r15
jae 0xde0cc
movq %r15, %rdi
shlq $0x5, %rdi
addq 0x8(%rbx), %rdi
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
callq 0xddc70
cmpq %r13, %r15
jb 0xde18a
movq 0x10(%rbx), %rsi
movl $0x1, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xc8339
movq %rax, 0x10(%rbx)
movq 0x18(%rbx), %r13
testq %r13, %r13
je 0xde106
leaq (,%r13,2), %rax
movq %rax, 0x18(%rbx)
incq 0x20(%rbx)
jmp 0xde116
movq $0x8, 0x18(%rbx)
movq $0x4, 0x20(%rbx)
movq 0x8(%rbx), %r15
movq 0x18(%rbx), %rdx
movl $0x20, %edi
xorl %esi, %esi
callq 0xc8389
movq %rax, 0x8(%rbx)
testq %r13, %r13
je 0xde162
leaq 0x8(%r15), %rbp
movq -0x8(%rbp), %rsi
testq %rsi, %rsi
je 0xde159
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xddff8
addq $0x20, %rbp
decq %r13
jne 0xde137
movq %r15, %rdi
xorl %esi, %esi
callq 0xc8315
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xddff8
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq