// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/t_list.c
// Function: handleClientsBlockedOnLists
void handleClientsBlockedOnLists(void) {
    while(listLength(server.ready_keys) != 0) {
        list *l;

        /* Point server.ready_keys to a fresh list and save the current one
         * locally. This way as we run the old list we are free to call
         * signalListAsReady() that may push new elements in server.ready_keys
         * when handling clients blocked into BRPOPLPUSH. */
        l = server.ready_keys;
        server.ready_keys = listCreate();

        while(listLength(l) != 0) {
            listNode *ln = listFirst(l);
            readyList *rl = ln->value;

            /* First of all remove this key from db->ready_keys so that
             * we can safely call signalListAsReady() against this key. */
            dictDelete(rl->db->ready_keys,rl->key);

            /* If the key exists and it's a list, serve blocked clients
             * with data. */
            robj *o = lookupKeyWrite(rl->db,rl->key);
            if (o != NULL && o->type == OBJ_LIST) {
                dictEntry *de;

                /* We serve clients in the same order they blocked for
                 * this key, from the first blocked to the last. */
                de = dictFind(rl->db->blocking_keys,rl->key);
                if (de) {
                    list *clients = dictGetVal(de);
                    int numclients = listLength(clients);

                    while(numclients--) {
                        listNode *clientnode = listFirst(clients);
                        client *receiver = clientnode->value;
                        robj *dstkey = receiver->bpop.target;
                        int where = (receiver->lastcmd &&
                                     receiver->lastcmd->proc == blpopCommand) ?
                                    LIST_HEAD : LIST_TAIL;
                        robj *value = listTypePop(o,where);

                        if (value) {
                            /* Protect receiver->bpop.target, that will be
                             * freed by the next unblockClient()
                             * call. */
                            if (dstkey) incrRefCount(dstkey);
                            unblockClient(receiver);

                            if (serveClientBlockedOnList(receiver,
                                rl->key,dstkey,rl->db,value,
                                where) == C_ERR)
                            {
                                /* If we failed serving the client we need
                                 * to also undo the POP operation. */
                                    listTypePush(o,value,where);
                            }

                            if (dstkey) decrRefCount(dstkey);
                            decrRefCount(value);
                        } else {
                            break;
                        }
                    }
                }

                if (listTypeLength(o) == 0) {
                    dbDelete(rl->db,rl->key);
                }
                /* We don't call signalModifiedKey() as it was already called
                 * when an element was pushed on the list. */
            }

            /* Free this item. */
            decrRefCount(rl->key);
            zfree(rl);
            listDelNode(l,ln);
        }
        listRelease(l); /* We have the new list on place at this point. */
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0xb40b6(%rip), %rax     # 0xf98a8
movq 0x928(%rax), %r14
cmpq $0x0, 0x28(%r14)
je 0x45989
movq %rax, %rbx
callq 0x26e0c
movq %rax, 0x928(%rbx)
movq %r14, 0x10(%rsp)
cmpq $0x0, 0x28(%r14)
je 0x4597c
movq (%r14), %rbx
movq 0x10(%rbx), %r15
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq 0x18(%rax), %rdi
callq 0x2a6dc
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x3aec2
testq %rax, %rax
je 0x4595b
movl (%rax), %ecx
andl $0xf, %ecx
cmpl $0x1, %ecx
jne 0x4595b
movq %rax, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq 0x10(%rax), %rdi
callq 0x2a5f9
testq %rax, %rax
je 0x45936
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movl 0x28(%rax), %r12d
subl $0x1, %r12d
jb 0x45936
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r14
movq 0x50(%r14), %rax
pushq $0x1
popq %rbp
testq %rax, %rax
movq 0x8(%rsp), %rdi
je 0x458c5
xorl %ebp, %ebp
leaq 0xdb(%rip), %rcx        # 0x45998
cmpq %rcx, 0x8(%rax)
setne %bpl
movq 0x180(%r14), %r13
movl %ebp, %esi
callq 0x44201
testq %rax, %rax
je 0x45936
movq %rax, %rbx
testq %r13, %r13
je 0x458e8
movq %r13, %rdi
callq 0x39e74
movq %r14, %rdi
callq 0x70160
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %r13, %rdx
movq %rbx, %r8
movl %ebp, %r9d
callq 0x45675
cmpl $-0x1, %eax
jne 0x4591c
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq 0x4414c
testq %r13, %r13
je 0x45929
movq %r13, %rdi
callq 0x3a265
movq %rbx, %rdi
callq 0x3a265
jmp 0x4588d
movq 0x8(%rsp), %rdi
callq 0x4427e
testq %rax, %rax
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
jne 0x4595b
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x3b1df
movq 0x8(%r15), %rdi
callq 0x3a265
movq %r15, %rdi
callq 0x328f9
movq %r14, %rdi
movq %rbx, %rsi
callq 0x26fa8
jmp 0x45818
movq %r14, %rdi
callq 0x26e2a
jmp 0x457eb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq