// File: /workspace/github_c_makefile_star2_O3/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 0x936c
incl %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x84af
testl %eax, %eax
jne 0x9448
leaq 0x20(%rbx), %rdi
movl 0x20(%rbx), %esi
incl %esi
movl $0x1, %edx
movl $0x1, %ecx
callq 0x84af
testl %eax, %eax
jne 0x9448
movl (%rbx), %eax
movl %eax, (%r15)
movq 0x8(%rbx), %rcx
movl (%rcx), %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl %eax, %esi
jge 0x9350
movl %esi, %edx
movq 0x8(%rcx), %rcx
movl (%rcx), %esi
addl %edx, %esi
cmpl %eax, %esi
jl 0x9340
notl %edx
movslq 0x10(%rbx), %rsi
addl %eax, %edx
movslq %edx, %rdx
imulq %rsi, %rdx
addq %rdx, %rcx
addq $0x18, %rcx
movq %rcx, (%r14)
jmp 0x9435
movl %ecx, (%r15)
movq 0x8(%rbx), %rax
movl (%rax), %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl %ecx, %edi
jge 0x9390
movl %edi, %esi
movq 0x8(%rax), %rax
movl (%rax), %edi
addl %esi, %edi
cmpl %ecx, %edi
jl 0x937e
notl %esi
jmp 0x9395
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 0x93cc
movq %rax, %rsi
movl %edi, %edx
movq 0x8(%rsi), %rsi
movl (%rsi), %edi
addl %edx, %edi
cmpl %ecx, %edi
jl 0x93bc
notl %edx
movslq 0x30(%rbx), %rdi
addl %ecx, %edx
movslq %edx, %rcx
imulq %rdi, %rcx
movl $0x0, 0x18(%rsi,%rcx)
movl 0x40(%rbx), %ecx
movl 0x44(%rbx), %edx
cmpl %edx, %ecx
jge 0x9433
movl (%rax), %esi
movslq 0x30(%rbx), %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %rax, %r8
cmpl %ecx, %esi
jg 0x9419
movl %esi, %r10d
movq %rax, %r8
movl %r10d, %r9d
movq 0x8(%r8), %r8
movl (%r8), %r10d
addl %r9d, %r10d
cmpl %ecx, %r10d
jle 0x9404
notl %r9d
incl %ecx
addl %ecx, %r9d
movslq %r9d, %r9
imulq %rdi, %r9
cmpl $0x0, 0x18(%r8,%r9)
je 0x9443
cmpl %edx, %ecx
jl 0x93f1
jmp 0x9446
movl (%rbx), %eax
incl %eax
movl %eax, 0x40(%rbx)
movl $0x1, 0x44(%rbx)
jmp 0x9446
movl %ecx, 0x40(%rbx)
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq