// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/ziplist.c
// Function: _ziplistInsert
unsigned char *__ziplistInsert(unsigned char *zl, unsigned char *p, unsigned char *s, unsigned int slen) {
    size_t curlen = intrev32ifbe(ZIPLIST_BYTES(zl)), reqlen;
    unsigned int prevlensize, 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 tail;

    /* Find out prevlen for the entry that is inserted. */
    if (p[0] != ZIP_END) {
        ZIP_DECODE_PREVLEN(p, prevlensize, prevlen);
    } 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. */
    int forcelarge = 0;
    nextdiff = (p[0] != ZIP_END) ? zipPrevLenByteDiff(p,reqlen) : 0;
    if (nextdiff == -4 && reqlen < 4) {
        nextdiff = 0;
        forcelarge = 1;
    }

    /* 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. */
        if (forcelarge)
            zipPrevEncodeLengthForceLarge(p+reqlen,reqlen);
        else
            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. */
        zipEntry(p+reqlen, &tail);
        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, %ebp
movq %rdx, %rcx
movq %rsi, %r12
movq %rdi, %rbx
movl (%rdi), %r15d
movb $0x0, 0x3(%rsp)
movq $0x75bcd15, 0x28(%rsp)  # imm = 0x75BCD15
movzbl (%rsi), %r13d
cmpl $0xfe, %r13d
je 0x3b222
cmpl $0xff, %r13d
jne 0x3b22c
movl 0x4(%rbx), %edi
cmpb $-0x1, (%rbx,%rdi)
je 0x3b229
addq %rbx, %rdi
movq %rcx, %r14
callq 0x3aaf1
movq %r14, %rcx
movl %eax, %r13d
jmp 0x3b22c
movl 0x1(%r12), %r13d
jmp 0x3b22c
xorl %r13d, %r13d
leaq 0x28(%rsp), %rdx
leaq 0x3(%rsp), %r14
movq %rcx, 0x30(%rsp)
movq %rcx, %rdi
movl %ebp, %esi
movq %r14, %rcx
callq 0x3abdf
movzbl (%r14), %edx
testl %eax, %eax
movl %ebp, 0x8(%rsp)
je 0x3b288
xorl %eax, %eax
cmpl $0xdf, %edx
jle 0x3b2d8
cmpl $0xe0, %edx
movq %r15, %r14
je 0x3b2f2
cmpl $0xf0, %edx
je 0x3b2f9
movl $0x1, %ecx
cmpl $0xfe, %edx
je 0x3b305
jmp 0x3b28d
movl %ebp, %eax
movq %r15, %r14
xorl %ecx, %ecx
cmpl $0xfe, %r13d
setb 0x2(%rsp)
setae %cl
leal 0x1(,%rcx,4), %ecx
movq %rcx, 0x10(%rsp)
leaq (%rcx,%rax), %rsi
cmpb $-0x40, %dl
setae %al
cmpl $0x40, %ebp
setb %cl
orb %al, %cl
movl $0x1, %eax
jne 0x3b32b
xorl %eax, %eax
cmpl $0x4000, %ebp           # imm = 0x4000
setae %al
leaq (%rax,%rax,2), %rax
addq $0x2, %rax
jmp 0x3b32b
cmpl $0xc0, %edx
movq %r15, %r14
je 0x3b300
cmpl $0xd0, %edx
jne 0x3b28d
movl $0x4, %ecx
jmp 0x3b305
movl $0x8, %ecx
jmp 0x3b305
movl $0x3, %ecx
jmp 0x3b305
movl $0x2, %ecx
xorl %eax, %eax
cmpl $0xfe, %r13d
setb 0x2(%rsp)
setae %al
leal 0x1(,%rax,4), %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%rcx), %rsi
movl $0x1, %eax
movl %r13d, 0x4(%rsp)
movl %edx, 0xc(%rsp)
addq %rax, %rsi
movb (%r12), %cl
xorl %edx, %edx
movl $0x0, %eax
cmpb $-0x1, %cl
je 0x3b364
xorl %eax, %eax
cmpb $-0x2, %cl
setne %al
negl %eax
orl $-0x5, %eax
xorl %ecx, %ecx
cmpl $0xfe, %esi
setae %cl
leal (%rax,%rcx,4), %eax
incl %eax
cmpl $-0x4, %eax
setne %cl
cmpq $0x4, %rsi
setae %r13b
orb %cl, %r13b
cmovnel %eax, %edx
movq %rdx, 0x18(%rsp)
subq %rbx, %r12
movq %r12, 0x20(%rsp)
leal (%r14,%rsi), %r12d
leal (%r12,%rdx), %r15d
movq %rbx, %rdi
movq %rsi, %rbp
movq %r15, %rsi
callq 0x3837d
movq 0x18(%rsp), %rcx
movq %rax, %rbx
movl %r15d, (%rax)
leal (%rcx,%r12), %eax
decl %eax
movq 0x20(%rsp), %r12
movb $-0x1, (%rbx,%rax)
leaq (%rbx,%r12), %r15
cmpb $-0x1, (%rbx,%r12)
je 0x3b3fa
movslq %ecx, %rax
movq %r12, %rcx
leaq (%r15,%rbp), %r12
movq %r15, %rsi
subq %rax, %rsi
notq %rcx
addq %rcx, %r14
addq %rax, %r14
movq %r12, %rdi
movq %r14, %rdx
callq 0x267e0
testb %r13b, %r13b
je 0x3b400
cmpl $0xfd, %ebp
movq %rbp, %rax
ja 0x3b40f
movb %al, (%r12)
jmp 0x3b419
movl %r12d, 0x4(%rbx)
jmp 0x3b44d
movb $-0x2, (%r12)
movl %ebp, 0x1(%r12)
movq %rbp, %rax
jmp 0x3b419
movb $-0x2, (%r12)
movl %eax, 0x1(%r12)
movq %rax, %rbp
addl %eax, 0x4(%rbx)
leaq 0x38(%rsp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x3ad62
movl 0xc(%r13), %eax
movl 0x10(%r13), %ecx
addq %r12, %rcx
cmpb $-0x1, (%rax,%rcx)
movq 0x20(%rsp), %r12
movq 0x18(%rsp), %rcx
je 0x3b44d
addl %ecx, 0x4(%rbx)
testl %ecx, %ecx
movl 0xc(%rsp), %r13d
je 0x3b478
addq %rbp, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3aed0
testq %rax, %rax
movl 0x8(%rsp), %ebp
je 0x3b4a4
movq %rax, %rbx
addq %rax, %r12
movq %r12, %r15
jmp 0x3b47c
movl 0x8(%rsp), %ebp
cmpb $0x0, 0x2(%rsp)
je 0x3b491
movl 0x4(%rsp), %eax
movb %al, (%r15)
movl $0x1, %eax
jmp 0x3b4ae
movb $-0x2, (%r15)
movl 0x4(%rsp), %eax
movl %eax, 0x1(%r15)
movl $0x5, %eax
jmp 0x3b4ae
xorl %ebx, %ebx
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movl %eax, %r12d
addq %r15, %r12
movq %r12, %rdi
movl %r13d, %esi
movl %ebp, %edx
callq 0x3a9f9
movl %eax, %edi
addq %r12, %rdi
cmpb $-0x41, %r13b
jbe 0x3b4db
movq 0x28(%rsp), %rsi
movl %r13d, %edx
callq 0x3ac64
jmp 0x3b4e7
movl %ebp, %edx
movq 0x30(%rsp), %rsi
callq 0x26c50
movzwl 0x8(%rbx), %eax
cmpw $-0x1, %ax
je 0x3b4f7
incl %eax
movw %ax, 0x8(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq