// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/server.c
// Function: evictionPoolPopulate
void evictionPoolPopulate(dict *sampledict, dict *keydict, struct evictionPoolEntry *pool) {
    int j, k, count;
    dictEntry *_samples[EVICTION_SAMPLES_ARRAY_SIZE];
    dictEntry **samples;

    /* Try to use a static buffer: this function is a big hit...
     * Note: it was actually measured that this helps. */
    if (server.maxmemory_samples <= EVICTION_SAMPLES_ARRAY_SIZE) {
        samples = _samples;
    } else {
        samples = zmalloc(sizeof(samples[0])*server.maxmemory_samples);
    }

    count = dictGetSomeKeys(sampledict,samples,server.maxmemory_samples);
    for (j = 0; j < count; j++) {
        unsigned long long idle;
        sds key;
        robj *o;
        dictEntry *de;

        de = samples[j];
        key = dictGetKey(de);
        /* If the dictionary we are sampling from is not the main
         * dictionary (but the expires one) we need to lookup the key
         * again in the key dictionary to obtain the value object. */
        if (sampledict != keydict) de = dictFind(keydict, key);
        o = dictGetVal(de);
        idle = estimateObjectIdleTime(o);

        /* Insert the element inside the pool.
         * First, find the first empty bucket or the first populated
         * bucket that has an idle time smaller than our idle time. */
        k = 0;
        while (k < MAXMEMORY_EVICTION_POOL_SIZE &&
               pool[k].key &&
               pool[k].idle < idle) k++;
        if (k == 0 && pool[MAXMEMORY_EVICTION_POOL_SIZE-1].key != NULL) {
            /* Can't insert if the element is < the worst element we have
             * and there are no empty buckets. */
            continue;
        } else if (k < MAXMEMORY_EVICTION_POOL_SIZE && pool[k].key == NULL) {
            /* Inserting into empty position. No setup needed before insert. */
        } else {
            /* Inserting in the middle. Now k points to the first element
             * greater than the element to insert.  */
            if (pool[MAXMEMORY_EVICTION_POOL_SIZE-1].key == NULL) {
                /* Free space on the right? Insert at k shifting
                 * all the elements from k to end to the right. */
                memmove(pool+k+1,pool+k,
                    sizeof(pool[0])*(MAXMEMORY_EVICTION_POOL_SIZE-k-1));
            } else {
                /* No free space on right? Insert at k-1 */
                k--;
                /* Shift all elements on the left of k (included) to the
                 * left, so we discard the element with smaller idle time. */
                sdsfree(pool[0].key);
                memmove(pool,pool+1,sizeof(pool[0])*k);
            }
        }
        pool[k].key = sdsdup(key);
        pool[k].idle = idle;
    }
    if (samples != _samples) zfree(samples);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
cmpl $0x10, 0x141cbe(%rip)   # 0x178aec
jg 0x36e40
leaq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x36e57
movslq 0x141ca5(%rip), %rdi    # 0x178aec
shlq $0x3, %rdi
callq 0x3acd0
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl 0x141c84(%rip), %edx    # 0x178aec
callq 0x2e830
movl %eax, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x37058
movq -0xb8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0x8(%rbp), %rax
cmpq -0x10(%rbp), %rax
je 0x36ecb
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x2dcb0
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x4a080
movq %rax, -0xc0(%rbp)
movl $0x0, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x10, -0x20(%rbp)
movb %al, -0xd9(%rbp)
jge 0x36f45
movq -0x18(%rbp), %rcx
movslq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rcx
xorl %eax, %eax
cmpq $0x0, 0x8(%rcx)
movb %al, -0xd9(%rbp)
je 0x36f45
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rax
cmpq -0xc0(%rbp), %rax
setb %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %al
testb $0x1, %al
jne 0x36f51
jmp 0x36f5c
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x36ef7
cmpl $0x0, -0x20(%rbp)
jne 0x36f75
movq -0x18(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
je 0x36f75
jmp 0x3704a
cmpl $0x10, -0x20(%rbp)
jge 0x36f93
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x36f93
jmp 0x3700d
movq -0x18(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
jne 0x36fdc
movq -0x18(%rbp), %rdi
movslq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
addq $0x10, %rdi
movq -0x18(%rbp), %rsi
movslq -0x20(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
movl $0x10, %eax
subl -0x20(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rdx
shlq $0x4, %rdx
callq 0x267e0
jmp 0x3700b
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x38620
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
callq 0x267e0
jmp 0x3700d
jmp 0x3700f
movq -0xc8(%rbp), %rdi
callq 0x38560
movq %rax, %rcx
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rcx
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x36e77
movq -0xb8(%rbp), %rax
leaq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
je 0x37077
movq -0xb8(%rbp), %rdi
callq 0x3afa0
addq $0xe0, %rsp
popq %rbp
retq