// File: /workspace/github_cpp_makefile_star2_O2/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 %r14
pushq %rbx
movq %rdi, %rbx
movabsq $0x7fffffff8, %r14      # imm = 0x7FFFFFFF8
cmpb $0x0, 0x28(%rbx)
je 0x1809
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
jns 0x176e
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 0x1496
cmpl $-0x1, %eax
je 0x1848
shll $0x15, %eax
movslq %eax, %rdx
movq 0x20(%rbx), %rcx
movq %rdx, %rax
shrq $0x12, %rax
andq %r14, %rax
movq (%rcx,%rax), %rax
testq %rax, %rax
je 0x178b
cmpb $0x0, 0x10(%rax)
je 0x17b5
xorl %eax, %eax
cmpl $0x7f, %eax
ja 0x17ff
movl %eax, %esi
movq (%rcx,%rsi,8), %rsi
testq %rsi, %rsi
je 0x17ac
testl %eax, %eax
je 0x17a7
cmpb $0x0, 0x10(%rsi)
je 0x17b0
movl 0x2c(%rsi), %eax
jmp 0x178d
incl %eax
jmp 0x178d
movl 0x28(%rsi), %eax
jmp 0x17c9
movq %rdx, %rsi
shrq $0x15, %rsi
movl %edx, %eax
andl $0x1fffff, %eax         # imm = 0x1FFFFF
movl %esi, %esi
movq (%rcx,%rsi,8), %rsi
movl 0x18(%rsi), %edi
cmpl 0x14(%rsi), %edi
jb 0x181d
movq (%rcx), %rax
movl 0x2c(%rax), %edx
cmpl $0x7f, %edx
jg 0x17ff
movslq %edx, %rax
movq (%rcx,%rax,8), %rsi
testq %rsi, %rsi
je 0x17fb
cmpb $0x0, 0x10(%rsi)
jne 0x17f6
movl 0x18(%rsi), %edi
cmpl 0x14(%rsi), %edi
jb 0x186c
movl 0x2c(%rsi), %edx
jmp 0x17d7
incl %edx
jmp 0x17d7
orq $-0x1, 0x8(%rbx)
jmp 0x1734
movq %rbx, %rdi
callq 0x1638
cmpb $0x0, 0x28(%rbx)
jne 0x173e
jmp 0x1860
movl %eax, %ecx
imull (%rbx), %eax
addq 0x8(%rsi), %rax
incl %edi
movl %edi, 0x18(%rsi)
movq 0x20(%rsi), %rdi
movl (%rdi,%rcx,4), %ecx
movl %ecx, 0x28(%rsi)
andq $-0x200000, %rdx        # imm = 0xFFE00000
orq %rcx, %rdx
movq %rdx, 0x8(%rbx)
popq %rbx
popq %r14
popq %rbp
retq
orq $-0x1, 0x8(%rbx)
leaq 0x17b0(%rip), %rdi      # 0x3004
movl $0xbc, %esi
xorl %eax, %eax
callq 0x1030
movslq (%rbx), %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x1140
movl 0x28(%rsi), %ecx
movq 0x8(%rsi), %rax
addq %rcx, %rax
incl %edi
movl %edi, 0x18(%rsi)
movq 0x20(%rsi), %rdi
movl (%rdi,%rcx,4), %ecx
movl %ecx, 0x28(%rsi)
shll $0x15, %edx
movslq %edx, %rdx
jmp 0x183c
nop