// File: /workspace/github_c_makefile_star2_O1/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, 0xc(%rsp)
movq %r8, %r15
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
movl $0x2e8, %esi            # imm = 0x2E8
callq 0xc8366
leaq 0x2c0(%rbx), %rdi
movq %rdi, 0x10(%rsp)
callq 0x11f33c
leaq -0xcf(%rip), %rdi       # 0x11a4b0
callq 0x13174e
movq %rax, 0x38(%rbx)
movq %r14, 0x20(%rsp)
movq %r14, 0x10(%rbx)
movq %r12, 0x18(%rbx)
movq %r13, 0x20(%rbx)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r15d, %ecx
shll %cl, %r14d
notl %r14d
cmpq %r12, %r14
jb 0x11a5b6
leaq (%r14,%r14), %rax
testq %r12, %rax
je 0x11a5bb
addq %r14, %r14
jmp 0x11a5a8
cmpq %r12, 0x20(%rbx)
jb 0x11a716
leaq 0xe0(%rbx), %rax
movq %rax, 0x28(%rsp)
xorl %eax, %eax
movq %r12, %rbp
cmpq %rax, 0x8(%rbx)
jne 0x11a606
testq %rax, %rax
leaq (%rax,%rax), %r15
movl $0x10, %eax
cmoveq %rax, %r15
movq (%rbx), %rdi
leaq (,%r15,8), %r13
testq %rdi, %rdi
je 0x11a60d
movq %r13, %rsi
callq 0xd3e0
jmp 0x11a615
movq %rax, 0x18(%rsp)
jmp 0x11a646
movq %r13, %rdi
callq 0xd160
movq %rax, (%rbx)
testq %rax, %rax
movq %r15, 0x18(%rsp)
jne 0x11a646
leaq 0x3d696(%rip), %rdi     # 0x157cbf
leaq 0x3d665(%rip), %rsi     # 0x157c95
movl $0x6dc, %edx            # imm = 0x6DC
leaq 0x3d667(%rip), %rcx     # 0x157ca3
movq %r13, %r8
xorl %eax, %eax
callq 0xc80f6
movq 0x10(%rbx), %r15
movq 0x38(%rbx), %rax
movq %rax, 0x30(%rsp)
movl $0x70, %edi
callq 0xd160
movq %rax, %r13
testq %rax, %rax
jne 0x11a68c
movl $0x70, %r8d
leaq 0x3db2d(%rip), %rdi     # 0x15819f
leaq 0x3d61c(%rip), %rsi     # 0x157c95
movl $0x33a, %edx            # imm = 0x33A
leaq 0x3d61e(%rip), %rcx     # 0x157ca3
xorl %eax, %eax
callq 0xc80f6
movl $0x70, %esi
movq %r13, %rdi
callq 0xc8366
movq %rbx, 0x48(%r13)
movb $0x1, 0x40(%r13)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x38(%r13)
movq %r15, (%r13)
movq %r12, 0x8(%r13)
movl 0xc(%rsp), %eax
movb %al, 0x10(%r13)
leaq 0x3ab(%rip), %rax       # 0x11aa72
movq %rax, 0x50(%r13)
movq 0x30(%rsp), %rax
movq %rax, 0x58(%r13)
movq 0x28(%rsp), %rax
movq %rax, 0x60(%r13)
movq 0x10(%rsp), %rax
movq %rax, 0x68(%r13)
movq (%rbx), %rax
movq 0x8(%rbx), %rdx
movq %r13, (%rax,%rdx,8)
incq %rdx
cmpq %r14, %r12
seta %cl
shlq %cl, %r14
shlq %cl, %rbp
movq %rdx, 0x8(%rbx)
addq %rbp, %r12
cmpq 0x20(%rbx), %r12
movq 0x18(%rsp), %rax
jbe 0x11a5d6
movq 0x8(%rbx), %r14
shlq $0x3, %r14
movq %r14, %rdi
callq 0xd160
movq %rax, 0x30(%rbx)
testq %rax, %rax
jne 0x11a753
leaq 0x3d589(%rip), %rdi     # 0x157cbf
leaq 0x3d558(%rip), %rsi     # 0x157c95
leaq 0x3d55f(%rip), %rcx     # 0x157ca3
movl $0x6f5, %edx            # imm = 0x6F5
movq %r14, %r8
xorl %eax, %eax
callq 0xc80f6
movb $0x1, 0x28(%rbx)
cmpq $0x0, 0x8(%rbx)
je 0x11a799
movq (%rbx), %rax
movq 0x30(%rbx), %rcx
movb 0x28(%rbx), %sil
xorl %edx, %edx
testb $0x1, %sil
je 0x11a77e
movq (%rbx), %rsi
movq (%rsi,%rdx,8), %rsi
movb 0x40(%rsi), %sil
jmp 0x11a780
xorl %esi, %esi
movq (%rax,%rdx,8), %rdi
movq 0x8(%rdi), %rdi
movq %rdi, (%rcx,%rdx,8)
incq %rdx
cmpq 0x8(%rbx), %rdx
jb 0x11a76b
movb %sil, 0x28(%rbx)
leaq 0x40(%rbx), %r13
leaq 0xe0(%rbx), %r14
movl $0xa0, %esi
movq %r13, %rdi
callq 0xc8366
movq 0x20(%rsp), %rbp
movq %rbp, 0xc0(%rbx)
leaq -0x314(%rip), %r12      # 0x11a4b0
movq %r12, %rdi
callq 0x13174e
movq %rax, 0xb0(%rbx)
movq %r12, %rdi
callq 0x130330
movq %rax, 0xb8(%rbx)
movq 0xb0(%rbx), %r15
movl $0x70, %esi
movq %r13, %rdi
callq 0xc8366
movq %r13, 0x88(%rbx)
movb $0x1, %al
movb %al, 0x80(%rbx)
movb $0x1, %cl
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x78(%rbx)
movq %rbp, 0x40(%rbx)
movl $0x18, %eax
movq %rax, 0x48(%rbx)
movl 0xc(%rsp), %r13d
movb %r13b, 0x50(%rbx)
leaq 0x41be(%rip), %rax      # 0x11e9f0
movq %rax, 0x90(%rbx)
movq %r15, 0x98(%rbx)
xorl %eax, %eax
movq %rax, 0xa0(%rbx)
movq 0x10(%rsp), %r15
movq %r15, 0xa8(%rbx)
movb %cl, 0xc8(%rbx)
movq %r14, 0xd0(%rbx)
movq %r15, 0xd8(%rbx)
movl $0x1e0, %esi            # imm = 0x1E0
movq %r14, %rdi
callq 0xc8366
movq %rbp, 0x2a8(%rbx)
movq %r12, %rdi
callq 0x13174e
movq %rax, %r12
movq %rax, 0x2a0(%rbx)
movl $0x70, %esi
movq %r14, %rdi
callq 0xc8366
movq %r14, 0x128(%rbx)
movb $0x1, %al
movb %al, 0x120(%rbx)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x118(%rbx)
movq %rbp, 0xe0(%rbx)
movq $0x10, 0xe8(%rbx)
movb %r13b, 0xf0(%rbx)
leaq 0x411c(%rip), %rax      # 0x11e9f8
movq %rax, 0x130(%rbx)
movq %r12, 0x138(%rbx)
xorl %eax, %eax
movq %rax, 0x140(%rbx)
movq %r15, 0x148(%rbx)
leaq 0x150(%rbx), %rdi
movq 0x2a0(%rbx), %r12
movl $0x70, %esi
callq 0xc8366
movq %r14, 0x198(%rbx)
movb $0x1, %al
movb %al, 0x190(%rbx)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x188(%rbx)
movq %rbp, 0x150(%rbx)
movl $0x18, %eax
movq %rax, 0x158(%rbx)
movb %r13b, 0x160(%rbx)
leaq 0x40a5(%rip), %rax      # 0x11e9f8
movq %rax, 0x1a0(%rbx)
movq %r12, 0x1a8(%rbx)
xorl %eax, %eax
movq %rax, 0x1b0(%rbx)
movq %r15, 0x1b8(%rbx)
leaq 0x1c0(%rbx), %rdi
movq 0x2a0(%rbx), %r12
movl $0x70, %esi
callq 0xc8366
movq %r14, 0x208(%rbx)
movb $0x1, %al
movb %al, 0x200(%rbx)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x1f8(%rbx)
movq %rbp, 0x1c0(%rbx)
movq $0x20, 0x1c8(%rbx)
movb %r13b, 0x1d0(%rbx)
leaq 0x402f(%rip), %rax      # 0x11e9f8
movq %rax, 0x210(%rbx)
movq %r12, 0x218(%rbx)
xorl %eax, %eax
movq %rax, 0x220(%rbx)
movq %r15, 0x228(%rbx)
leaq 0x230(%rbx), %rdi
movq 0x2a0(%rbx), %r12
movl $0x70, %esi
callq 0xc8366
movq %r14, 0x278(%rbx)
movb $0x1, %al
movb %al, 0x270(%rbx)
movabsq $0x3fc0000000000000, %rcx # imm = 0x3FC0000000000000
movq %rcx, 0x268(%rbx)
movq %rbp, 0x230(%rbx)
movq $0x28, 0x238(%rbx)
movb %r13b, 0x240(%rbx)
leaq 0x3fb9(%rip), %rcx      # 0x11e9f8
movq %rcx, 0x280(%rbx)
movq %r12, 0x288(%rbx)
xorl %ecx, %ecx
movq %rcx, 0x290(%rbx)
movq %r15, 0x298(%rbx)
movb %al, 0x2b0(%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq