// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movl %ecx, %eax
movq %rdx, %rbx
movq %rsi, %r15
movl (%rdi), %r12d
movb $0x0, 0xb(%rsp)
movq $0x75bcd15, 0x58(%rsp)  # imm = 0x75BCD15
cmpb $-0x1, (%rsi)
movl %ecx, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
je 0xa0c7
leaq 0x38(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0xa4f5
movl 0xc(%rsp), %eax
movl 0x4(%r13), %r14d
jmp 0xa0e7
movq %rdi, %rcx
movl 0x4(%rdi), %edi
cmpb $-0x1, (%rcx,%rdi)
je 0xa0e4
addq %rcx, %rdi
callq 0xa617
movl %eax, %r14d
movl 0xc(%rsp), %eax
jmp 0xa0e7
xorl %r14d, %r14d
leaq 0x58(%rsp), %rdx
leaq 0xb(%rsp), %rcx
movq %rbx, %rdi
movl %eax, %esi
movl %eax, %ebp
callq 0xab30
movl %ebp, %ecx
testl %eax, %eax
je 0xa157
movzbl 0xb(%rsp), %eax
cmpl $0xdf, %eax
jle 0xa12b
cmpl $0xe0, %eax
je 0xa140
cmpl $0xf0, %eax
je 0xa147
movl $0x1, %ecx
cmpl $0xfe, %eax
je 0xa157
jmp 0xa155
cmpl $0xc0, %eax
je 0xa14e
cmpl $0xd0, %eax
jne 0xa155
movl $0x4, %ecx
jmp 0xa157
movl $0x8, %ecx
jmp 0xa157
movl $0x3, %ecx
jmp 0xa157
movl $0x2, %ecx
jmp 0xa157
xorl %ecx, %ecx
movq %rbx, 0x30(%rsp)
movl %ecx, %eax
xorl %ecx, %ecx
movl %r14d, 0x1c(%rsp)
cmpl $0xfe, %r14d
setae %cl
movzbl 0xb(%rsp), %edi
xorl %edx, %edx
movl 0xc(%rsp), %esi
cmpl $0x4000, %esi           # imm = 0x4000
setae %dl
movq %rdi, 0x28(%rsp)
cmpl $0xc0, %edi
leaq 0x2(%rdx,%rdx,2), %rbx
movl $0x1, %edx
cmovaeq %rdx, %rbx
leal 0x1(,%rcx,4), %ecx
cmpl $0x40, %esi
cmovbq %rdx, %rbx
movq %rcx, 0x20(%rsp)
addq %rcx, %rax
addq %rax, %rbx
movq %r15, %r14
movb (%r15), %al
cmpb $-0x1, %al
je 0xa1df
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 0xa1e2
xorl %r15d, %r15d
movq 0x10(%rsp), %rdi
subq %rdi, %r14
leal (%r12,%rbx), %ebp
leal (%r15,%rbp), %r13d
movq %r13, %rsi
callq 0xb7d2
movl %r13d, (%rax)
leal (%r15,%rbp), %ecx
decl %ecx
movb $-0x1, (%rax,%rcx)
leaq (%rax,%r14), %r13
cmpb $-0x1, (%rax,%r14)
movq %r14, 0x60(%rsp)
je 0xa24a
movq %rax, 0x10(%rsp)
movslq %r15d, %rax
leaq (%rbx,%r13), %rbp
movq %r13, %rsi
subq %rax, %rsi
notq %r14
addq %rax, %r14
addq %r14, %r12
movq %rbp, %rdi
movq %r12, %rdx
callq 0x4320
cmpl $0xfd, %ebx
ja 0xa253
movb %bl, (%rbp)
jmp 0xa25a
movl %r14d, 0x4(%rax)
movq %rax, %r12
jmp 0xa28a
movb $-0x2, (%rbp)
movl %ebx, 0x1(%rbp)
movq 0x10(%rsp), %r12
addl %ebx, 0x4(%r12)
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0xa4f5
movl 0xc(%r14), %eax
movl 0x10(%r14), %ecx
addq %rbp, %rcx
cmpb $-0x1, (%rax,%rcx)
je 0xa28a
addl %r15d, 0x4(%r12)
testl %r15d, %r15d
movl 0x1c(%rsp), %ebp
je 0xa2ac
addq %rbx, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0xafb7
movq %rax, %r12
movq 0x60(%rsp), %r13
addq %rax, %r13
movq 0x30(%rsp), %rbx
movq 0x28(%rsp), %r15
movq 0x20(%rsp), %rax
testq %r13, %r13
je 0xa2e1
cmpl $0xfd, %ebp
ja 0xa2d3
movb %bpl, (%r13)
movl $0x1, %eax
jmp 0xa2e1
movb $-0x2, (%r13)
movl %ebp, 0x1(%r13)
movl $0x5, %eax
movl %eax, %eax
addq %rax, %r13
cmpb $-0x41, %r15b
jbe 0xa2f3
movb %r15b, 0x38(%rsp)
jmp 0xa304
movl 0xc(%rsp), %ecx
cmpl $0x3f, %ecx
ja 0xa397
movb %cl, 0x38(%rsp)
movl $0x1, %r14d
leaq 0x38(%rsp), %rsi
movq %r13, %rdi
movq %r14, %rdx
callq 0x4240
addq %r14, %r13
cmpb $-0x41, %r15b
jbe 0xa362
movq 0x58(%rsp), %rax
cmpl $0xdf, %r15d
jle 0xa3b9
cmpl $0xe0, %r15d
je 0xa3fb
cmpl $0xf0, %r15d
je 0xa404
cmpl $0xfe, %r15d
jne 0xa41f
movb %al, (%r13)
jmp 0xa371
movl 0xc(%rsp), %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4240
movzwl 0x8(%r12), %eax
cmpw $-0x1, %ax
je 0xa385
incl %eax
movw %ax, 0x8(%r12)
movq %r12, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x3fff, %ecx           # imm = 0x3FFF
ja 0xa3d1
movl %ecx, %eax
shrl $0x8, %eax
orb $0x40, %al
movb %al, 0x38(%rsp)
movb %cl, 0x39(%rsp)
movl $0x2, %r14d
jmp 0xa30a
cmpl $0xc0, %r15d
je 0xa415
cmpl $0xd0, %r15d
jne 0xa41f
movl %eax, (%r13)
jmp 0xa371
movb $-0x80, 0x38(%rsp)
movl %ecx, %eax
shrl $0x18, %eax
movb %al, 0x39(%rsp)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x3a(%rsp)
movb %ch, 0x3b(%rsp)
movb %cl, 0x3c(%rsp)
movl $0x5, %r14d
jmp 0xa30a
movq %rax, (%r13)
jmp 0xa371
movw %ax, (%r13)
shrl $0x10, %eax
movb %al, 0x2(%r13)
jmp 0xa371
movw %ax, (%r13)
jmp 0xa371
leal 0xf(%r15), %eax
cmpb $0xe, %al
jb 0xa371
leaq 0x26cd(%rip), %rdi      # 0xcaff
leaq 0x267f(%rip), %rsi      # 0xcab8
leaq 0x27bf(%rip), %rcx      # 0xcbff
movl $0x154, %edx            # imm = 0x154
callq 0x4190