// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x88a9
movl $0x3, -0x4(%rbp)
jmp 0x8a80
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x8830
cmpl $0x0, %eax
je 0x88cb
movq -0x10(%rbp), %rdi
movl -0x18(%rbp), %esi
callq 0x8830
cmpl $0x0, %eax
jne 0x88d7
movl $0x2, -0x4(%rbp)
jmp 0x8a80
movl -0x14(%rbp), %eax
cmpl -0x18(%rbp), %eax
jle 0x88eb
movl $0x0, -0x4(%rbp)
jmp 0x8a80
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
leaq -0x3c(%rbp), %rdx
callq 0x83f0
movq %rax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jg 0x89c4
movl -0x3c(%rbp), %eax
movq -0x28(%rbp), %rcx
addl (%rcx), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x892e
movl -0x14(%rbp), %eax
movl %eax, -0x48(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x8997
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movl -0x48(%rbp), %eax
subl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x10(%rcx), %eax
cltq
addq %rax, %rdi
addq $0x18, %rdi
movq -0x28(%rbp), %rsi
movl -0x44(%rbp), %eax
subl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x10(%rcx), %eax
cltq
addq %rax, %rsi
addq $0x18, %rsi
movl -0x40(%rbp), %eax
addl $0x1, %eax
subl -0x44(%rbp), %eax
movq -0x10(%rbp), %rcx
imull 0x10(%rcx), %eax
movslq %eax, %rdx
callq 0x8200
movq -0x28(%rbp), %rax
movl (%rax), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %edx
subl -0x48(%rbp), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x88ff
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
je 0x8a24
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x8a13
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq (%rax), %rdi
callq 0x81c0
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
jmp 0x8a22
movq -0x30(%rbp), %rax
movq (%rax), %rax
addq $0x8, %rax
movq %rax, -0x30(%rbp)
jmp 0x89d0
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x8a66
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edx
xorl %ecx, %ecx
movl $0x1, %esi
movl %ecx, %edi
callq 0x8360
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpq $0x0, -0x38(%rbp)
jne 0x8a64
movl $0x1, -0x4(%rbp)
jmp 0x8a80
jmp 0x8a66
movl -0x18(%rbp), %edx
subl -0x14(%rbp), %edx
addl $0x1, %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)