// File: /workspace/github_c_makefile_star2_O1/heltilda[P]cicada/lnklst.c
// Function: addPLLElement
ccInt addPLLElement(pinned_LL *basePLL, void **newElementPtr, ccInt *newElementIndex)
{
    ccInt counter, rtrn;
    
    
        // Case 1:  add to the top of the list
    
    if (basePLL->lowestFreeSpot > basePLL->data.elementNum)   {             // shouldn't move what's in the lower sublists
        rtrn = addElements(&(basePLL->data), 1, ccFalse);         // with my current insertElements scheme
        if (rtrn != passed)  return rtrn;
        rtrn = addElements(&(basePLL->references), 1, ccTrue);     // references must be initially set to 0
        if (rtrn != passed)  return rtrn;
        
        *newElementIndex = basePLL->data.elementNum;
        *newElementPtr = element(&(basePLL->data), *newElementIndex);
        basePLL->lowestFreeSpot = *newElementIndex+1;
        basePLL->highestFreeSpot = 1;         }   // cannot equal lowestFreeSpot: we need it to be lower than any spots that open up
    
    
        // Case 2:  go to the lowest free element in the existing list
    
    else  {
        *newElementIndex = basePLL->lowestFreeSpot;
        *newElementPtr = element(&(basePLL->data), *newElementIndex);
        *LL_int(&(basePLL->references), *newElementIndex) = 0;
        
        if (basePLL->lowestFreeSpot >= basePLL->highestFreeSpot)  {
            basePLL->lowestFreeSpot = basePLL->data.elementNum+1;
            basePLL->highestFreeSpot = 1;     }
        
        else  {
        for (counter = basePLL->lowestFreeSpot+1; counter <= basePLL->highestFreeSpot; counter++)  {
        if (*LL_int(&(basePLL->references), counter) == 0)  {
            basePLL->lowestFreeSpot = counter;
            counter = basePLL->highestFreeSpot;
    }   }}}
    
    return passed;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movl (%rdi), %esi
movl 0x40(%rdi), %ecx
cmpl %esi, %ecx
jle 0x92bd
incl %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x84af
testl %eax, %eax
jne 0x939c
leaq 0x20(%rbx), %rdi
movl 0x20(%rbx), %esi
incl %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x84af
testl %eax, %eax
jne 0x939c
movl (%rbx), %eax
movl %eax, (%r15)
movq 0x8(%rbx), %rcx
movl (%rcx), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl %eax, %esi
jge 0x9298
movl %esi, %edx
movq 0x8(%rcx), %rcx
movl (%rcx), %esi
addl %edx, %esi
cmpl %eax, %esi
jl 0x9288
notl %edx
movslq 0x10(%rbx), %rsi
addl %eax, %edx
movslq %edx, %rdx
imulq %rsi, %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movq %rcx, (%r14)
incl %eax
movl %eax, 0x40(%rbx)
addq $0x44, %rbx
jmp 0x9394
movl %ecx, (%r15)
movq 0x8(%rbx), %rax
movl (%rax), %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl %ecx, %edi
jge 0x92e1
movl %edi, %esi
movq 0x8(%rax), %rax
movl (%rax), %edi
addl %esi, %edi
cmpl %ecx, %edi
jl 0x92cf
notl %esi
jmp 0x92e6
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movslq 0x10(%rbx), %rdi
addl %ecx, %esi
movslq %esi, %rsi
imulq %rdi, %rsi
addq %rsi, %rax
addq $0x18, %rax
movq %rax, (%r14)
movq 0x28(%rbx), %rax
movl (%rax), %edi
movq %rax, %rsi
cmpl %ecx, %edi
jge 0x931d
movq %rax, %rsi
movl %edi, %edx
movq 0x8(%rsi), %rsi
movl (%rsi), %edi
addl %edx, %edi
cmpl %ecx, %edi
jl 0x930d
notl %edx
movslq 0x30(%rbx), %rdi
addl %ecx, %edx
movslq %edx, %rcx
imulq %rdi, %rcx
movl $0x0, 0x18(%rsi,%rcx)
movl 0x40(%rbx), %edx
movl 0x44(%rbx), %ecx
cmpl %ecx, %edx
jge 0x9389
movl (%rax), %esi
movslq 0x30(%rbx), %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %rax, %r8
cmpl %edx, %esi
jg 0x936a
movl %esi, %r10d
movq %rax, %r8
movl %r10d, %r9d
movq 0x8(%r8), %r8
movl (%r8), %r10d
addl %r9d, %r10d
cmpl %edx, %r10d
jle 0x9355
notl %r9d
incl %edx
addl %edx, %r9d
movslq %r9d, %r9
imulq %rdi, %r9
cmpl $0x0, 0x18(%r8,%r9)
jne 0x9383
movl %edx, 0x40(%rbx)
movl %ecx, %edx
cmpl %ecx, %edx
jl 0x9342
jmp 0x939a
movl (%rbx), %eax
incl %eax
movl %eax, 0x40(%rbx)
addq $0x44, %rbx
movl $0x1, (%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq