// File: /workspace/github_c_makefile_star2_O3/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 0x974c7(%rip), %rbp     # 0xc9fa8
cmpl $0x0, 0x7bc(%rbp)
je 0x32b07
leaq 0x64bda(%rip), %rsi     # 0x976cb
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2dc63
movq 0x8(%rbx), %rax
movq 0x38(%rbx), %r13
movq %rax, (%rsp)
movl 0x30(%rax), %r14d
movq 0x10(%r13), %rax
movq 0x8(%rax), %rdi
callq 0x1f710
testl %eax, %eax
js 0x32bc7
cmpl %eax, 0x480(%rbp)
jle 0x32bc7
movq 0x10(%rbp), %rcx
movl %eax, %r15d
shlq $0x6, %r15
addq %rcx, %r15
movq %r15, 0x8(%rbx)
movq %r15, %r12
testl %r14d, %r14d
js 0x32b6c
movq %r15, %r12
cmpl %r14d, 0x480(%rbp)
jle 0x32b6c
shlq $0x6, %r14
addq %r14, %rcx
movq %rcx, 0x8(%rbx)
movq %rcx, %r12
movq (%rsp), %r14
cmpq %r15, %r14
je 0x32bd7
movq 0x8(%r13), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x31673
movq %r12, %rdi
movq %r13, %rsi
callq 0x315f8
testq %rax, %rax
je 0x32bba
movq %rax, %r12
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x31673
movq %r15, %rdi
movq %r13, %rsi
callq 0x315f8
testq %rax, %rax
je 0x32be7
leaq 0x97c3f(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
jmp 0x32c24
leaq 0x97c32(%rip), %rax     # 0xca800
movq 0x90(%rax), %rsi
jmp 0x32c24
leaq 0x97c22(%rip), %rax     # 0xca800
movq 0x88(%rax), %rsi
jmp 0x32c24
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x317f0
movq %r12, %rdi
callq 0x306f3
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0x31a36
incq 0x560(%rbp)
leaq 0x97be0(%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 0x2d97c