// File: /workspace/github_c_makefile_star2_O2/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 0x8f49e(%rip), %r15     # 0xc7800
movq 0x50(%r15), %rdx
callq 0x2f9d9
testq %rax, %rax
je 0x38385
movq %rax, %r14
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2eec6
testl %eax, %eax
je 0x3838f
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq %r14, %rdi
callq 0x3700e
testq %rax, %rax
je 0x38479
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
callq 0x2f988
movq %rax, %r12
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
testq %r12, %r12
je 0x383d3
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2eec6
testl %eax, %eax
jne 0x38385
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x36f24
movq %rax, %r13
movq %r15, %rdi
callq 0x2eacc
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0x382c4
movq %r13, %rdi
callq 0x2ee1f
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x51ec5(%rip), %rsi     # 0x8a2da
pushq $0x10
popq %rdi
movq %r15, %rdx
callq 0x5b488
movq %r14, %rdi
callq 0x3700e
testq %rax, %rax
jne 0x38452
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x2fc3b
movq 0x8(%rbx), %rax
movl 0x30(%rax), %ecx
leaq 0x52056(%rip), %rsi     # 0x8a49d
pushq $0x4
popq %rdi
movq %r15, %rdx
callq 0x5b488
movq 0x8(%rbx), %rdi
movq %r15, %rsi
callq 0x2fbc0
movq %r15, %rdi
callq 0x2ee1f
leaq 0x8eb3b(%rip), %rax     # 0xc6fa8
incq 0x560(%rax)
jmp 0x38385
movq 0x50(%r15), %rsi
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2c10d