// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/quicklist.c
// Function: quicklistDelRange
int quicklistDelRange(quicklist *quicklist, const long start,
                      const long count) {
    if (count <= 0)
        return 0;

    unsigned long extent = count; /* range is inclusive of start position */

    if (start >= 0 && extent > (quicklist->count - start)) {
        /* if requesting delete more elements than exist, limit to list size. */
        extent = quicklist->count - start;
    } else if (start < 0 && extent > (unsigned long)(-start)) {
        /* else, if at negative offset, limit max size to rest of list. */
        extent = -start; /* c.f. LREM -29 29; just delete until end. */
    }

    quicklistEntry entry;
    if (!quicklistIndex(quicklist, start, &entry))
        return 0;

    D("Quicklist delete request for start %ld, count %ld, extent: %ld", start,
      count, extent);
    quicklistNode *node = entry.node;

    /* iterate over next nodes until everything is deleted. */
    while (extent) {
        quicklistNode *next = node->next;

        unsigned long del;
        int delete_entire_node = 0;
        if (entry.offset == 0 && extent >= node->count) {
            /* If we are deleting more than the count of this node, we
             * can just delete the entire node without ziplist math. */
            delete_entire_node = 1;
            del = node->count;
        } else if (entry.offset >= 0 && extent >= node->count) {
            /* If deleting more nodes after this one, calculate delete based
             * on size of current node. */
            del = node->count - entry.offset;
        } else if (entry.offset < 0) {
            /* If offset is negative, we are in the first run of this loop
             * and we are deleting the entire range
             * from this start offset to end of list.  Since the Negative
             * offset is the number of elements until the tail of the list,
             * just use it directly as the deletion count. */
            del = -entry.offset;

            /* If the positive offset is greater than the remaining extent,
             * we only delete the remaining extent, not the entire offset.
             */
            if (del > extent)
                del = extent;
        } else {
            /* else, we are deleting less than the extent of this node, so
             * use extent directly. */
            del = extent;
        }

        D("[%ld]: asking to del: %ld because offset: %d; (ENTIRE NODE: %d), "
          "node count: %u",
          extent, del, entry.offset, delete_entire_node, node->count);

        if (delete_entire_node) {
            __quicklistDelNode(quicklist, node);
        } else {
            quicklistDecompressNodeForUse(node);
            node->zl = ziplistDeleteRange(node->zl, entry.offset, del);
            quicklistNodeUpdateSz(node);
            node->count -= del;
            quicklist->count -= del;
            quicklistDeleteIfEmpty(quicklist, node);
            if (node)
                quicklistRecompressOnly(quicklist, node);
        }

        extent -= del;

        node = next;

        entry.offset = 0;
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
xorl %ebp, %ebp
testq %rdx, %rdx
jg 0x2f5c0
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
testq %rsi, %rsi
js 0x2f5d4
movq 0x10(%rbx), %r12
subq %rsi, %r12
cmpq %rdx, %r12
jb 0x2f5eb
testq %rsi, %rsi
jns 0x2f5e8
movq %rsi, %r12
negq %r12
cmpq %rdx, %r12
cmovaeq %rdx, %r12
jmp 0x2f5eb
movq %rdx, %r12
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
callq 0x26fac
testl %eax, %eax
je 0x2f70e
movl $0x1, %ebp
testq %r12, %r12
je 0x2f5af
movq 0x10(%rsp), %r13
movq %r13, %r14
movl 0x34(%rsp), %eax
testl %eax, %eax
jne 0x2f624
movzwl 0x1c(%r14), %r15d
cmpq %r15, %r12
jae 0x2f654
testl %eax, %eax
js 0x2f632
movzwl 0x1c(%r14), %ecx
cmpq %rcx, %r12
jae 0x2f63d
movb $0x1, %cl
testl %eax, %eax
js 0x2f646
movq %r12, %r15
jmp 0x2f656
subl %eax, %ecx
movslq %ecx, %r15
movb $0x1, %cl
jmp 0x2f656
negl %eax
cmpq %rax, %r12
cmovbq %r12, %rax
movq %rax, %r15
jmp 0x2f656
xorl %ecx, %ecx
movq 0x8(%r14), %r13
testb %cl, %cl
je 0x2f6ed
testq %r14, %r14
je 0x2f686
movl 0x1c(%r14), %eax
movl $0x30000, %ecx          # imm = 0x30000
andl %ecx, %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x2f686
movq %r14, %rdi
callq 0x2e916
orb $0x10, 0x1e(%r14)
movq 0x10(%r14), %rdi
movl 0x34(%rsp), %esi
movl %r15d, %edx
callq 0x3ec1d
movq %rax, 0x10(%r14)
movq %rax, %rdi
callq 0x3ef6d
movl %eax, 0x18(%r14)
movl 0x1c(%r14), %eax
subl %r15d, %eax
movw %ax, 0x1c(%r14)
subq %r15, 0x10(%rbx)
cmpw $0x0, 0x1c(%r14)
jne 0x2f6cc
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2edc8
xorl %r14d, %r14d
testq %r14, %r14
je 0x2f6f8
movl 0x1c(%r14), %eax
movl $0x130000, %ecx         # imm = 0x130000
andl %ecx, %eax
cmpl $0x110000, %eax         # imm = 0x110000
jne 0x2f6f8
movq %r14, %rdi
callq 0x2e893
jmp 0x2f6f8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2edc8
movl $0x0, 0x34(%rsp)
subq %r15, %r12
jne 0x2f60f
jmp 0x2f5af
xorl %ebp, %ebp
jmp 0x2f5af