// File: /workspace/github_c_makefile_star2_O3/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
je 0xd4283
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd4144
movq 0x18(%rbx), %rcx
cmpq %rcx, %rax
jae 0xd42f5
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 0xd3eac
leaq 0x7263c(%rip), %rdi     # 0x1468c6
leaq 0x7264c(%rip), %rsi     # 0x1468dd
leaq 0x71288(%rip), %rcx     # 0x145520
movl $0xe7, %edx
xorl %eax, %eax
callq 0xbe592
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
je 0xd42f5
leaq -0x1(%rcx), %rdx
movabsq $0x4c04e557831f75b5, %rax # imm = 0x4C04E557831F75B5
andq %rdx, %rax
movq 0x8(%rbx), %rsi
movq %rax, %rdi
shlq $0x5, %rdi
cmpq $0x0, (%rsi,%rdi)
je 0xd425c
movabsq $0x42c60dee75c083c3, %rax # imm = 0x42C60DEE75C083C3
andq %rax, %rdx
movq %rdx, %rax
shlq $0x5, %rax
cmpq $0x0, (%rsi,%rax)
cmovneq %rcx, %rdx
movq %rdx, %rax
jmp 0xd425c
leaq 0x80(%rsp), %r12
leaq 0x28(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
callq 0xbe802
movq %r14, (%r15)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl $0x1, %esi
movq %rbx, %rdi
callq 0xd442f
cmpq 0x18(%rbx), %rax
jae 0xd435f
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 0xd3eac
jmp 0xd4420
movq 0x10(%rbx), %rsi
movl $0x1, %edi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0xbe7d5
movq %rax, 0x10(%rbx)
movq 0x8(%rbx), %r15
movq 0x18(%rbx), %r13
testq %r13, %r13
je 0xd43d3
leaq (,%r13,2), %rdx
movq %rdx, 0x18(%rbx)
incq 0x20(%rbx)
movl $0x20, %edi
xorl %esi, %esi
callq 0xbe825
movq %rax, 0x8(%rbx)
leaq 0x8(%r15), %rbp
movq -0x8(%rbp), %rsi
testq %rsi, %rsi
je 0xd43c8
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xd4234
addq $0x20, %rbp
decq %r13
jne 0xd43a6
jmp 0xd43f8
movq $0x8, 0x18(%rbx)
movq $0x4, 0x20(%rbx)
movl $0x20, %edi
movl $0x8, %edx
xorl %esi, %esi
callq 0xbe825
movq %rax, 0x8(%rbx)
movq %r15, %rdi
xorl %esi, %esi
callq 0xbe7b1
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movups (%r12), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0xd4234
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq