// File: /workspace/github_c_makefile_star2_O2/srned[P]baselib/ziplist.c
// Function: _ziplistInsert
static unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) {
    size_t curlen = intrev32ifbe(ZIPLIST_BYTES(zl)), reqlen, prevlen = 0;
    size_t offset;
    int nextdiff = 0;
    unsigned char encoding = 0;
    long long value = 123456789; /* initialized to avoid warning. Using a value
                                    that is easy to see if for some reason
                                    we use it uninitialized. */
    zlentry entry, tail;

    /* Find out prevlen for the entry that is inserted. */
    if (p[0] != ZIP_END) {
        entry = zipEntry(p);
        prevlen = entry.prevrawlen;
    } else {
        unsigned char *ptail = ZIPLIST_ENTRY_TAIL(zl);
        if (ptail[0] != ZIP_END) {
            prevlen = zipRawEntryLength(ptail);
        }
    }

    /* See if the entry can be encoded */
    if (zipTryEncoding(s,slen,&value,&encoding)) {
        /* 'encoding' is set to the appropriate integer encoding */
        reqlen = zipIntSize(encoding);
    } else {
        /* 'encoding' is untouched, however zipEncodeLength will use the
         * string length to figure out how to encode it. */
        reqlen = slen;
    }
    /* We need space for both the length of the previous entry and
     * the length of the payload. */
    reqlen += zipPrevEncodeLength(NULL,prevlen);
    reqlen += zipEncodeLength(NULL,encoding,slen);

    /* When the insert position is not equal to the tail, we need to
     * make sure that the next entry can hold this entry's length in
     * its prevlen field. */
    nextdiff = (p[0] != ZIP_END) ? zipPrevLenByteDiff(p,reqlen) : 0;

    /* Store offset because a realloc may change the address of zl. */
    offset = p-zl;
    zl = ziplistResize(zl,curlen+reqlen+nextdiff);
    p = zl+offset;

    /* Apply memory move when necessary and update tail offset. */
    if (p[0] != ZIP_END) {
        /* Subtract one because of the ZIP_END bytes */
        memmove(p+reqlen,p-nextdiff,curlen-offset-1+nextdiff);

        /* Encode this entry's raw length in the next entry. */
        zipPrevEncodeLength(p+reqlen,reqlen);

        /* Update offset for tail */
        ZIPLIST_TAIL_OFFSET(zl) =
            intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+reqlen);

        /* 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. */
        tail = zipEntry(p+reqlen);
        if (p[reqlen+tail.headersize+tail.len] != ZIP_END) {
            ZIPLIST_TAIL_OFFSET(zl) =
                intrev32ifbe(intrev32ifbe(ZIPLIST_TAIL_OFFSET(zl))+nextdiff);
        }
    } else {
        /* This element will be the new tail. */
        ZIPLIST_TAIL_OFFSET(zl) = intrev32ifbe(p-zl);
    }

    /* 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) {
        offset = p-zl;
        zl = __ziplistCascadeUpdate(zl,p+reqlen);
        p = zl+offset;
    }

    /* Write the entry */
    p += zipPrevEncodeLength(p,prevlen);
    p += zipEncodeLength(p,encoding,slen);
    if (ZIP_IS_STR(encoding)) {
        memcpy(p,s,slen);
    } else {
        zipSaveInteger(p,value,encoding);
    }
    ZIPLIST_INCR_LENGTH(zl,1);
    return zl;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x14(%rsp)
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r12
movl (%rdi), %ebp
movb $0x0, 0xb(%rsp)
movq $0x75bcd15, 0x48(%rsp)  # imm = 0x75BCD15
cmpb $-0x1, (%rsi)
je 0x9673
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x9a2a
movl 0x4(%r14), %eax
jmp 0x968b
movl 0x4(%r12), %edi
cmpb $-0x1, (%r12,%rdi)
je 0x98c7
addq %r12, %rdi
callq 0x9b05
movl %eax, 0xc(%rsp)
leaq 0x48(%rsp), %rdx
leaq 0xb(%rsp), %r14
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %ebx
movl %ebx, %esi
movq %r14, %rcx
callq 0x9f7e
movl %eax, %ecx
movb (%r14), %r14b
movzbl %r14b, %r15d
movl %ebx, %eax
testl %ecx, %ecx
je 0x96c6
movl %r15d, %edi
callq 0xa1b1
movl %r15d, 0x10(%rsp)
movl %eax, %eax
xorl %ecx, %ecx
cmpl $0xfe, 0xc(%rsp)
setae %cl
xorl %edx, %edx
cmpl $0x4000, %ebx           # imm = 0x4000
setae %dl
movb %r14b, 0xa(%rsp)
cmpb $-0x40, %r14b
movl %ebx, %esi
leaq 0x2(%rdx,%rdx,2), %rbx
pushq $0x1
popq %rdx
cmovaeq %rdx, %rbx
leal 0x1(,%rcx,4), %ecx
cmpl $0x40, %esi
cmovbq %rdx, %rbx
movq %rcx, 0x50(%rsp)
addq %rcx, %rax
addq %rax, %rbx
movb (%r13), %al
cmpb $-0x1, %al
je 0x973d
xorl %ecx, %ecx
cmpb $-0x2, %al
setne %cl
negl %ecx
orl $-0x5, %ecx
xorl %eax, %eax
cmpl $0xfe, %ebx
setae %al
leal (%rcx,%rax,4), %r15d
incl %r15d
jmp 0x9740
xorl %r15d, %r15d
subq %r12, %r13
leal (%r15,%rbp), %esi
addl %ebx, %esi
movq %r12, %rdi
callq 0xa38d
leaq (%rax,%r13), %r12
cmpb $-0x1, (%rax,%r13)
je 0x9791
movq %rax, 0x18(%rsp)
movslq %r15d, %rax
leaq (%r12,%rbx), %r14
movq %r12, %rsi
subq %rax, %rsi
movq %r13, %rcx
notq %rcx
addq %rax, %rcx
addq %rcx, %rbp
movq %r14, %rdi
movq %rbp, %rdx
callq 0x4320
cmpl $0xfd, %ebx
ja 0x979a
movl %ebx, %eax
jmp 0x97a0
movl %r13d, 0x4(%rax)
movq %rax, %rbp
jmp 0x97d3
movl %ebx, 0x1(%r14)
movb $-0x2, %al
movq 0x18(%rsp), %rcx
movb %al, (%r14)
addl %ebx, 0x4(%rcx)
leaq 0x28(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x9a2a
movl 0xc(%rbp), %eax
movl 0x10(%rbp), %ecx
movq 0x18(%rsp), %rbp
addq %r14, %rcx
cmpb $-0x1, (%rax,%rcx)
je 0x97d3
addl %r15d, 0x4(%rbp)
testl %r15d, %r15d
je 0x9803
addq %rbx, %r12
movq %rbp, %rdi
movq %r12, %rsi
callq 0xa3a1
testq %rax, %rax
movb 0xa(%rsp), %cl
movl 0x10(%rsp), %edx
je 0x9832
movq %rax, %rbp
addq %rax, %r13
movq %r13, %r12
movq 0x20(%rsp), %r14
jmp 0x9810
movq 0x20(%rsp), %r14
movb 0xa(%rsp), %cl
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %eax
cmpl $0xfd, %eax
ja 0x9823
movb %al, (%r12)
pushq $0x1
jmp 0x982f
movb $-0x2, (%r12)
movl %eax, 0x1(%r12)
pushq $0x5
popq %rax
jmp 0x9841
xorl %ebp, %ebp
xorl %r12d, %r12d
movq 0x20(%rsp), %r14
movq 0x50(%rsp), %rax
movl %eax, %r13d
addq %r12, %r13
cmpb $-0x41, %cl
jbe 0x989b
movb %cl, 0x28(%rsp)
movb %cl, (%r13)
movq 0x48(%rsp), %rax
cmpl $0xc0, %edx
je 0x997a
cmpl $0xd0, %edx
je 0x9939
cmpl $0xe0, %edx
je 0x994d
cmpl $0xf0, %edx
je 0x993f
cmpl $0xfe, %edx
jne 0x9953
movb %al, 0x1(%r13)
jmp 0x9917
movl 0x14(%rsp), %ebx
cmpl $0x3f, %ebx
ja 0x98ac
movb %bl, 0x28(%rsp)
pushq $0x1
jmp 0x98f5
cmpl $0x3fff, %ebx           # imm = 0x3FFF
ja 0x98d4
movl %ebx, %eax
shrl $0x8, %eax
orb $0x40, %al
movb %al, 0x28(%rsp)
movb %bl, 0x29(%rsp)
pushq $0x2
jmp 0x98f5
movl $0x0, 0xc(%rsp)
jmp 0x968f
movb $-0x80, 0x28(%rsp)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, 0x29(%rsp)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x2a(%rsp)
movb %bh, 0x2b(%rsp)
movb %bl, 0x2c(%rsp)
pushq $0x5
popq %r15
leaq 0x28(%rsp), %rsi
movq %r13, %rdi
movq %r15, %rdx
callq 0x4240
addq %r15, %r13
movl %ebx, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x4240
movzwl 0x8(%rbp), %eax
cmpw $-0x1, %ax
je 0x9927
incl %eax
movw %ax, 0x8(%rbp)
movq %rbp, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, 0x1(%r13)
jmp 0x9917
movw %ax, 0x1(%r13)
shrl $0x10, %eax
movb %al, 0x3(%r13)
jmp 0x9917
movq %rax, 0x1(%r13)
jmp 0x9917
addb $0xf, %cl
cmpb $0xe, %cl
jb 0x9917
leaq 0x21be(%rip), %rdi      # 0xbb20
leaq 0x2170(%rip), %rsi      # 0xbad9
leaq 0x22b0(%rip), %rcx      # 0xbc20
movl $0x154, %edx            # imm = 0x154
callq 0x4190
movw %ax, 0x1(%r13)
jmp 0x9917