// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: serveClientBlockedOnList
int serveClientBlockedOnList(redisClient *receiver, robj *key, robj *dstkey, redisDb *db, robj *value, int where)
{
    robj *argv[3];

    // 执行的是 BLPOP 或 BRPOP
    if (dstkey == NULL) {
        /* Propagate the [LR]POP operation. */
        argv[0] = (where == REDIS_HEAD) ? shared.lpop :
                                          shared.rpop;
        argv[1] = key;
        propagate((where == REDIS_HEAD) ?
            server.lpopCommand : server.rpopCommand,
            db->id,argv,2,REDIS_PROPAGATE_AOF|REDIS_PROPAGATE_REPL);

        /* BRPOP/BLPOP */
        addReplyMultiBulkLen(receiver,2);
        addReplyBulk(receiver,key);
        addReplyBulk(receiver,value);

    // 执行的是 BRPOPLPUSH 
    } else {
        /* BRPOPLPUSH */

        // 取出目标对象
        robj *dstobj =
            lookupKeyWrite(receiver->db,dstkey);
        if (!(dstobj &&
             checkType(receiver,dstobj,REDIS_LIST)))
        {
            /* Propagate the RPOP operation. */
            // 传播 RPOP 命令
            argv[0] = shared.rpop;
            argv[1] = key;
            propagate(server.rpopCommand,
                db->id,argv,2,
                REDIS_PROPAGATE_AOF|
                REDIS_PROPAGATE_REPL);

            // 将值推入到 dstobj 中，如果 dstobj 不存在，
            // 那么新创建一个
            rpoplpushHandlePush(receiver,dstkey,dstobj,
                value);

            /* Propagate the LPUSH operation. */
            // 传播 LPUSH 命令
            argv[0] = shared.lpush;
            argv[1] = dstkey;
            argv[2] = value;
            propagate(server.lpushCommand,
                db->id,argv,3,
                REDIS_PROPAGATE_AOF|
                REDIS_PROPAGATE_REPL);
        } else {
            /* BRPOPLPUSH failed because of wrong
             * destination type. */
            return REDIS_ERR;
        }
    }
    return REDIS_OK;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, %r14
testq %rdx, %rdx
je 0x38762
movq %rdx, %r13
movq 0x8(%r14), %rdi
movq %rdx, %rsi
callq 0x2f988
movq %rax, %rbp
testq %rax, %rax
je 0x386d4
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2eec6
testl %eax, %eax
je 0x386d4
pushq $-0x1
popq %rax
jmp 0x387d9
leaq 0x8f125(%rip), %rax     # 0xc7800
movq 0x130(%rax), %rax
movq %r15, %rcx
movq %rbx, %r15
movq %rsp, %rbx
movq %rax, (%rbx)
movq %r12, 0x8(%rbx)
leaq 0x8e8af(%rip), %rax     # 0xc6fa8
movq 0x338(%rax), %rdi
movl 0x30(%rcx), %esi
movq %rcx, %r12
pushq $0x2
popq %rcx
pushq $0x3
popq %r8
movq %rbx, %rdx
callq 0x24c05
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %r15, %rcx
callq 0x382c4
leaq 0x8f0d3(%rip), %rax     # 0xc7800
movq 0x140(%rax), %rax
movq %rax, (%rbx)
movq %r13, 0x8(%rbx)
movq %r15, 0x10(%rbx)
leaq 0x8e862(%rip), %rax     # 0xc6fa8
movq 0x328(%rax), %rdi
movl 0x30(%r12), %esi
movq %rbx, %rdx
pushq $0x3
popq %rcx
movl %ecx, %r8d
callq 0x24c05
jmp 0x387d7
leaq 0x8f097(%rip), %rax     # 0xc7800
leaq 0x138(%rax), %rcx
addq $0x130, %rax            # imm = 0x130
leaq 0x8e82b(%rip), %rsi     # 0xc6fa8
leaq 0x330(%rsi), %rdi
addq $0x338, %rsi            # imm = 0x338
testl %r9d, %r9d
cmoveq %rcx, %rax
movq (%rax), %rax
movq %rsp, %rdx
movq %rax, (%rdx)
movq %r12, 0x8(%rdx)
cmoveq %rdi, %rsi
movq (%rsi), %rdi
movl 0x30(%r15), %esi
pushq $0x2
popq %rcx
pushq $0x3
popq %r8
callq 0x24c05
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x2c7c7
movq %r14, %rdi
movq %r12, %rsi
callq 0x2c84a
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2c84a
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq