// File: /workspace/github_c_makefile_star2_O3/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 0x551b6
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x31724
testq %rax, %rax
je 0x551ed
leaq 0x75656(%rip), %rax     # 0xca800
movq 0xe0(%rax), %rsi
jmp 0x55311
movq 0x38(%rbx), %r12
movl $0x4, %r13d
leaq 0x47e82(%rip), %r14     # 0x9d049
movq (%r12,%r13,8), %rax
movq 0x8(%rax), %rdi
movq %r14, %rsi
callq 0x1f2e0
testl %eax, %eax
jne 0x55303
incq %r13
cmpq %r13, %r15
jne 0x551c7
cmpl $0x4, %r15d
jle 0x5518d
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x31355
testl %eax, %eax
jne 0x55347
cmpq $0x0, 0x8(%rsp)
js 0x55326
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rdi
movslq -0x8(%rdi), %rsi
callq 0x550ba
cmpl $-0x1, %eax
je 0x55338
movq 0x38(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rsi
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x588b3
movq %r14, %rdi
callq 0x37035
cmpl $-0x1, %eax
je 0x5532f
leaq 0x10(%rsp), %rsi
movl %eax, %edi
callq 0x37998
testq %rax, %rax
je 0x5532f
movq %rax, %r14
cmpl $0x5, %r15d
jl 0x5528f
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x31a36
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
movq %r14, %rdx
callq 0x317f0
cmpq $0x0, 0x8(%rsp)
je 0x552cf
movq 0x8(%rbx), %r14
movq 0x38(%rbx), %rax
movq 0x8(%rax), %r15
callq 0x23461
addq 0x8(%rsp), %rax
movq %r14, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x32a5e
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x319b8
leaq 0x75519(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
leaq 0x74cae(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
jmp 0x55347
leaq 0x754f6(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x2d97c
leaq 0x47d24(%rip), %rsi     # 0x9d051
jmp 0x5533f
leaq 0x47d66(%rip), %rsi     # 0x9d09c
jmp 0x5533f
leaq 0x47d32(%rip), %rsi     # 0x9d071
movq %rbx, %rdi
callq 0x2dc63
addq $0x60, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq