// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movb %r9b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
andb $0x1, %al
movb %al, -0x29(%rbp)
movq -0x8(%rbp), %rdi
movl $0x2e8, %esi            # imm = 0x2E8
callq 0x9d4f0
movq -0x8(%rbp), %rdi
addq $0x2c0, %rdi            # imm = 0x2C0
callq 0x10f980
leaq -0x18c(%rip), %rdi      # 0x107860
callq 0x127d30
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
cltq
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rcx
movq -0x8(%rbp), %rdx
movb $0x1, %al
cmpq 0x18(%rdx), %rcx
movb %al, -0x61(%rbp)
jb 0x107a76
movq -0x40(%rbp), %rax
shlq %rax
movq -0x8(%rbp), %rcx
andq 0x18(%rcx), %rax
cmpq $0x0, %rax
setne %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x107a7f
jmp 0x107a8c
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
jmp 0x107a4a
movq $0x0, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x20(%rcx), %rax
ja 0x107c05
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x50(%rbp), %rax
jne 0x107b61
cmpq $0x0, -0x50(%rbp)
jbe 0x107ad8
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x70(%rbp)
jmp 0x107ae3
movl $0x10, %eax
movq %rax, -0x70(%rbp)
jmp 0x107ae3
movq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x107b15
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x50(%rbp), %rsi
shlq $0x3, %rsi
callq 0x43a0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x107b2c
movq -0x50(%rbp), %rdi
shlq $0x3, %rdi
callq 0x4150
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x107b5f
movq -0x50(%rbp), %r8
shlq $0x3, %r8
leaq 0x4f882(%rip), %rdi     # 0x1573c7
leaq 0x4f851(%rip), %rsi     # 0x15739d
movl $0x6dc, %edx            # imm = 0x6DC
leaq 0x4f853(%rip), %rcx     # 0x1573ab
movb $0x0, %al
callq 0x9cf40
jmp 0x107b61
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x58(%rbp), %rdx
movb -0x29(%rbp), %cl
movq -0x8(%rbp), %rax
movq 0x38(%rax), %r9
movq -0x8(%rbp), %r10
addq $0xe0, %r10
movq -0x8(%rbp), %rax
addq $0x2c0, %rax            # imm = 0x2C0
leaq 0x258(%rip), %r8        # 0x107df0
andb $0x1, %cl
movzbl %cl, %ecx
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x107d40
movq %rax, %rdx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x58(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0x107bf2
movq -0x40(%rbp), %rax
shlq %rax
movq %rax, -0x40(%rbp)
movq -0x48(%rbp), %rax
shlq %rax
movq %rax, -0x48(%rbp)
jmp 0x107bf4
movq -0x48(%rbp), %rax
addq -0x58(%rbp), %rax
movq %rax, -0x58(%rbp)
jmp 0x107aa0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
shlq $0x3, %rdi
callq 0x4150
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x30(%rax)
jne 0x107c59
movq -0x8(%rbp), %rax
movq 0x8(%rax), %r8
shlq $0x3, %r8
leaq 0x4f788(%rip), %rdi     # 0x1573c7
leaq 0x4f757(%rip), %rsi     # 0x15739d
movl $0x6f5, %edx            # imm = 0x6F5
leaq 0x4f759(%rip), %rcx     # 0x1573ab
movb $0x0, %al
callq 0x9cf40
movq -0x8(%rbp), %rax
movb $0x1, 0x28(%rax)
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x107cd9
movq -0x8(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x28(%rcx)
movb %al, -0x71(%rbp)
je 0x107c9b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movb 0x40(%rax), %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %cl
movq -0x8(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x28(%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdx
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x60(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x107c69
movq -0x8(%rbp), %rdi
addq $0x40, %rdi
movq -0x10(%rbp), %rsi
movb -0x29(%rbp), %al
movq -0x8(%rbp), %rcx
addq $0xe0, %rcx
movq -0x8(%rbp), %r8
addq $0x2c0, %r8             # imm = 0x2C0
andb $0x1, %al
movzbl %al, %edx
callq 0x107e10
movq -0x8(%rbp), %rdi
addq $0xe0, %rdi
movq -0x10(%rbp), %rsi
movb -0x29(%rbp), %al
movq -0x8(%rbp), %rcx
addq $0x2c0, %rcx            # imm = 0x2C0
andb $0x1, %al
movzbl %al, %edx
callq 0x107f00
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)