// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/t_list.c
// Function: rpoplpushCommand
void rpoplpushCommand(redisClient *c) {
    robj *sobj, *value;
    
    // 来源列表
    if ((sobj = lookupKeyWriteOrReply(c,c->argv[1],shared.nullbulk)) == NULL ||
        checkType(c,sobj,REDIS_LIST)) return;

    // 空列表，没有元素可 pop ，直接返回
    if (listTypeLength(sobj) == 0) {
        /* This may only happen after loading very old RDB files. Recent
         * versions of Redis delete keys of empty lists. */
        addReply(c,shared.nullbulk);

    // 源列表非空
    } else {

        // 目标对象
        robj *dobj = lookupKeyWrite(c->db,c->argv[2]);
        robj *touchedkey = c->argv[1];

        // 检查目标对象是否列表
        if (dobj && checkType(c,dobj,REDIS_LIST)) return;
        // 从源列表中弹出值
        value = listTypePop(sobj,REDIS_TAIL);
        /* We saved touched key, and protect it, since rpoplpushHandlePush
         * may change the client command argument vector (it does not
         * currently). */
        incrRefCount(touchedkey);
        // 将值推入目标列表中，如果目标列表不存在，那么创建一个新列表
        rpoplpushHandlePush(c,c->argv[2],dobj,value);

        /* listTypePop returns an object with its refcount incremented */
        decrRefCount(value);

        /* Delete the source list when it is empty */
        notifyKeyspaceEvent(REDIS_NOTIFY_LIST,"rpop",touchedkey,c->db->id);

        // 如果源列表已经为空，那么将它删除
        if (listTypeLength(sobj) == 0) {
            dbDelete(c->db,touchedkey);
            notifyKeyspaceEvent(REDIS_NOTIFY_GENERIC,"del",
                                touchedkey,c->db->id);
        }

        signalModifiedKey(c->db,touchedkey);

        decrRefCount(touchedkey);

        server.dirty++;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x8(%rax), %rsi
leaq 0x8fb20(%rip), %r15     # 0xca800
movq 0x50(%r15), %rdx
callq 0x314a5
testq %rax, %rax
je 0x3ad05
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x308e7
testl %eax, %eax
je 0x3ad0f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x398e9
testq %rax, %rax
je 0x3ae01
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
callq 0x31454
movq %rax, %r12
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
testq %r12, %r12
je 0x3ad55
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x308e7
testl %eax, %eax
jne 0x3ad05
movq %r14, %rdi
movl $0x1, %esi
callq 0x397fd
movq %rax, %r13
movq %r15, %rdi
callq 0x3041b
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x3ac40
movq %r13, %rdi
callq 0x30834
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x59531(%rip), %rsi     # 0x942ca
movl $0x10, %edi
movq %r15, %rdx
callq 0x608b5
movq %r14, %rdi
callq 0x398e9
testq %rax, %rax
jne 0x3adda
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x3174b
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x596c0(%rip), %rsi     # 0x9448d
movl $0x4, %edi
movq %r15, %rdx
callq 0x608b5
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x316b7
movq %r15, %rdi
callq 0x30834
leaq 0x8f1b3(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x3ad05
movq 0x50(%r15), %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2d6f0