// File: jstaursky[P]hutch/src/Sleigh/sleigh.cc
// Function: PcodeCacher::expandPool(unsigned int)
VarnodeData* PcodeCacher::expandPool (uint4 size)

{ // Expand the pool so that -size- more elements fit
    // Return pointer to first available element
    uint4 curmax = endpool - poolstart;
    uint4 cursize = curpool - poolstart;
    if (cursize + size <= curmax)
        return curpool; // No expansion necessary
    uint4 increase = (cursize + size) - curmax;
    if (increase < 100) // Increase by at least 100
        increase = 100;

    uint4 newsize = curmax + increase;

    VarnodeData* newpool = new VarnodeData[newsize];
    for (uint4 i = 0; i < cursize; ++i)
        newpool[i] = poolstart[i]; // Copy old data
    // Update references to the old pool
    for (uint4 i = 0; i < issued.size (); ++i) {
        VarnodeData* outvar = issued[i].outvar;
        if (outvar != (VarnodeData*)0) {
            outvar = newpool + (outvar - poolstart);
            issued[i].outvar = outvar;
        }
        VarnodeData* invar = issued[i].invar;
        if (invar != (VarnodeData*)0) {
            invar = newpool + (invar - poolstart);
            issued[i].invar = invar;
        }
    }
    list<RelativeRecord>::iterator iter;
    for (iter = label_refs.begin (); iter != label_refs.end (); ++iter) {
        VarnodeData* ref = (*iter).dataptr;
        (*iter).dataptr = newpool + (ref - poolstart);
    }

    delete[] poolstart; // Free up old pool
    poolstart = newpool;
    curpool = newpool + (cursize + size);
    endpool = newpool + newsize;
    return newpool + cursize;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movl %esi, 0xa4(%rsp)
movq 0xa8(%rsp), %rcx
movq %rcx, 0x48(%rsp)
movq 0x10(%rcx), %rax
movq (%rcx), %rdx
subq %rdx, %rax
movl $0x18, %esi
cqto
idivq %rsi
movl %eax, 0xa0(%rsp)
movq 0x8(%rcx), %rax
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movl %eax, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
addl 0xa4(%rsp), %eax
cmpl 0xa0(%rsp), %eax
ja 0x11a076
movq 0x48(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0xb0(%rsp)
jmp 0x11a3ff
movl 0x9c(%rsp), %eax
addl 0xa4(%rsp), %eax
subl 0xa0(%rsp), %eax
movl %eax, 0x98(%rsp)
cmpl $0x64, 0x98(%rsp)
jae 0x11a0a7
movl $0x64, 0x98(%rsp)
movl 0xa0(%rsp), %eax
addl 0x98(%rsp), %eax
movl %eax, 0x94(%rsp)
movl 0x94(%rsp), %eax
movl $0x18, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0xce140
movq %rax, 0x88(%rsp)
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jae 0x11a15c
movq 0x48(%rsp), %rax
movq (%rax), %rcx
movl 0x84(%rsp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rcx
movq 0x88(%rsp), %rax
movl 0x84(%rsp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x11a0f7
movl $0x0, 0x80(%rsp)
movq 0x48(%rsp), %rdi
movl 0x80(%rsp), %eax
movq %rax, 0x40(%rsp)
addq $0x18, %rdi
callq 0xde7e0
movq %rax, %rcx
movq 0x40(%rsp), %rax
cmpq %rcx, %rax
jae 0x11a2ba
movq 0x48(%rsp), %rdi
addq $0x18, %rdi
movl 0x80(%rsp), %eax
movl %eax, %esi
callq 0xd9830
movq 0x8(%rax), %rax
movq %rax, 0x78(%rsp)
cmpq $0x0, 0x78(%rsp)
je 0x11a21a
movq 0x48(%rsp), %rdi
movq 0x88(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x78(%rsp), %rax
movq (%rdi), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x30(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x78(%rsp)
movq 0x78(%rsp), %rax
movq %rax, 0x38(%rsp)
addq $0x18, %rdi
movl 0x80(%rsp), %eax
movl %eax, %esi
callq 0xd9830
movq 0x38(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x48(%rsp), %rdi
addq $0x18, %rdi
movl 0x80(%rsp), %eax
movl %eax, %esi
callq 0xd9830
movq 0x10(%rax), %rax
movq %rax, 0x70(%rsp)
cmpq $0x0, 0x70(%rsp)
je 0x11a2a2
movq 0x48(%rsp), %rdi
movq 0x88(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rax
movq (%rdi), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x20(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x28(%rsp)
addq $0x18, %rdi
movl 0x80(%rsp), %eax
movl %eax, %esi
callq 0xd9830
movq 0x28(%rsp), %rcx
movq %rcx, 0x10(%rax)
jmp 0x11a2a4
movl 0x80(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x80(%rsp)
jmp 0x11a167
leaq 0x68(%rsp), %rdi
callq 0xe1af0
movq 0x48(%rsp), %rdi
addq $0x30, %rdi
callq 0xd97f0
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x48(%rsp), %rdi
addq $0x30, %rdi
callq 0xd9130
movq %rax, 0x58(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xd6e50
testb $0x1, %al
jne 0x11a309
jmp 0x11a377
leaq 0x68(%rsp), %rdi
callq 0xd2560
movq 0x48(%rsp), %rcx
movq (%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rax
movq (%rcx), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq 0x10(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
callq 0xd2560
movq 0x18(%rsp), %rcx
movq %rcx, (%rax)
leaq 0x68(%rsp), %rdi
callq 0xe1a60
jmp 0x11a2e1
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x11a394
movq 0x8(%rsp), %rdi
callq 0xdb380
movq 0x48(%rsp), %rax
movq 0x88(%rsp), %rcx
movq %rcx, (%rax)
movq 0x88(%rsp), %rcx
movl 0x9c(%rsp), %edx
addl 0xa4(%rsp), %edx
movl %edx, %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq 0x88(%rsp), %rcx
movl 0x94(%rsp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq 0x88(%rsp), %rax
movl 0x9c(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
addq $0xb8, %rsp
retq
nop