// File: /workspace/github_c_makefile_star2_O3/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
movq 0x48(%rdi), %r13
addq 0x28(%rdi), %r13
movl %edx, %eax
cmpq %rax, %r13
cmovael %edx, %r13d
testl %r13d, %r13d
je 0x2f25f
movq %r13, %rbx
cmpq $-0x1, 0x50(%r15)
je 0x2f27d
cmpl $0x0, 0x58(%r15)
jne 0x2f25a
movq %r15, %rdi
movl $0x1, %esi
callq 0x2e787
decq %rbx
jne 0x2f23f
movq 0x20(%r15), %rbp
cmpq $-0x1, 0x50(%r15)
je 0x2f281
movq 0x40(%r15), %rax
cmpq %rax, %rbp
cmovbeq %rax, %rbp
movb $0x1, %al
movl %eax, 0xc(%rsp)
jmp 0x2f289
movq 0x20(%r15), %rbp
movl $0x0, 0xc(%rsp)
callq 0x26a30
testl %r13d, %r13d
je 0x2f378
leal (,%r13,2), %ecx
leal (%rcx,%rcx,4), %r8d
leaq 0x10(%r15), %r12
cmpq $0x5, %r13
movl $0x4, %r9d
cmovaeq %r13, %r9
xorl %ecx, %ecx
xorl %ebx, %ebx
movl 0xc(%rsp), %edi
movq %rbp, 0x10(%rsp)
subq $0x1, %r8
jb 0x2f373
andq %rbp, %rax
movb $0x1, %sil
xorl %edx, %edx
movl %esi, %ebp
andb %dil, %bpl
cmpb $0x1, %bpl
jne 0x2f2f2
movq 0x50(%r15), %rsi
cmpq %rsi, %rax
jae 0x2f2f2
cmpq 0x38(%r15), %rax
cmovaeq %rsi, %rax
jmp 0x2f352
shlq $0x5, %rdx
cmpq 0x8(%r12,%rdx), %rax
jae 0x2f352
addq %r12, %rdx
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je 0x2f326
testq %rdx, %rdx
je 0x2f350
movq %rdx, (%r14)
addq $0x8, %r14
movq 0x10(%rdx), %rdx
incq %rbx
cmpq %rbx, %r13
jne 0x2f30c
jmp 0x2f37b
incq %rcx
cmpq %r9, %rcx
jbe 0x2f352
movq %r8, 0x20(%rsp)
movq %r9, 0x18(%rsp)
callq 0x26a30
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movl 0xc(%rsp), %edi
andq 0x10(%rsp), %rax
xorl %ecx, %ecx
movl $0x1, %edx
xorl %esi, %esi
testb %bpl, %bpl
jne 0x2f2d4
incq %rax
cmpq %r13, %rbx
movq 0x10(%rsp), %rbp
jb 0x2f2c2
movl %ebx, %r13d
jmp 0x2f37b
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq