// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/quicklist.c
// Function: quicklistNext
int quicklistNext(quicklistIter *iter, quicklistEntry *entry) {
    initEntry(entry);

    if (!iter) {
        D("Returning because no iter!");
        return 0;
    }

    entry->quicklist = iter->quicklist;
    entry->node = iter->current;

    if (!iter->current) {
        D("Returning because current node is NULL")
        return 0;
    }

    unsigned char *(*nextFn)(unsigned char *, unsigned char *) = NULL;
    int offset_update = 0;

    if (!iter->zi) {
        /* If !zi, use current index. */
        quicklistDecompressNodeForUse(iter->current);
        iter->zi = ziplistIndex(iter->current->zl, iter->offset);
    } else {
        /* else, use existing iterator offset and get prev/next as necessary. */
        if (iter->direction == AL_START_HEAD) {
            nextFn = ziplistNext;
            offset_update = 1;
        } else if (iter->direction == AL_START_TAIL) {
            nextFn = ziplistPrev;
            offset_update = -1;
        }
        iter->zi = nextFn(iter->current->zl, iter->zi);
        iter->offset += offset_update;
    }

    entry->zi = iter->zi;
    entry->offset = iter->offset;

    if (iter->zi) {
        /* Populate value from existing ziplist position */
        ziplistGet(entry->zi, &entry->value, &entry->sz, &entry->longval);
        return 1;
    } else {
        /* We ran out of ziplist entries.
         * Pick next node, update offset, then re-run retrieval. */
        quicklistCompress(iter->quicklist, iter->current);
        if (iter->direction == AL_START_HEAD) {
            /* Forward traversal */
            D("Jumping to start of next node");
            iter->current = iter->current->next;
            iter->offset = 0;
        } else if (iter->direction == AL_START_TAIL) {
            /* Reverse traversal */
            D("Jumping to end of previous node");
            iter->current = iter->current->prev;
            iter->offset = -1;
        }
        iter->zi = NULL;
        return quicklistNext(iter, entry);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %eax, %eax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsi)
movq $-0x75bcd15, 0x20(%rsi) # imm = 0xF8A432EB
movups %xmm0, (%rsi)
movabsq $0x75bcd1500000000, %rbp # imm = 0x75BCD1500000000
movq %rbp, 0x28(%rsi)
testq %rdi, %rdi
je 0x2c6ac
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rcx
movq %rcx, (%rsi)
movq 0x8(%rdi), %rdi
movq %rdi, 0x8(%rsi)
testq %rdi, %rdi
je 0x2c6ac
leaq 0x18(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x10(%rbx), %r15
leaq 0x20(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x28(%rbx), %rax
movq %rax, (%rsp)
leaq 0xf1f5(%rip), %r13      # 0x3b76b
movq 0x10(%r14), %rsi
testq %rsi, %rsi
je 0x2c5b4
xorl %r12d, %r12d
cmpl $0x0, 0x20(%r14)
sete %cl
movq %r13, %rax
jne 0x2c596
leaq 0xf1af(%rip), %rax      # 0x3b745
movb %cl, %r12b
movq 0x10(%rdi), %rdi
callq *%rax
movq %rax, 0x10(%r14)
movq 0x18(%r14), %rcx
leaq (%rcx,%r12,2), %rcx
decq %rcx
movq %rcx, 0x18(%r14)
jmp 0x2c5ee
movl 0x1c(%rdi), %eax
movl $0x30000, %ecx          # imm = 0x30000
andl %ecx, %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x2c5d9
callq 0x2b72e
movq 0x8(%r14), %rax
orl $0x100000, 0x1c(%rax)   # imm = 0x100000
movq 0x8(%r14), %rdi
movq 0x10(%rdi), %rdi
movl 0x18(%r14), %esi
callq 0x3b680
movq %rax, 0x10(%r14)
movq 0x18(%r14), %rcx
movq %rax, 0x10(%rbx)
movl %ecx, 0x2c(%rbx)
testq %rax, %rax
jne 0x2c691
movq 0x8(%r14), %rsi
movl 0x1c(%rsi), %eax
btl $0x14, %eax
jb 0x2c615
movq (%r14), %rdi
callq 0x2b79c
jmp 0x2c629
andl $0x30000, %eax          # imm = 0x30000
cmpl $0x10000, %eax          # imm = 0x10000
jne 0x2c629
movq %rsi, %rdi
callq 0x2b6ab
movl 0x20(%r14), %eax
cmpl $0x1, %eax
je 0x2c642
testl %eax, %eax
jne 0x2c658
movq 0x8(%r14), %rax
addq $0x8, %rax
xorl %ecx, %ecx
jmp 0x2c64d
movq 0x8(%r14), %rax
movq $-0x1, %rcx
movq (%rax), %rax
movq %rax, 0x8(%r14)
movq %rcx, 0x18(%r14)
movq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movups %xmm0, (%r15)
movq $-0x75bcd15, 0x20(%rbx) # imm = 0xF8A432EB
movups %xmm0, (%rbx)
movq %rbp, 0x28(%rbx)
movq (%r14), %rax
movq %rax, (%rbx)
movq 0x8(%r14), %rdi
movq %rdi, 0x8(%rbx)
testq %rdi, %rdi
jne 0x2c576
xorl %eax, %eax
jmp 0x2c6ac
movq %rax, %rdi
movq 0x10(%rsp), %rsi
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
callq 0x3b7cf
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq