// File: /workspace/github_c_makefile_star2_O3/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 0x3ad62
movb (%r14), %al
cmpb $-0x1, %al
setne %cl
sete %dl
testl %ebp, %ebp
sete %sil
xorl %r12d, %r12d
orb %dl, %sil
jne 0x3b0ab
movq %r14, %r15
movq %r14, %rdi
callq 0x3aaf1
movl %eax, %eax
addq %rax, %r14
incl %r12d
movb (%r15,%rax), %al
cmpb $-0x1, %al
setne %cl
je 0x3b0ab
cmpl %ebp, %r12d
jb 0x3b088
movq 0x20(%rsp), %r15
movl %r14d, %ebp
subl %r15d, %ebp
je 0x3b1b4
testb %cl, %cl
je 0x3b148
movl 0xc(%rsp), %ecx
xorl %edx, %edx
cmpb $-0x2, %al
setne %dl
negl %edx
orl $-0x5, %edx
xorl %eax, %eax
cmpl $0xfe, %ecx
setae %al
leal (%rdx,%rax,4), %esi
notl %esi
movslq %esi, %rsi
addq %rsi, %r14
cmpl $0xfd, %ecx
jbe 0x3b0f8
movl %ecx, 0x1(%r14)
movb $-0x2, %cl
leal (%rdx,%rax,4), %r13d
incl %r13d
movb %cl, (%r14)
subl %ebp, 0x4(%rbx)
leaq 0x28(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x3ad62
movl 0xc(%r15), %eax
addl 0x10(%r15), %eax
cmpb $-0x1, (%r14,%rax)
je 0x3b128
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 0x3b159
movl 0xc(%rsp), %eax
addl %ebx, %eax
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0x4(%rbx)
xorl %r13d, %r13d
movq %rbx, %rdi
movl (%rbx), %ebx
subl %ebp, %ebx
leal (%rbx,%r13), %r14d
movq %rdi, %rbp
movq %r14, %rsi
callq 0x3837d
movl %r14d, (%rax)
leal (%rbx,%r13), %ecx
decl %ecx
movb $-0x1, (%rax,%rcx)
movzwl 0x8(%rax), %ecx
cmpw $-0x1, %cx
je 0x3b18d
subl %r12d, %ecx
movw %cx, 0x8(%rax)
testl %r13d, %r13d
je 0x3b1b1
subq %rbp, %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 0x3aed0
movq %rax, %rbx
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq