// File: 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
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x30(%rbp)
movl 0x10(%rcx), %eax
addl 0x14(%rcx), %eax
cmpl $0x7f, %eax
jb 0x1671
leaq 0x3a19(%rip), %rdi      # 0x5072
movl $0x3c, %esi
xorl %edx, %edx
callq 0x13a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x187d
cmpl $0x1, -0x14(%rbp)
ja 0x168d
leaq 0x3a10(%rip), %rdi      # 0x508e
movl $0x41, %esi
movl $0x1, %edx
callq 0x13a0
movl $0x0, -0x18(%rbp)
xorl %eax, %eax
cmpl $0x7f, -0x18(%rbp)
movb %al, -0x31(%rbp)
jge 0x16b6
movq -0x30(%rbp), %rax
movq 0x20(%rax), %rax
movslq -0x18(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
setne %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x16bf
jmp 0x16cc
jmp 0x16c1
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x1694
movl $0x38, %edi
callq 0x1130
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x16ed
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x187d
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rsi
movq 0x20(%rax), %rcx
movslq -0x18(%rbp), %rdx
movq %rsi, (%rcx,%rdx,8)
movq -0x20(%rbp), %rcx
movl $0x0, 0x18(%rcx)
movq -0x20(%rbp), %rcx
movb $0x0, 0x10(%rcx)
movl (%rax), %eax
movl -0x14(%rbp), %ecx
addl $0x1, %ecx
imull %ecx, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x1130
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x1748
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x187d
movq -0x30(%rbp), %rsi
addq $0x18, %rsi
leaq -0x14(%rbp), %rdi
callq 0x2630
movq -0x30(%rbp), %rdx
movl (%rax), %eax
movl %eax, 0x18(%rdx)
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movslq (%rdx), %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq (%rdx), %rsi
cqto
idivq %rsi
xorl %eax, %eax
subq %rdx, %rax
addq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x14(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x14(%rax)
movl -0x14(%rbp), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x1130
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x17c8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x187d
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %edx
subl $0x1, %edx
movq -0x20(%rbp), %rcx
movl %edx, 0x30(%rcx)
movq 0x20(%rax), %rcx
movl -0x18(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movl 0x2c(%rcx), %edx
movq -0x20(%rbp), %rcx
movl %edx, 0x2c(%rcx)
movl -0x18(%rbp), %ecx
movq 0x20(%rax), %rax
movl -0x18(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x2c(%rax)
movq -0x20(%rbp), %rax
cmpl $0x7f, 0x2c(%rax)
jae 0x182e
movq -0x30(%rbp), %rax
movl -0x18(%rbp), %ecx
movq 0x20(%rax), %rax
movq -0x20(%rbp), %rdx
movl 0x2c(%rdx), %edx
movq (%rax,%rdx,8), %rax
movl %ecx, 0x30(%rax)
movl $0x1, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x14(%rbp), %eax
ja 0x185f
movl -0x24(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x24(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x1835
movq -0x30(%rbp), %rax
movq -0x20(%rbp), %rcx
movl $0x0, 0x28(%rcx)
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)