// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/ziplist.c
// Function: _ziplistDelete
unsigned char *__ziplistDelete(unsigned char *zl, unsigned char *p, unsigned int num) {
    unsigned int i, totlen, deleted = 0;
    size_t offset;
    int nextdiff = 0;
    zlentry first, tail;

    zipEntry(p, &first);
    for (i = 0; p[0] != ZIP_END && i < num; i++) {
        p += zipRawEntryLength(p);
        deleted++;
    }

    totlen = p-first.p;
    if (totlen > 0) {
        if (p[0] != ZIP_END) {
            /* Storing `prevrawlen` in this entry may increase or decrease the
             * number of bytes required compare to the current `prevrawlen`.
             * There always is room to store this, because it was previously
             * stored by an entry that is now being deleted. */
            nextdiff = zipPrevLenByteDiff(p,first.prevrawlen);
            p -= nextdiff;
            zipPrevEncodeLength(p,first.prevrawlen);

            /* Update offset for tail */
            ZIPLIST_TAIL_OFFSET(zl) =
                intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))-totlen);

            /* When the tail contains more than one entry, we need to take
             * "nextdiff" in account as well. Otherwise, a change in the
             * size of prevlen doesn't have an effect on the *tail* offset. */
            zipEntry(p, &tail);
            if (p[tail.headersize+tail.len] != ZIP_END) {
                ZIPLIST_TAIL_OFFSET(zl) =
                   intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+nextdiff);
            }

            /* Move tail to the front of the ziplist */
            memmove(first.p,p,
                intrev32ifbe(ZIPLIST_BYTES(zl))-(p-zl)-1);
        } else {
            /* The entire tail was deleted. No need to move memory. */
            ZIPLIST_TAIL_OFFSET(zl) =
                intrev32ifbe((first.p-zl)-first.prevrawlen);
        }

        /* Resize and update length */
        offset = first.p-zl;
        zl = ziplistResize(zl, intrev32ifbe(ZIPLIST_BYTES(zl))-totlen+nextdiff);
        ZIPLIST_INCR_LENGTH(zl,-deleted);
        p = zl+offset;

        /* When nextdiff != 0, the raw length of the next entry has changed, so
         * we need to cascade the update throughout the ziplist */
        if (nextdiff != 0)
            zl = __ziplistCascadeUpdate(zl,p);
    }
    return zl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x3532d
xorl %r12d, %r12d
movb (%r14), %dl
cmpb $-0x1, %dl
je 0x355ba
cmpl %ebp, %r12d
jae 0x355ba
movq %r14, %rdi
callq 0x35133
movl %eax, %eax
addq %rax, %r14
incl %r12d
jmp 0x3559b
movq 0x20(%rsp), %r15
movl %r14d, %ebp
subl %r15d, %ebp
je 0x356b1
cmpb $-0x1, %dl
je 0x35657
movl 0xc(%rsp), %eax
xorl %ecx, %ecx
cmpb $-0x2, %dl
setne %cl
negl %ecx
orl $-0x5, %ecx
xorl %edx, %edx
cmpl $0xfe, %eax
setae %dl
leal (%rcx,%rdx,4), %esi
notl %esi
movslq %esi, %rsi
addq %rsi, %r14
cmpl $0xfd, %eax
jbe 0x35607
movl %eax, 0x1(%r14)
movb $-0x2, %al
leal (%rcx,%rdx,4), %r13d
incl %r13d
movb %al, (%r14)
subl %ebp, 0x4(%rbx)
leaq 0x28(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3532d
movl 0xc(%r15), %eax
addl 0x10(%r15), %eax
cmpb $-0x1, (%r14,%rax)
je 0x35637
addl %r13d, 0x4(%rbx)
movq 0x20(%rsp), %r15
movl (%rbx), %edx
movq %r14, %rax
notq %rax
addq %rbx, %rdx
addq %rax, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x267e0
jmp 0x35668
movl 0xc(%rsp), %eax
addl %ebx, %eax
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0x4(%rbx)
xorl %r13d, %r13d
movl %r13d, %esi
subl %ebp, %esi
addl (%rbx), %esi
movq %rbx, %rdi
callq 0x3542d
movzwl 0x8(%rax), %ecx
cmpl $0xffff, %ecx           # imm = 0xFFFF
je 0x3568a
subl %r12d, %ecx
movw %cx, 0x8(%rax)
testl %r13d, %r13d
je 0x356ae
subq %rbx, %r15
movq %rax, %rsi
addq %r15, %rsi
movq %rax, %rdi
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x35441
movq %rax, %rbx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq