// File: /workspace/github_c_makefile_star2_O2/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 0x5b94c
testl %eax, %eax
jne 0x38b6a
pushq $0x1
popq %r13
movslq 0x30(%rbx), %rdx
leaq -0x1(%rdx), %rax
cmpq %rax, %r13
jge 0x38a1f
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x2f988
testq %rax, %rax
je 0x38a1a
movq %rax, %r14
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x38a4b
movq %r14, %rdi
callq 0x3700e
testq %rax, %rax
jne 0x38a5b
incq %r13
jmp 0x389dd
testb $0x8, 0x90(%rbx)
jne 0x38b57
movq 0x38(%rbx), %rsi
addq $0x8, %rsi
addl $-0x2, %edx
movq (%rsp), %rcx
movq %rbx, %rdi
xorl %r8d, %r8d
callq 0x3848e
jmp 0x38b6a
leaq 0x8edae(%rip), %rax     # 0xc7800
movq 0x70(%rax), %rsi
jmp 0x38b62
movq %r14, %rdi
movl %ebp, %esi
callq 0x36f24
testq %rax, %rax
je 0x38b79
movq %rax, %r12
testl %ebp, %ebp
leaq 0x51878(%rip), %rax     # 0x8a2f2
leaq 0x51859(%rip), %r15     # 0x8a2da
cmoveq %rax, %r15
pushq $0x2
popq %rsi
movq %rbx, %rdi
callq 0x2c7c7
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
movq %rbx, %rdi
callq 0x2c84a
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2c84a
movq %r12, %rdi
callq 0x2ee1f
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
pushq $0x10
popq %rdi
movq %r15, %rsi
callq 0x5b488
movq %r14, %rdi
callq 0x3700e
testq %rax, %rax
jne 0x38b09
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x2fc3b
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %rcx
movq (%rcx,%r13,8), %rdx
movl 0x30(%rax), %ecx
leaq 0x5199c(%rip), %rsi     # 0x8a49d
pushq $0x4
popq %rdi
callq 0x5b488
xorl %r14d, %r14d
testl %ebp, %ebp
sete %r14b
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rsi
callq 0x2fbc0
leaq 0x8e47e(%rip), %rax     # 0xc6fa8
incq 0x560(%rax)
leaq 0x8ecc8(%rip), %rax     # 0xc7800
movq 0x130(%rax,%r14,8), %rdx
movq 0x38(%rbx), %rax
movq (%rax,%r13,8), %rcx
pushq $0x2
popq %rsi
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2dd2e
jmp 0x38b6a
leaq 0x8eca2(%rip), %rax     # 0xc7800
movq 0x58(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x56524(%rip), %rdi     # 0x8f0a4
leaq 0x563eb(%rip), %rsi     # 0x8ef72
movl $0x5f8, %edx            # imm = 0x5F8
callq 0x4906b
pushq $0x1
popq %rdi
callq 0x1f3b0