// File: /workspace/github_c_makefile_star2_O3/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 0xb3d37(%rip), %rbx     # 0x1018a8
movq 0x928(%rbx), %r14
cmpq $0x0, 0x28(%r14)
je 0x4dd49
leaq 0x28(%r14), %r12
callq 0x2b17c
movq %rax, 0x928(%rbx)
cmpq $0x0, 0x28(%r14)
je 0x4dd24
movq %r14, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq (%r14), %rbx
movq 0x10(%rbx), %r15
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq 0x18(%rax), %rdi
callq 0x2ecb5
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x41ad6
testq %rax, %rax
je 0x4dcfd
movl (%rax), %ecx
andl $0xf, %ecx
cmpl $0x1, %ecx
jne 0x4dcfd
movq %rax, (%rsp)
movq %rbx, 0x18(%rsp)
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq 0x10(%rax), %rdi
callq 0x2ebca
testq %rax, %rax
je 0x4dcd4
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movl 0x28(%rax), %r12d
testl %r12d, %r12d
je 0x4dcd4
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r14
movq 0x50(%r14), %rax
testq %rax, %rax
je 0x4dc42
xorl %ebp, %ebp
leaq 0x120(%rip), %rcx       # 0x4dd58
cmpq %rcx, 0x8(%rax)
setne %bpl
jmp 0x4dc47
movl $0x1, %ebp
movq (%rsp), %rdi
movq 0x180(%r14), %rbx
movl %ebp, %esi
callq 0x4c426
testq %rax, %rax
je 0x4dcd4
movq %rax, %r13
testq %rbx, %rbx
je 0x4dc85
movq %rbx, %rdi
callq 0x407a8
movq %r14, %rdi
callq 0x7cca6
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
jmp 0x4dc99
movq %r14, %rdi
callq 0x7cca6
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq %r14, %rdi
xorl %edx, %edx
movq %r13, %r8
movl %ebp, %r9d
callq 0x4d9e0
cmpl $-0x1, %eax
jne 0x4dcb7
movq (%rsp), %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x4c380
testq %rbx, %rbx
je 0x4dcc4
movq %rbx, %rdi
callq 0x40c8f
decl %r12d
movq %r13, %rdi
callq 0x40c8f
jmp 0x4dc11
movq (%rsp), %rdi
callq 0x4c4aa
testq %rax, %rax
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
jne 0x4dcfd
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x41e5f
movq 0x8(%r15), %rdi
callq 0x40c8f
movq %r15, %rdi
callq 0x38413
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b331
cmpq $0x0, (%r12)
jne 0x4dba8
movq %r14, %rdi
callq 0x2b19c
leaq 0xb3b75(%rip), %rbx     # 0x1018a8
movq 0x928(%rbx), %r14
leaq 0x28(%r14), %r12
cmpq $0x0, 0x28(%r14)
jne 0x4db87
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq