// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/quicklist.c
// Function: quicklistInsert
REDIS_STATIC void _quicklistInsert(quicklist *quicklist, quicklistEntry *entry,
                                   void *value, const size_t sz, int after) {
    int full = 0, at_tail = 0, at_head = 0, full_next = 0, full_prev = 0;
    int fill = quicklist->fill;
    quicklistNode *node = entry->node;
    quicklistNode *new_node = NULL;

    if (!node) {
        /* we have no reference node, so let's create only node in the list */
        D("No node given!");
        new_node = quicklistCreateNode();
        new_node->zl = ziplistPush(ziplistNew(), value, sz, ZIPLIST_HEAD);
        __quicklistInsertNode(quicklist, NULL, new_node, after);
        new_node->count++;
        quicklist->count++;
        return;
    }

    /* Populate accounting flags for easier boolean checks later */
    if (!_quicklistNodeAllowInsert(node, fill, sz)) {
        D("Current node is full with count %d with requested fill %lu",
          node->count, fill);
        full = 1;
    }

    if (after && (entry->offset == node->count)) {
        D("At Tail of current ziplist");
        at_tail = 1;
        if (!_quicklistNodeAllowInsert(node->next, fill, sz)) {
            D("Next node is full too.");
            full_next = 1;
        }
    }

    if (!after && (entry->offset == 0)) {
        D("At Head");
        at_head = 1;
        if (!_quicklistNodeAllowInsert(node->prev, fill, sz)) {
            D("Prev node is full too.");
            full_prev = 1;
        }
    }

    /* Now determine where and how to insert the new element */
    if (!full && after) {
        D("Not full, inserting after current position.");
        quicklistDecompressNodeForUse(node);
        unsigned char *next = ziplistNext(node->zl, entry->zi);
        if (next == NULL) {
            node->zl = ziplistPush(node->zl, value, sz, ZIPLIST_TAIL);
        } else {
            node->zl = ziplistInsert(node->zl, next, value, sz);
        }
        node->count++;
        quicklistNodeUpdateSz(node);
        quicklistRecompressOnly(quicklist, node);
    } else if (!full && !after) {
        D("Not full, inserting before current position.");
        quicklistDecompressNodeForUse(node);
        node->zl = ziplistInsert(node->zl, entry->zi, value, sz);
        node->count++;
        quicklistNodeUpdateSz(node);
        quicklistRecompressOnly(quicklist, node);
    } else if (full && at_tail && node->next && !full_next && after) {
        /* If we are: at tail, next has free space, and inserting after:
         *   - insert entry at head of next node. */
        D("Full and tail, but next isn't full; inserting next node head");
        new_node = node->next;
        quicklistDecompressNodeForUse(new_node);
        new_node->zl = ziplistPush(new_node->zl, value, sz, ZIPLIST_HEAD);
        new_node->count++;
        quicklistNodeUpdateSz(new_node);
        quicklistRecompressOnly(quicklist, new_node);
    } else if (full && at_head && node->prev && !full_prev && !after) {
        /* If we are: at head, previous has free space, and inserting before:
         *   - insert entry at tail of previous node. */
        D("Full and head, but prev isn't full, inserting prev node tail");
        new_node = node->prev;
        quicklistDecompressNodeForUse(new_node);
        new_node->zl = ziplistPush(new_node->zl, value, sz, ZIPLIST_TAIL);
        new_node->count++;
        quicklistNodeUpdateSz(new_node);
        quicklistRecompressOnly(quicklist, new_node);
    } else if (full && ((at_tail && node->next && full_next && after) ||
                        (at_head && node->prev && full_prev && !after))) {
        /* If we are: full, and our prev/next is full, then:
         *   - create new node and attach to quicklist */
        D("\tprovisioning new node...");
        new_node = quicklistCreateNode();
        new_node->zl = ziplistPush(ziplistNew(), value, sz, ZIPLIST_HEAD);
        new_node->count++;
        quicklistNodeUpdateSz(new_node);
        __quicklistInsertNode(quicklist, node, new_node, after);
    } else if (full) {
        /* else, node is full we need to split it. */
        /* covers both after and !after cases */
        D("\tsplitting node...");
        quicklistDecompressNodeForUse(node);
        new_node = _quicklistSplitNode(node, entry->offset, after);
        new_node->zl = ziplistPush(new_node->zl, value, sz,
                                   after ? ZIPLIST_HEAD : ZIPLIST_TAIL);
        new_node->count++;
        quicklistNodeUpdateSz(new_node);
        __quicklistInsertNode(quicklist, node, new_node, after);
        _quicklistMergeNodes(quicklist, node);
    }

    quicklist->count++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movq %rcx, %r15
movq %rdx, %r12
movq %rdi, %rbx
movq 0x8(%rsi), %r14
testq %r14, %r14
jne 0x2c026
movl $0x20, %edi
callq 0x382d1
movq %rax, %r14
movq $0x0, 0x10(%rax)
movl $0x0, 0x18(%rax)
movl $0xffe00000, %eax       # imm = 0xFFE00000
andl 0x1c(%r14), %eax
orl $0x90000, %eax          # imm = 0x90000
xorps %xmm0, %xmm0
movups %xmm0, (%r14)
movl %eax, 0x1c(%r14)
callq 0x3ae98
movq %rax, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x3b65e
movq %rax, 0x10(%r14)
testl %ebp, %ebp
je 0x2bfe7
movq $0x0, (%r14)
cmpq $0x0, 0x8(%rbx)
jne 0x2bffb
leaq 0x8(%rbx), %rax
jmp 0x2bff8
movq $0x0, 0x8(%r14)
cmpq $0x0, (%rbx)
movq %rbx, %rax
jne 0x2bffb
movq %r14, (%rax)
movl 0x18(%rbx), %eax
testl %eax, %eax
jne 0x2c009
movq %r14, 0x8(%rbx)
movq %r14, (%rbx)
incl %eax
movl %eax, 0x18(%rbx)
incw 0x1c(%r14)
incq 0x10(%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r13
movswl 0x1c(%rbx), %esi
movq %r14, %rdi
movl %esi, 0xc(%rsp)
movq %r15, %rdx
callq 0x26d20
movl 0x2c(%r13), %esi
testl %ebp, %ebp
je 0x2c095
movl 0x1c(%r14), %edx
movzwl %dx, %ecx
cmpl %ecx, %esi
je 0x2c0da
testl %eax, %eax
je 0x2c197
andl $0x30000, %edx          # imm = 0x30000
cmpl $0x20000, %edx          # imm = 0x20000
jne 0x2c076
movq %r14, %rdi
callq 0x2b72e
orb $0x10, 0x1e(%r14)
movq 0x10(%r14), %rdi
movq 0x10(%r13), %rsi
callq 0x3b745
movq 0x10(%r14), %rdi
testq %rax, %rax
je 0x2c2c3
movq %rax, %rsi
jmp 0x2c0ca
testl %esi, %esi
je 0x2c14e
testl %eax, %eax
je 0x2c197
movl $0x30000, %eax          # imm = 0x30000
andl 0x1c(%r14), %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x2c0c2
movq %r14, %rdi
callq 0x2b72e
orb $0x10, 0x1e(%r14)
movq 0x10(%r14), %rdi
movq 0x10(%r13), %rsi
movq %r12, %rdx
movl %r15d, %ecx
callq 0x3b887
jmp 0x2c2d3
movq 0x8(%r14), %rdi
movl %esi, 0x14(%rsp)
movl 0xc(%rsp), %esi
movl %edx, 0x10(%rsp)
movq %r15, %rdx
movl %eax, 0xc(%rsp)
callq 0x26d20
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %esi
cmpl $0x0, 0xc(%rsp)
jne 0x2c05b
movq 0x8(%r14), %rcx
testq %rcx, %rcx
je 0x2c218
testl %eax, %eax
je 0x2c218
movl $0x30000, %eax          # imm = 0x30000
andl 0x1c(%rcx), %eax
cmpl $0x20000, %eax          # imm = 0x20000
movq %rcx, %r14
jne 0x2c13d
movq %r14, %rdi
callq 0x2b72e
orb $0x10, 0x1e(%r14)
movq 0x10(%r14), %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
jmp 0x2c2ce
movq (%r14), %rdi
movl 0xc(%rsp), %esi
movq %r15, %rdx
movl %eax, 0xc(%rsp)
callq 0x26d20
cmpl $0x0, 0xc(%rsp)
jne 0x2c0a5
testl %eax, %eax
sete %cl
movq (%r14), %rsi
testq %rsi, %rsi
sete %dl
orb %cl, %dl
je 0x2c2a0
testq %rsi, %rsi
sete %cl
testl %eax, %eax
setne %al
xorl %esi, %esi
orb %cl, %al
je 0x2c22b
movl $0x30000, %eax          # imm = 0x30000
andl 0x1c(%r14), %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x2c1b8
movq %r14, %rdi
callq 0x2b72e
orb $0x10, 0x1e(%r14)
movl 0x2c(%r13), %esi
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %eax, 0xc(%rsp)
movq %r14, %rdi
movl %ebp, %edx
callq 0x2be72
movq %rax, %r13
movq 0x10(%rax), %rdi
movq %r12, %rsi
movl %r15d, %edx
movl 0xc(%rsp), %ecx
callq 0x3b65e
movq %rax, 0x10(%r13)
incw 0x1c(%r13)
movq %rax, %rdi
callq 0x3bbc5
movl %eax, 0x18(%r13)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x2b8c6
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bd8f
jmp 0x2c013
testl %eax, %eax
sete %al
testq %rcx, %rcx
setne %cl
testb %cl, %al
je 0x2c197
movl $0x20, %edi
callq 0x382d1
movq %rax, %r13
movq $0x0, 0x10(%rax)
movl $0x0, 0x18(%rax)
movl $0xffe00000, %eax       # imm = 0xFFE00000
andl 0x1c(%r13), %eax
orl $0x90000, %eax          # imm = 0x90000
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movl %eax, 0x1c(%r13)
callq 0x3ae98
movq %rax, %rdi
movq %r12, %rsi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0x3b65e
movq %rax, 0x10(%r13)
incw 0x1c(%r13)
movq %rax, %rdi
callq 0x3bbc5
movl %eax, 0x18(%r13)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
movl %ebp, %ecx
callq 0x2b8c6
jmp 0x2c013
movl $0x30000, %eax          # imm = 0x30000
andl 0x1c(%rsi), %eax
cmpl $0x20000, %eax          # imm = 0x20000
movq %rsi, %r14
jne 0x2c2bf
movq %r14, %rdi
callq 0x2b72e
orb $0x10, 0x1e(%r14)
movq 0x10(%r14), %rdi
movq %r12, %rsi
movl %r15d, %edx
movl $0x1, %ecx
callq 0x3b65e
movq %rax, 0x10(%r14)
incw 0x1c(%r14)
movq %rax, %rdi
callq 0x3bbc5
movl %eax, 0x18(%r14)
movl $0x130000, %eax         # imm = 0x130000
andl 0x1c(%r14), %eax
cmpl $0x110000, %eax         # imm = 0x110000
jne 0x2c013
movq %r14, %rdi
callq 0x2b6ab
jmp 0x2c013