// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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
movq %rsi, %r12
movq %rdi, %rbp
leaq 0x18(%rsi), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsi), %rax
movq %rax, 0x10(%rsp)
leaq 0x28(%rsi), %rax
movq %rax, (%rsp)
movabsq $0x75bcd1500000000, %r14 # imm = 0x75BCD1500000000
movl $0x30000, %r15d         # imm = 0x30000
leaq 0xf313(%rip), %r13      # 0x3eafc
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%r12)
movq $-0x75bcd15, 0x20(%r12) # imm = 0xF8A432EB
movups %xmm0, (%r12)
movq %r14, 0x28(%r12)
testq %rbp, %rbp
je 0x2f91c
movq (%rbp), %rax
movq %rax, (%r12)
movq 0x8(%rbp), %rdi
movq %rdi, 0x8(%r12)
testq %rdi, %rdi
je 0x2f91c
movq 0x10(%rbp), %rsi
testq %rsi, %rsi
je 0x2f863
xorl %ebx, %ebx
cmpl $0x0, 0x20(%rbp)
sete %cl
movq %r13, %rax
jne 0x2f846
leaq 0xf290(%rip), %rax      # 0x3ead6
movb %cl, %bl
movq 0x10(%rdi), %rdi
callq *%rax
movq %rax, 0x10(%rbp)
movq 0x18(%rbp), %rax
leaq (%rax,%rbx,2), %rax
decq %rax
movq %rax, 0x18(%rbp)
jmp 0x2f894
movl 0x1c(%rdi), %eax
andl %r15d, %eax
cmpl $0x20000, %eax          # imm = 0x20000
jne 0x2f880
callq 0x2e916
movq 0x8(%rbp), %rax
orl $0x100000, 0x1c(%rax)   # imm = 0x100000
movq 0x8(%rbp), %rax
movq 0x10(%rax), %rdi
movl 0x18(%rbp), %esi
callq 0x3ea40
movq %rax, 0x10(%rbp)
movq 0x10(%rbp), %rdi
movq %rdi, 0x10(%r12)
movl 0x18(%rbp), %eax
movl %eax, 0x2c(%r12)
testq %rdi, %rdi
jne 0x2f920
movq 0x8(%rbp), %rsi
movl 0x1c(%rsi), %eax
btl $0x14, %eax
jb 0x2f8c2
movq (%rbp), %rdi
callq 0x2e984
jmp 0x2f8e1
testq %rsi, %rsi
sete %cl
andl $0x30000, %eax          # imm = 0x30000
cmpl $0x10000, %eax          # imm = 0x10000
setne %al
orb %cl, %al
jne 0x2f8e1
movq %rsi, %rdi
callq 0x2e893
movl 0x20(%rbp), %eax
cmpl $0x1, %eax
je 0x2f8f9
testl %eax, %eax
jne 0x2f90f
movq 0x8(%rbp), %rax
addq $0x8, %rax
xorl %ecx, %ecx
jmp 0x2f904
movq 0x8(%rbp), %rax
movq $-0x1, %rcx
movq (%rax), %rax
movq %rax, 0x8(%rbp)
movq %rcx, 0x18(%rbp)
movq $0x0, 0x10(%rbp)
jmp 0x2f7e9
xorl %eax, %eax
jmp 0x2f938
movq 0x8(%rsp), %rsi
movq (%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x3eb60
movl $0x1, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq