// File: /workspace/github_c_makefile_star2_O2/nilyang[P]redis-tdd-annotation/src/cluster.c
// Function: restoreCommand
void restoreCommand(redisClient *c) {
    long long ttl;
    rio payload;
    int j, type, replace = 0;
    robj *obj;

    /* Parse additional options */
    // 是否使用了 REPLACE 选项？
    for (j = 4; j < c->argc; j++) {
        if (!strcasecmp(c->argv[j]->ptr,"replace")) {
            replace = 1;
        } else {
            addReply(c,shared.syntaxerr);
            return;
        }
    }

    /* Make sure this key does not already exist here... */
    // 如果没有给定 REPLACE 选项，并且键已经存在，那么返回错误
    if (!replace && lookupKeyWrite(c->db,c->argv[1]) != NULL) {
        addReply(c,shared.busykeyerr);
        return;
    }

    /* Check if the TTL value makes sense */
    // 取出（可能有的） TTL 值
    if (getLongLongFromObjectOrReply(c,c->argv[2],&ttl,NULL) != REDIS_OK) {
        return;
    } else if (ttl < 0) {
        addReplyError(c,"Invalid TTL value, must be >= 0");
        return;
    }

    /* Verify RDB version and data checksum. */
    // 检查 RDB 版本和校验和
    if (verifyDumpPayload(c->argv[3]->ptr,sdslen(c->argv[3]->ptr)) == REDIS_ERR)
    {
        addReplyError(c,"DUMP payload version or checksum are wrong");
        return;
    }

    // 读取 DUMP 数据，并反序列化出键值对的类型和值
    rioInitWithBuffer(&payload,c->argv[3]->ptr);
    if (((type = rdbLoadObjectType(&payload)) == -1) ||
        ((obj = rdbLoadObject(type,&payload)) == NULL))
    {
        addReplyError(c,"Bad data format");
        return;
    }

    /* Remove the old key if needed. */
    // 如果给定了 REPLACE 选项，那么先删除数据库中已存在的同名键
    if (replace) dbDelete(c->db,c->argv[1]);

    /* Create the key and set the TTL if any */
    // 将键值对添加到数据库
    dbAdd(c->db,c->argv[1],obj);

    // 如果键带有 TTL 的话，设置键的 TTL
    if (ttl) setExpire(c->db,c->argv[1],mstime()+ttl);

    signalModifiedKey(c->db,c->argv[1]);

    addReply(c,shared.ok);
    server.dirty++;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
movslq 0x30(%rdi), %r12
movq 0x38(%rdi), %r15
movb $0x1, %bpl
pushq $0x4
popq %r13
leaq 0x42243(%rip), %r14     # 0x93009
cmpq %r12, %r13
jge 0x50df4
movq (%r15,%r13,8), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0x1f2e0
incq %r13
xorl %ebp, %ebp
testl %eax, %eax
je 0x50dc6
leaq 0x76a15(%rip), %rax     # 0xc7800
movq 0x80(%rax), %rsi
jmp 0x50e1a
testb $0x1, %bpl
je 0x50e34
movq 0x8(%rbx), %rdi
movq 0x8(%r15), %rsi
callq 0x2f988
testq %rax, %rax
je 0x50e30
leaq 0x769ed(%rip), %rax     # 0xc7800
movq 0xe0(%rax), %rsi
movq %rbx, %rdi
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c10d
movq 0x38(%rbx), %r15
movq 0x10(%r15), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x2f617
testl %eax, %eax
jne 0x50f62
cmpq $0x0, (%rsp)
js 0x50f41
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
movslq -0x8(%rdi), %rsi
callq 0x50ce8
cmpl $-0x1, %eax
je 0x50f53
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x8(%rsp), %r14
movq %r14, %rdi
callq 0x5421f
movq %r14, %rdi
callq 0x34904
cmpl $-0x1, %eax
je 0x50f4a
leaq 0x8(%rsp), %rsi
movl %eax, %edi
callq 0x3522d
testq %rax, %rax
je 0x50f4a
movq %rax, %r14
testb $0x1, %bpl
jne 0x50ecf
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x2fc3b
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x2fa09
cmpq $0x0, (%rsp)
je 0x50f0d
movq 0x8(%rbx), %r14
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
callq 0x22843
addq (%rsp), %rax
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x30b2d
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x2fbc0
leaq 0x768db(%rip), %rax     # 0xc7800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
leaq 0x76070(%rip), %rax     # 0xc6fa8
incq 0x560(%rax)
jmp 0x50f62
leaq 0x420c9(%rip), %rsi     # 0x93011
jmp 0x50f5a
leaq 0x4210b(%rip), %rsi     # 0x9305c
jmp 0x50f5a
leaq 0x420d7(%rip), %rsi     # 0x93031
movq %rbx, %rdi
callq 0x2c2da
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq