// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0xb5598(%rip), %rbx     # 0x106858
movq 0x918(%rbx), %r14
cmpq $0x0, 0x28(%r14)
je 0x51486
leaq 0x28(%r14), %r12
callq 0x2e33c
movq %rax, 0x918(%rbx)
cmpq $0x0, 0x28(%r14)
je 0x51461
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 0x31dba
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x44f66
testq %rax, %rax
je 0x5143a
movl (%rax), %ecx
andl $0xf, %ecx
cmpl $0x1, %ecx
jne 0x5143a
movq %rax, (%rsp)
movq %rbx, 0x18(%rsp)
movq (%r15), %rax
movq 0x8(%r15), %rsi
movq 0x10(%rax), %rdi
callq 0x31cca
testq %rax, %rax
je 0x51411
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movl 0x28(%rax), %r12d
incl %r12d
decl %r12d
je 0x51411
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rax), %r14
movq 0x50(%r14), %rax
testq %rax, %rax
je 0x51394
xorl %ebp, %ebp
leaq 0x10b(%rip), %rcx       # 0x51495
cmpq %rcx, 0x8(%rax)
setne %bpl
jmp 0x51399
movl $0x1, %ebp
movq (%rsp), %rdi
movq 0x180(%r14), %rbx
movl %ebp, %esi
callq 0x4fb96
testq %rax, %rax
je 0x51411
movq %rax, %r13
testq %rbx, %rbx
je 0x513c0
movq %rbx, %rdi
callq 0x43c0c
movq %r14, %rdi
callq 0x806f2
movq (%r15), %rcx
movq 0x8(%r15), %rsi
movq %r14, %rdi
movq %rbx, %rdx
movq %r13, %r8
movl %ebp, %r9d
callq 0x5112f
cmpl $-0x1, %eax
jne 0x513f3
movq (%rsp), %rdi
movq %r13, %rsi
movl %ebp, %edx
callq 0x4faf0
testq %rbx, %rbx
je 0x51400
movq %rbx, %rdi
callq 0x440f3
movq %r13, %rdi
callq 0x440f3
testq %r13, %r13
jne 0x51363
movq (%rsp), %rdi
callq 0x4fc1c
testq %rax, %rax
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r12
movq 0x18(%rsp), %rbx
jne 0x5143a
movq (%r15), %rdi
movq 0x8(%r15), %rsi
callq 0x452f3
movq 0x8(%r15), %rdi
callq 0x440f3
movq %r15, %rdi
callq 0x3b3df
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e4f4
cmpq $0x0, (%r12)
jne 0x512f7
movq %r14, %rdi
callq 0x2e360
leaq 0xb53e8(%rip), %rbx     # 0x106858
movq 0x918(%rbx), %r14
leaq 0x28(%r14), %r12
cmpq $0x0, 0x28(%r14)
jne 0x512d6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq