// File: /workspace/github_c_makefile_star2_O3/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
movq %rdi, %rbx
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x882d
movl %edx, %r14d
movl %esi, %r15d
movl (%rbx), %eax
cmpl %esi, %eax
setl %cl
testl %esi, %esi
setle %dl
orb %cl, %dl
movl $0x2, %ebp
jne 0x8832
cmpl %r14d, %eax
setl %al
testl %r14d, %r14d
setle %cl
orb %al, %cl
jne 0x8832
xorl %ebp, %ebp
cmpl %r14d, %r15d
ja 0x8832
movl (%rdi), %eax
movl $0x1, %r12d
movq %rdi, %r13
cmpl %r15d, %eax
jge 0x8710
movq %rdi, %r13
movl %eax, %r12d
movq 0x8(%r13), %r13
movl (%r13), %eax
addl %r12d, %eax
cmpl %r15d, %eax
jl 0x86fa
incl %r12d
leaq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
cmpl %r14d, %r12d
jg 0x87b6
movq %rbx, 0x10(%rsp)
leal 0x1(%r14), %ebx
movl (%r13), %ecx
leal (%rcx,%r12), %eax
leal (%rcx,%r12), %edx
decl %edx
cmpl %r15d, %r12d
movl %r15d, %ebp
cmovgl %r12d, %ebp
cmpl %r14d, %edx
jle 0x8791
movl %ebp, %ecx
subl %r12d, %ecx
movq 0x10(%rsp), %rdx
movl 0x10(%rdx), %edx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%r13), %rdi
addq $0x18, %rdi
movl %ebx, %ecx
subl %r12d, %ecx
imull %edx, %ecx
movslq %ecx, %rcx
leaq (%rcx,%r13), %rsi
addq $0x18, %rsi
subl %ebx, %eax
imull %edx, %eax
movslq %eax, %rdx
callq 0x8220
movl (%r13), %ecx
addl %ecx, %r12d
movl %r12d, %eax
movl %ebx, %edx
jmp 0x8793
movl %eax, %edx
subl %edx, %ebp
addl %ecx, %ebp
movl %ebp, (%r13)
movq 0x8(%r13), %r13
movl %eax, %r12d
cmpl %r14d, %eax
jle 0x872b
movq 0x8(%rsp), %rax
movq (%rax), %rdi
xorl %ebp, %ebp
movq 0x10(%rsp), %rbx
testq %rdi, %rdi
je 0x87f3
movq %rbx, %r13
movq 0x8(%rsp), %rbx
cmpl $0x0, (%rdi)
movq 0x8(%rdi), %r12
je 0x87d5
addq $0x8, %rdi
movq %rdi, %rbx
jmp 0x87dd
callq 0x81c0
movq %r12, (%rbx)
movq %r12, %rdi
testq %r12, %r12
jne 0x87c3
movq 0x8(%rsp), %rax
cmpq $0x0, (%rax)
movq %r13, %rbx
jne 0x8822
movslq 0x10(%rbx), %rdi
addq $0x18, %rdi
callq 0x81d0
testq %rax, %rax
je 0x8843
movl $0x0, (%rax)
movl $0x1, 0x10(%rax)
movq $0x0, 0x8(%rax)
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
notl %r14d
addl %r15d, %r14d
addl %r14d, (%rbx)
jmp 0x8832
movl $0x3, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq $0x0, (%rax)
movl $0x1, %ebp
jmp 0x8832