// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %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)
movl $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 0x40b48
jmp 0x40afe
jmp 0x40b00
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xfe, %eax
jge 0x40b17
movl $0x1, -0x34(%rbp)
jmp 0x40b1e
movl $0x5, -0x34(%rbp)
jmp 0x40b20
cmpl $0x1, -0x34(%rbp)
jne 0x40b32
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x40b44
cmpl $0x5, -0x34(%rbp)
jne 0x40b42
movq -0x10(%rbp), %rax
movl 0x1(%rax), %eax
movl %eax, -0x38(%rbp)
jmp 0x40b44
jmp 0x40b46
jmp 0x40b76
movq -0x8(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x4(%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x40b74
movq -0x78(%rbp), %rdi
callq 0x3ff20
movl %eax, -0x38(%rbp)
jmp 0x40b76
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x50(%rbp), %rdx
leaq -0x45(%rbp), %rcx
callq 0x40090
cmpl $0x0, %eax
je 0x40ba0
movzbl -0x45(%rbp), %edi
callq 0x3fc70
movl %eax, %eax
movq %rax, -0x30(%rbp)
jmp 0x40ba7
movl -0x1c(%rbp), %eax
movq %rax, -0x30(%rbp)
movl -0x38(%rbp), %esi
xorl %eax, %eax
movl %eax, %edi
callq 0x3fe30
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 0x3fd00
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movl $0x0, -0x7c(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
cmpl $0xff, %eax
je 0x40c02
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0x3fed0
movl %eax, -0x80(%rbp)
jmp 0x40c09
xorl %eax, %eax
movl %eax, -0x80(%rbp)
jmp 0x40c09
movl -0x80(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $-0x4, -0x44(%rbp)
jne 0x40c2a
cmpq $0x4, -0x30(%rbp)
jae 0x40c2a
movl $0x0, -0x44(%rbp)
movl $0x1, -0x7c(%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 0x40690
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 0x40d2a
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 0x267e0
cmpl $0x0, -0x7c(%rbp)
je 0x40cc0
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0x3fea0
jmp 0x40cd3
movq -0x10(%rbp), %rdi
addq -0x30(%rbp), %rdi
movq -0x30(%rbp), %rax
movl %eax, %esi
callq 0x3fe30
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), %rdi
addq -0x30(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x40400
movq -0x10(%rbp), %rax
movq -0x30(%rbp), %rcx
movl -0x60(%rbp), %edx
addq %rdx, %rcx
movl -0x64(%rbp), %edx
addq %rdx, %rcx
movzbl (%rax,%rcx), %eax
cmpl $0xff, %eax
je 0x40d28
movq -0x8(%rbp), %rax
movl 0x4(%rax), %ecx
addl -0x44(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x4(%rax)
jmp 0x40d3e
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 0x40d74
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 0x406e0
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x3fe30
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 0x3fd00
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 0x40dd4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x26c60
jmp 0x40de5
movq -0x10(%rbp), %rdi
movq -0x50(%rbp), %rsi
movzbl -0x45(%rbp), %edx
callq 0x401a0
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
cmpl $0xffff, %eax           # imm = 0xFFFF
jge 0x40e0a
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 $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)