// File: /workspace/github_c_makefile_star2_O2/johsteffens[P]beth/lib/bcore/bcore_tbman.c
// Function: bcore_tbman_s_init
void bcore_tbman_s_init( bcore_tbman_s* o, uz_t pool_size, uz_t min_block_size, uz_t max_block_size, uz_t stepping_method, bl_t full_align )
{
    bcore_memzero( o, sizeof( *o ) );
    bcore_mutex_s_init( &o->mutex );

    o->internal_btree = bcore_btree_vd_s_create( bcore_tbman_external_alloc );

    /// The following three values are configurable parameters of memory manager
    o->pool_size      = pool_size;
    o->min_block_size = min_block_size;
    o->max_block_size = max_block_size;

    uz_t mask_bxp  = stepping_method;
    uz_t size_mask = ( 1 << mask_bxp ) - 1;
    uz_t size_inc  = o->min_block_size;
    while( ( size_mask < o->min_block_size ) || ( ( size_mask << 1 ) & o->min_block_size ) != 0 ) size_mask <<= 1;

    uz_t space = 0;

    for( uz_t block_size = o->min_block_size; block_size <= o->max_block_size; block_size += size_inc )
    {
        if( o->size == space )
        {
            space = space > 0 ? space * 2 : 16;

            if( o->data )
            {
                o->data = realloc( o->data, sizeof( block_manager_s* ) * space );
            }
            else
            {
                o->data = malloc( sizeof( block_manager_s* ) * space );
            }

            if( !o->data ) ERR( "Failed allocating %zu bytes", sizeof( block_manager_s* ) * space );
        }

        o->data[ o->size ] = block_manager_s_create
            (
                o,
                o->pool_size,
                block_size,
                full_align,
                ( fp_lost_alignment )tbman_s_lost_alignment,
                o->internal_btree,
                &o->down_manager,
                &o->mutex
            );

        o->size++;

        if( block_size > size_mask )
        {
            size_mask <<= 1;
            size_inc  <<= 1;
        }
    }

    o->block_size_array = malloc( o->size * sizeof( uz_t ) );
    if( !o->block_size_array ) ERR( "Failed allocating %zu bytes", o->size * sizeof( uz_t ) );

    o->aligned = true;
    for( uz_t i = 0; i < o->size; i++ )
    {
        o->aligned = o->aligned && o->data[ i ]->aligned;
        o->block_size_array[ i ] = o->data[ i ]->block_size;
    }

    external_manager_s_init( &o->external_manager, pool_size, full_align, &o->down_manager, &o->mutex );
    down_manager_s_init( &o->down_manager, pool_size, full_align, &o->mutex );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, %r13d
movq %r8, %r14
movq %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movl $0x2e8, %esi            # imm = 0x2E8
callq 0x6028b
leaq 0x2c0(%rbx), %rdi
movq %rdi, 0x18(%rsp)
callq 0x97954
leaq -0xcd(%rip), %rdi       # 0x93707
callq 0xa4173
movq %rax, 0x38(%rbx)
movq %r15, 0x28(%rsp)
movq %r15, 0x10(%rbx)
movq %r12, %r15
movq %r12, 0x18(%rbx)
movq %rbp, 0x20(%rbx)
pushq $-0x1
popq %rax
movl %r14d, %ecx
shll %cl, %eax
notl %eax
movq %rax, %r14
cmpq %r15, %rax
setb %cl
addq %rax, %rax
testq %r15, %rax
setne %dl
orb %cl, %dl
jne 0x937fb
leaq 0xe0(%rbx), %rax
movq %rax, 0x10(%rsp)
movzbl %r13b, %eax
movl %eax, 0xc(%rsp)
xorl %eax, %eax
movq %r15, %r13
movq 0x8(%rbx), %r12
cmpq %rbp, %r13
ja 0x93949
cmpq %rax, %r12
movq %r15, 0x30(%rsp)
jne 0x9386e
testq %rax, %rax
leaq (%rax,%rax), %rcx
pushq $0x10
popq %rax
cmoveq %rax, %rcx
movq (%rbx), %rdi
movq %rcx, 0x20(%rsp)
leaq (,%rcx,8), %rbp
testq %rdi, %rdi
je 0x93875
movq %rbp, %rsi
callq 0xd3f0
jmp 0x9387d
movq %rax, 0x20(%rsp)
jmp 0x938a9
movq %rbp, %rdi
callq 0xd160
movq %rax, (%rbx)
testq %rax, %rax
jne 0x938a9
leaq 0x374bb(%rip), %rdi     # 0xcad47
leaq 0x3748a(%rip), %rsi     # 0xcad1d
movl $0x6dc, %edx            # imm = 0x6DC
leaq 0x3748c(%rip), %rcx     # 0xcad2b
movq %rbp, %r8
xorl %eax, %eax
callq 0x60031
movq 0x10(%rbx), %r12
movq 0x38(%rbx), %r15
pushq $0x70
popq %rdi
callq 0xd160
movq %rax, %rbp
testq %rax, %rax
jne 0x938e6
leaq 0x3795f(%rip), %rdi     # 0xcb227
leaq 0x3744e(%rip), %rsi     # 0xcad1d
movl $0x33a, %edx            # imm = 0x33A
leaq 0x37450(%rip), %rcx     # 0xcad2b
pushq $0x70
popq %r8
xorl %eax, %eax
callq 0x60031
subq $0x8, %rsp
movq %rbp, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movl 0x14(%rsp), %r8d
leaq 0x235(%rip), %r9        # 0x93b37
pushq 0x20(%rsp)
pushq 0x20(%rsp)
pushq %r15
callq 0x96e85
addq $0x20, %rsp
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %rbp, (%rax,%rdx,8)
incq %rdx
cmpq %r14, %r13
seta %cl
shlq %cl, %r14
movq 0x30(%rsp), %r15
shlq %cl, %r15
movq %rdx, 0x8(%rbx)
addq %r15, %r13
movq 0x20(%rbx), %rbp
movq 0x20(%rsp), %rax
jmp 0x9382a
shlq $0x3, %r12
movq %r12, %rdi
callq 0xd160
movq %rax, 0x30(%rbx)
testq %rax, %rax
jne 0x93982
leaq 0x373e2(%rip), %rdi     # 0xcad47
leaq 0x373b1(%rip), %rsi     # 0xcad1d
leaq 0x373b8(%rip), %rcx     # 0xcad2b
movl $0x6f5, %edx            # imm = 0x6F5
movq %r12, %r8
xorl %eax, %eax
callq 0x60031
movb $0x1, 0x28(%rbx)
movb $0x1, %cl
xorl %eax, %eax
cmpq 0x8(%rbx), %rax
jae 0x939b7
movq (%rbx), %rdx
movq (%rdx,%rax,8), %rdx
testb $0x1, %cl
je 0x939a1
movb 0x40(%rdx), %cl
jmp 0x939a3
xorl %ecx, %ecx
movb %cl, 0x28(%rbx)
movq 0x8(%rdx), %rdx
movq 0x30(%rbx), %rsi
movq %rdx, (%rsi,%rax,8)
incq %rax
jmp 0x9398a
leaq 0x40(%rbx), %r12
movl $0xa0, %esi
movq %r12, %rdi
callq 0x6028b
movq 0x28(%rsp), %r13
movq %r13, 0xc0(%rbx)
leaq -0x2d4(%rip), %r14      # 0x93707
movq %r14, %rdi
callq 0xa4173
movq %rax, 0xb0(%rbx)
movq %r14, %rdi
callq 0xa2d88
movq %rax, 0xb8(%rbx)
subq $0x8, %rsp
leaq 0x34ef(%rip), %r9       # 0x96ef3
pushq $0x18
popq %rcx
movq %r12, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl 0x14(%rsp), %r15d
movl %r15d, %r8d
movq 0x20(%rsp), %r12
pushq %r12
pushq $0x0
pushq 0xb0(%rbx)
callq 0x96e85
addq $0x20, %rsp
movb $0x1, %al
movb %al, 0xc8(%rbx)
movq 0x10(%rsp), %rbp
movq %rbp, 0xd0(%rbx)
movq %r12, 0xd8(%rbx)
movl $0x1e0, %esi            # imm = 0x1E0
movq %rbp, %rdi
callq 0x6028b
movq %r13, 0x2a8(%rbx)
movq %r14, %rdi
callq 0xa4173
movq %rax, 0x2a0(%rbx)
subq $0x8, %rsp
leaq 0x3482(%rip), %r14      # 0x96efb
pushq $0x10
popq %rcx
movq %rbp, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movl %r15d, %r8d
movq %r14, %r9
pushq %r12
pushq $0x0
pushq %rax
callq 0x96e85
addq $0x20, %rsp
leaq 0x150(%rbx), %rdi
subq $0x8, %rsp
movq %rbp, %rsi
movq %r13, %rdx
pushq $0x18
popq %rcx
movl %r15d, %r8d
movq %r14, %r9
pushq %r12
pushq $0x0
pushq 0x2a0(%rbx)
callq 0x96e85
addq $0x20, %rsp
leaq 0x1c0(%rbx), %rdi
subq $0x8, %rsp
pushq $0x20
popq %rcx
movq %rbp, %rsi
movq %r13, %rdx
movl %r15d, %r8d
movq %r14, %r9
pushq %r12
pushq $0x0
pushq 0x2a0(%rbx)
callq 0x96e85
addq $0x20, %rsp
leaq 0x230(%rbx), %rdi
subq $0x8, %rsp
pushq $0x28
popq %rcx
movq %rbp, %rsi
movq %r13, %rdx
movl %r15d, %r8d
movq %r14, %r9
pushq %r12
pushq $0x0
pushq 0x2a0(%rbx)
callq 0x96e85
addq $0x20, %rsp
movb $0x1, %al
movb %al, 0x2b0(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq