// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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 0x48(%rdi), %rbp
addq 0x28(%rdi), %rbp
movl %edx, %eax
cmpq %rax, %rbp
cmovael %edx, %ebp
testl %ebp, %ebp
movq %rdi, (%rsp)
je 0x194d5
movq %rbp, %rbx
cmpq $-0x1, 0x50(%rdi)
je 0x194d5
cmpq $0x0, 0x58(%rdi)
jne 0x194d0
movq (%rsp), %rdi
movl $0x1, %esi
callq 0x18971
movq (%rsp), %rdi
decq %rbx
jne 0x194b0
movq 0x20(%rdi), %rcx
movq 0x50(%rdi), %r13
cmpq $-0x1, %r13
je 0x194ee
movq 0x40(%rdi), %rax
cmpq %rax, %rcx
cmovbeq %rax, %rcx
movq %rcx, 0x8(%rsp)
callq 0x125a0
testl %ebp, %ebp
je 0x19604
leal (,%rbp,2), %ecx
leal (%rcx,%rcx,4), %edx
movq (%rsp), %rdi
leaq 0x10(%rdi), %r9
cmpq $0x5, %rbp
movl $0x4, %r10d
cmovaeq %rbp, %r10
xorl %ecx, %ecx
xorl %ebx, %ebx
movq 0x8(%rsp), %r8
movq %r9, 0x20(%rsp)
movq %r10, 0x18(%rsp)
subq $0x1, %rdx
jb 0x19600
movq %rdx, 0x10(%rsp)
andq %r8, %rax
xorl %r15d, %r15d
cmpq $-0x1, %r13
sete %dl
testq %r15, %r15
setne %sil
orb %dl, %sil
jne 0x1956e
movq 0x50(%rdi), %rdx
cmpq %rdx, %rax
jae 0x1956e
cmpq 0x38(%rdi), %rax
cmovaeq %rdx, %rax
jmp 0x195d9
movq %r15, %rdx
shlq $0x5, %rdx
cmpq 0x8(%r9,%rdx), %rax
jae 0x195d9
addq %r9, %rdx
movq (%rdx), %rdx
movq (%rdx,%rax,8), %rdx
testq %rdx, %rdx
je 0x195ac
testq %rdx, %rdx
sete %r12b
je 0x195d2
movq %rdx, (%r14)
addq $0x8, %r14
movq 0x10(%rdx), %rdx
incq %rbx
cmpq %rbx, %rbp
jne 0x1958b
movq %rbp, %rbx
jmp 0x195d2
incq %rcx
movb $0x1, %r12b
cmpq %r10, %rcx
jbe 0x195d4
callq 0x125a0
movq 0x18(%rsp), %r10
movq 0x20(%rsp), %r9
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
andq %r8, %rax
xorl %ecx, %ecx
testb %r12b, %r12b
je 0x19606
cmpq $-0x1, %r13
je 0x195ef
leaq 0x1(%r15), %rdx
testq %r15, %r15
movq %rdx, %r15
je 0x19548
incq %rax
cmpq %rbp, %rbx
movq 0x10(%rsp), %rdx
jb 0x19533
movl %ebx, %ebp
jmp 0x19606
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq