// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/dict.c
// Function: dictScan
unsigned long dictScan(dict *d,
                       unsigned long v,
                       dictScanFunction *fn,
                       void *privdata)
{
    dictht *t0, *t1;
    const dictEntry *de;
    unsigned long m0, m1;

    if (dictSize(d) == 0) return 0;

    if (!dictIsRehashing(d)) {
        t0 = &(d->ht[0]);
        m0 = t0->sizemask;

        /* Emit entries at cursor */
        de = t0->table[v & m0];
        while (de) {
            fn(privdata, de);
            de = de->next;
        }

    } else {
        t0 = &d->ht[0];
        t1 = &d->ht[1];

        /* Make sure t0 is the smaller and t1 is the bigger table */
        if (t0->size > t1->size) {
            t0 = &d->ht[1];
            t1 = &d->ht[0];
        }

        m0 = t0->sizemask;
        m1 = t1->sizemask;

        /* Emit entries at cursor */
        de = t0->table[v & m0];
        while (de) {
            fn(privdata, de);
            de = de->next;
        }

        /* Iterate over indices in larger table that are the expansion
         * of the index pointed to by the cursor in the smaller table */
        do {
            /* Emit entries at cursor */
            de = t1->table[v & m1];
            while (de) {
                fn(privdata, de);
                de = de->next;
            }

            /* Increment bits not covered by the smaller mask */
            v = (((v | m0) + 1) & ~m0) | (v & m0);

            /* Continue while bits covered by mask difference is non-zero */
        } while (v & (m0 ^ m1));
    }

    /* Set unmasked bits so incrementing the reversed cursor
     * operates on the masked bits of the smaller table */
    v |= ~m0;

    /* Increment the reverse cursor */
    v = rev(v);
    v++;
    v = rev(v);

    return v;
}

// Assembly:
movq 0x28(%rdi), %rax
addq 0x48(%rdi), %rax
jne 0x2ad48
xorl %eax, %eax
retq
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %rbx
cmpq $-0x1, 0x50(%rdi)
je 0x2ae1d
leaq 0x10(%rdi), %rax
leaq 0x30(%rdi), %rsi
movq 0x18(%rdi), %rcx
xorl %edx, %edx
cmpq 0x38(%rdi), %rcx
seta %dl
movq %rax, %rcx
cmovaq %rsi, %rcx
cmovaq %rax, %rsi
shll $0x5, %edx
movq 0x10(%rcx), %rbp
movq %rsi, 0x10(%rsp)
movq 0x10(%rsi), %rax
movq %rax, (%rsp)
movq %rbp, %r12
andq %rbx, %r12
shlq $0x3, %r12
addq 0x10(%rdi,%rdx), %r12
movq (%r12), %r12
testq %r12, %r12
je 0x2adc5
movq %r14, %rdi
movq %r12, %rsi
callq *%r15
addq $0x10, %r12
jmp 0x2adad
movq %rbp, %r12
notq %r12
movq (%rsp), %rax
xorq %rbp, %rax
movq %rax, 0x8(%rsp)
movq %rbx, %r13
andq (%rsp), %r13
shlq $0x3, %r13
movq 0x10(%rsp), %rax
addq (%rax), %r13
movq (%r13), %r13
testq %r13, %r13
je 0x2ae02
movq %r14, %rdi
movq %r13, %rsi
callq *%r15
addq $0x10, %r13
jmp 0x2adea
movq %rbx, %rax
orq %rbp, %rax
incq %rax
andq %r12, %rax
andq %rbp, %rbx
orq %rax, %rbx
testq %rbx, 0x8(%rsp)
jne 0x2add7
jmp 0x2ae4a
movq 0x20(%rdi), %r13
movq %r13, %r12
andq %rbx, %r13
shlq $0x3, %r13
addq 0x10(%rdi), %r13
movq (%r13), %r13
testq %r13, %r13
je 0x2ae47
movq %r14, %rdi
movq %r13, %rsi
callq *%r15
addq $0x10, %r13
jmp 0x2ae2f
notq %r12
orq %rbx, %r12
movq %r12, %rdi
callq 0x2ae69
leaq 0x1(%rax), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2ae69