// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x60, %rsp
movq %rdi, %rbx
movslq 0x30(%rdi), %r15
cmpq $0x5, %r15
jge 0x5574c
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x31454
testq %rax, %rax
je 0x55783
leaq 0x750c0(%rip), %rax     # 0xca800
movq 0xe0(%rax), %rsi
jmp 0x558a7
movq 0x38(%rbx), %r12
movl $0x4, %r13d
leaq 0x478ac(%rip), %r14     # 0x9d009
movq (%r12,%r13,8), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0x1f2e0
testl %eax, %eax
jne 0x55899
incq %r13
cmpq %r13, %r15
jne 0x5575d
cmpl $0x4, %r15d
jle 0x55723
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31082
testl %eax, %eax
jne 0x558dd
cmpq $0x0, 0x8(%rsp)
js 0x558bc
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
movslq -0x8(%rdi), %rsi
callq 0x55650
cmpl $-0x1, %eax
je 0x558ce
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x58e45
movq %r14, %rdi
callq 0x36df9
cmpl $-0x1, %eax
je 0x558c5
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x377d0
testq %rax, %rax
je 0x558c5
movq %rax, %r14
cmpl $0x5, %r15d
jl 0x55825
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x3174b
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x314ef
cmpq $0x0, 0x8(%rsp)
je 0x55865
movq 0x8(%rbx), %r14
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
callq 0x232a3
addq 0x8(%rsp), %rax
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x32732
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x316b7
leaq 0x74f83(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
leaq 0x74718(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x558dd
leaq 0x74f60(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2d6f0
leaq 0x4774e(%rip), %rsi     # 0x9d011
jmp 0x558d5
leaq 0x47790(%rip), %rsi     # 0x9d05c
jmp 0x558d5
leaq 0x4775c(%rip), %rsi     # 0x9d031
movq %rbx, %rdi
callq 0x2d9d7
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq