// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/redis.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);
    }

#if 1 /* Use bulk get by default. */
    count = dictGetRandomKeys(sampledict,samples,server.maxmemory_samples);
#else
    count = server.maxmemory_samples;
    for (j = 0; j < count; j++) samples[j] = dictGetRandomKey(sampledict);
#endif

    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 < REDIS_EVICTION_POOL_SIZE &&
               pool[k].key &&
               pool[k].idle < idle) k++;
        if (k == 0 && pool[REDIS_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 < REDIS_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[REDIS_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])*(REDIS_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, 0xe8e86(%rip)    # 0x114024
jg 0x2b1b0
leaq -0xb0(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x2b1c7
movslq 0xe8e6d(%rip), %rdi     # 0x114024
shlq $0x3, %rdi
callq 0x2e130
movq %rax, -0xb8(%rbp)
movq -0x8(%rbp), %rdi
movq -0xb8(%rbp), %rsi
movl 0xe8e4c(%rip), %edx     # 0x114024
callq 0x245e0
movl %eax, -0x24(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x2b3c8
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 0x2b23b
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x23aa0
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x3bac0
movq %rax, -0xc0(%rbp)
movl $0x0, -0x20(%rbp)
xorl %eax, %eax
cmpl $0x10, -0x20(%rbp)
movb %al, -0xd9(%rbp)
jge 0x2b2b5
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 0x2b2b5
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 0x2b2c1
jmp 0x2b2cc
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x2b267
cmpl $0x0, -0x20(%rbp)
jne 0x2b2e5
movq -0x18(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
je 0x2b2e5
jmp 0x2b3ba
cmpl $0x10, -0x20(%rbp)
jge 0x2b303
movq -0x18(%rbp), %rax
movslq -0x20(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x2b303
jmp 0x2b37d
movq -0x18(%rbp), %rax
cmpq $0x0, 0xf8(%rax)
jne 0x2b34c
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 0x1f780
jmp 0x2b37b
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2c160
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rsi
addq $0x10, %rsi
movslq -0x20(%rbp), %rdx
shlq $0x4, %rdx
callq 0x1f780
jmp 0x2b37d
jmp 0x2b37f
movq -0xc8(%rbp), %rdi
callq 0x2c130
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 0x2b1e7
movq -0xb8(%rbp), %rax
leaq -0xb0(%rbp), %rcx
cmpq %rcx, %rax
je 0x2b3e7
movq -0xb8(%rbp), %rdi
callq 0x2e3a0
addq $0xe0, %rsp
popq %rbp
retq