// File: /workspace/github_c_makefile_star2_O0/johsteffens[P]beth/lib/bcore/bcore_flect.c
// Function: bcore_flect_try_d_self
bcore_self_s* bcore_flect_try_d_self( tp_t type )
{
    // try reflection registry
    assert( self_map_s_g != NULL );
    bcore_mutex_s_lock( &self_map_s_g->mutex );
    vd_t* p_val = bcore_hmap_u3vd_s_get( self_map_s_g->hmap, type );
    bcore_mutex_s_unlock( &self_map_s_g->mutex );
    if( p_val ) return *p_val;

    // try constructing self by reflection creator
    bcore_self_s* self = NULL;
    assert( creator_map_s_g != NULL );

    bcore_mutex_s_lock( &creator_map_s_g->mutex );
    fp_t* p_func = bcore_hmap_u3vd_s_getf( creator_map_s_g->hmap, type );
    bcore_mutex_s_unlock( &creator_map_s_g->mutex );

    if( p_func )
    {
        self = ( ( bcore_flect_create_self_fp )*p_func )();
        bcore_self_s* discard_self = NULL; // in case multiple threads land here, redundant creations are discarded again

        if( self->type != type )
        {
            ERR( "Type of created reflection '%s' differs from requested type '%s'.\n"
                 "Requested type was probably mapped to the wrong self-creator during registration.\n",
                 ifnameof( self->type ), ifnameof( type ) );
        }

        bcore_self_s_check_integrity( self );

        bcore_mutex_s_lock( &self_map_s_g->mutex );
        bcore_flect_set_trait( self );

        if( bcore_hmap_u3vd_s_exists( self_map_s_g->hmap, type ) )
        {
            // If this reflection has meanwhile been registered by another thread,
            // kill current self and retrieve registered version
            discard_self = self;
            self = *bcore_hmap_u3vd_s_get( self_map_s_g->hmap, type );
        }
        else
        {
            // else: register current self
            bcore_hmap_u3vd_s_set( self_map_s_g->hmap, type, self, true );
        }
        bcore_mutex_s_unlock( &self_map_s_g->mutex );

        if( discard_self ) bcore_self_s_discard( discard_self );
    }

    return self;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq 0x10af55(%rip), %rdi    # 0x1b2308
addq $0x8, %rdi
callq 0x10fc20
movq 0x10af45(%rip), %rax    # 0x1b2308
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0xab640
movq %rax, -0x18(%rbp)
movq 0x10af2e(%rip), %rdi    # 0x1b2308
addq $0x8, %rdi
callq 0x10fc70
cmpq $0x0, -0x18(%rbp)
je 0xa73fa
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0xa754b
movq $0x0, -0x20(%rbp)
movq 0x10af07(%rip), %rdi    # 0x1b2310
addq $0x8, %rdi
callq 0x10fc20
movq 0x10aef7(%rip), %rax    # 0x1b2310
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0xab7f0
movq %rax, -0x28(%rbp)
movq 0x10aee0(%rip), %rdi    # 0x1b2310
addq $0x8, %rdi
callq 0x10fc70
cmpq $0x0, -0x28(%rbp)
je 0xa7543
movq -0x28(%rbp), %rax
callq *(%rax)
movq %rax, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0xa74a6
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0xa0a30
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0xa0a30
movq -0x38(%rbp), %r8
movq %rax, %r9
leaq 0xa6b87(%rip), %rdi     # 0x14e013
leaq 0xa632f(%rip), %rsi     # 0x14d7c2
movl $0x8f3, %edx            # imm = 0x8F3
leaq 0xa6b8b(%rip), %rcx     # 0x14e02a
movb $0x0, %al
callq 0x9cf40
movq -0x20(%rbp), %rdi
callq 0xa6ef0
movq 0x10ae52(%rip), %rdi    # 0x1b2308
addq $0x8, %rdi
callq 0x10fc20
movq -0x20(%rbp), %rdi
callq 0xa7560
movq 0x10ae39(%rip), %rax    # 0x1b2308
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0xac3f0
testb $0x1, %al
jne 0xa74e1
jmp 0xa7505
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x10ae18(%rip), %rax    # 0x1b2308
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0xab640
movq (%rax), %rax
movq %rax, -0x20(%rbp)
jmp 0xa7521
movq 0x10adfc(%rip), %rax    # 0x1b2308
movq (%rax), %rdi
movq -0x10(%rbp), %rsi
movq -0x20(%rbp), %rdx
movl $0x1, %ecx
callq 0xab870
movq 0x10ade0(%rip), %rdi    # 0x1b2308
addq $0x8, %rdi
callq 0x10fc70
cmpq $0x0, -0x30(%rbp)
je 0xa7541
movq -0x30(%rbp), %rdi
callq 0xa54c0
jmp 0xa7543
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)