// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movl %r9d, 0xc(%rsp)
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movl $0x2e8, %esi            # imm = 0x2E8
callq 0xbe802
leaq 0x2c0(%rbx), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1140f0
leaq -0xcf(%rip), %rdi       # 0x10f2a8
callq 0x1261be
movq %rbx, %rsi
movq %rax, 0x38(%rbx)
movq %r15, 0x30(%rsp)
movq %r15, 0x10(%rbx)
movq %r12, 0x18(%rbx)
movq %r13, 0x20(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %r14d, %ecx
shll %cl, %eax
notl %eax
movq %rax, %r14
cmpq %r12, %rax
setb %cl
addq %rax, %rax
testq %r12, %rax
setne %dl
orb %cl, %dl
jne 0x10f3a0
cmpq %r12, %r13
movq %rsi, 0x10(%rsp)
jae 0x10f3c9
movq 0x8(%rsi), %rbp
jmp 0x10f517
leaq 0xe0(%rsi), %rax
movq %rax, 0x38(%rsp)
movq 0x8(%rsi), %rbp
movq $0x0, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq %r12, 0x40(%rsp)
cmpq 0x20(%rsp), %rbp
jne 0x10f464
leaq (,%rbp,2), %rcx
testq %rbp, %rbp
movl $0x10, %eax
cmoveq %rax, %rcx
movq (%rsi), %rdi
movq %rcx, 0x20(%rsp)
leaq (,%rcx,8), %r13
testq %rdi, %rdi
je 0x10f426
movq %r13, %rsi
callq 0xd3f0
jmp 0x10f42e
movq %r13, %rdi
callq 0xd160
movq 0x10(%rsp), %rsi
movq %rax, (%rsi)
testq %rax, %rax
jne 0x10f464
leaq 0x3d8d5(%rip), %rdi     # 0x14cd17
leaq 0x3d8a4(%rip), %rsi     # 0x14cced
movl $0x6dc, %edx            # imm = 0x6DC
leaq 0x3d8a6(%rip), %rcx     # 0x14ccfb
movq %r13, %r8
xorl %eax, %eax
callq 0xbe592
movq 0x10(%rsp), %rsi
movq 0x10(%rsi), %rbx
movq 0x38(%rsi), %rbp
movl $0x70, %edi
movq %rsi, %r15
callq 0xd160
testq %rax, %rax
movq 0x40(%rsp), %r12
je 0x10f883
movq %rax, %r13
movl $0x70, %esi
movq %rax, %rdi
callq 0xbe802
movq %r15, 0x48(%r13)
movb $0x1, 0x40(%r13)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x38(%r13)
movq %rbx, (%r13)
movq 0x28(%rsp), %rdx
movq %rdx, 0x8(%r13)
movl 0xc(%rsp), %eax
movb %al, 0x10(%r13)
leaq 0x3be(%rip), %rax       # 0x10f888
movq %rax, 0x50(%r13)
movq %rbp, 0x58(%r13)
movq 0x38(%rsp), %rax
movq %rax, 0x60(%r13)
movq 0x18(%rsp), %rax
movq %rax, 0x68(%r13)
movq (%r15), %rax
movq 0x8(%r15), %rbp
movq %r13, (%rax,%rbp,8)
incq %rbp
cmpq %r14, %rdx
seta %cl
shlq %cl, %r14
shlq %cl, %r12
movq %rbp, 0x8(%r15)
addq %r12, %rdx
movq %rdx, 0x28(%rsp)
cmpq 0x20(%r15), %rdx
movq %r15, %rsi
jbe 0x10f3e7
leaq (,%rbp,8), %r12
movq %r12, %rdi
callq 0xd160
movq 0x10(%rsp), %r15
movq %rax, 0x30(%r15)
testq %rax, %rax
jne 0x10f562
leaq 0x3d7db(%rip), %rdi     # 0x14cd17
leaq 0x3d7aa(%rip), %rsi     # 0x14cced
leaq 0x3d7b1(%rip), %rcx     # 0x14ccfb
movl $0x6f5, %edx            # imm = 0x6F5
movq %r12, %r8
xorl %eax, %eax
callq 0xbe592
movq 0x10(%rsp), %r15
movq 0x8(%r15), %rbp
movb $0x1, 0x28(%r15)
testq %rbp, %rbp
je 0x10f59f
movq (%r15), %rax
movq 0x30(%r15), %rcx
movb $0x1, %sil
xorl %edx, %edx
movq (%rax,%rdx,8), %rdi
testb $0x1, %sil
je 0x10f588
movb 0x40(%rdi), %sil
jmp 0x10f58a
xorl %esi, %esi
movq 0x8(%rdi), %rdi
movq %rdi, (%rcx,%rdx,8)
incq %rdx
cmpq 0x8(%r15), %rdx
jb 0x10f578
movb %sil, 0x28(%r15)
leaq 0x40(%r15), %r14
leaq 0xe0(%r15), %r12
movl $0xa0, %esi
movq %r14, %rdi
callq 0xbe802
movq 0x30(%rsp), %rbp
movq %rbp, 0xc0(%r15)
leaq -0x322(%rip), %rbx      # 0x10f2a8
movq %rbx, %rdi
callq 0x1261be
movq %rax, 0xb0(%r15)
movq %rbx, %rdi
callq 0x124cf3
movq %rax, 0xb8(%r15)
movq 0xb0(%r15), %rbx
movl $0x70, %esi
movq %r14, %rdi
callq 0xbe802
movq %r14, 0x88(%r15)
movb $0x1, %al
movb %al, 0x80(%r15)
movb $0x1, %cl
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x78(%r15)
movq %rbp, 0x40(%r15)
movl $0x18, %eax
movq %rax, 0x48(%r15)
movl 0xc(%rsp), %r13d
movb %r13b, 0x50(%r15)
leaq 0x40c3(%rip), %rax      # 0x1136fc
movq %rax, 0x90(%r15)
movq %rbx, 0x98(%r15)
xorl %eax, %eax
movq %rax, 0xa0(%r15)
movq 0x18(%rsp), %rbx
movq %rbx, 0xa8(%r15)
movb %cl, 0xc8(%r15)
movq %r12, 0xd0(%r15)
movq %rbx, 0xd8(%r15)
movl $0x1e0, %esi            # imm = 0x1E0
movq %r12, %rdi
callq 0xbe802
movq %rbp, 0x2a8(%r15)
leaq -0x3e4(%rip), %rdi      # 0x10f2a8
callq 0x1261be
movq %rax, %r14
movq %rax, 0x2a0(%r15)
movl $0x70, %esi
movq %r12, %rdi
callq 0xbe802
movq %r12, 0x128(%r15)
movb $0x1, %al
movb %al, 0x120(%r15)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x118(%r15)
movq %rbp, 0xe0(%r15)
movq $0x10, 0xe8(%r15)
movb %r13b, 0xf0(%r15)
leaq 0x401b(%rip), %rax      # 0x113704
movq %rax, 0x130(%r15)
movq %r14, 0x138(%r15)
xorl %eax, %eax
movq %rax, 0x140(%r15)
movq %rbx, 0x148(%r15)
leaq 0x150(%r15), %rdi
movq 0x2a0(%r15), %r14
movl $0x70, %esi
callq 0xbe802
movq %r12, 0x198(%r15)
movb $0x1, %al
movb %al, 0x190(%r15)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x188(%r15)
movq %rbp, 0x150(%r15)
movl $0x18, %eax
movq %rax, 0x158(%r15)
movb %r13b, 0x160(%r15)
leaq 0x3fa3(%rip), %rax      # 0x113704
movq %rax, 0x1a0(%r15)
movq %r14, 0x1a8(%r15)
xorl %eax, %eax
movq %rax, 0x1b0(%r15)
movq %rbx, 0x1b8(%r15)
leaq 0x1c0(%r15), %rdi
movq 0x2a0(%r15), %r14
movl $0x70, %esi
callq 0xbe802
movq %r12, 0x208(%r15)
movb $0x1, %al
movb %al, 0x200(%r15)
movabsq $0x3fc0000000000000, %rax # imm = 0x3FC0000000000000
movq %rax, 0x1f8(%r15)
movq %rbp, 0x1c0(%r15)
movq $0x20, 0x1c8(%r15)
movb %r13b, 0x1d0(%r15)
leaq 0x3f2c(%rip), %rax      # 0x113704
movq %rax, 0x210(%r15)
movq %r14, 0x218(%r15)
xorl %eax, %eax
movq %rax, 0x220(%r15)
movq %rbx, 0x228(%r15)
leaq 0x230(%r15), %rdi
movq 0x2a0(%r15), %r14
movl $0x70, %esi
callq 0xbe802
movq %r12, 0x278(%r15)
movb $0x1, %al
movb %al, 0x270(%r15)
movabsq $0x3fc0000000000000, %rcx # imm = 0x3FC0000000000000
movq %rcx, 0x268(%r15)
movq %rbp, 0x230(%r15)
movq $0x28, 0x238(%r15)
movb %r13b, 0x240(%r15)
leaq 0x3eb5(%rip), %rcx      # 0x113704
movq %rcx, 0x280(%r15)
movq %r14, 0x288(%r15)
xorl %ecx, %ecx
movq %rcx, 0x290(%r15)
movq %rbx, 0x298(%r15)
movb %al, 0x2b0(%r15)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0xd956