// File: /workspace/github_c_makefile_star2_O3/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 0x60858
testl %eax, %eax
jne 0x3b5b8
movl 0x30(%rbx), %edx
cmpl $0x3, %edx
jl 0x3b469
movl $0x1, %r13d
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x31724
testq %rax, %rax
je 0x3b459
movq %rax, %r14
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x3b49e
movq %r14, %rdi
callq 0x39979
testq %rax, %rax
jne 0x3b4b6
incq %r13
movslq 0x30(%rbx), %rdx
leaq -0x1(%rdx), %rax
cmpq %rax, %r13
jl 0x3b429
testb $0x8, 0x90(%rbx)
jne 0x3b491
movq 0x38(%rbx), %rsi
addq $0x8, %rsi
addl $-0x2, %edx
movq (%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x3ae72
jmp 0x3b5b8
leaq 0x8f368(%rip), %rax     # 0xca800
movq 0x58(%rax), %rsi
jmp 0x3b4a9
leaq 0x8f35b(%rip), %rax     # 0xca800
movq 0x70(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
jmp 0x3b5b8
movq %r14, %rdi
movl %ebp, %esi
callq 0x3988d
testq %rax, %rax
je 0x3b5c7
movq %rax, %r12
testl %ebp, %ebp
leaq 0x58e5d(%rip), %rax     # 0x94332
leaq 0x58e3e(%rip), %r15     # 0x9431a
cmoveq %rax, %r15
movl $0x2, %esi
movq %rbx, %rdi
callq 0x2e168
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdi
callq 0x2e204
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2e204
movq %r12, %rdi
callq 0x30b0c
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
movl $0x10, %edi
movq %r15, %rsi
callq 0x60371
movq %r14, %rdi
callq 0x39979
testq %rax, %rax
jne 0x3b56a
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x31a36
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
leaq 0x58f7d(%rip), %rsi     # 0x944dd
movl $0x4, %edi
callq 0x60371
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x319b8
leaq 0x8ea1d(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
leaq 0x8f267(%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 0x2f870
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5db12(%rip), %rdi     # 0x990e0
leaq 0x5d9d9(%rip), %rsi     # 0x98fae
movl $0x5f8, %edx            # imm = 0x5F8
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0