// File: /workspace/github_cpp_makefile_star2_O3/WbtLm[P]mempool/./mempool.cpp
// Function: mpnsp::memPool::allocMemFromPool()
void* mpnsp::memPool::allocMemFromPool()
{
    if(__builtin_expect(status==0,0))
    {
        memPoolInit();
        if(status==0)
        {
            return malloc(unitSize);
        }
    }
    if(topPtr<=-1)
    {
        maxNumInNode=std::min(maxNumInNode<<1,MaxAllocNum);
        int ret=createNewNode(maxNumInNode);
        topPtr=ret<<OffsetBits;
        if(ret==-1)
        {
            topPtr=-1;
            myErrorOperate("allocMemFromPool.there is too many unit. So . Have to call to malloc.",__LINE__,0);
            return malloc(unitSize);
        }
    }
    #define alloc_head(idx) (node->head+idx*unitSize)
    #define alloc_ptr(idx) (node->ptrArr+idx)
    uint nodeIdx=topPtr>>OffsetBits;
    uint offsetIdx=topPtr & MaskOffsetNumb;
    if(nodeArr[nodeIdx]==NULL || nodeArr[nodeIdx]->deleted)      //如果当前节点不存在 or 被删除了
    {
        for(nodeIdx=0;nodeIdx<=MaxNodeNum;)
        {
            if(__builtin_expect(nodeArr[nodeIdx]==NULL,0))
                nodeIdx++;
            else if(nodeArr[nodeIdx]->deleted==1 || nodeIdx==0)
            {
                nodeIdx=nodeArr[nodeIdx]->nptr;
            }
            else
                break;
        }
        if(nodeIdx>MaxNodeNum)
        {
            topPtr=-1;
            return allocMemFromPool();
        }
        offsetIdx=nodeArr[nodeIdx]->top;
    }
    memNode *node=nodeArr[nodeIdx];

    void*retPtr=alloc_head(offsetIdx);
    uint &nodeTop=node->top;
    if(__builtin_expect(node->used >= node->size,0)) //当前节点容纳不下
    {
        int i;
        for(i=nodeArr[0]->nptr;i<=MaxNodeNum;)
        {
            if(__builtin_expect(nodeArr[i]==NULL,0))
                i++;
            else if(nodeArr[i]->deleted==1 || nodeArr[i]->used >= nodeArr[i]->size)
            {
                i=nodeArr[i]->nptr;
            }
            else //能容得下
            {
                node=nodeArr[i];
                retPtr=node->head+node->top;
                node->used++;

                node->top=*alloc_ptr(node->top);
                topPtr=i<<OffsetBits;
                topPtr|=node->top;
                return retPtr;
            }
        }
        //当前容纳不下且也没有节点能容纳下
        topPtr=-1;
        return allocMemFromPool();  //一层递归
    }
    else
    {
        node->used++;
        node->top=*alloc_ptr(offsetIdx);
        topPtr&=~MaskOffsetNumb;
        topPtr|=node->top;
    }
    return retPtr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
movabsq $0x7fffffff8, %r12      # imm = 0x7FFFFFFF8
leaq -0x28(%rbp), %r15
cmpb $0x0, 0x28(%rbx)
je 0x1907
movq (%r14), %rcx
testq %rcx, %rcx
jns 0x1883
movl 0x18(%rbx), %eax
movl 0x1c(%rbx), %esi
addl %esi, %esi
cmpl %esi, %eax
cmovbl %eax, %esi
movl %esi, 0x1c(%rbx)
movq %rbx, %rdi
callq 0x154e
cmpl $-0x1, %eax
je 0x194e
shll $0x15, %eax
movslq %eax, %rcx
movq 0x20(%rbx), %rdi
movq %rcx, %rax
shrq $0x12, %rax
andq %r12, %rax
movq (%rdi,%rax), %rax
testq %rax, %rax
je 0x18a0
cmpb $0x0, 0x10(%rax)
je 0x18cc
xorl %eax, %eax
movl %eax, %edx
movq (%rdi,%rdx,8), %rdx
testq %rdx, %rdx
je 0x18c3
testl %eax, %eax
je 0x18b7
cmpb $0x0, 0x10(%rdx)
je 0x18c7
movl 0x2c(%rdx), %eax
cmpl $0x80, %eax
jb 0x18a2
jmp 0x18fb
incl %eax
jmp 0x18ba
movl 0x28(%rdx), %eax
jmp 0x18e0
movq %rcx, %rdx
shrq $0x15, %rdx
movl %ecx, %eax
andl $0x1fffff, %eax         # imm = 0x1FFFFF
movl %edx, %edx
movq (%rdi,%rdx,8), %rdx
movl 0x18(%rdx), %esi
cmpl 0x14(%rdx), %esi
jb 0x191b
movq %r14, %rsi
movq %r15, %rdx
callq 0x11f9
testb $0x1, %al
je 0x197d
movq $-0x1, (%r14)
jmp 0x184a
movq %rbx, %rdi
callq 0x1732
cmpb $0x0, 0x28(%rbx)
jne 0x1854
jmp 0x1969
movl %eax, %edi
imull (%rbx), %eax
addq 0x8(%rdx), %rax
incl %esi
movl %esi, 0x18(%rdx)
movq 0x20(%rdx), %rsi
movl (%rsi,%rdi,4), %esi
movl %esi, 0x28(%rdx)
andq $-0x200000, %rcx        # imm = 0xFFE00000
orq %rsi, %rcx
movq %rcx, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq $-0x1, 0x8(%rbx)
leaq 0x16a7(%rip), %rdi      # 0x3004
movl $0xbc, %esi
xorl %eax, %eax
callq 0x1040
movslq (%rbx), %rdi
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x1140
movq -0x28(%rbp), %rax
jmp 0x1941
nop