// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0xbb9f3
leaq 0x95244(%rip), %rdi     # 0x150c1d
leaq 0x95254(%rip), %rsi     # 0x150c34
movl $0xe7, %edx
leaq 0x93df3(%rip), %rcx     # 0x14f7df
movb $0x0, %al
callq 0x9cf40
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xbb8f0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0xbba50
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rdi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xbb4d0
movq %rax, -0x8(%rbp)
jmp 0xbbc3f
leaq -0x40(%rbp), %rdi
callq 0xbb3c0
movq -0x18(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x40(%rbp), %rax
movl $0x1, %esi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x18(%rsp)
callq 0xbbc50
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jae 0xbbae5
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x20(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rdi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xbb4d0
movq %rax, -0x8(%rbp)
jmp 0xbbc3f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %edi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x9d330
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0xbbb4d
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
shlq %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x20(%rax)
jmp 0xbbb65
movq -0x10(%rbp), %rax
movq $0x8, 0x18(%rax)
movq -0x10(%rbp), %rax
movq $0x4, 0x20(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdx
movl $0x20, %edi
xorl %eax, %eax
movl %eax, %esi
callq 0x9d540
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0xbbc04
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
cmpq $0x0, (%rax)
je 0xbbbf4
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
addq $0x8, %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xbb9b0
jmp 0xbbbf6
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xbbb8e
movq -0x48(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9d210
movq -0x60(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0xbb9b0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)