// File: /workspace/github_c_makefile_star2_O2/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 0x6f891
leaq 0x54f59(%rip), %rdi     # 0xc47d0
leaq 0x54f69(%rip), %rsi     # 0xc47e7
leaq 0x53b3b(%rip), %rcx     # 0xc33c0
movl $0xe7, %edx
xorl %eax, %eax
callq 0x60031
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6f7f3
cmpq 0x18(%rbx), %rax
jae 0x6f8c0
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 0x6f5ca
leaq 0x80(%rsp), %r12
leaq 0x28(%rsp), %r15
movq %r15, %rdi
callq 0x6f548
movq %r14, (%r15)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x6f9e0
cmpq 0x18(%rbx), %rax
jae 0x6f923
shlq $0x5, %rax
addq 0x8(%rbx), %rax
movq 0x10(%r12), %rcx
movq %rcx, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rax, %rdi
callq 0x6f5ca
jmp 0x6f9d1
movq 0x10(%rbx), %rsi
pushq $0x1
popq %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x6025e
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %r15
movq 0x18(%rbx), %r13
testq %r13, %r13
je 0x6f956
leaq (,%r13,2), %rdx
movq %rdx, 0x18(%rbx)
incq 0x20(%rbx)
jmp 0x6f969
movq $0x8, 0x18(%rbx)
movq $0x4, 0x20(%rbx)
pushq $0x8
popq %rdx
pushq $0x20
popq %rdi
xorl %esi, %esi
callq 0x602ac
movq %rax, 0x8(%rbx)
leaq 0x8(%r15), %rbp
subq $0x1, %r13
jb 0x6f9a9
movq -0x8(%rbp), %rsi
testq %rsi, %rsi
je 0x6f9a3
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x6f857
addq $0x20, %rbp
jmp 0x6f97b
movq %r15, %rdi
xorl %esi, %esi
callq 0x6023e
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6f857
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq