// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_hmap_tp_st.c
// Function: bcore_hmap_tp_st_selftest
void bcore_hmap_tp_st_selftest( void )
{
    bcore_life_s* l = bcore_life_s_create();
    st_s* log = st_s_createf( "== bcore_hmap_tp_st_selftest " );
    st_s_push_char_n( log, '=', 80 - log->size );
    st_s_push_char( log, '\n' );

    bcore_hmap_tp_st_s* map = bcore_life_s_push_aware( l, bcore_hmap_tp_st_s_create() );
    const uz_t cycles = 200000;

    typedef struct
    {
        tp_t key;
        u3_t val;
    } kv_s;

    kv_s* kvbuf = bcore_alloc( NULL, cycles * sizeof( kv_s ) );
    uz_t kvbuf_size = 0;

    clock_t time = clock();
    st_s_pushf( log, "Mixed access: " );

    {
        u3_t rval1 = 1;
        u3_t rval2 = 12345;
        for( uz_t i = 0; i < cycles; i++ )
        {
            rval1 = bcore_lcg00_u3( rval1 );
            rval2 = bcore_lcg00_u3( rval2 );
            kv_s kv;
            kv.key = ( tp_t )rval1;
            kv.val = rval2;
            kvbuf[ kvbuf_size++ ] = kv;

            // set
            bcore_hmap_tp_st_s_set_d( map, kv.key, st_s_create_typed( TYPEOF_u3_t, &kv.val ) );

            // retrieve
            rval1 = bcore_lcg00_u3( rval1 );
            kv = kvbuf[ rval1 % kvbuf_size ];

            u3_t val = 0;
            st_s_parse_fa( bcore_hmap_tp_st_s_get( map, kv.key ), 0, -1, "#<u3_t*>", &val );
            if( kv.val != val ) ERR( "value mismatch (%lu vs %lu)", kv.val, val );

            // delete
            rval1 = bcore_lcg00_u3( rval1 );
            if( ( ( rval1 >> 10 ) & 1 ) == 1 )
            {
                rval1 = bcore_lcg00_u3( rval1 );
                uz_t idx = rval1 % kvbuf_size;
                kv_s kv = kvbuf[ idx ];
                if( !bcore_hmap_tp_st_s_get( map, kv.key ) )  ERR( "key (%lu) not found", kv.key );
                bcore_hmap_tp_st_s_remove( map, kv.key );
                if( bcore_hmap_tp_st_s_get(  map, kv.key ) )  ERR( "deleted key still exists (%lu)", kv.key );
                kvbuf_size--;
                kvbuf[ idx ] = kvbuf[ kvbuf_size ];
            }
        }
    }

    time = clock() - time;
    st_s_pushf( log, "(%5.3fs)\n", ( double )time/CLOCKS_PER_SEC );
    st_s_push_st_d( log, hmap_tp_st_s_status( map ) );

    time = clock();
    bcore_hmap_tp_st_s* map2 = bcore_life_s_push_aware( l, bcore_hmap_tp_st_s_clone( map ) );
    time = clock() - time;
    st_s_pushf( log, "Clone .......... %5.3fs\n", ( double )time/CLOCKS_PER_SEC );

    time = clock();
    if( bcore_compare_aware( map, map2 ) != 0 )
    {
        ERR( "comparison failed:\n%s", bcore_diff_aware( map, map2 )->sc );
    }

    time = clock() - time;
    st_s_pushf( log, "Comparison ..... %5.3fs\n", ( double )time/CLOCKS_PER_SEC );

    time = clock();
    bcore_hmap_tp_st_s* map3 = bcore_life_s_push_aware( l, bcore_hmap_tp_st_s_create() );
    bcore_via_a_nset( (bcore_via*)map3, typeof( "map" ), bcore_via_a_nget( (bcore_via*)map, typeof( "map" ) ) );
    time = clock() - time;
    st_s_pushf( log, "Via-assign ..... %5.3fs\n", ( double )time/CLOCKS_PER_SEC );
    time = clock();
    uz_t map_size = bcore_hmap_tp_st_s_size( map );
    for( uz_t i = 0; i < map_size; i++ )
    {
        tp_t key = bcore_hmap_tp_st_s_idx_key( map, i );
        if( key != 0 )
        {
            u3_t val1 = 0;
            st_s_parse_fa( bcore_hmap_tp_st_s_get( map, key ), 0, -1, "#<u3_t*>", &val1 );
            ASSERT( bcore_hmap_tp_st_s_exists( map3, key ) );
            u3_t val2 = 1;
            st_s_parse_fa( bcore_hmap_tp_st_s_get( map3, key ), 0, -1, "#<u3_t*>", &val2 );
            ASSERT( val1 == val2 );
        }
    }
    time = clock() - time;
    st_s_pushf( log, "verify assign .. %5.3fs\n", ( double )time/CLOCKS_PER_SEC );

    time = clock();
    st_s_pushf( log, "\nRead-access of %lu keys: ", kvbuf_size );
    uz_t read_cycles = 20;
    for( uz_t j = 0; j < read_cycles; j++ )
    {
        for( uz_t i = 0; i < kvbuf_size; i++ )
        {
            u3_t val = 0;
            st_s_parse_fa( bcore_hmap_tp_st_s_get( map, kvbuf[ i ].key ), 0, -1, "#<u3_t*>", &val );
            if( val != kvbuf[ i ].val ) ERR( "value mismatch (%lu vs %lu)", val, kvbuf[ i ].val );
        }
    }
    time = clock() - time;
    st_s_pushf( log, "(%gs per access)\n", ( ( double )time/CLOCKS_PER_SEC ) / ( kvbuf_size * read_cycles ) );

    st_s_pushf( log, "\n" );
    st_s_pushf( log, "Removal: " );
    time = clock();
    while( kvbuf_size )
    {
        kvbuf_size--;
        kv_s kv = kvbuf[ kvbuf_size ];
        if( !bcore_hmap_tp_st_s_get( map, kv.key ) )  ERR( "key (%lu) not found", kv.key );
        bcore_hmap_tp_st_s_remove( map, kv.key );
        if( bcore_hmap_tp_st_s_get( map, kv.key ) )  ERR( "deleted key still exists (%lu)", kv.key );
    }
    time = clock() - time;
    st_s_pushf( log, "(%5.3fs)\n", ( double )time/CLOCKS_PER_SEC );
    st_s_push_st_d( log, hmap_tp_st_s_status( map ) );
    bcore_alloc( kvbuf, 0 );
    bcore_life_s_discard( l );

    st_s_push_char_n( log, '=', 80 );

    bcore_msg_fa( "#<sc_t>\n", log->sc );
    st_s_discard( log );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movabsq $0x1c140000000001cd, %rbp # imm = 0x1C140000000001CD
xorl %eax, %eax
callq 0x717ac
movq %rax, %r14
leaq 0x53cbd(%rip), %rdi     # 0xc4a55
xorl %eax, %eax
callq 0x8ebc4
movq %rax, %rbx
pushq $0x50
popq %rdx
subq 0x10(%rax), %rdx
pushq $0x3d
popq %rsi
movq %rax, %rdi
callq 0x8f175
pushq $0xa
popq %rsi
movq %rbx, %rdi
callq 0x8f0ee
xorl %eax, %eax
callq 0x3082b
movq %r14, 0x78(%rsp)
movq %r14, %rdi
movq %rax, %rsi
callq 0x71a4d
movq %rax, %r14
movl $0x30d400, %esi         # imm = 0x30D400
xorl %edi, %edi
callq 0x6023e
movq %rax, %r12
callq 0xd340
movq %rax, 0x70(%rsp)
leaq 0x45ea2(%rip), %rsi     # 0xb6c9b
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8f42b
movq %r14, 0x20(%rsp)
addq $0x8, %r14
movq %r14, 0x38(%rsp)
pushq $0x1
popq %rbx
movl $0x3039, %eax           # imm = 0x3039
movl $0x30d40, %r14d         # imm = 0x30D40
movq $0x0, 0x28(%rsp)
movq %r12, 0x48(%rsp)
subq $0x1, %r14
jb 0x70fde
imulq %rbp, %rbx
incq %rbx
imulq %rbp, %rax
incq %rax
movq %rbx, 0x50(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x58(%rsp)
movq 0x28(%rsp), %r13
leaq 0x1(%r13), %r15
shlq $0x4, %r13
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%r12,%r13)
movabsq $-0x5aa4411ac4e2880e, %rdi # imm = 0xA55BBEE53B1D77F2
leaq 0x58(%rsp), %rsi
callq 0x8eeed
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
movq %rax, %rdx
callq 0x69f92
imulq %rbp, %rbx
incq %rbx
movq %rbx, %rax
xorl %edx, %edx
divq %r15
shlq $0x4, %rdx
movups (%r12,%rdx), %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x40(%rsp)
movq 0x50(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0x71546
movq %rax, %rdi
xorl %esi, %esi
pushq $-0x1
popq %rdx
leaq 0x51a70(%rip), %rcx     # 0xc2945
leaq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x91e11
movq 0x58(%rsp), %r8
movq 0x40(%rsp), %r9
cmpq %r9, %r8
je 0x70f0f
leaq 0x47c37(%rip), %rdi     # 0xb8b2e
leaq 0x53b75(%rip), %rsi     # 0xc4a73
pushq $0x51
popq %rdx
leaq 0x5337b(%rip), %rcx     # 0xc4283
xorl %eax, %eax
callq 0x60031
imulq %rbp, %rbx
incq %rbx
btl $0xa, %ebx
jb 0x70f26
movq %r15, 0x28(%rsp)
jmp 0x70fd4
imulq %rbp, %rbx
incq %rbx
movq %rbx, %rax
xorl %edx, %edx
divq %r15
movq %rdx, %r15
shlq $0x4, %r15
movq (%r12,%r15), %r12
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x71546
testq %rax, %rax
jne 0x70f77
leaq 0x47bd2(%rip), %rdi     # 0xb8b2e
leaq 0x53b10(%rip), %rsi     # 0xc4a73
pushq $0x5a
popq %rdx
leaq 0x53332(%rip), %rcx     # 0xc429f
movq %r12, %r8
xorl %eax, %eax
callq 0x60031
movq 0x38(%rsp), %rdi
movq %r12, %rsi
callq 0x6a128
movq %rbp, %rdi
movq %r12, %rsi
callq 0x71546
testq %rax, %rax
je 0x70fb6
leaq 0x47b93(%rip), %rdi     # 0xb8b2e
leaq 0x53ad1(%rip), %rsi     # 0xc4a73
pushq $0x5c
popq %rdx
leaq 0x53307(%rip), %rcx     # 0xc42b3
movq %r12, %r8
xorl %eax, %eax
callq 0x60031
movq 0x48(%rsp), %r12
addq %r12, %r13
addq %r12, %r15
movups (%r13), %xmm0
movups %xmm0, (%r15)
movabsq $0x1c140000000001cd, %rbp # imm = 0x1C140000000001CD
movq 0x18(%rsp), %rax
jmp 0x70e32
callq 0xd340
subq 0x70(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x3907b(%rip), %xmm0    # 0xaa070
leaq 0x532d6(%rip), %rsi     # 0xc42d2
movq 0x30(%rsp), %r15
movq %r15, %rdi
movb $0x1, %al
callq 0x8f42b
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0x7155e
movq %r15, %rdi
movq %rax, %rsi
callq 0x8f2e5
callq 0xd340
movq %rax, %rbx
movq %rbp, %rdi
callq 0x3084c
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x71a4d
movq %rax, %r14
callq 0xd340
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x39018(%rip), %xmm0    # 0xaa070
leaq 0x532da(%rip), %rsi     # 0xc4339
movq %r15, %rdi
movb $0x1, %al
callq 0x8f42b
callq 0xd340
movq %rax, %rbx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x81306
testl %eax, %eax
je 0x710ae
movq %rbp, %rdi
movq %r14, %rsi
callq 0x81ada
movq 0x8(%rax), %r8
leaq 0x47a98(%rip), %rdi     # 0xb8b2e
leaq 0x539d6(%rip), %rsi     # 0xc4a73
leaq 0x45c94(%rip), %rcx     # 0xb6d38
pushq $0x6f
popq %rdx
xorl %eax, %eax
callq 0x60031
callq 0xd340
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
movsd 0x38fad(%rip), %xmm1    # 0xaa070
divsd %xmm1, %xmm0
leaq 0x532aa(%rip), %rsi     # 0xc4378
movq 0x30(%rsp), %r12
movq %r12, %rdi
movb $0x1, %al
callq 0x8f42b
callq 0xd340
movq %rax, %rbx
xorl %eax, %eax
callq 0x3082b
movq 0x78(%rsp), %rdi
movq %rax, %rsi
callq 0x71a4d
movq %rax, %r13
movq (%rbp), %rdi
callq 0x71612
leaq 0x80(%rsp), %r14
movabsq $0x80f5919176d2d91, %r15 # imm = 0x80F5919176D2D91
movq %r14, %rdi
movq %rax, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x8aec5
movq 0x10(%r14), %rax
leaq 0x50(%rsp), %rbp
movq %rax, 0x10(%rbp)
movups (%r14), %xmm0
movaps %xmm0, (%rbp)
movq (%r13), %rdi
callq 0x71612
movq 0x10(%rbp), %rcx
movq %rcx, 0x10(%rsp)
movaps (%rbp), %xmm0
movups %xmm0, (%rsp)
movq %rax, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x8aef8
callq 0xd340
subq %rbx, %rax
cvtsi2sd %rax, %xmm0
divsd 0x38ef6(%rip), %xmm0    # 0xaa070
leaq 0x53210(%rip), %rsi     # 0xc4391
movq %r12, %rdi
movb $0x1, %al
callq 0x8f42b
callq 0xd340
movq %rax, 0x18(%rsp)
movq 0x38(%rsp), %rdi
callq 0x6a227
movq %rax, %r14
movq %r13, %rbp
movq %r13, %rbx
addq $0x8, %rbx
pushq $-0x1
popq %r13
xorl %r15d, %r15d
cmpq %r15, %r14
je 0x712a7
movq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x6a22c
testq %rax, %rax
je 0x7129f
movq %rax, %r12
andq $0x0, 0x50(%rsp)
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x71546
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x5174e(%rip), %rcx     # 0xc2945
leaq 0x50(%rsp), %r8
xorl %eax, %eax
callq 0x91e11
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6a16d
testb %al, %al
jne 0x7123b
leaq 0x3942e(%rip), %rdi     # 0xaa647
leaq 0x53866(%rip), %rsi     # 0xc4a86
leaq 0x47907(%rip), %rdx     # 0xb8b2e
leaq 0x53845(%rip), %rcx     # 0xc4a73
movl $0x83, %r8d
xorl %eax, %eax
callq 0x5ffac
movq $0x1, 0x40(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x71546
movq %rax, %rdi
xorl %esi, %esi
movq %r13, %rdx
leaq 0x516e7(%rip), %rcx     # 0xc2945
leaq 0x40(%rsp), %r8
xorl %eax, %eax
callq 0x91e11
movq 0x50(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x7129f
leaq 0x393ca(%rip), %rdi     # 0xaa647
leaq 0x53829(%rip), %rsi     # 0xc4aad
leaq 0x478a3(%rip), %rdx     # 0xb8b2e
leaq 0x537e1(%rip), %rcx     # 0xc4a73
movl $0x86, %r8d
xorl %eax, %eax
callq 0x5ffac
incq %r15
jmp 0x711b3
callq 0xd340
subq 0x18(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x38db2(%rip), %xmm0    # 0xaa070
leaq 0x53136(%rip), %rsi     # 0xc43fb
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x8f42b
callq 0xd340
movq %rax, 0x70(%rsp)
leaq 0x52ff7(%rip), %rsi     # 0xc42dc
movq %rbx, %rdi
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x8f42b
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x18(%rsp)
leaq 0x5163c(%rip), %r14     # 0xc2945
pushq $-0x1
popq %r15
leaq 0x50(%rsp), %r13
xorl %r12d, %r12d
movq 0x18(%rsp), %rbx
movq 0x28(%rsp), %rbp
cmpq $0x14, %r12
je 0x7138d
subq $0x1, %rbp
jb 0x71388
andq $0x0, 0x50(%rsp)
movq -0x8(%rbx), %rsi
movq 0x20(%rsp), %rdi
callq 0x71546
movq %rax, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r14, %rcx
movq %r13, %r8
xorl %eax, %eax
callq 0x91e11
movq 0x50(%rsp), %r8
movq (%rbx), %r9
cmpq %r9, %r8
je 0x71382
leaq 0x477c6(%rip), %rdi     # 0xb8b2e
leaq 0x53704(%rip), %rsi     # 0xc4a73
movl $0x95, %edx
leaq 0x52f08(%rip), %rcx     # 0xc4283
xorl %eax, %eax
callq 0x60031
addq $0x10, %rbx
jmp 0x71325
incq %r12
jmp 0x71315
callq 0xd340
subq 0x70(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x38ccc(%rip), %xmm0    # 0xaa070
movq 0x28(%rsp), %r14
imulq $0x14, %r14, %rax
movq %rax, %xmm1
punpckldq 0x432f6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x432fe(%rip), %xmm1    # 0xb46c0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
leaq 0x52f1e(%rip), %rsi     # 0xc42f7
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x8f42b
leaq 0x551dc(%rip), %rsi     # 0xc65cb
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8f42b
leaq 0x45af6(%rip), %rsi     # 0xb6ef6
movq %rbx, %rdi
xorl %eax, %eax
callq 0x8f42b
callq 0xd340
movq %rax, 0x18(%rsp)
movq %r14, %rax
shlq $0x4, %rax
movq 0x48(%rsp), %rcx
leaq (%rcx,%rax), %rbx
addq $-0x10, %rbx
leaq 0x476ff(%rip), %r14     # 0xb8b2e
leaq 0x5363d(%rip), %r15     # 0xc4a73
leaq 0x52e76(%rip), %r12     # 0xc42b3
movq 0x20(%rsp), %r13
subq $0x1, 0x28(%rsp)
jb 0x714b4
movq (%rbx), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x71546
testq %rax, %rax
jne 0x71479
movq %r14, %rdi
movq %r15, %rsi
movl $0xa2, %edx
leaq 0x52e30(%rip), %rcx     # 0xc429f
movq %rbp, %r8
xorl %eax, %eax
callq 0x60031
movq 0x38(%rsp), %rdi
movq %rbp, %rsi
callq 0x6a128
movq %r13, %rdi
movq %rbp, %rsi
callq 0x71546
testq %rax, %rax
je 0x714ae
movq %r14, %rdi
movq %r15, %rsi
movl $0xa4, %edx
movq %r12, %rcx
movq %rbp, %r8
xorl %eax, %eax
callq 0x60031
addq $-0x10, %rbx
jmp 0x71442
callq 0xd340
subq 0x18(%rsp), %rax
cvtsi2sd %rax, %xmm0
divsd 0x38ba5(%rip), %xmm0    # 0xaa070
leaq 0x52e00(%rip), %rsi     # 0xc42d2
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movb $0x1, %al
callq 0x8f42b
movq 0x20(%rsp), %rdi
callq 0x7155e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x8f2e5
movq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x6023e
movq 0x78(%rsp), %rdi
callq 0x717c7
pushq $0x3d
popq %rsi
pushq $0x50
popq %rdx
movq %rbx, %rdi
callq 0x8f175
movq 0x8(%rbx), %rsi
leaq 0x5ab83(%rip), %rdi     # 0xcc0a8
xorl %eax, %eax
callq 0x5fc08
movq %rbx, %rdi
callq 0x8edd4
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq