// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jg 0x2982a
movl $0x0, -0x4(%rbp)
jmp 0x29ace
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x18(%rbp)
jl 0x29860
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x29860
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
subq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x29882
cmpq $0x0, -0x18(%rbp)
jge 0x29880
movq -0x28(%rbp), %rax
xorl %ecx, %ecx
subq -0x18(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x29880
xorl %eax, %eax
subq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x29882
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x288a0
cmpl $0x0, %eax
jne 0x298a4
movl $0x0, -0x4(%rbp)
jmp 0x29ace
movq -0x50(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x29ac7
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x29903
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0x1c(%rcx), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x29903
movl $0x1, -0x74(%rbp)
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0x29969
cmpl $0x0, -0x2c(%rbp)
jl 0x29938
movq -0x28(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0x1c(%rcx), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
cmpq %rcx, %rax
jb 0x29938
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
subl -0x2c(%rbp), %eax
cltq
movq %rax, -0x70(%rbp)
jmp 0x29967
cmpl $0x0, -0x2c(%rbp)
jge 0x2995d
xorl %eax, %eax
subl -0x2c(%rbp), %eax
cltq
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
cmpq -0x28(%rbp), %rax
jbe 0x2995b
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x29965
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x29967
jmp 0x29969
cmpl $0x0, -0x74(%rbp)
je 0x29981
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x28540
jmp 0x29aa4
jmp 0x29983
cmpq $0x0, -0x60(%rbp)
je 0x299bb
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x10, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x299bb
movq -0x60(%rbp), %rdi
callq 0x27a80
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0xffefffff, %ecx       # imm = 0xFFEFFFFF
orl $0x100000, %ecx         # imm = 0x100000
movl %ecx, 0x1c(%rax)
jmp 0x299bd
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x2c(%rbp), %esi
movq -0x70(%rbp), %rax
movl %eax, %edx
callq 0x415d0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x41a50
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x70(%rbp), %rdx
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
subq %rdx, %rcx
movl %ecx, %edx
movl 0x1c(%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, 0x1c(%rax)
movq -0x70(%rbp), %rdx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x10(%rax)
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cmpl $0x0, %eax
jne 0x29a59
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x28540
movq $0x0, -0x60(%rbp)
jmp 0x29a5b
cmpq $0x0, -0x60(%rbp)
je 0x29aa2
jmp 0x29a64
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x14, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x29a9e
jmp 0x29a78
cmpq $0x0, -0x60(%rbp)
je 0x29a9a
movq -0x60(%rbp), %rax
movl 0x1c(%rax), %eax
shrl $0x10, %eax
andl $0x3, %eax
cmpl $0x1, %eax
jne 0x29a9a
movq -0x60(%rbp), %rdi
callq 0x27980
jmp 0x29a9c
jmp 0x29a9e
jmp 0x29aa0
jmp 0x29aa2
jmp 0x29aa4
movq -0x70(%rbp), %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x2c(%rbp)
jmp 0x298ac
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)