// File: /workspace/github_c_makefile_star2_O0/johsteffens[P]beth/lib/bcore/bcore_btree.c
// Function: btree_pp_s_selftest
static st_s* btree_pp_s_selftest( void )
{
    st_s* log = st_s_createf( "== btree_pp_s_selftest " );
    st_s_push_char_n( log, '=', 80 - log->size );
    st_s_push_char( log, '\n' );
    bcore_btree_pp_s* t = bcore_btree_pp_s_create( NULL );
    const uz_t cycles = 200000;

    bcore_btree_pp_kv_s* kvbuf = bcore_alloc( NULL, cycles * sizeof( bcore_btree_pp_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++ )
        {
            bcore_btree_pp_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_pp_s_exists( t, ( kv.key = ( bcore_btree_pp_key_t )(intptr_t)( ( rval1 = bcore_xsg_u2( rval1 ) ) << 8 ) ) ) );
            kv.val = ( bcore_btree_pp_val_t )(intptr_t)( rval2 = bcore_xsg_u2( rval2 ) );
            kvbuf[ kvbuf_size++ ] = kv;

            // set
            bcore_btree_pp_s_set( t, kv.key, kv.val );

            // retrieve
            rval1 = bcore_xsg_u2( rval1 );
            kv = kvbuf[ rval1 % kvbuf_size ];
            bcore_btree_pp_val_t* val_ptr = bcore_btree_pp_s_val( t, kv.key );
            if( kv.val != *val_ptr ) ERR( "value mismatch (%lu vs %lu)", kv.val, *val_ptr );

            // delete
            rval1 = bcore_xsg_u2( rval1 );
            if( ( ( rval1 >> 10 ) & 1 ) == 1 )
            {
                rval1 = bcore_xsg_u2( rval1 );
                uz_t idx = rval1 % kvbuf_size;
                bcore_btree_pp_kv_s kv = kvbuf[ idx ];
                if( !bcore_btree_pp_s_val( t, kv.key ) )  ERR( "key (%lu) not found", kv.key );
                bcore_btree_pp_s_remove( t, kv.key );
                if( bcore_btree_pp_s_val( 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_pp_s_check_consistency( t->root );
    st_s_push_st_d( log, bcore_btree_pp_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_pp_s_val( t, kvbuf[ i ].key ) != kvbuf[ i ].val ) ERR( "value mismatch (%lu vs %lu)", kvbuf[ i ].key, kvbuf[ i ].val );
        }
    }
    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_pp_s_largest_below_equal( t, (bcore_btree_pp_key_t)1 ) != NULL ) 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_pp_key_t key0 = ( u0_t* )kvbuf[ i ].key + j;
            bcore_btree_pp_kv_s* kv1 = bcore_btree_pp_s_largest_below_equal( t, key0 );
            if( !kv1 ) ERR( "largest_below_equal( %lu ) failed", key0 );
            // stored keys have a minimum distance of 256, so this test should yield key0 - key1 == j;
            if( ( (u0_t*)key0 - (u0_t*)kv1->key != j ) ) ERR( "largest_below_equal failed at distance %j: key0=%lu, key1=%lu", j, key0, kv1->key );
        }
    }
    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_pp_kv_s kv = kvbuf[ kvbuf_size ];
        if( !bcore_btree_pp_s_val( t, kv.key ) )  ERR( "key (%lu) not found", kv.key );
        bcore_btree_pp_s_remove( t, kv.key );
        if( bcore_btree_pp_s_val( 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_pp_s_status( t ) );

    bcore_btree_pp_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 $0xf0, %rsp
leaq 0x2f4c4(%rip), %rdi     # 0x159346
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 0x125920
movq %rax, -0x10(%rbp)
movq $0x30d40, -0x18(%rbp)   # imm = 0x30D40
xorl %eax, %eax
movl %eax, %edi
movl $0x30d400, %esi         # imm = 0x30D400
callq 0x9d210
movq %rax, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
leaq 0x17662(%rip), %rsi     # 0x14155b
movb $0x0, %al
callq 0x100120
movq $0x1, -0x38(%rbp)
movq $0x3039, -0x40(%rbp)    # imm = 0x3039
movq $0x0, -0x48(%rbp)
cmpq $0x30d40, -0x48(%rbp)   # imm = 0x30D40
jae 0x12a16e
jmp 0x129f28
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movq -0xc8(%rbp), %rdi
movl %eax, %eax
movl %eax, %esi
movq %rsi, -0x38(%rbp)
shlq $0x8, %rsi
movq %rsi, -0x58(%rbp)
callq 0x126510
testb $0x1, %al
jne 0x129f60
jmp 0x129f62
jmp 0x129f28
movq -0x40(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movl %eax, %eax
movq %rax, -0x40(%rbp)
movq %rax, -0x50(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movq %rcx, %rdx
addq $0x1, %rdx
movq %rdx, -0x28(%rbp)
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x58(%rbp), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x126660
movq -0x38(%rbp), %rax
movl %eax, %edi
callq 0x12af40
movl %eax, %eax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x38(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq -0x28(%rbp)
movq -0xd0(%rbp), %rax
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rax), %rcx
movq %rcx, -0x58(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x1265c0
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
cmpq (%rcx), %rax
je 0x12a040
movq -0x50(%rbp), %r8
movq -0x60(%rbp), %rax
movq (%rax), %r9
leaq 0x2f338(%rip), %rdi     # 0x15935e
leaq 0x2efd0(%rip), %rsi     # 0x158ffd
movl $0x8e4, %edx            # imm = 0x8E4
leaq 0x26697(%rip), %rcx     # 0x1506d0
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 0x12a15b
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, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0x78(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x1265c0
cmpq $0x0, %rax
jne 0x12a0de
movq -0x78(%rbp), %r8
leaq 0x2f29a(%rip), %rdi     # 0x15935e
leaq 0x2ef32(%rip), %rsi     # 0x158ffd
movl $0x8ed, %edx            # imm = 0x8ED
leaq 0x26615(%rip), %rcx     # 0x1506ec
movb $0x0, %al
callq 0x9cf40
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x1267f0
movq -0x10(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x1265c0
cmpq $0x0, %rax
je 0x12a123
movq -0x78(%rbp), %r8
leaq 0x2f255(%rip), %rdi     # 0x15935e
leaq 0x2eeed(%rip), %rsi     # 0x158ffd
movl $0x8ef, %edx            # imm = 0x8EF
leaq 0x265e4(%rip), %rcx     # 0x150700
movb $0x0, %al
callq 0x9cf40
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x20(%rbp), %rcx
movq -0x28(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x12a15d
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
jmp 0x129f18
callq 0x4300
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x923b(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
leaq 0x26587(%rip), %rsi     # 0x15071f
movb $0x1, %al
callq 0x100120
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x125190
movq -0x8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x126c30
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0xfff40
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x26543(%rip), %rsi     # 0x150729
movb $0x0, %al
callq 0x100120
movq $0x14, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movq -0x88(%rbp), %rax
cmpq -0x80(%rbp), %rax
jae 0x12a2e4
movq $0x0, -0x90(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x12a2cb
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
callq 0x1265c0
movq (%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x90(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
je 0x12a2b2
movq -0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %r8
movq -0x20(%rbp), %rax
movq -0x90(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %r9
leaq 0x2f0c6(%rip), %rdi     # 0x15935e
leaq 0x2ed5e(%rip), %rsi     # 0x158ffd
movl $0x903, %edx            # imm = 0x903
leaq 0x26425(%rip), %rcx     # 0x1506d0
movb $0x0, %al
callq 0x9cf40
jmp 0x12a2b4
movq -0x90(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x90(%rbp)
jmp 0x12a21c
jmp 0x12a2cd
movq -0x88(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x88(%rbp)
jmp 0x12a200
callq 0x4300
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x90c2(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movq -0x80(%rbp), %rcx
imulq %rcx, %rax
movq %rax, %xmm1
movaps 0x14bde(%rip), %xmm2    # 0x13ef00
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x14be2(%rip), %xmm2    # 0x13ef10
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x263fc(%rip), %rsi     # 0x150744
movb $0x1, %al
callq 0x100120
callq 0x4300
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rdx
leaq 0x2f00b(%rip), %rsi     # 0x159372
movb $0x0, %al
callq 0x100120
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x126590
cmpq $0x0, %rax
je 0x12a3a3
leaq 0x2efd5(%rip), %rdi     # 0x15935e
leaq 0x2ec6d(%rip), %rsi     # 0x158ffd
movl $0x90b, %edx            # imm = 0x90B
leaq 0x2eff3(%rip), %rcx     # 0x15938f
movb $0x0, %al
callq 0x9cf40
movq $0x0, -0x98(%rbp)
cmpq $0xa, -0x98(%rbp)
jae 0x12a4d0
movq $0x0, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x12a4b7
movq -0x20(%rbp), %rax
movq -0xa0(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
addq -0x98(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x126590
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jne 0x12a444
movq -0xa8(%rbp), %r8
leaq 0x2ef34(%rip), %rdi     # 0x15935e
leaq 0x2ebcc(%rip), %rsi     # 0x158ffd
movl $0x912, %edx            # imm = 0x912
leaq 0x2ef72(%rip), %rcx     # 0x1593af
movb $0x0, %al
callq 0x9cf40
movq -0xa8(%rbp), %rax
movq -0xb0(%rbp), %rcx
movq (%rcx), %rcx
subq %rcx, %rax
cmpq -0x98(%rbp), %rax
je 0x12a49e
movq -0x98(%rbp), %r8
movq -0xa8(%rbp), %r9
movq -0xb0(%rbp), %rax
movq (%rax), %rax
leaq 0x2eede(%rip), %rdi     # 0x15935e
leaq 0x2eb76(%rip), %rsi     # 0x158ffd
movl $0x914, %edx            # imm = 0x914
leaq 0x2ef3e(%rip), %rcx     # 0x1593d1
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9cf40
jmp 0x12a4a0
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x12a3c7
jmp 0x12a4b9
movq -0x98(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x98(%rbp)
jmp 0x12a3ae
callq 0x4300
movq -0x30(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x8ed6(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
addq %rax, %rax
leaq (%rax,%rax,4), %rax
movq %rax, %xmm1
movaps 0x149f3(%rip), %xmm2    # 0x13ef00
punpckldq %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movapd 0x149f7(%rip), %xmm2    # 0x13ef10
subpd %xmm2, %xmm1
movaps %xmm1, %xmm2
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
leaq 0x2eedc(%rip), %rsi     # 0x15940f
movb $0x1, %al
callq 0x100120
movq -0x8(%rbp), %rdi
leaq 0x284dc(%rip), %rsi     # 0x152a21
movb $0x0, %al
callq 0x100120
movq -0x8(%rbp), %rdi
leaq 0x1725f(%rip), %rsi     # 0x1417b6
movb $0x0, %al
callq 0x100120
callq 0x4300
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x12a633
movq -0x28(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq %rcx, -0xc0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x1265c0
cmpq $0x0, %rax
jne 0x12a5e0
movq -0xc0(%rbp), %r8
leaq 0x2ed98(%rip), %rdi     # 0x15935e
leaq 0x2ea30(%rip), %rsi     # 0x158ffd
movl $0x921, %edx            # imm = 0x921
leaq 0x26113(%rip), %rcx     # 0x1506ec
movb $0x0, %al
callq 0x9cf40
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x1267f0
movq -0x10(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x1265c0
cmpq $0x0, %rax
je 0x12a62e
movq -0xc0(%rbp), %r8
leaq 0x2ed4a(%rip), %rdi     # 0x15935e
leaq 0x2e9e2(%rip), %rsi     # 0x158ffd
movl $0x923, %edx            # imm = 0x923
leaq 0x260d9(%rip), %rcx     # 0x150700
movb $0x0, %al
callq 0x9cf40
jmp 0x12a567
callq 0x4300
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
cvtsi2sdq -0x30(%rbp), %xmm0
movsd 0x8d76(%rip), %xmm1     # 0x1333c8
divsd %xmm1, %xmm0
leaq 0x260c2(%rip), %rsi     # 0x15071f
movb $0x1, %al
callq 0x100120
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x12a68f
leaq 0x2ece9(%rip), %rdi     # 0x15935e
leaq 0x2e981(%rip), %rsi     # 0x158ffd
movl $0x928, %edx            # imm = 0x928
leaq 0x2ec80(%rip), %rcx     # 0x159308
movb $0x0, %al
callq 0x9cf40
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x126c30
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0xfff40
movq -0x10(%rbp), %rdi
callq 0x1259d0
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 $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)