// File: /workspace/github_c_makefile_star2_O2/heltilda[P]cicada/lnklst.c
// Function: compareElements
ccBool compareElements(linkedlist *sourceList, ccInt sourceBegin, linkedlist * destList, ccInt destBegin, ccInt numberToCompare)
{
    ccInt firstCompared, lastCompared, elementSize, sourceBottom, destBottom, rtrn;
    sublistHeader *currentSourceSublist, *currentDestSublist;
    
    
        // make sure params were passed correctly
    
    if ((sourceList->memory == NULL) || (destList->memory == NULL))  return init_err;
    if (sourceList->elementSize != destList->elementSize)  return mismatched_indices_err;
    if (numberToCompare == 0)  return ccTrue;
    if ((!elementExists(sourceList, sourceBegin)) || (!elementExists(destList, destBegin)))
        return out_of_range_err;
    if ((!elementExists(sourceList, sourceBegin+numberToCompare-1)) || (!elementExists(destList, destBegin+numberToCompare-1)))
        return out_of_range_err;
    
    elementSize = sourceList->elementSize;
    
    currentSourceSublist = findSublist(sourceList, sourceBegin, &sourceBottom);
    currentDestSublist = findSublist(destList, destBegin, &destBottom);
    
    firstCompared = 1;
    lastCompared = numberToCompare-1;
    
    
        // Now, by chunks (size of each sublist), do straight comparisons of memory.
    
    while (lastCompared < numberToCompare)
    {
        if (currentSourceSublist->numElements + sourceBottom < sourceBegin+firstCompared)   {
            sourceBottom += currentSourceSublist->numElements;
            currentSourceSublist = currentSourceSublist->nextSublist;    }
        
        if (currentDestSublist->numElements + destBottom < destBegin+firstCompared)    {
            destBottom += currentDestSublist->numElements;
            currentDestSublist = currentDestSublist->nextSublist;    }
        
        lastCompared = numberToCompare;
        if (sourceBottom+currentSourceSublist->numElements < sourceBegin+lastCompared)
            lastCompared = sourceBottom + currentSourceSublist->numElements - sourceBegin;
        if (destBottom+currentDestSublist->numElements < destBegin+lastCompared)
            lastCompared = destBottom + currentDestSublist->numElements - destBegin;
        
        rtrn = memcmp((void *) ((char *) currentSourceSublist + (firstCompared+sourceBegin-sourceBottom-1)*elementSize + sublistHeaderSize),
                        (void *) ((char *) currentDestSublist + (firstCompared+destBegin-destBottom-1)*elementSize + sublistHeaderSize),
                        (size_t) (lastCompared-firstCompared+1)*elementSize);
        if (rtrn != 0)  return ccFalse;
        
        firstCompared = lastCompared+1;
    }
    
    return ccTrue;
}

// Assembly:
movb $0x3, %al
cmpq $0x0, 0x8(%rdi)
je 0x8dd9
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r13
cmpq $0x0, 0x8(%rdx)
je 0x8dcb
movslq 0x10(%rdi), %r9
movb $0x4, %al
cmpl 0x10(%r13), %r9d
jne 0x8dcb
movl %r8d, %ebx
testl %r8d, %r8d
je 0x8dc9
movl %ecx, %r14d
movl %esi, %r15d
movl (%rdi), %edx
cmpl %esi, %edx
setl %al
testl %esi, %esi
setle %cl
orb %al, %cl
movb $0x2, %al
jne 0x8dcb
movl (%r13), %ecx
cmpl %r14d, %ecx
setl %sil
testl %r14d, %r14d
setle %r8b
orb %sil, %r8b
jne 0x8dcb
leal (%rbx,%r15), %r8d
leal (%rbx,%r15), %esi
decl %esi
cmpl %esi, %edx
setl %dl
movl %r8d, 0x1c(%rsp)
cmpl $0x2, %r8d
setl %sil
orb %dl, %sil
jne 0x8dcb
leal (%rbx,%r14), %edx
leal (%rbx,%r14), %esi
decl %esi
cmpl %esi, %ecx
setl %cl
cmpl $0x2, %edx
setl %dl
orb %cl, %dl
jne 0x8dcb
leaq 0x18(%rsp), %rdx
movl %r15d, %esi
movq %r9, 0x20(%rsp)
callq 0x83ba
movq %rax, %rbp
leaq 0x14(%rsp), %rdx
movq %r13, %rdi
movl %r14d, %esi
callq 0x83ba
movq %rax, %r12
leal -0x1(%rbx), %r13d
leaq 0x18(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x10(%rsp)
pushq $0x1
popq %rdx
leaq 0x14(%rsp), %rax
movl (%rax), %r8d
cmpl %ebx, %r13d
jge 0x8dc9
movq %rbp, %r11
movl (%rbp), %ecx
movl 0x10(%rsp), %ebp
addl %ebp, %ecx
leal (%rdx,%r15), %eax
cmpl %eax, %ecx
jge 0x8d12
movl %ecx, 0x18(%rsp)
movq 0x8(%r11), %r11
movl %ecx, %ebp
movq %r12, %r10
movl (%r12), %esi
addl %r8d, %esi
leal (%rdx,%r14), %ecx
cmpl %ecx, %esi
jge 0x8d37
movl %esi, 0x14(%rsp)
movq 0x8(%r10), %r10
movl (%r10), %edi
addl %esi, %edi
movl %esi, 0xc(%rsp)
jmp 0x8d41
movl %esi, %edi
movl %r8d, 0xc(%rsp)
movl %r8d, %esi
movl (%r11), %r8d
addl %ebp, %r8d
movl %r8d, %r9d
subl %r15d, %r9d
cmpl 0x1c(%rsp), %r8d
cmovgel %ebx, %r9d
leal (%r9,%r14), %r8d
movl %edi, %r13d
subl %r14d, %r13d
cmpl %r8d, %edi
cmovgel %r9d, %r13d
movl %ebp, 0x10(%rsp)
movl %ebp, %edi
notl %edi
addl %edi, %eax
notl %esi
addl %esi, %ecx
movl %r13d, %r8d
subl %edx, %r8d
movq 0x20(%rsp), %r9
imull %r9d, %eax
cltq
movq %r11, %rbp
leaq (%r11,%rax), %rdi
addq $0x18, %rdi
imull %r9d, %ecx
movslq %ecx, %rax
movq %r10, %r12
leaq (%r10,%rax), %rsi
addq $0x18, %rsi
incl %r8d
movslq %r8d, %rdx
imulq %r9, %rdx
callq 0x8180
movl %eax, %ecx
leal 0x1(%r13), %edx
xorl %eax, %eax
testl %ecx, %ecx
movl 0xc(%rsp), %r8d
je 0x8ceb
jmp 0x8dcb
movb $0x1, %al
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq