// File: /workspace/github_cpp_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x8(%rdi), %r14
leaq 0x17c0(%rip), %r15      # 0x3004
movabsq $0x7fffffff8, %r12      # imm = 0x7FFFFFFF8
cmpb $0x0, 0x28(%rbx)
je 0x194c
cmpq $0x0, 0x8(%rbx)
jns 0x18b2
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 0x155e
movl %eax, %r13d
shll $0x15, %eax
cltq
movq %rax, 0x8(%rbx)
cmpl $-0x1, %r13d
jne 0x18a8
movq $-0x1, 0x8(%rbx)
movq %r15, %rdi
movl $0xbc, %esi
xorl %eax, %eax
callq 0x1040
movslq (%rbx), %rdi
callq 0x1140
cmpl $-0x1, %r13d
je 0x199a
movq 0x8(%rbx), %rcx
movq 0x20(%rbx), %rdi
movq %rcx, %rax
shrq $0x12, %rax
andq %r12, %rax
movq (%rdi,%rax), %rax
testq %rax, %rax
je 0x18d3
cmpb $0x1, 0x10(%rax)
jne 0x191a
xorl %edx, %edx
movl %edx, %eax
movq (%rdi,%rax,8), %rax
testq %rax, %rax
je 0x18f7
testl %edx, %edx
je 0x18ea
cmpb $0x0, 0x10(%rax)
je 0x18fb
movl 0x2c(%rax), %edx
cmpl $0x80, %edx
jb 0x18d5
jmp 0x18fb
incl %edx
jmp 0x18ed
cmpl $0x80, %edx
jb 0x190f
movq $-0x1, (%r14)
jmp 0x184e
movl %edx, %eax
movq (%rdi,%rax,8), %rax
movl 0x28(%rax), %eax
jmp 0x1928
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 0x1974
movq %r14, %rsi
leaq -0x30(%rbp), %rdx
callq 0x11f9
testb $0x1, %al
jne 0x184e
jmp 0x19a9
movq %rbx, %rdi
callq 0x172a
cmpb $0x0, 0x28(%rbx)
jne 0x1858
movslq (%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1140
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 $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x30(%rbp), %rax
jmp 0x199a
nop