// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/ziplist.c
// Function: _ziplistCascadeUpdate
unsigned char *__ziplistCascadeUpdate(unsigned char *zl, unsigned char *p) {
    size_t curlen = intrev32ifbe(ZIPLIST_BYTES(zl)), rawlen, rawlensize;
    size_t offset, noffset, extra;
    unsigned char *np;
    zlentry cur, next;

    while (p[0] != ZIP_END) {
        zipEntry(p, &cur);
        rawlen = cur.headersize + cur.len;
        rawlensize = zipPrevEncodeLength(NULL,rawlen);

        /* Abort if there is no next entry. */
        if (p[rawlen] == ZIP_END) break;
        zipEntry(p+rawlen, &next);

        /* Abort when "prevlen" has not changed. */
        if (next.prevrawlen == rawlen) break;

        if (next.prevrawlensize < rawlensize) {
            /* The "prevlen" field of "next" needs more bytes to hold
             * the raw length of "cur". */
            offset = p-zl;
            extra = rawlensize-next.prevrawlensize;
            zl = ziplistResize(zl,curlen+extra);
            p = zl+offset;

            /* Current pointer and offset for next element. */
            np = p+rawlen;
            noffset = np-zl;

            /* Update tail offset when next element is not the tail element. */
            if ((zl+intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))) != np) {
                ZIPLIST_TAIL_OFFSET(zl) =
                    intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+extra);
            }

            /* Move the tail to the back. */
            memmove(np+rawlensize,
                np+next.prevrawlensize,
                curlen-noffset-next.prevrawlensize-1);
            zipPrevEncodeLength(np,rawlen);

            /* Advance the cursor */
            p += rawlen;
            curlen += extra;
        } else {
            if (next.prevrawlensize > rawlensize) {
                /* This would result in shrinking, which we want to avoid.
                 * So, set "rawlen" in the available bytes. */
                zipPrevEncodeLengthForceLarge(p+rawlen,rawlen);
            } else {
                zipPrevEncodeLength(p+rawlen,rawlen);
            }

            /* Stop here, as the raw length of "next" has not changed. */
            break;
        }
    }
    return zl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movl (%rdi), %eax
movq %rax, 0x10(%rsp)
movb (%rsi), %r15b
cmpb $-0x1, %r15b
je 0x35561
movq %r14, %rdi
leaq 0x38(%rsp), %rsi
callq 0x3532d
movl 0x44(%rsp), %r15d
addl 0x48(%rsp), %r15d
xorl %ebx, %ebx
cmpl $0xfe, %r15d
setae %bpl
cmpb $-0x1, (%r14,%r15)
je 0x35561
leaq (%r14,%r15), %r13
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x3532d
cmpl %r15d, 0x1c(%rsp)
je 0x35561
movb %bpl, %bl
leal 0x1(,%rbx,4), %ebx
movl 0x18(%rsp), %r12d
cmpl %ebx, %r12d
jae 0x35544
movq 0x8(%rsp), %rdi
subq %rdi, %r14
movq %rbx, %rbp
subq %r12, %rbp
movq 0x10(%rsp), %rax
leaq (%rax,%rbp), %r13
movl %r13d, %esi
callq 0x3542d
addq %r15, %r14
addq %rax, %r14
movl 0x4(%rax), %edx
leaq (%rax,%rdx), %rcx
cmpq %r14, %rcx
je 0x35500
addl %edx, %ebp
movl %ebp, 0x4(%rax)
addq %r14, %rbx
addq %r14, %r12
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rcx
addq %rax, %rcx
movq %r12, %rdx
notq %rdx
addq %rcx, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x267e0
cmpl $0xfd, %r15d
jbe 0x35537
movl %r15d, 0x1(%r14)
movb $-0x2, %r15b
movb %r15b, (%r14)
movq %r13, 0x10(%rsp)
jmp 0x35461
cmpl %ebx, %r12d
ja 0x35558
cmpl $0xfd, %r15d
ja 0x35558
movb %r15b, (%r13)
jmp 0x35561
movb $-0x2, (%r13)
movl %r15d, 0x1(%r13)
movq 0x8(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq