// File: /workspace/github_cpp_makefile_star2_O3/WbtLm[P]mempool/./mempool.cpp
// Function: mpnsp::memPool::createNewNode(unsigned int)
int mpnsp::memPool::createNewNode(uint num)//返回值是新开辟的位置
{
    if(__builtin_expect(nodeNum+deletedNum>=MaxNodeNum,0))
    {
        myErrorOperate("memPool.nodes are too many.",__LINE__,0);
        return -1;
    }
    if(num<=1)
    {
        myErrorOperate("createNewNode.num must >1",__LINE__,1);
    }
    int i;
    for(i=0;i<MaxNodeNum && nodeArr[i]!=NULL;i++);//ok 寻找一个空节点
    memNode *node=(memNode*)malloc(sizeof(memNode));
    if(__builtin_expect(node==NULL,0))
        return -1;
    nodeArr[i]=node;
    node->used=0;
    node->deleted=0;
    node->memory=(char*)malloc(unitSize*(num+1));
    if(__builtin_expect(node->memory==NULL,0))
        return -1;
    MaxAllocNum=std::max(num,MaxAllocNum);
    node->head=node->memory+unitSize-((long long)node->memory%unitSize);//内存对齐
    node->size=num;
    node->ptrArr=(uint*)malloc(num*sizeof(uint*));
    if(__builtin_expect(node->ptrArr==NULL,0))
        return -1;
    node->fptr=i-1;
    node->nptr=nodeArr[i-1]->nptr;
    nodeArr[i-1]->nptr=i;
    if(node->nptr < MaxNodeNum)
    {
        nodeArr[node->nptr]->fptr=i;
    }

    for(int j=1;j<=num;j++)//ok
    {
        node->ptrArr[j-1]=j;
    }
    node->top=0;
    nodeNum++;
    return i;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x10(%rdi), %r15d
movl 0x14(%rdi), %eax
addl %r15d, %eax
cmpl $0x7f, %eax
jae 0x16a4
cmpl $0x2, %esi
jb 0x16be
movq %rdi, %rbx
movq 0x20(%rdi), %r12
xorl %r13d, %r13d
movq %rsi, -0x40(%rbp)
cmpq $0x0, (%r12,%r13,8)
je 0x159f
incq %r13
cmpq $0x7f, %r13
jne 0x1589
movl $0x7f, %r13d
movl $0x38, %edi
callq 0x1140
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x1693
movq %rax, %r14
movl %r15d, -0x2c(%rbp)
movl %r13d, %eax
movq %r14, (%r12,%rax,8)
movl $0x0, 0x18(%r14)
movb $0x0, 0x10(%r14)
movq %rbx, -0x38(%rbp)
movslq (%rbx), %rbx
movq -0x40(%rbp), %r15
leal 0x1(%r15), %r12d
movl %ebx, %edi
imull %r12d, %edi
callq 0x1140
movq %rax, (%r14)
testq %rax, %rax
je 0x16b7
movq -0x38(%rbp), %rdx
movl 0x18(%rdx), %ecx
cmpl %r15d, %ecx
cmovbel %r15d, %ecx
movl %ecx, 0x18(%rdx)
movq %rax, %rcx
addq %rbx, %rcx
cqto
idivq %rbx
subq %rdx, %rcx
movq %rcx, 0x8(%r14)
movl %r15d, 0x14(%r14)
movl %r15d, %edi
shlq $0x3, %rdi
callq 0x1140
movq %rax, 0x20(%r14)
testq %rax, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
je 0x1693
leal -0x1(%r13), %ecx
movl %ecx, 0x30(%r14)
movq -0x38(%rbp), %r15
movq 0x20(%r15), %rcx
movslq %r13d, %rdx
movq -0x8(%rcx,%rdx,8), %rdx
movl 0x2c(%rdx), %esi
movl %esi, 0x2c(%r14)
movl %r13d, 0x2c(%rdx)
movl 0x2c(%r14), %edx
cmpq $0x7e, %rdx
ja 0x166e
movq (%rcx,%rdx,8), %rcx
movl %r13d, 0x30(%rcx)
movl $0x1, %ecx
movl %ecx, -0x4(%rax,%rcx,4)
incq %rcx
cmpq %rcx, %r12
jne 0x1673
movl $0x0, 0x28(%r14)
movl -0x2c(%rbp), %eax
incl %eax
movl %eax, 0x10(%r15)
movl %r13d, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1959(%rip), %rdi      # 0x3004
movl $0x3c, %esi
xorl %eax, %eax
callq 0x1040
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x1693
leaq 0x193f(%rip), %rdi      # 0x3004
movl $0x41, %esi
xorl %eax, %eax
callq 0x1040
movl $0x1, %edi
callq 0x1130
nop