// File: /workspace/github_c_makefile_star2_O3/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 0x8fac4(%rip), %r15     # 0xca800
movq 0x50(%r15), %rdx
callq 0x317a6
testq %rax, %rax
je 0x3ad61
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
movl $0x1, %edx
callq 0x30bbf
testl %eax, %eax
je 0x3ad6b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x39979
testq %rax, %rax
je 0x3ae5d
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
callq 0x31724
movq %rax, %r12
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
testq %r12, %r12
je 0x3adb1
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x30bbf
testl %eax, %eax
jne 0x3ad61
movq %r14, %rdi
movl $0x1, %esi
callq 0x3988d
movq %rax, %r13
movq %r15, %rdi
callq 0x306f3
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x3ac9c
movq %r13, %rdi
callq 0x30b0c
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x59525(%rip), %rsi     # 0x9431a
movl $0x10, %edi
movq %r15, %rdx
callq 0x60371
movq %r14, %rdi
callq 0x39979
testq %rax, %rax
jne 0x3ae36
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x31a36
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x596b4(%rip), %rsi     # 0x944dd
movl $0x4, %edi
movq %r15, %rdx
callq 0x60371
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x319b8
movq %r15, %rdi
callq 0x30b0c
leaq 0x8f157(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x3ad61
movq 0x50(%r15), %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2d97c