// File: /workspace/github_c_makefile_star2_O1/srned[P]baselib/ziplist.c
// Function: _ziplistCascadeUpdate
static 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) {
        cur = zipEntry(p);
        rawlen = cur.headersize + cur.len;
        rawlensize = zipPrevEncodeLength(NULL,rawlen);

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

        /* 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 $0x38, %rsp
cmpb $-0x1, (%rsi)
movq %rdi, 0x8(%rsp)
je 0xb0f0
movq %rsi, %r14
movl (%rdi), %eax
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0xa4f5
movl 0x28(%rsp), %r15d
addl 0x24(%rsp), %r15d
xorl %ebx, %ebx
cmpl $0xfe, %r15d
setae %r12b
cmpb $-0x1, (%r14,%r15)
je 0xb0f0
leaq (%r14,%r15), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0xa4f5
cmpl %r15d, 0x1c(%rsp)
je 0xb0f0
movb %r12b, %bl
leal 0x1(,%rbx,4), %ebx
movl 0x18(%rsp), %r13d
cmpl %ebx, %r13d
jae 0xb0d4
movq 0x8(%rsp), %rdi
subq %rdi, %r14
movq %rbx, %r12
subq %r13, %r12
movq 0x10(%rsp), %rax
leaq (%r12,%rax), %rbp
movl %ebp, %esi
callq 0xb7d2
movl %ebp, (%rax)
leal -0x1(%rbp), %ecx
movb $-0x1, (%rax,%rcx)
addq %r15, %r14
addq %rax, %r14
movl 0x4(%rax), %edx
leaq (%rax,%rdx), %rcx
cmpq %r14, %rcx
je 0xb081
addl %edx, %r12d
movl %r12d, 0x4(%rax)
addq %r14, %rbx
addq %r14, %r13
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rcx
addq %rax, %rcx
movq %r13, %rdx
notq %rdx
addq %rcx, %rdx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4320
cmpl $0xfd, %r15d
ja 0xb0b6
movb %r15b, (%r14)
jmp 0xb0be
movb $-0x2, (%r14)
movl %r15d, 0x1(%r14)
leaq 0x18(%rsp), %r13
cmpb $-0x1, (%r14)
movq %rbp, 0x10(%rsp)
jne 0xafe2
jmp 0xb0f0
cmpl %ebx, %r13d
ja 0xb0e8
cmpl $0xfd, %r15d
ja 0xb0e8
movb %r15b, (%rbp)
jmp 0xb0f0
movb $-0x2, (%rbp)
movl %r15d, 0x1(%rbp)
movq 0x8(%rsp), %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq