// File: /workspace/github_c_makefile_star2_O3/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 $0x68, %rsp
cmpb $-0x1, (%rsi)
movq %rdi, 0x10(%rsp)
je 0x3b038
movq %rsi, %r14
movl (%rdi), %r13d
leaq 0x28(%rsp), %r12
movq %rsi, %rdi
movq %r12, %rsi
callq 0x3ad62
movl 0xc(%r12), %r15d
addl 0x10(%r12), %r15d
cmpb $-0x1, (%r14,%r15)
je 0x3b038
leaq (%r14,%r15), %r12
xorl %eax, %eax
cmpl $0xfe, %r15d
setb %bl
setae %al
leal 0x1(,%rax,4), %ebp
movq %r12, %rdi
leaq 0x48(%rsp), %rsi
callq 0x3ad62
cmpl %r15d, 0x4c(%rsp)
je 0x3b038
movq %r12, %rax
movb %bl, 0xf(%rsp)
movl %ebp, %ebx
movl 0x48(%rsp), %r12d
cmpl %ebx, %r12d
jae 0x3b020
movq 0x10(%rsp), %rdi
subq %rdi, %r14
addq %r15, %r14
movq %rbx, %rbp
subq %r12, %rbp
movq %r13, 0x18(%rsp)
addq %rbp, %r13
movl %r13d, %esi
callq 0x3837d
movl %r13d, (%rax)
movq %r13, 0x20(%rsp)
leal -0x1(%r13), %ecx
movb $-0x1, (%rax,%rcx)
addq %rax, %r14
movl 0x4(%rax), %edx
leaq (%rax,%rdx), %rcx
cmpq %r14, %rcx
je 0x3afa5
addl %edx, %ebp
movl %ebp, 0x4(%rax)
addq %r14, %rbx
addq %r14, %r12
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rcx
addq %rax, %rcx
movq %r12, %rdx
notq %rdx
addq %rcx, %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x267e0
testb $0x1, 0xf(%rsp)
jne 0x3afda
movl %r15d, 0x1(%r14)
movb $-0x2, %r15b
movb %r15b, (%r14)
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
callq 0x3ad62
movl 0x34(%rsp), %r15d
addl 0x38(%rsp), %r15d
xorl %eax, %eax
cmpl $0xfe, %r15d
setb %bl
setae %al
leal 0x1(,%rax,4), %ebp
leaq (%r14,%r15), %r12
cmpb $-0x1, (%r14,%r15)
movq 0x20(%rsp), %r13
jne 0x3af31
jmp 0x3b038
cmpl %ebx, %r12d
ja 0x3b031
testb $0x1, 0xf(%rsp)
je 0x3b031
movb %r15b, (%rax)
jmp 0x3b038
movb $-0x2, (%rax)
movl %r15d, 0x1(%rax)
movq 0x10(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq