// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
movl $0x0, -0x44(%rbp)
movb $0x0, -0x45(%rbp)
movq $0x75bcd15, -0x50(%rbp) # imm = 0x75BCD15
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0xe742
movq -0x10(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0xebb0
movq -0xb0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movl -0x6c(%rbp), %eax
movq %rax, -0x38(%rbp)
jmp 0xe77c
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0xe77a
movq -0xb8(%rbp), %rdi
callq 0xeda0
movl %eax, %eax
movq %rax, -0x38(%rbp)
jmp 0xe77c
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x50(%rbp), %rdx
leaq -0x45(%rbp), %rcx
callq 0xf700
cmpl $0x0, %eax
je 0xe7a6
movzbl -0x45(%rbp), %edi
callq 0xfab0
movl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0xe7ad
movl -0x1c(%rbp), %eax
movq %rax, -0x30(%rbp)
movq -0x38(%rbp), %rax
movl %eax, %esi
xorl %eax, %eax
movl %eax, %edi
callq 0xfdb0
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movb -0x45(%rbp), %al
movl -0x1c(%rbp), %edx
xorl %ecx, %ecx
movl %ecx, %edi
movzbl %al, %esi
callq 0xfe20
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0xe807
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0xff50
movl %eax, -0xdc(%rbp)
jmp 0xe811
xorl %eax, %eax
movl %eax, -0xdc(%rbp)
jmp 0xe811
movl -0xdc(%rbp), %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x28(%rbp), %rax
addq -0x30(%rbp), %rax
movslq -0x44(%rbp), %rcx
addq %rcx, %rax
movl %eax, %esi
callq 0xffa0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0xe937
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq -0x44(%rbp), %rcx
xorl %eax, %eax
subq %rcx, %rax
addq %rax, %rsi
movq -0x28(%rbp), %rdx
subq -0x40(%rbp), %rdx
subq $0x1, %rdx
movslq -0x44(%rbp), %rax
addq %rax, %rdx
callq 0x4320
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0xfdb0
movq -0x8(%rbp), %rax
movl 0x4(%rax), %eax
addq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xebb0
movq -0xd8(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x80(%rbp), %edx
addq %rdx, %rcx
movl -0x84(%rbp), %edx
addq %rdx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
je 0xe935
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
addl -0x44(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0xe94b
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
cmpl $0x0, -0x44(%rbp)
je 0xe981
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
addq -0x30(%rbp), %rsi
callq 0xfff0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movl %eax, %esi
callq 0xfdb0
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movb -0x45(%rbp), %al
movl -0x1c(%rbp), %edx
movzbl %al, %esi
callq 0xfe20
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movzbl -0x45(%rbp), %eax
andl $0xc0, %eax
cmpl $0xc0, %eax
jge 0xe9e4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x4240
jmp 0xe9f5
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movzbl -0x45(%rbp), %edx
callq 0x10220
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jge 0xea1a
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
addl $0x1, %eax
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x8(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopw (%rax,%rax)