// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: blockingPopGenericCommand
void blockingPopGenericCommand(redisClient *c, int where) {
    robj *o;
    mstime_t timeout;
    int j;

    // 取出 timeout 参数
    if (getTimeoutFromObjectOrReply(c,c->argv[c->argc-1],&timeout,UNIT_SECONDS)
        != REDIS_OK) return;

    // 遍历所有列表键
    for (j = 1; j < c->argc-1; j++) {

        // 取出列表键
        o = lookupKeyWrite(c->db,c->argv[j]);

        // 有非空列表？
        if (o != NULL) {
            if (o->type != REDIS_LIST) {
                addReply(c,shared.wrongtypeerr);
                return;
            } else {
                // 非空列表
                if (listTypeLength(o) != 0) {
                    /* Non empty list, this is like a non normal [LR]POP. */
                    char *event = (where == REDIS_HEAD) ? "lpop" : "rpop";

                    // 弹出值
                    robj *value = listTypePop(o,where);

                    redisAssert(value != NULL);

                    // 回复客户端
                    addReplyMultiBulkLen(c,2);
                    // 回复弹出元素的列表
                    addReplyBulk(c,c->argv[j]);
                    // 回复弹出值
                    addReplyBulk(c,value);

                    decrRefCount(value);

                    notifyKeyspaceEvent(REDIS_NOTIFY_LIST,event,
                                        c->argv[j],c->db->id);

                    // 删除空列表
                    if (listTypeLength(o) == 0) {
                        dbDelete(c->db,c->argv[j]);
                        notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"del",
                                            c->argv[j],c->db->id);
                    }

                    signalModifiedKey(c->db,c->argv[j]);

                    server.dirty++;

                    /* Replicate it as an [LR]POP instead of B[LR]POP. */
                    // 传播一个 [LR]POP 而不是 B[LR]POP
                    rewriteClientCommandVector(c,2,
                        (where == REDIS_HEAD) ? shared.lpop : shared.rpop,
                        c->argv[j]);
                    return;
                }
            }
        }
    }

    /* If we are inside a MULTI/EXEC and the list is empty the only thing
     * we can do is treating it as a timeout (even with timeout 0). */
    // 如果命令在一个事务中执行，那么为了不产生死等待
    // 服务器只能向客户端发送一个空回复
    if (c->flags & REDIS_MULTI) {
        addReply(c,shared.nullmultibulk);
        return;
    }

    /* If the list is empty or the key does not exists we must block */
    // 所有输入列表键都不存在，只能阻塞了
    blockForKeys(c, c->argv + 1, c->argc - 2, timeout, NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movslq 0x30(%rdi), %rcx
movq -0x8(%rax,%rcx,8), %rsi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x60d78
testl %eax, %eax
jne 0x3b54a
movl 0x30(%rbx), %edx
cmpl $0x3, %edx
jl 0x3b3fb
movl $0x1, %r13d
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x31454
testq %rax, %rax
je 0x3b3eb
movq %rax, %r14
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x3b430
movq %r14, %rdi
callq 0x398e9
testq %rax, %rax
jne 0x3b448
incq %r13
movslq 0x30(%rbx), %rdx
leaq -0x1(%rdx), %rax
cmpq %rax, %r13
jl 0x3b3bb
testb $0x8, 0x90(%rbx)
jne 0x3b423
movq 0x38(%rbx), %rsi
addq $0x8, %rsi
addl $-0x2, %edx
movq (%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x3ae16
jmp 0x3b54a
leaq 0x8f3d6(%rip), %rax     # 0xca800
movq 0x58(%rax), %rsi
jmp 0x3b43b
leaq 0x8f3c9(%rip), %rax     # 0xca800
movq 0x70(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
jmp 0x3b54a
movq %r14, %rdi
movl %ebp, %esi
callq 0x397fd
testq %rax, %rax
je 0x3b559
movq %rax, %r12
testl %ebp, %ebp
leaq 0x58e7b(%rip), %rax     # 0x942e2
leaq 0x58e5c(%rip), %r15     # 0x942ca
cmoveq %rax, %r15
movl $0x2, %esi
movq %rbx, %rdi
callq 0x2ded8
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdi
callq 0x2df74
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2df74
movq %r12, %rdi
callq 0x30834
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
movl $0x10, %edi
movq %r15, %rsi
callq 0x608b5
movq %r14, %rdi
callq 0x398e9
testq %rax, %rax
jne 0x3b4fc
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x3174b
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
leaq 0x58f9b(%rip), %rsi     # 0x9448d
movl $0x4, %edi
callq 0x608b5
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x316b7
leaq 0x8ea8b(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
leaq 0x8f2d5(%rip), %rax     # 0xca800
movq 0x130(%rax,%r14,8), %rdx
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rcx
movq %rbx, %rdi
movl $0x2, %esi
xorl %eax, %eax
callq 0x2f581
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5db37(%rip), %rdi     # 0x99097
leaq 0x5d9fe(%rip), %rsi     # 0x98f65
movl $0x5f8, %edx            # imm = 0x5F8
callq 0x4d037
movl $0x1, %edi
callq 0x1f3b0