// File: /workspace/github_c_makefile_star2_O0/johsteffens[P]beth/lib/bcore/bcore_btree.c
// Function: btree_vd_s_selftest
static st_s* btree_vd_s_selftest( void )
{
    st_s* log = st_s_createf( "== btree_vd_s_selftest " );
    st_s_push_char_n( log, '=', 80 - log->size );
    st_s_push_char( log, '\n' );

    bcore_btree_vd_s* t = bcore_btree_vd_s_create( NULL );
    const uz_t cycles = 200000;

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

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

    {
        u3_t rval = 1;
        for( uz_t i = 0; i < cycles; i++ )
        {
            bcore_btree_vd_kv_s kv;

            // use multiple of 256 to allow nearest_... tests
            // The left-shift can produce key repetitions on 32bit systems. The loop below ensures stored keys are not repeated.
            while( bcore_btree_vd_s_exists( t, ( kv.key = ( bcore_btree_vd_key_t )(intptr_t)( ( rval = bcore_xsg_u2( rval ) ) << 8 ) ) ) );
            kvbuf[ kvbuf_size++ ] = kv;

            // set
            bcore_btree_vd_s_set( t, kv.key );

            // retrieve
            rval = bcore_xsg_u2( rval );
            kv = kvbuf[ rval % kvbuf_size ];
            if( !bcore_btree_vd_s_exists( t, kv.key ) ) ERR( "key %lu does not exist", kv.key );

            // delete
            rval = bcore_xsg_u2( rval );
            if( ( ( rval >> 10 ) & 1 ) == 1 )
            {
                rval = bcore_xsg_u2( rval );
                uz_t idx = rval % kvbuf_size;
                bcore_btree_vd_kv_s kv = kvbuf[ idx ];
                if( !bcore_btree_vd_s_exists( t, kv.key ) ) ERR( "key %lu does not exist", kv.key );
                bcore_btree_vd_s_remove( t, kv.key );
                if( bcore_btree_vd_s_exists( t, 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 );

    bcore_btree_node_vd_s_check_consistency( t->root );
    st_s_push_st_d( log, bcore_btree_vd_s_status( t ) );

    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++ )
        {
            if( !bcore_btree_vd_s_exists( t, kvbuf[ i ].key ) ) ERR( "key %lu does not exist", kvbuf[ i ].key );
        }
    }
    time = clock() - time;
    st_s_pushf( log, "(%gs per access)\n", ( ( double )time/CLOCKS_PER_SEC ) / ( kvbuf_size * read_cycles ) );

    time = clock();
    st_s_pushf( log, "largest_below_equal - test: ", kvbuf_size );
    if( bcore_btree_vd_s_largest_below_equal( t, (bcore_btree_vd_key_t)1 ) != 0 ) ERR( "largest_below_equal( 1 ) failed" );
    for( uz_t j = 0; j < 10; j++ )
    {
        for( uz_t i = 0; i < kvbuf_size; i++ )
        {
            bcore_btree_vd_key_t key0 = ( u0_t* )kvbuf[ i ].key + j;
            bcore_btree_vd_key_t key1 = bcore_btree_vd_s_largest_below_equal( t, key0 );
            // stored keys have a minimum distance of 256, so this test should yield key0 - key1 == j;
            if( ( (u0_t*)key0 - (u0_t*)key1 != j ) ) ERR( "largest_below_equal failed at distance %j: key0=%lu, key1=%lu", j, key0, key1 );
        }
    }
    time = clock() - time;
    st_s_pushf( log, "(%5.3gs per test)\n", ( ( double )time/CLOCKS_PER_SEC ) / ( kvbuf_size * 10 ) );


    st_s_pushf( log, "\n" );
    st_s_pushf( log, "Removal: " );
    time = clock();
    while( kvbuf_size )
    {
        kvbuf_size--;
        bcore_btree_vd_kv_s kv = kvbuf[ kvbuf_size ];
        if( !bcore_btree_vd_s_exists( t, kv.key ) ) ERR( "key %lu does not exist", kv.key );
        bcore_btree_vd_s_remove( t, kv.key );
        if( bcore_btree_vd_s_exists( t, 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 );

    if( t->root ) ERR( "root still exists" );

    st_s_push_st_d( log, bcore_btree_vd_s_status( t ) );

    bcore_btree_vd_s_discard( t );
    bcore_alloc( kvbuf, 0 );
    st_s_push_char_n( log, '=', 80 );
    st_s_push_char( log, '\n' );
    return log;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
leaq 0x2ed10(%rip), %rdi     # 0x159422
movb $0x0, %al
callq 0xff350
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movl $0x50, %edx
subq 0x10(%rax), %rdx
movl $0x3d, %esi
callq 0xffca0
movq -0x8(%rbp), %rdi
movl $0xa, %esi
callq 0xffba0
xorl %eax, %eax
movl %eax, %edi
callq 0x127d30
movq %rax, -0x10(%rbp)
movq $0x30d40, -0x18(%rbp)   # imm = 0x30D40
xorl %eax, %eax
movl %eax, %edi
movl $0x186a00, %esi         # imm = 0x186A00
callq 0x9d210
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x16dd2(%rip), %rsi     # 0x14155b
movb $0x0, %al
callq 0x100120
movq $0x1, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpq $0x30d40, -0x40(%rbp)   # imm = 0x30D40
jae 0x12a989
jmp 0x12a7b0
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movq -0xa0(%rbp), %rdi
movl %eax, %eax
movl %eax, %esi
movq %rsi, -0x38(%rbp)
shlq $0x8, %rsi
movq %rsi, -0x48(%rbp)
callq 0x128820
testb $0x1, %al
jne 0x12a7e8
jmp 0x12a7ea
jmp 0x12a7b0
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
movq -0x48(%rbp), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x1288f0
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x38(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x28(%rbp)
movq -0xa8(%rbp), %rax
movq (%rax,%rdx,8), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12a87f
movq -0x48(%rbp), %r8
leaq 0x2ebd5(%rip), %rdi     # 0x15943a
leaq 0x2e791(%rip), %rsi     # 0x158ffd
movl $0xc0b, %edx            # imm = 0xC0B
leaq 0x2ebd6(%rip), %rcx     # 0x15944e
movb $0x0, %al
callq 0x9cf40
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shrq $0xa, %rax
andq $0x1, %rax
cmpq $0x1, %rax
jne 0x12a976
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x28(%rbp)
movq %rdx, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12a90d
movq -0x58(%rbp), %r8
leaq 0x2eb47(%rip), %rdi     # 0x15943a
leaq 0x2e703(%rip), %rsi     # 0x158ffd
movl $0xc14, %edx            # imm = 0xC14
leaq 0x2eb48(%rip), %rcx     # 0x15944e
movb $0x0, %al
callq 0x9cf40
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x128a10
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12a92d
jmp 0x12a952
movq -0x58(%rbp), %r8
leaq 0x2eb02(%rip), %rdi     # 0x15943a
leaq 0x2e6be(%rip), %rsi     # 0x158ffd
movl $0xc16, %edx            # imm = 0xC16
leaq 0x25db5(%rip), %rcx     # 0x150700
movb $0x0, %al
callq 0x9cf40
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rdx
movq -0x28(%rbp), %rsi
movq (%rdx,%rsi,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x12a978
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x12a7a0
callq 0x4300
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x8a20(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
leaq 0x25d6c(%rip), %rsi     # 0x15071f
movb $0x1, %al
callq 0x100120
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x127610
movq -0x8(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x128e20
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0xfff40
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x25d28(%rip), %rsi     # 0x150729
movb $0x0, %al
callq 0x100120
movq $0x14, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x60(%rbp), %rax
jae 0x12aa9d
movq $0x0, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x12aa8a
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12aa7a
movq -0x20(%rbp), %rax
movq -0x70(%rbp), %rcx
movq (%rax,%rcx,8), %r8
leaq 0x2e9da(%rip), %rdi     # 0x15943a
leaq 0x2e596(%rip), %rsi     # 0x158ffd
movl $0xc2a, %edx            # imm = 0xC2A
leaq 0x2e9db(%rip), %rcx     # 0x15944e
movb $0x0, %al
callq 0x9cf40
jmp 0x12aa7c
movq -0x70(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x70(%rbp)
jmp 0x12aa2a
jmp 0x12aa8c
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x12aa18
callq 0x4300
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x8909(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %xmm1
movaps 0x14425(%rip), %xmm2    # 0x13ef00
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x14429(%rip), %xmm2    # 0x13ef10
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x25c43(%rip), %rsi     # 0x150744
movb $0x1, %al
callq 0x100120
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x2e852(%rip), %rsi     # 0x159372
movb $0x0, %al
callq 0x100120
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1288a0
cmpq $0x0, %rax
je 0x12ab5c
leaq 0x2e8f8(%rip), %rdi     # 0x15943a
leaq 0x2e4b4(%rip), %rsi     # 0x158ffd
movl $0xc32, %edx            # imm = 0xC32
leaq 0x2e83a(%rip), %rcx     # 0x15938f
movb $0x0, %al
callq 0x9cf40
movq $0x0, -0x78(%rbp)
cmpq $0xa, -0x78(%rbp)
jae 0x12ac27
movq $0x0, -0x80(%rbp)
movq -0x80(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x12ac14
movq -0x20(%rbp), %rax
movq -0x80(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
movq -0x88(%rbp), %rsi
callq 0x1288a0
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq -0x90(%rbp), %rcx
subq %rcx, %rax
cmpq -0x78(%rbp), %rax
je 0x12ac01
movq -0x78(%rbp), %r8
movq -0x88(%rbp), %r9
movq -0x90(%rbp), %rax
leaq 0x2e857(%rip), %rdi     # 0x15943a
leaq 0x2e413(%rip), %rsi     # 0x158ffd
movl $0xc3a, %edx            # imm = 0xC3A
leaq 0x2e7db(%rip), %rcx     # 0x1593d1
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9cf40
jmp 0x12ac03
movq -0x80(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x80(%rbp)
jmp 0x12ab77
jmp 0x12ac16
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x12ab64
callq 0x4300
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x877f(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
addq %rax, %rax
leaq (%rax,%rax,4), %rax
movq %rax, %xmm1
movaps 0x1429c(%rip), %xmm2    # 0x13ef00
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x142a0(%rip), %xmm2    # 0x13ef10
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x2e785(%rip), %rsi     # 0x15940f
movb $0x1, %al
callq 0x100120
movq -0x8(%rbp), %rdi
leaq 0x27d85(%rip), %rsi     # 0x152a21
movb $0x0, %al
callq 0x100120
movq -0x8(%rbp), %rdi
leaq 0x16b08(%rip), %rsi     # 0x1417b6
movb $0x0, %al
callq 0x100120
callq 0x4300
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x12ad77
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12ad24
movq -0x98(%rbp), %r8
leaq 0x2e730(%rip), %rdi     # 0x15943a
leaq 0x2e2ec(%rip), %rsi     # 0x158ffd
movl $0xc48, %edx            # imm = 0xC48
leaq 0x2e731(%rip), %rcx     # 0x15944e
movb $0x0, %al
callq 0x9cf40
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x128a10
movq -0x10(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x128820
testb $0x1, %al
jne 0x12ad4a
jmp 0x12ad72
movq -0x98(%rbp), %r8
leaq 0x2e6e2(%rip), %rdi     # 0x15943a
leaq 0x2e29e(%rip), %rsi     # 0x158ffd
movl $0xc4a, %edx            # imm = 0xC4A
leaq 0x25995(%rip), %rcx     # 0x150700
movb $0x0, %al
callq 0x9cf40
jmp 0x12acbe
callq 0x4300
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x8632(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
leaq 0x2597e(%rip), %rsi     # 0x15071f
movb $0x1, %al
callq 0x100120
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x12add3
leaq 0x2e681(%rip), %rdi     # 0x15943a
leaq 0x2e23d(%rip), %rsi     # 0x158ffd
movl $0xc4f, %edx            # imm = 0xC4F
leaq 0x2e53c(%rip), %rcx     # 0x159308
movb $0x0, %al
callq 0x9cf40
movq -0x8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x128e20
movq -0xb8(%rbp), %rdi
movq %rax, %rsi
callq 0xfff40
movq -0x10(%rbp), %rdi
callq 0x127de0
movq -0x20(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x9d210
movq -0x8(%rbp), %rdi
movl $0x3d, %esi
movl $0x50, %edx
callq 0xffca0
movq -0x8(%rbp), %rdi
movl $0xa, %esi
callq 0xffba0
movq -0x8(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)