// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/db.c
// Function: moveCommand
void moveCommand(redisClient *c) {
    robj *o;
    redisDb *src, *dst;
    int srcid;

    if (server.cluster_enabled) {
        addReplyError(c,"MOVE is not allowed in cluster mode");
        return;
    }

    /* Obtain source and target DB pointers */
    // 源数据库
    src = c->db;
    // 源数据库的 id
    srcid = c->db->id;

    // 切换到目标数据库
    if (selectDb(c,atoi(c->argv[2]->ptr)) == REDIS_ERR) {
        addReply(c,shared.outofrangeerr);
        return;
    }

    // 目标数据库
    dst = c->db;

    // 切换回源数据库
    selectDb(c,srcid); /* Back to the source DB */

    /* If the user is moving using as target the same
     * DB as the source DB it is probably an error. */
    // 如果源数据库和目标数据库相等，那么返回错误
    if (src == dst) {
        addReply(c,shared.sameobjecterr);
        return;
    }

    /* Check if the element exists and get a reference */
    // 取出要移动的对象
    o = lookupKeyWrite(c->db,c->argv[1]);
    if (!o) {
        addReply(c,shared.czero);
        return;
    }

    /* Return zero if the key already exists in the target DB */
    // 如果键已经存在于目标数据库，那么返回
    if (lookupKeyWrite(dst,c->argv[1]) != NULL) {
        addReply(c,shared.czero);
        return;
    }

    // 将键添加到目标数据库中
    dbAdd(dst,c->argv[1],o);
    // 增加对对象的引用计数，避免接下来在源数据库中删除时 o 被清理
    incrRefCount(o);

    /* OK! key moved, free the entry in the source DB */
    // 将键从源数据库中返回
    dbDelete(src,c->argv[1]);

    server.dirty++;

    addReply(c,shared.cone);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
leaq 0x977f3(%rip), %rbp     # 0xc9fa8
cmpl $0x0, 0x7bc(%rbp)
je 0x327db
leaq 0x64e94(%rip), %rsi     # 0x97659
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d9d7
movq 0x8(%rbx), %r14
movq 0x38(%rbx), %r13
movl 0x30(%r14), %r12d
movq 0x10(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1f710
testl %eax, %eax
js 0x3288c
cmpl %eax, 0x480(%rbp)
jle 0x3288c
movl %eax, %r15d
shlq $0x6, %r15
addq 0x10(%rbp), %r15
movq %r15, 0x8(%rbx)
testl %r12d, %r12d
js 0x32831
cmpl %r12d, 0x480(%rbp)
jle 0x32831
shlq $0x6, %r12
addq 0x10(%rbp), %r12
movq %r12, 0x8(%rbx)
cmpq %r15, %r14
je 0x3289c
movq 0x8(%rbx), %r12
movq 0x8(%r13), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x313a3
movq %r12, %rdi
movq %r13, %rsi
callq 0x31328
testq %rax, %rax
je 0x3287f
movq %rax, %r12
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x313a3
movq %r15, %rdi
movq %r13, %rsi
callq 0x31328
testq %rax, %rax
je 0x328ac
leaq 0x97f7a(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
jmp 0x328e9
leaq 0x97f6d(%rip), %rax     # 0xca800
movq 0x90(%rax), %rsi
jmp 0x328e9
leaq 0x97f5d(%rip), %rax     # 0xca800
movq 0x88(%rax), %rsi
jmp 0x328e9
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x314ef
movq %r12, %rdi
callq 0x3041b
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0x3174b
incq 0x560(%rbp)
leaq 0x97f1b(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d6f0