// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, %r12
movl (%rdi), %r13d
movb $0x0, 0x7(%rsp)
movq $0x75bcd15, 0x28(%rsp)  # imm = 0x75BCD15
cmpb $-0x1, (%rsi)
je 0xa0f1
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
callq 0xa55f
movl 0x4(%r15), %eax
jmp 0xa109
movl 0x4(%r12), %edi
cmpb $-0x1, (%r12,%rdi)
je 0xa1d2
addq %r12, %rdi
callq 0xa690
movl %eax, 0x8(%rsp)
leaq 0x28(%rsp), %rdx
leaq 0x7(%rsp), %r15
movq %r14, %rdi
movl %ebx, %esi
movq %r15, %rcx
callq 0xabb2
movb (%r15), %dl
movzbl %dl, %esi
testl %eax, %eax
movl %ebx, 0xc(%rsp)
je 0xa167
xorl %eax, %eax
cmpl $0xdf, %esi
jle 0xa1bb
cmpl $0xe0, %esi
je 0xa1df
cmpl $0xf0, %esi
je 0xa1e6
movl $0x1, %ecx
cmpl $0xfe, %esi
je 0xa1f2
jmp 0xa169
movl %ebx, %eax
xorl %ecx, %ecx
cmpl $0xfe, 0x8(%rsp)
setb 0x5(%rsp)
setae %cl
leal 0x1(,%rcx,4), %ecx
movq %rcx, 0x18(%rsp)
leaq (%rcx,%rax), %rbx
movl $0x1, %eax
movb $0x1, %cl
cmpb $-0x41, %dl
ja 0xa21b
movl 0xc(%rsp), %ecx
cmpl $0x40, %ecx
jb 0xa1b7
xorl %eax, %eax
cmpl $0x4000, %ecx           # imm = 0x4000
setae %al
leaq (%rax,%rax,2), %rax
addq $0x2, %rax
xorl %ecx, %ecx
jmp 0xa21b
cmpl $0xc0, %esi
je 0xa1ed
cmpl $0xd0, %esi
jne 0xa169
movl $0x4, %ecx
jmp 0xa1f2
movl $0x0, 0x8(%rsp)
jmp 0xa10d
movl $0x8, %ecx
jmp 0xa1f2
movl $0x3, %ecx
jmp 0xa1f2
movl $0x2, %ecx
xorl %eax, %eax
cmpl $0xfe, 0x8(%rsp)
setb 0x5(%rsp)
setae %al
leal 0x1(,%rax,4), %eax
movq %rax, 0x18(%rsp)
leaq (%rax,%rcx), %rbx
movl $0x1, %eax
movb $0x1, %cl
movl %ecx, 0x10(%rsp)
movq %r14, 0x50(%rsp)
addq %rax, %rbx
movb (%rbp), %al
cmpb $-0x1, %al
movb %dl, 0x6(%rsp)
movl %esi, 0x14(%rsp)
je 0xa256
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), %r14d
incl %r14d
jmp 0xa259
xorl %r14d, %r14d
subq %r12, %rbp
movq %rbp, 0x20(%rsp)
leal (%rbx,%r13), %ebp
leal (%r14,%rbp), %r15d
movq %r12, %rdi
movq %r15, %rsi
callq 0xb82e
movq %rax, %r12
movl %r15d, (%rax)
leal (%r14,%rbp), %eax
decl %eax
movq 0x20(%rsp), %rbp
movb $-0x1, (%r12,%rax)
leaq (%r12,%rbp), %r15
cmpb $-0x1, (%r12,%rbp)
je 0xa2c5
movslq %r14d, %rax
movq %rbp, %rcx
leaq (%r15,%rbx), %rbp
movq %r15, %rsi
subq %rax, %rsi
notq %rcx
addq %rax, %rcx
addq %rcx, %r13
movq %rbp, %rdi
movq %r13, %rdx
callq 0x4320
cmpl $0xfd, %ebx
ja 0xa2cc
movl %ebx, %eax
jmp 0xa2d1
movl %ebp, 0x4(%r12)
jmp 0xa304
movl %ebx, 0x1(%rbp)
movb $-0x2, %al
movb %al, (%rbp)
addl %ebx, 0x4(%r12)
leaq 0x30(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
callq 0xa55f
movl 0xc(%r13), %eax
movl 0x10(%r13), %ecx
addq %rbp, %rcx
cmpb $-0x1, (%rax,%rcx)
movq 0x20(%rsp), %rbp
je 0xa304
addl %r14d, 0x4(%r12)
testl %r14d, %r14d
je 0xa325
addq %rbx, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xaff6
testq %rax, %rax
je 0xa355
movq %rax, %r12
addq %rax, %rbp
movq %rbp, %r15
movl 0xc(%rsp), %ebx
movl 0x10(%rsp), %ecx
cmpb $0x0, 0x5(%rsp)
je 0xa342
movl 0x8(%rsp), %eax
movb %al, (%r15)
movl $0x1, %eax
jmp 0xa368
movb $-0x2, (%r15)
movl 0x8(%rsp), %eax
movl %eax, 0x1(%r15)
movl $0x5, %eax
jmp 0xa368
xorl %r12d, %r12d
xorl %r15d, %r15d
movl 0xc(%rsp), %ebx
movl 0x10(%rsp), %ecx
movq 0x18(%rsp), %rax
movl %eax, %r14d
addq %r15, %r14
testb %cl, %cl
je 0xa3b7
movb 0x6(%rsp), %cl
movb %cl, (%r14)
movq 0x28(%rsp), %rax
movl 0x14(%rsp), %edx
cmpl $0xdf, %edx
jle 0xa3e7
cmpl $0xe0, %edx
je 0xa472
cmpl $0xf0, %edx
je 0xa478
cmpl $0xfe, %edx
jne 0xa48d
movb %al, 0x1(%r14)
jmp 0xa44c
cmpl $0x3f, %ebx
ja 0xa3c8
movb %bl, 0x30(%rsp)
movl $0x1, %r15d
jmp 0xa42a
cmpl $0x3fff, %ebx           # imm = 0x3FFF
ja 0xa405
movl %ebx, %eax
shrl $0x8, %eax
orb $0x40, %al
movb %al, 0x30(%rsp)
movb %bl, 0x31(%rsp)
movl $0x2, %r15d
jmp 0xa42a
cmpl $0xc0, %edx
je 0xa486
cmpl $0xd0, %edx
jne 0xa48d
movl %eax, 0x1(%r14)
jmp 0xa44c
movb $-0x80, 0x30(%rsp)
movl %ebx, %eax
shrl $0x18, %eax
movb %al, 0x31(%rsp)
movl %ebx, %eax
shrl $0x10, %eax
movb %al, 0x32(%rsp)
movb %bh, 0x33(%rsp)
movb %bl, 0x34(%rsp)
movl $0x5, %r15d
leaq 0x30(%rsp), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x4240
addq %r15, %r14
movl %ebx, %edx
movq %r14, %rdi
movq 0x50(%rsp), %rsi
callq 0x4240
movzwl 0x8(%r12), %eax
cmpw $-0x1, %ax
je 0xa460
incl %eax
movw %ax, 0x8(%r12)
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x1(%r14)
jmp 0xa44c
movw %ax, 0x1(%r14)
shrl $0x10, %eax
movb %al, 0x3(%r14)
jmp 0xa44c
movw %ax, 0x1(%r14)
jmp 0xa44c
addb $0xf, %cl
cmpb $0xe, %cl
jb 0xa44c
leaq 0x26c4(%rip), %rdi      # 0xcb60
leaq 0x2676(%rip), %rsi      # 0xcb19
leaq 0x27b6(%rip), %rcx      # 0xcc60
movl $0x154, %edx            # imm = 0x154
callq 0x4190