// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/dict.c
// Function: dictGetSomeKeys
unsigned int dictGetSomeKeys(dict *d, dictEntry **des, unsigned int count) {
    unsigned long j; /* internal hash table id, 0 or 1. */
    unsigned long tables; /* 1 or 2 tables? */
    unsigned long stored = 0, maxsizemask;
    unsigned long maxsteps;

    if (dictSize(d) < count) count = dictSize(d);
    maxsteps = count*10;

    /* Try to do a rehashing work proportional to 'count'. */
    for (j = 0; j < count; j++) {
        if (dictIsRehashing(d))
            _dictRehashStep(d);
        else
            break;
    }

    tables = dictIsRehashing(d) ? 2 : 1;
    maxsizemask = d->ht[0].sizemask;
    if (tables > 1 && maxsizemask < d->ht[1].sizemask)
        maxsizemask = d->ht[1].sizemask;

    /* Pick a random point inside the larger table. */
    unsigned long i = random() & maxsizemask;
    unsigned long emptylen = 0; /* Continuous empty entries so far. */
    while(stored < count && maxsteps--) {
        for (j = 0; j < tables; j++) {
            /* Invariant of the dict.c rehashing: up to the indexes already
             * visited in ht[0] during the rehashing, there are no populated
             * buckets, so we can skip ht[0] for indexes between 0 and idx-1. */
            if (tables == 2 && j == 0 && i < (unsigned long) d->rehashidx) {
                /* Moreover, if we are currently out of range in the second
                 * table, there will be no elements in both tables up to
                 * the current rehashing index, so we jump if possible.
                 * (this happens when going from big to small table). */
                if (i >= d->ht[1].size) i = d->rehashidx;
                continue;
            }
            if (i >= d->ht[j].size) continue; /* Out of range for this table. */
            dictEntry *he = d->ht[j].table[i];

            /* Count contiguous empty buckets, and jump to other
             * locations if they reach 'count' (with a minimum of 5). */
            if (he == NULL) {
                emptylen++;
                if (emptylen >= 5 && emptylen > count) {
                    i = random() & maxsizemask;
                    emptylen = 0;
                }
            } else {
                emptylen = 0;
                while (he) {
                    /* Collect all the elements of the buckets found non
                     * empty while iterating. */
                    *des = he;
                    des++;
                    he = he->next;
                    stored++;
                    if (stored == count) return stored;
                }
            }
        }
        i = (i+1) & maxsizemask;
    }
    return stored;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x10(%rdi), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rdi), %r12
addq 0x28(%rdi), %r12
movl %edx, %eax
cmpq %rax, %r12
cmovael %edx, %r12d
imull $0xa, %r12d, %r13d
movq %r12, %rbx
movq 0x50(%r15), %rax
subq $0x1, %rbx
jb 0x2ac07
cmpq $-0x1, %rax
je 0x2ac27
movq %r15, %rdi
callq 0x2a57a
jmp 0x2abed
movq 0x20(%r15), %rcx
cmpq $-0x1, %rax
je 0x2ac3b
movq 0x40(%r15), %rax
cmpq %rax, %rcx
cmovbeq %rax, %rcx
movq %rcx, (%rsp)
movb $0x1, %bpl
pushq $0x2
jmp 0x2ac43
movq 0x20(%r15), %rax
movq %rax, (%rsp)
pushq $0x1
popq %rax
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
jmp 0x2ac49
movq %rcx, (%rsp)
xorl %ebp, %ebp
pushq $0x1
popq %rax
movq %rax, 0x8(%rsp)
callq 0x26a30
cmpq $0x5, %r12
pushq $0x4
popq %r9
cmovaeq %r12, %r9
xorl %ebx, %ebx
xorb $0x1, %bpl
xorl %ecx, %ecx
movq (%rsp), %rdi
cmpq %r12, %rbx
jae 0x2ad26
subq $0x1, %r13
jb 0x2ad26
movq %r13, 0x18(%rsp)
andq %rdi, %rax
xorl %r13d, %r13d
movq 0x8(%rsp), %r8
cmpq %r8, %r13
je 0x2ad19
testq %r13, %r13
setne %dl
orb %bpl, %dl
jne 0x2acb0
movq 0x50(%r15), %rdx
cmpq %rdx, %rax
jae 0x2acb0
cmpq 0x38(%r15), %rax
cmovaeq %rdx, %rax
jmp 0x2ad11
movq %r13, %rdx
shlq $0x5, %rdx
movq 0x20(%rsp), %rsi
cmpq 0x8(%rsi,%rdx), %rax
jae 0x2ad11
addq %rsi, %rdx
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je 0x2acec
testq %rdx, %rdx
je 0x2ad0f
movq %rdx, (%r14)
addq $0x8, %r14
movq 0x10(%rdx), %rdx
incq %rbx
cmpq %rbx, %r12
jne 0x2acd2
jmp 0x2ad29
incq %rcx
cmpq %r9, %rcx
jbe 0x2ad11
movq %r9, 0x10(%rsp)
callq 0x26a30
movq 0x10(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
andq %rdi, %rax
xorl %ecx, %ecx
incq %r13
jmp 0x2ac89
incq %rax
movq 0x18(%rsp), %r13
jmp 0x2ac66
movl %ebx, %r12d
movl %r12d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq