// File: /workspace/github_c_makefile_star2_O2/heltilda[P]cicada/lnklst.c
// Function: deleteElements
ccInt deleteElements(linkedlist *theList, ccInt firstDelete, ccInt lastDelete)
{
    sublistHeader *tempSublist, *currentSublist, **parentPtr, *tempPtr;
    ccInt bottom, top, firstCopy, copyBottom;
    
    if (theList->memory == NULL)  return init_err;
    if ((!elementExists(theList, firstDelete)) || (!elementExists(theList, lastDelete))) return out_of_range_err;
    if (firstDelete > lastDelete)  return passed;
    currentSublist = findSublist(theList, firstDelete, &bottom);
    
    
        // First, find the sublist in which we stop deleting, then copy what comes after back down towards the bottom.
    
    while (bottom <= lastDelete)
    {
        top = bottom + currentSublist->numElements - 1;
        copyBottom = bottom;
        if (bottom < firstDelete) copyBottom = firstDelete;      // i.e. if it's the first pass
        
        firstCopy = top + 1;
        if (lastDelete < top)  {
            firstCopy = lastDelete + 1;
            memmove((void *) (((char *) currentSublist) + (copyBottom-bottom)*theList->elementSize + sublistHeaderSize),
                    (void *) (((char *) currentSublist) + (firstCopy-bottom)*theList->elementSize + sublistHeaderSize),
                    (top + 1 - firstCopy)*theList->elementSize);        }
        
        bottom += currentSublist->numElements;         // bottom goes by the old indexing; before the elements were deleted
        currentSublist->numElements -= (firstCopy-copyBottom);
        currentSublist = currentSublist->nextSublist;
    }
    
    
        // Now get rid of null lists.
    
    parentPtr = &(theList->memory);
    while (*parentPtr != NULL)    {
        
        tempSublist = *parentPtr;
        
        if (tempSublist->numElements == 0)   {
            tempPtr = tempSublist->nextSublist;
            free((void *) *parentPtr);
            *parentPtr = tempPtr;        }
        else  {
            parentPtr = &((*parentPtr)->nextSublist);
    }   }
    
    
        // If we went too far and deleted the first sublist, recreate it
    
    if (theList->memory == NULL)  {
        tempPtr = newSublist(0, 1, theList->elementSize, ccFalse);
        theList->memory = tempPtr;
        if (tempPtr == NULL)  return out_of_memory_err;    }
    
    theList->elementNum -= lastDelete - firstDelete + 1;
    
    return passed;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
cmpq $0x0, 0x8(%rdi)
je 0x874f
movl %edx, %ebx
movl %esi, %r14d
movl (%rdi), %eax
cmpl %esi, %eax
setl %cl
testl %esi, %esi
setle %dl
orb %cl, %dl
pushq $0x2
popq %r15
jne 0x8753
cmpl %ebx, %eax
setl %al
testl %ebx, %ebx
setle %cl
orb %al, %cl
jne 0x8753
xorl %r15d, %r15d
cmpl %ebx, %r14d
ja 0x8753
leaq 0x8(%rdi), %rax
movq %rax, (%rsp)
leaq 0x14(%rsp), %r12
movq %rdi, 0x8(%rsp)
movl %r14d, %esi
movq %r12, %rdx
callq 0x83ba
movq %rax, %r15
movl (%r12), %r13d
leal 0x1(%rbx), %r12d
cmpl %ebx, %r13d
jg 0x8765
movl (%r15), %ecx
leal (%rcx,%r13), %eax
leal (%rcx,%r13), %edx
decl %edx
cmpl %r14d, %r13d
movl %r14d, %ebp
cmovgl %r13d, %ebp
cmpl %ebx, %edx
jle 0x873a
movl %ebp, %ecx
subl %r13d, %ecx
movq 0x8(%rsp), %rdx
movl 0x10(%rdx), %edx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r15,%rcx), %rdi
addq $0x18, %rdi
movl %r12d, %ecx
subl %r13d, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%r15,%rcx), %rsi
addq $0x18, %rsi
subl %r12d, %eax
imull %edx, %eax
movslq %eax, %rdx
callq 0x8220
movl (%r15), %ecx
addl %ecx, %r13d
movl %r13d, %eax
movl %r12d, %edx
jmp 0x873c
movl %eax, %edx
subl %edx, %ebp
addl %ecx, %ebp
movl %ebp, (%r15)
movq 0x8(%r15), %r15
movl %eax, %r13d
jmp 0x86cb
pushq $0x3
popq %r15
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r15
movq 0x8(%rsp), %r13
movq (%r15), %rdi
testq %rdi, %rdi
je 0x8792
cmpl $0x0, (%rdi)
jne 0x8789
movq 0x8(%rdi), %r12
callq 0x81c0
movq %r12, (%r15)
jmp 0x876e
addq $0x8, %rdi
movq %rdi, %r15
jmp 0x876e
movq (%rsp), %rax
cmpq $0x0, (%rax)
jne 0x87b9
movl 0x10(%r13), %edx
pushq $0x1
popq %r15
xorl %edi, %edi
movl %r15d, %esi
xorl %ecx, %ecx
callq 0x837c
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x8753
notl %ebx
addl %r14d, %ebx
addl %ebx, (%r13)
xorl %r15d, %r15d
jmp 0x8753