// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/quicklist.c
// Function: quicklistIndex
int quicklistIndex(const quicklist *quicklist, const long long idx,
                   quicklistEntry *entry) {
    quicklistNode *n;
    unsigned long long accum = 0;
    unsigned long long index;
    int forward = idx < 0 ? 0 : 1; /* < 0 -> reverse, 0+ -> forward */

    initEntry(entry);
    entry->quicklist = quicklist;

    if (!forward) {
        index = (-idx) - 1;
        n = quicklist->tail;
    } else {
        index = idx;
        n = quicklist->head;
    }

    if (index >= quicklist->count)
        return 0;

    while (likely(n)) {
        if ((accum + n->count) > index) {
            break;
        } else {
            D("Skipping over (%p) %u at accum %lld", (void *)n, n->count,
              accum);
            accum += n->count;
            n = forward ? n->next : n->prev;
        }
    }

    if (!n)
        return 0;

    D("Found node: %p at accum %llu, idx %llu, sub+ %llu, sub- %llu", (void *)n,
      accum, index, index - accum, (-index) - 1 + accum);

    entry->node = n;
    if (forward) {
        /* forward = normal head-to-tail offset. */
        entry->offset = index - accum;
    } else {
        /* reverse = need negative offset for tail-to-head, so undo
         * the result of the original if (index < 0) above. */
        entry->offset = (-index) - 1 + accum;
    }

    quicklistDecompressNodeForUse(entry->node);
    entry->zi = ziplistIndex(entry->node->zl, entry->offset);
    ziplistGet(entry->zi, &entry->value, &entry->sz, &entry->longval);
    /* The caller will use our result, so we don't re-compress here.
     * The caller can recompress or delete the node as needed. */
    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rdx
movl $0x1, %eax
xorl %ecx, %ecx
cmpq $0x0, %rdx
cmovll %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $-0x75bcd15, 0x20(%rax) # imm = 0xF8A432EB
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
movl $0x75bcd15, 0x2c(%rax)  # imm = 0x75BCD15
movq -0x20(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x10(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
cmpl $0x0, -0x3c(%rbp)
jne 0x2894f
xorl %eax, %eax
subq -0x18(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x28962
movq -0x18(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x2897c
movl $0x0, -0x4(%rbp)
jmp 0x28ade
jmp 0x2897e
cmpq $0x0, -0x28(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
cltq
cmpq $0x0, %rax
je 0x289f4
movq -0x30(%rbp), %rax
movq -0x28(%rbp), %rcx
movl 0x1c(%rcx), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, %ecx
addq %rcx, %rax
cmpq -0x38(%rbp), %rax
jbe 0x289b5
jmp 0x289f4
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, %eax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x3c(%rbp)
je 0x289df
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x289ea
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x2897e
cmpq $0x0, -0x28(%rbp)
jne 0x28a07
movl $0x0, -0x4(%rbp)
jmp 0x28ade
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpl $0x0, -0x3c(%rbp)
je 0x28a2c
movq -0x38(%rbp), %rax
subq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x28a43
xorl %eax, %eax
subq -0x38(%rbp), %rax
subq $0x1, %rax
addq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, 0x2c(%rax)
jmp 0x28a45
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x28a8d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x1c(%rax), %eax
shrl $0x10, %eax
andl $0x3, %eax
cmpl $0x2, %eax
jne 0x28a8d
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x27a80
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x1c(%rax), %ecx
andl $0xffefffff, %ecx       # imm = 0xFFEFFFFF
orl $0x100000, %ecx         # imm = 0x100000
movl %ecx, 0x1c(%rax)
jmp 0x28a8f
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rax
movl 0x2c(%rax), %esi
callq 0x41120
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x20(%rbp), %rsi
addq $0x18, %rsi
movq -0x20(%rbp), %rdx
addq $0x28, %rdx
movq -0x20(%rbp), %rcx
addq $0x20, %rcx
callq 0x41470
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)