LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: scanCallback
void scanCallback(void *privdata, const dictEntry *de) {
    void **pd = (void**) privdata;
    list *keys = pd[0];
    robj *o = pd[1];
    robj *key, *val = NULL;

    if (o == NULL) {
        sds sdskey = dictGetKey(de);
        key = createStringObject(sdskey, sdslen(sdskey));
    } else if (o->type == REDIS_SET) {
        key = dictGetKey(de);
        incrRefCount(key);
    } else if (o->type == REDIS_HASH) {
        key = dictGetKey(de);
        incrRefCount(key);
        val = dictGetVal(de);
        incrRefCount(val);
    } else if (o->type == REDIS_ZSET) {
        key = dictGetKey(de);
        incrRefCount(key);
        val = createStringObjectFromLongDouble(*(double*)dictGetVal(de));
    } else {
        redisPanic("Type not handled in SCAN callback.");
    }

    listAddNodeTail(keys, key);
    if (val) listAddNodeTail(keys, val);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq (%rdi), %rbx
movq 0x8(%rdi), %rax
testq %rax, %rax
je 0x3206a
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
je 0x32099
cmpl $0x3, %eax
je 0x3207b
cmpl $0x2, %eax
jne 0x320de
movq (%r14), %r14
movq %r14, %rdi
callq 0x306f3
jmp 0x320c0
movq (%r14), %rdi
movslq -0x8(%rdi), %rsi
callq 0x3068f
movq %rax, %r14
jmp 0x320c0
movq (%r14), %r15
movq %r15, %rdi
callq 0x306f3
movq 0x8(%r14), %rax
fldl (%rax)
fstpt (%rsp)
callq 0x306f7
movq %rax, %r14
jmp 0x320b0
movq (%r14), %r15
movq %r15, %rdi
callq 0x306f3
movq 0x8(%r14), %r14
movq %r14, %rdi
callq 0x306f3
movq %rbx, %rdi
movq %r15, %rsi
callq 0x204cb
testq %r14, %r14
je 0x320d4
movq %rbx, %rdi
movq %r14, %rsi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x204cb
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x654b5(%rip), %rdi     # 0x9759a
leaq 0x669ad(%rip), %rsi     # 0x98a99
movl $0x267, %edx            # imm = 0x267
callq 0x4cae0
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: parseScanCursorOrReply
int parseScanCursorOrReply(redisClient *c, robj *o, unsigned long *cursor) {
    char *eptr;

    /* Use strtoul() because we need an *unsigned* long, so
     * getLongLongFromObject() does not cover the whole cursor space. */
    errno = 0;
    *cursor = strtoul(o->ptr, &eptr, 10);
    if (isspace(((char*)o->ptr)[0]) || eptr[0] != '\0' || errno == ERANGE)
    {
        addReplyError(c, "invalid cursor");
        return REDIS_ERR;
    }
    return REDIS_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
callq 0x1f810
movq %rax, %r14
movl $0x0, (%rax)
movq 0x8(%r12), %rdi
movq %rsp, %rsi
movl $0xa, %edx
callq 0x1fba0
movq %rax, (%r15)
callq 0x1f550
movq (%rax), %rax
movq 0x8(%r12), %rcx
movsbq (%rcx), %rcx
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x3215d
movq (%rsp), %rax
cmpb $0x0, (%rax)
jne 0x3215d
xorl %eax, %eax
cmpl $0x22, (%r14)
jne 0x32171
leaq 0x6545b(%rip), %rsi     # 0x975bf
movq %rbx, %rdi
callq 0x2dc63
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: typeCommand
void typeCommand(redisClient *c) {
    robj *o;
    char *type;

    o = lookupKeyRead(c->db,c->argv[1]);

    if (o == NULL) {
        type = "none";
    } else {
        switch(o->type) {
        case REDIS_STRING: type = "string"; break;
        case REDIS_LIST: type = "list"; break;
        case REDIS_SET: type = "set"; break;
        case REDIS_ZSET: type = "zset"; break;
        case REDIS_HASH: type = "hash"; break;
        default: type = "unknown"; break;
        }
    }

    addReplyStatus(c,type);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x31673
movq %r14, %rdi
movq %r15, %rsi
callq 0x315f8
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leaq 0x97884(%rip), %rdx     # 0xc9fa8
incq 0x368(%rdx,%rcx,8)
testq %rax, %rax
je 0x3274b
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
ja 0x32754
leaq 0x64ffa(%rip), %rcx     # 0x9773c
movslq (%rcx,%rax,4), %rsi
addq %rcx, %rsi
jmp 0x3275b
leaq 0x64f26(%rip), %rsi     # 0x97678
jmp 0x3275b
leaq 0x64d93(%rip), %rsi     # 0x974ee
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x2ddb7
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: shutdownCommand
void shutdownCommand(redisClient *c) {
    int flags = 0;

    if (c->argc > 2) {
        addReply(c,shared.syntaxerr);
        return;
    } else if (c->argc == 2) {

        // 停机时不进行保存
        if (!strcasecmp(c->argv[1]->ptr,"nosave")) {
            flags |= REDIS_SHUTDOWN_NOSAVE;

        // 停机时进行保存
        } else if (!strcasecmp(c->argv[1]->ptr,"save")) {
            flags |= REDIS_SHUTDOWN_SAVE;

        } else {
            addReply(c,shared.syntaxerr);
            return;
        }
    }

    /* When SHUTDOWN is called while the server is loading a dataset in
     * memory we need to make sure no attempt is performed to save
     * the dataset on shutdown (otherwise it could overwrite the current DB
     * with half-read data).
     *
     * Also when in Sentinel mode clear the SAVE flag and force NOSAVE. */
    if (server.loading || server.sentinel_mode)
        flags = (flags & ~REDIS_SHUTDOWN_SAVE) | REDIS_SHUTDOWN_NOSAVE;

    if (prepareForShutdown(flags) == REDIS_OK) exit(0);

    addReplyError(c,"Errors trying to SHUTDOWN. Check logs.");
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x30(%rdi), %ecx
cmpl $0x3, %ecx
jl 0x32794
leaq 0x98082(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2d97c
xorl %eax, %eax
cmpl $0x2, %ecx
jne 0x327d9
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %r14
leaq 0x64ed9(%rip), %rsi     # 0x97687
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
je 0x327d4
leaq 0x6546c(%rip), %rsi     # 0x97c2d
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x32777
movl $0x1, %eax
jmp 0x327d9
movl $0x2, %eax
leaq 0x977c8(%rip), %rcx     # 0xc9fa8
movl 0x84(%rcx), %edx
orl 0x2f0(%rcx), %edx
movl $0x2, %edi
cmovel %eax, %edi
xorl %eax, %eax
callq 0x26885
testl %eax, %eax
je 0x32815
leaq 0x64e88(%rip), %rsi     # 0x9768e
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2dc63
xorl %edi, %edi
callq 0x1f2b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: getExpire
long long getExpire(redisDb *db, robj *key) {
    dictEntry *de;

    /* No expire? return ASAP */
    // 获取键的过期时间
    // 如果过期时间不存在，那么直接返回
    if (dictSize(db->expires) == 0 ||
       (de = dictFind(db->expires,key->ptr)) == NULL) return -1;

    /* The entry was found in the expire dict, this means it should also
     * be present in the main dict (safety check). */
    redisAssertWithInfo(NULL,key,dictFind(db->dict,key->ptr) != NULL);

    // 返回过期时间
    return dictGetSignedIntegerVal(de);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
movq 0x8(%rdi), %rdi
movq 0x28(%rdi), %rax
movq $-0x1, %r14
addq 0x48(%rdi), %rax
je 0x32a27
movq %rsi, %rbx
movq 0x8(%rsi), %rsi
callq 0x226ac
testq %rax, %rax
je 0x32a27
movq %rax, %r12
movq (%r15), %rdi
movq 0x8(%rbx), %rsi
callq 0x226ac
testq %rax, %rax
je 0x32a36
movq 0x8(%r12), %r14
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x64cb2(%rip), %rdx     # 0x976ef
leaq 0x66055(%rip), %rcx     # 0x98a99
xorl %edi, %edi
movq %rbx, %rsi
movl $0x465, %r8d            # imm = 0x465
callq 0x4d277
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: setExpire
void setExpire(redisDb *db, robj *key, long long when) {

    dictEntry *kde, *de;

    /* Reuse the sds from the main dict in the expire dict */
    // 取出键
    kde = dictFind(db->dict,key->ptr);

    redisAssertWithInfo(NULL,key,kde != NULL);

    // 根据键取出键的过期时间
    de = dictReplaceRaw(db->expires,dictGetKey(kde));

    // 设置键的过期时间
    // 这里是直接使用整数值来保存过期时间，不是用 INT 编码的 String 对象
    dictSetSignedIntegerVal(de,when);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdi), %rdi
movq 0x8(%rsi), %rsi
callq 0x226ac
testq %rax, %rax
je 0x32a93
movq 0x8(%r15), %rdi
movq (%rax), %rsi
callq 0x22768
movq %rbx, 0x8(%rax)
popq %rbx
popq %r14
popq %r15
retq
leaq 0x64c79(%rip), %rdx     # 0x97713
leaq 0x65ff8(%rip), %rcx     # 0x98a99
xorl %edi, %edi
movq %r14, %rsi
movl $0x449, %r8d            # imm = 0x449
callq 0x4d277
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: propagateExpire
void propagateExpire(redisDb *db, robj *key) {
    robj *argv[2];

    // 构造一个 DEL key 命令
    argv[0] = shared.del;
    argv[1] = key;
    incrRefCount(argv[0]);
    incrRefCount(argv[1]);

    // 传播到 AOF 
    if (server.aof_state != REDIS_AOF_OFF)
        feedAppendOnlyFile(server.delCommand,db->id,argv,2);

    // 传播到所有附属节点
    replicationFeedSlaves(server.slaves,db->id,argv,2);

    decrRefCount(argv[0]);
    decrRefCount(argv[1]);
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x97bb2(%rip), %rax     # 0xca800
movq 0x128(%rax), %rdi
movq %rdi, (%rsp)
movq %rsi, 0x8(%rsp)
callq 0x306f3
movq %r14, %rdi
callq 0x306f3
leaq 0x97336(%rip), %r14     # 0xc9fa8
cmpl $0x0, 0x4d0(%r14)
je 0x32c93
movq 0x318(%r14), %rdi
movl 0x30(%rbx), %esi
movq %rsp, %rdx
movl $0x2, %ecx
callq 0x498f0
movq 0x1c0(%r14), %rdi
movl 0x30(%rbx), %esi
movq %rsp, %rbx
movq %rbx, %rdx
movl $0x2, %ecx
callq 0x33795
movq (%rbx), %rdi
callq 0x30b0c
movq 0x8(%rbx), %rdi
callq 0x30b0c
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: ttlGenericCommand
void ttlGenericCommand(redisClient *c, int output_ms) {
    long long expire, ttl = -1;

    /* If the key does not exist at all, return -2 */
    // 取出键
    if (lookupKeyRead(c->db,c->argv[1]) == NULL) {
        addReplyLongLong(c,-2);
        return;
    }

    /* The key exists. Return -1 if it has no expire, or the actual
     * TTL value otherwise. */
    // 取出过期时间
    expire = getExpire(c->db,c->argv[1]);

    if (expire != -1) {
        // 计算剩余生存时间
        ttl = expire-mstime();
        if (ttl < 0) ttl = 0;
    }

    if (ttl == -1) {
        // 键是持久的
        addReplyLongLong(c,-1);
    } else {
        // 返回 TTL 
        // (ttl+500)/1000 计算的是渐近秒数
        addReplyLongLong(c,output_ms ? ttl : ((ttl+500)/1000));
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebp
movq %rdi, %rbx
movq 0x8(%rdi), %r14
movq 0x38(%rdi), %rax
movq 0x8(%rax), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x31673
movq %r14, %rdi
movq %r15, %rsi
callq 0x315f8
xorl %ecx, %ecx
testq %rax, %rax
sete %cl
leaq 0x9708f(%rip), %rdx     # 0xc9fa8
incq 0x368(%rdx,%rcx,8)
testq %rax, %rax
je 0x32f79
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x329dd
cmpq $-0x1, %rax
je 0x32f82
movq %rax, %r14
callq 0x23461
subq %rax, %r14
xorl %esi, %esi
testq %r14, %r14
cmovgq %r14, %rsi
testl %ebp, %ebp
jne 0x32f89
addq $0x1f4, %rsi            # imm = 0x1F4
shrq $0x3, %rsi
movabsq $0x20c49ba5e353f7cf, %rcx # imm = 0x20C49BA5E353F7CF
movq %rsi, %rax
mulq %rcx
movq %rdx, %rsi
shrq $0x4, %rsi
jmp 0x32f89
movq $-0x2, %rsi
jmp 0x32f89
movq $-0x1, %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2e133
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: persistCommand
void persistCommand(redisClient *c) {
    dictEntry *de;

    // 取出键
    de = dictFind(c->db->dict,c->argv[1]->ptr);

    if (de == NULL) {
        // 键没有过期时间
        addReply(c,shared.czero);

    } else {

        // 键带有过期时间，那么将它移除
        if (removeExpire(c->db,c->argv[1])) {
            addReply(c,shared.cone);
            server.dirty++;

        // 键已经是持久的了
        } else {
            addReply(c,shared.czero);
        }
    }
}

// Assembly:
pushq %rbx
movq %rdi, %rbx
movq 0x8(%rdi), %rax
movq 0x38(%rdi), %rcx
movq (%rax), %rdi
movq 0x8(%rcx), %rax
movq 0x8(%rax), %rsi
callq 0x226ac
testq %rax, %rax
je 0x33005
movq 0x8(%rbx), %rdi
movq 0x38(%rbx), %rax
movq 0x8(%rax), %rsi
callq 0x31957
testl %eax, %eax
je 0x33005
leaq 0x97817(%rip), %rax     # 0xca800
movq 0x28(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
leaq 0x96fac(%rip), %rax     # 0xc9fa8
incq 0x560(%rax)
popq %rbx
retq
leaq 0x977f4(%rip), %rax     # 0xca800
movq 0x20(%rax), %rsi
movq %rbx, %rdi
popq %rbx
jmp 0x2d97c
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/db.c
// Function: getKeysUsingCommandTable
int *getKeysUsingCommandTable(struct redisCommand *cmd,robj **argv, int argc, int *numkeys) {
    int j, i = 0, last, *keys;
    REDIS_NOTUSED(argv);

    if (cmd->firstkey == 0) {
        *numkeys = 0;
        return NULL;
    }
    last = cmd->lastkey;
    if (last < 0) last = argc+last;
    keys = zmalloc(sizeof(int)*((last - cmd->firstkey)+1));
    for (j = cmd->firstkey; j <= last; j += cmd->keystep) {
        redisAssert(j < argc);
        keys[i++] = j;
    }
    *numkeys = i;
    return keys;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rcx, %rbx
movl 0x30(%rdi), %eax
xorl %r15d, %r15d
testl %eax, %eax
je 0x33078
movl %edx, %ebp
movq %rdi, %r14
movl 0x34(%rdi), %ecx
movl %ecx, %r12d
sarl $0x1f, %r12d
andl %edx, %r12d
addl %ecx, %r12d
movl %r12d, %ecx
subl %eax, %ecx
incl %ecx
movslq %ecx, %rdi
shlq $0x2, %rdi
callq 0x299b5
movl 0x30(%r14), %ecx
cmpl %r12d, %ecx
jg 0x3307a
xorl %r15d, %r15d
cmpl %ebp, %ecx
jge 0x33086
movl %ecx, (%rax,%r15,4)
incq %r15
addl 0x38(%r14), %ecx
cmpl %r12d, %ecx
jle 0x33062
jmp 0x3307a
xorl %eax, %eax
movl %r15d, (%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x646a6(%rip), %rdi     # 0x97733
leaq 0x65a05(%rip), %rsi     # 0x98a99
movl $0x596, %edx            # imm = 0x596
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: feedReplicationBacklog
void feedReplicationBacklog(void *ptr, size_t len) {
    unsigned char *p = ptr;

    // 将长度累加到全局 offset 中
    server.master_repl_offset += len;

    /* This is a circular buffer, so write as much data we can at every
     * iteration and rewind the "idx" index if we reach the limit. */
    // 环形 buffer ，每次写尽可能多的数据，并在到达尾部时将 idx 重置到头部
    while(len) {
        // 从 idx 到 backlog 尾部的字节数
        size_t thislen = server.repl_backlog_size - server.repl_backlog_idx;
        // 如果 idx 到 backlog 尾部这段空间足以容纳要写入的内容
        // 那么直接将写入数据长度设为 len
        // 在将这些 len 字节复制之后，这个 while 循环将跳出
        if (thislen > len) thislen = len;
        // 将 p 中的 thislen 字节内容复制到 backlog
        memcpy(server.repl_backlog+server.repl_backlog_idx,p,thislen);
        // 更新 idx ，指向新写入的数据之后
        server.repl_backlog_idx += thislen;
        // 如果写入达到尾部，那么将索引重置到头部
        if (server.repl_backlog_idx == server.repl_backlog_size)
            server.repl_backlog_idx = 0;
        // 减去已写入的字节数
        len -= thislen;
        // 将指针移动到已被写入数据的后面，指向未被复制数据的开头
        p += thislen;
        // 增加实际长度
        server.repl_backlog_histlen += thislen;
    }
    // histlen 的最大值只能等于 backlog_size
    // 另外，当 histlen 大于 repl_backlog_size 时，
    // 表示写入数据的前头有一部分数据被自己的尾部覆盖了
    // 举个例子，例如 abcde 要写入到一个只有三个字节的环形数组中
    // 且假设索引为 0
    // 那么 abc 首先被写入，数组为 [a, b, c] 
    // 然后 de 被写入，数组为 [d, e, c]
    if (server.repl_backlog_histlen > server.repl_backlog_size)
        server.repl_backlog_histlen = server.repl_backlog_size;
    /* Set the offset of the first byte we have in the backlog. */
    // 记录程序可以依靠 backlog 来还原的数据的第一个字节的偏移量
    // 比如 master_repl_offset = 10086
    // repl_backlog_histlen = 30
    // 那么 backlog 所保存的数据的第一个字节的偏移量为
    // 10086 - 30 + 1 = 10056 + 1 = 10057
    // 这说明如果从服务器如果从 10057 至 10086 之间的任何时间断线
    // 那么从服务器都可以使用 PSYNC
    server.repl_backlog_off = server.master_repl_offset -
                              server.repl_backlog_histlen + 1;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
leaq 0x96916(%rip), %r12     # 0xc9fa8
addq %rsi, 0x5f0(%r12)
testq %rsi, %rsi
je 0x33717
movq %rsi, %rbx
movq %rdi, %r14
movq 0x608(%r12), %r15
movq 0x618(%r12), %rdi
xorl %r13d, %r13d
subq %rdi, %r15
cmpq %rbx, %r15
cmovaeq %rbx, %r15
addq 0x600(%r12), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x1fbd0
movq 0x618(%r12), %rdi
addq %r15, %rdi
movq 0x608(%r12), %rax
cmpq %rax, %rdi
cmoveq %r13, %rdi
movq %rdi, 0x618(%r12)
addq %r15, %r14
movq 0x610(%r12), %rcx
addq %r15, %rcx
movq %rcx, 0x610(%r12)
subq %r15, %rbx
movq %rax, %r15
jne 0x336b8
jmp 0x33727
movq 0x608(%r12), %rax
movq 0x610(%r12), %rcx
cmpq %rax, %rcx
jle 0x33737
movq %rax, 0x610(%r12)
movq %rax, %rcx
movq 0x5f0(%r12), %rax
subq %rcx, %rax
incq %rax
movq %rax, 0x620(%r12)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: feedReplicationBacklogWithObject
void feedReplicationBacklogWithObject(robj *o) {
    char llstr[REDIS_LONGSTR_SIZE];
    void *p;
    size_t len;

    if (o->encoding == REDIS_ENCODING_INT) {
        len = ll2string(llstr,sizeof(llstr),(long)o->ptr);
        p = llstr;
    } else {
        len = sdslen(o->ptr);
        p = o->ptr;
    }
    feedReplicationBacklog(p,len);
}

// Assembly:
pushq %rbx
subq $0x20, %rsp
movl $0xf0, %eax
andl (%rdi), %eax
movq 0x8(%rdi), %rdx
cmpl $0x10, %eax
jne 0x33781
movq %rsp, %rbx
movl $0x15, %esi
movq %rbx, %rdi
callq 0x300c7
movq %rbx, %rdx
jmp 0x33784
movl -0x8(%rdx), %eax
movslq %eax, %rsi
movq %rdx, %rdi
callq 0x33682
addq $0x20, %rsp
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: refreshGoodSlavesCount
void refreshGoodSlavesCount(void) {
    listIter li;
    listNode *ln;
    int good = 0;

    if (!server.repl_min_slaves_to_write ||
        !server.repl_min_slaves_max_lag) return;

    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        redisClient *slave = ln->value;

        // 计算延迟值
        time_t lag = server.unixtime - slave->repl_ack_time;

        // 计入 GOOD
        if (slave->replstate == REDIS_REPL_ONLINE &&
            lag <= server.repl_min_slaves_max_lag) good++;
    }

    // 更新状态良好的从服务器数量
    server.repl_good_slaves_count = good;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
leaq 0x9608e(%rip), %r14     # 0xc9fa8
cmpl $0x0, 0x638(%r14)
je 0x33f92
cmpl $0x0, 0x63c(%r14)
je 0x33f92
movq 0x1c0(%r14), %rdi
movq %rsp, %rbx
movq %rbx, %rsi
callq 0x20637
movq %rbx, %rdi
callq 0x20654
xorl %ebp, %ebp
testq %rax, %rax
je 0x33f8b
movq %rsp, %rbx
movq 0x10(%rax), %rax
cmpl $0x9, 0x98(%rax)
jne 0x33f7e
movq 0x798(%r14), %rcx
subq 0xc8(%rax), %rcx
movslq 0x63c(%r14), %rax
xorl %edx, %edx
cmpq %rax, %rcx
setle %dl
addl %edx, %ebp
movq %rbx, %rdi
callq 0x20654
testq %rax, %rax
jne 0x33f52
movl %ebp, 0x640(%r14)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationSendAck
void replicationSendAck(void) {
    redisClient *c = server.master;

    if (c != NULL) {
        c->flags |= REDIS_MASTER_FORCE_REPLY;
        addReplyMultiBulkLen(c,3);
        addReplyBulkCString(c,"REPLCONF");
        addReplyBulkCString(c,"ACK");
        // 发送偏移量
        addReplyBulkLongLong(c,c->reploff);
        c->flags &= ~REDIS_MASTER_FORCE_REPLY;
    }
}

// Assembly:
pushq %rbx
leaq 0x95c53(%rip), %rax     # 0xc9fa8
movq 0x660(%rax), %rbx
testq %rbx, %rbx
je 0x343a9
orb $0x20, 0x91(%rbx)
movl $0x3, %esi
movq %rbx, %rdi
callq 0x2e168
leaq 0x604f8(%rip), %rsi     # 0x94874
movq %rbx, %rdi
callq 0x2e051
leaq 0x604f5(%rip), %rsi     # 0x94880
movq %rbx, %rdi
callq 0x2e051
movq 0xb8(%rbx), %rsi
movq %rbx, %rdi
callq 0x2e277
andb $-0x21, 0x91(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationAbortSyncTransfer
void replicationAbortSyncTransfer(void) {
    redisAssert(server.repl_state == REDIS_REPL_TRANSFER);

    aeDeleteFileEvent(server.el,server.repl_transfer_s,AE_READABLE);
    close(server.repl_transfer_s);
    close(server.repl_transfer_fd);
    unlink(server.repl_transfer_tmpfile);
    zfree(server.repl_transfer_tmpfile);
    server.repl_state = REDIS_REPL_CONNECT;
}

// Assembly:
pushq %rbx
leaq 0x957e8(%rip), %rbx     # 0xc9fa8
cmpl $0x4, 0x674(%rbx)
jne 0x34817
movq 0x28(%rbx), %rdi
movl 0x690(%rbx), %esi
movl $0x1, %edx
callq 0x20ce8
movl 0x690(%rbx), %edi
callq 0x1f170
movl 0x694(%rbx), %edi
callq 0x1f170
movq 0x698(%rbx), %rdi
callq 0x1f3a0
movq 0x698(%rbx), %rdi
callq 0x29af7
movl $0x1, 0x674(%rbx)
popq %rbx
retq
leaq 0x635b1(%rip), %rdi     # 0x97dcf
leaq 0x62f67(%rip), %rsi     # 0x9778c
movl $0x38d, %edx            # imm = 0x38D
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationDiscardCachedMaster
void replicationDiscardCachedMaster(void) {

    if (server.cached_master == NULL) return;

    redisLog(REDIS_NOTICE,"Discarding previously cached master state.");
    server.cached_master->flags &= ~REDIS_MASTER;
    freeClient(server.cached_master);
    server.cached_master = NULL;
}

// Assembly:
pushq %rbx
leaq 0x94f51(%rip), %rbx     # 0xc9fa8
cmpq $0x0, 0x668(%rbx)
je 0x35092
leaq 0x63721(%rip), %rsi     # 0x98789
movl $0x2, %edi
xorl %eax, %eax
callq 0x23223
movq 0x668(%rbx), %rdi
andl $-0x3, 0x90(%rdi)
callq 0x2e517
movq $0x0, 0x668(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationResurrectCachedMaster
void replicationResurrectCachedMaster(int newfd) {
    
    // 设置 master
    server.master = server.cached_master;
    server.cached_master = NULL;

    server.master->fd = newfd;

    server.master->flags &= ~(REDIS_CLOSE_AFTER_REPLY|REDIS_CLOSE_ASAP);

    server.master->authenticated = 1;
    server.master->lastinteraction = server.unixtime;

    // 回到已连接状态
    server.repl_state = REDIS_REPL_CONNECTED;

    /* Re-add to the list of clients. */
    // 将 master 重新加入到客户端列表中
    listAddNodeTail(server.clients,server.master);
    // 监听 master 的读事件
    if (aeCreateFileEvent(server.el, newfd, AE_READABLE,
                          readQueryFromClient, server.master)) {
        redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
        freeClientAsync(server.master); /* Close ASAP. */
    }

    /* We may also need to install the write handler as well if there is
     * pending data in the write buffers. */
    if (server.master->bufpos || listLength(server.master->reply)) {
        if (aeCreateFileEvent(server.el, newfd, AE_WRITABLE,
                          sendReplyToClient, server.master)) {
            redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the writable handler: %s", strerror(errno));
            freeClientAsync(server.master); /* Close ASAP. */
        }
    }
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movl %edi, %ebx
leaq 0x94f07(%rip), %r14     # 0xc9fa8
movq 0x668(%r14), %rsi
movq %rsi, 0x660(%r14)
movq $0x0, 0x668(%r14)
movl %edi, (%rsi)
andl $0xfffffbbf, 0x90(%rsi) # imm = 0xFFFFFBBF
movl $0x1, 0x94(%rsi)
movq 0x798(%r14), %rax
movq %rax, 0x80(%rsi)
movl $0x5, 0x674(%r14)
movq 0x1b0(%r14), %rdi
callq 0x204cb
movq 0x28(%r14), %rdi
movq 0x660(%r14), %r8
leaq -0x7f49(%rip), %rcx     # 0x2d1be
movl %ebx, %esi
movl $0x1, %edx
callq 0x20c22
testl %eax, %eax
je 0x35145
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x6368a(%rip), %rsi     # 0x987b4
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23223
movq 0x660(%r14), %rdi
callq 0x2e90b
movq 0x660(%r14), %r8
cmpl $0x0, 0x170(%r8)
jne 0x35161
movq 0x60(%r8), %rax
cmpq $0x0, 0x28(%rax)
je 0x351b1
movq 0x28(%r14), %rdi
leaq -0x7da0(%rip), %rcx     # 0x2d3cc
movl %ebx, %esi
movl $0x2, %edx
callq 0x20c22
testl %eax, %eax
je 0x351b1
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x63676(%rip), %rsi     # 0x98805
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23223
movq 0x660(%r14), %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2e90b
addq $0x8, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: connectWithMaster
int connectWithMaster(void) {
    int fd;

    // 连接主服务器
    fd = anetTcpNonBlockConnect(NULL,server.masterhost,server.masterport);
    if (fd == -1) {
        redisLog(REDIS_WARNING,"Unable to connect to MASTER: %s",
            strerror(errno));
        return REDIS_ERR;
    }

    // 监听主服务器 fd 的读和写事件，并绑定文件事件处理器
    if (aeCreateFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE,syncWithMaster,NULL) ==
            AE_ERR)
    {
        close(fd);
        redisLog(REDIS_WARNING,"Can't create readable event for SYNC");
        return REDIS_ERR;
    }

    // 初始化统计变量
    server.repl_transfer_lastio = server.unixtime;
    server.repl_transfer_s = fd;

    // 将状态改为已连接
    server.repl_state = REDIS_REPL_CONNECTING;

    return REDIS_OK;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
leaq 0x94996(%rip), %r15     # 0xc9fa8
movq 0x650(%r15), %rsi
movl 0x658(%r15), %edx
xorl %edi, %edi
callq 0x21973
cmpl $-0x1, %eax
je 0x35672
movl %eax, %ebx
movq 0x28(%r15), %rdi
leaq -0x480(%rip), %rcx      # 0x351b9
xorl %r14d, %r14d
movl %eax, %esi
movl $0x3, %edx
xorl %r8d, %r8d
callq 0x20c22
cmpl $-0x1, %eax
je 0x35696
movq 0x798(%r15), %rax
movq %rax, 0x6a0(%r15)
movl %ebx, 0x690(%r15)
movl $0x2, 0x674(%r15)
jmp 0x356b6
callq 0x1f810
movl (%rax), %edi
callq 0x1f630
leaq 0x62ef8(%rip), %rsi     # 0x9857d
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x23223
jmp 0x356b0
movl %ebx, %edi
callq 0x1f170
leaq 0x62ef9(%rip), %rsi     # 0x9859d
movl $0x3, %edi
xorl %eax, %eax
callq 0x23223
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: undoConnectWithMaster
void undoConnectWithMaster(void) {
    int fd = server.repl_transfer_s;

    // 连接必须处于正在连接状态
    redisAssert(server.repl_state == REDIS_REPL_CONNECTING ||
                server.repl_state == REDIS_REPL_RECEIVE_PONG);
    aeDeleteFileEvent(server.el,fd,AE_READABLE|AE_WRITABLE);
    close(fd);
    server.repl_transfer_s = -1;
    // 回到 CONNECT 状态
    server.repl_state = REDIS_REPL_CONNECT;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0x948de(%rip), %r14     # 0xc9fa8
movl 0x674(%r14), %eax
andl $-0x2, %eax
cmpl $0x2, %eax
jne 0x35715
movl 0x690(%r14), %ebx
movq 0x28(%r14), %rdi
movl %ebx, %esi
movl $0x3, %edx
callq 0x20ce8
movl %ebx, %edi
callq 0x1f170
movl $0xffffffff, 0x690(%r14) # imm = 0xFFFFFFFF
movl $0x1, 0x674(%r14)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
leaq 0x62ea6(%rip), %rdi     # 0x985c2
leaq 0x62069(%rip), %rsi     # 0x9778c
movl $0x615, %edx            # imm = 0x615
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: cancelReplicationHandshake
int cancelReplicationHandshake(void) {
    if (server.repl_state == REDIS_REPL_TRANSFER) {
        replicationAbortSyncTransfer();
    } else if (server.repl_state == REDIS_REPL_CONNECTING ||
             server.repl_state == REDIS_REPL_RECEIVE_PONG)
    {
        undoConnectWithMaster();
    } else {
        return 0;
    }
    return 1;
}

// Assembly:
pushq %rax
leaq 0x94869(%rip), %rax     # 0xc9fa8
movl 0x674(%rax), %ecx
cmpl $0x4, %ecx
jne 0x35751
callq 0x347b8
jmp 0x35760
andl $-0x2, %ecx
xorl %eax, %eax
cmpl $0x2, %ecx
jne 0x35765
callq 0x356bf
movl $0x1, %eax
popq %rcx
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationSetMaster
void replicationSetMaster(char *ip, int port) {

    // 清除原有的主服务器地址（如果有的话）
    sdsfree(server.masterhost);

    // IP
    server.masterhost = sdsnew(ip);

    // 端口
    server.masterport = port;

    // 清除原来可能有的主服务器信息。。。

    // 如果之前有其他地址，那么释放它
    if (server.master) freeClient(server.master);
    // 断开所有从服务器的连接，强制所有从服务器执行重同步
    disconnectSlaves(); /* Force our slaves to resync with us as well. */
    // 清空可能有的 master 缓存，因为已经不会执行 PSYNC 了
    replicationDiscardCachedMaster(); /* Don't try a PSYNC. */
    // 释放 backlog ，同理， PSYNC 目前已经不会执行了
    freeReplicationBacklog(); /* Don't allow our chained slaves to PSYNC. */
    // 取消之前的复制进程（如果有的话）
    cancelReplicationHandshake();

    // 进入连接状态（重点）
    server.repl_state = REDIS_REPL_CONNECT;
    server.master_repl_offset = 0;
    server.repl_down_since = 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
leaq 0x94830(%rip), %r15     # 0xc9fa8
movq 0x650(%r15), %rdi
callq 0x2850d
movq %r14, %rdi
callq 0x28486
movq %rax, 0x650(%r15)
movl %ebx, 0x658(%r15)
movq 0x660(%r15), %rdi
testq %rdi, %rdi
je 0x357ab
callq 0x2e517
callq 0x2e4f1
callq 0x3504f
callq 0x33631
callq 0x35737
movl $0x1, 0x674(%r15)
xorl %eax, %eax
movq %rax, 0x5f0(%r15)
movq %rax, 0x6b0(%r15)
popq %rbx
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationCacheMaster
void replicationCacheMaster(redisClient *c) {
    listNode *ln;

    redisAssert(server.master != NULL && server.cached_master == NULL);
    redisLog(REDIS_NOTICE,"Caching the disconnected master state.");

    /* Remove from the list of clients, we don't want this client to be
     * listed by CLIENT LIST or processed in any way by batch operations. */
    // 从客户端链表中移除主服务器
    ln = listSearchKey(server.clients,c);
    redisAssert(ln != NULL);
    listDelNode(server.clients,ln);

    /* Save the master. Server.master will be set to null later by
     * replicationHandleMasterDisconnection(). */
    // 缓存 master
    server.cached_master = server.master;

    /* Remove the event handlers and close the socket. We'll later reuse
     * the socket of the new connection with the master during PSYNC. */
    // 删除事件监视，关闭 socket
    aeDeleteFileEvent(server.el,c->fd,AE_READABLE);
    aeDeleteFileEvent(server.el,c->fd,AE_WRITABLE);
    close(c->fd);

    /* Set fd to -1 so that we can safely call freeClient(c) later. */
    c->fd = -1;

    /* Invalidate the Peer ID cache. */
    if (c->peerid) {
        sdsfree(c->peerid);
        c->peerid = NULL;
    }

    /* Caching the master happens instead of the actual freeClient() call,
     * so make sure to adjust the replication state. This function will
     * also set server.master to NULL. */
    // 重置复制状态，并将 server.master 设为 NULL
    // 并强制断开这个服务器的所有从服务器，让它们执行 resync 
    replicationHandleMasterDisconnection();
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
leaq 0x945f7(%rip), %r14     # 0xc9fa8
cmpq $0x0, 0x660(%r14)
je 0x35a6d
cmpq $0x0, 0x668(%r14)
jne 0x35a6d
movq %rdi, %rbx
leaq 0x62d8b(%rip), %rsi     # 0x98762
movl $0x2, %edi
xorl %eax, %eax
callq 0x23223
movq 0x1b0(%r14), %rdi
movq %rbx, %rsi
callq 0x20729
testq %rax, %rax
je 0x35a82
movq 0x1b0(%r14), %rdi
movq %rax, %rsi
callq 0x205b1
movq 0x660(%r14), %rax
movq %rax, 0x668(%r14)
movq 0x28(%r14), %rdi
movl (%rbx), %esi
movl $0x1, %edx
callq 0x20ce8
movq 0x28(%r14), %rdi
movl (%rbx), %esi
movl $0x2, %edx
callq 0x20ce8
movl (%rbx), %edi
callq 0x1f170
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
movq 0x168(%rbx), %rdi
testq %rdi, %rdi
je 0x35a61
callq 0x2850d
movq $0x0, 0x168(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x2e892
leaq 0x62cb8(%rip), %rdi     # 0x9872c
leaq 0x61d11(%rip), %rsi     # 0x9778c
movl $0x6e0, %edx            # imm = 0x6E0
jmp 0x35a95
leaq 0x6356d(%rip), %rdi     # 0x98ff6
leaq 0x61cfc(%rip), %rsi     # 0x9778c
movl $0x6e7, %edx            # imm = 0x6E7
callq 0x4ca32
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationScriptCacheInit
void replicationScriptCacheInit(void) {
    // 最大缓存脚本数
    server.repl_scriptcache_size = 10000;
    // 字典
    server.repl_scriptcache_dict = dictCreate(&replScriptCacheDictType,NULL);
    // FIFO 队列
    server.repl_scriptcache_fifo = listCreate();
}

// Assembly:
pushq %rbx
leaq 0x944fc(%rip), %rbx     # 0xc9fa8
movl $0x2710, 0x708(%rbx)    # imm = 0x2710
leaq 0x93fc3(%rip), %rdi     # 0xc9a80
xorl %esi, %esi
callq 0x2217b
movq %rax, 0x6f8(%rbx)
callq 0x203fc
movq %rax, 0x700(%rbx)
popq %rbx
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationCountAcksByOffset
int replicationCountAcksByOffset(long long offset) {
    listIter li;
    listNode *ln;
    int count = 0;

    listRewind(server.slaves,&li);
    while((ln = listNext(&li))) {
        redisClient *slave = ln->value;

        if (slave->replstate != REDIS_REPL_ONLINE) continue;
        if (slave->repl_ack_off >= offset) count++;
    }
    return count;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x943cf(%rip), %rax     # 0xc9fa8
movq 0x1c0(%rax), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0x20637
movq %r14, %rdi
callq 0x20654
xorl %ebp, %ebp
testq %rax, %rax
je 0x35c25
movq %rsp, %r14
movq 0x10(%rax), %rax
cmpl $0x9, 0x98(%rax)
jne 0x35c18
xorl %ecx, %ecx
cmpq %rbx, 0xc0(%rax)
setge %cl
addl %ecx, %ebp
movq %r14, %rdi
callq 0x20654
testq %rax, %rax
jne 0x35bfd
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: waitCommand
void waitCommand(redisClient *c) {
    mstime_t timeout;
    long numreplicas, ackreplicas;
    long long offset = c->woff;

    /* Argument parsing. */
    if (getLongFromObjectOrReply(c,c->argv[1],&numreplicas,NULL) != REDIS_OK)
        return;
    if (getTimeoutFromObjectOrReply(c,c->argv[2],&timeout,UNIT_MILLISECONDS)
        != REDIS_OK) return;

    /* First try without blocking at all. */
    ackreplicas = replicationCountAcksByOffset(c->woff);
    if (ackreplicas >= numreplicas || c->flags & REDIS_MULTI) {
        addReplyLongLong(c,ackreplicas);
        return;
    }

    /* Otherwise block the client and put it into our list of clients
     * waiting for ack from slaves. */
    c->bpop.timeout = timeout;
    c->bpop.reploffset = offset;
    c->bpop.numreplicas = numreplicas;
    listAddNodeTail(server.clients_waiting_acks,c);
    blockClient(c,REDIS_BLOCKED_WAIT);

    /* Make sure that the server will send an ACK request to all the slaves
     * before returning to the event loop. */
    replicationRequestAckFromSlaves();
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rax
movq 0x148(%rdi), %r14
movq 0x8(%rax), %rsi
leaq 0x8(%rsp), %rdx
xorl %ecx, %ecx
callq 0x313b2
testl %eax, %eax
jne 0x35cee
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0x60858
testl %eax, %eax
jne 0x35cee
movq 0x148(%rbx), %rdi
callq 0x35bc7
movslq %eax, %rsi
movq 0x8(%rsp), %rax
cmpq %rsi, %rax
jle 0x35ce6
testb $0x8, 0x90(%rbx)
jne 0x35ce6
movq 0x10(%rsp), %rcx
movq %rcx, 0x120(%rbx)
movq %r14, 0x140(%rbx)
movl %eax, 0x138(%rbx)
leaq 0x942eb(%rip), %r14     # 0xc9fa8
movq 0x710(%r14), %rdi
movq %rbx, %rsi
callq 0x204cb
movq %rbx, %rdi
movl $0x2, %esi
callq 0x608cc
movl $0x1, 0x718(%r14)
jmp 0x35cee
movq %rbx, %rdi
callq 0x2e133
addq $0x18, %rsp
popq %rbx
popq %r14
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbSaveLen
int rdbSaveLen(rio *rdb, uint32_t len) {
    unsigned char buf[2];
    size_t nwritten;

    if (len < (1<<6)) {
        /* Save a 6 bit len */
        buf[0] = (len&0xFF)|(REDIS_RDB_6BITLEN<<6);
        if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
        nwritten = 1;

    } else if (len < (1<<14)) {
        /* Save a 14 bit len */
        buf[0] = ((len>>8)&0xFF)|(REDIS_RDB_14BITLEN<<6);
        buf[1] = len&0xFF;
        if (rdbWriteRaw(rdb,buf,2) == -1) return -1;
        nwritten = 2;

    } else {
        /* Save a 32 bit len */
        buf[0] = (REDIS_RDB_32BITLEN<<6);
        if (rdbWriteRaw(rdb,buf,1) == -1) return -1;
        len = htonl(len);
        if (rdbWriteRaw(rdb,&len,4) == -1) return -1;
        nwritten = 1+4;
    }

    return nwritten;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebp
movq %rdi, %rbx
cmpl $0x3f, %esi
ja 0x363d5
leaq 0xa(%rsp), %rsi
movb %bpl, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x361b8
movl $0x1, %ecx
jmp 0x36401
cmpl $0x3fff, %ebp           # imm = 0x3FFF
ja 0x36413
movl %ebp, %eax
shrl $0x8, %eax
orb $0x40, %al
leaq 0xa(%rsp), %rsi
movb %al, (%rsi)
movb %bpl, 0x1(%rsi)
movl $0x2, %edx
movq %rbx, %rdi
callq 0x361b8
movl $0x2, %ecx
cmpl $-0x1, %eax
je 0x3640b
movl %ecx, %r14d
jmp 0x36453
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x36453
leaq 0xa(%rsp), %rsi
movb $-0x80, (%rsi)
movl $0x1, %edx
movq %rbx, %rdi
callq 0x361b8
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x36453
bswapl %ebp
leaq 0xc(%rsp), %rsi
movl %ebp, (%rsi)
movl $0x4, %edx
movq %rbx, %rdi
callq 0x361b8
movl $0x5, %ecx
cmpl $-0x1, %eax
jne 0x36406
movl %r14d, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbLoadLen
uint32_t rdbLoadLen(rio *rdb, int *isencoded) {
    unsigned char buf[2];
    uint32_t len;
    int type;

    if (isencoded) *isencoded = 0;

    // 读入 length ，这个值可能已经被编码，也可能没有
    if (rioRead(rdb,buf,1) == 0) return REDIS_RDB_LENERR;

    type = (buf[0]&0xC0)>>6;

    // 编码值，进行解码
    if (type == REDIS_RDB_ENCVAL) {
        /* Read a 6 bit encoding type. */
        if (isencoded) *isencoded = 1;
        return buf[0]&0x3F;

    // 6 位整数
    } else if (type == REDIS_RDB_6BITLEN) {
        /* Read a 6 bit len. */
        return buf[0]&0x3F;

    // 14 位整数
    } else if (type == REDIS_RDB_14BITLEN) {
        /* Read a 14 bit len. */
        if (rioRead(rdb,buf+1,1) == 0) return REDIS_RDB_LENERR;
        return ((buf[0]&0x3F)<<8)|buf[1];

    // 32 位整数
    } else {
        /* Read a 32 bit len. */
        if (rioRead(rdb,&len,4) == 0) return REDIS_RDB_LENERR;
        return ntohl(len);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
testq %rsi, %rsi
je 0x3647e
movl $0x0, (%r14)
leaq 0xa(%rsp), %r15
movl $0x1, %r13d
movq 0x30(%rbx), %rax
cmpq %r13, %rax
movq %r13, %r12
cmovbq %rax, %r12
testq %rax, %rax
cmoveq %r13, %r12
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *(%rbx)
testq %rax, %rax
je 0x365c2
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x364c6
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *%rax
addq %r12, %r15
addq %r12, 0x28(%rbx)
subq %r12, %r13
jne 0x36489
movzbl 0xa(%rsp), %eax
movl %eax, %ecx
shrl $0x6, %ecx
cmpl $0x3, %ecx
jne 0x364f5
testq %r14, %r14
je 0x364ed
movl $0x1, (%r14)
andl $0x3f, %eax
jmp 0x365c7
cmpb $0x40, %al
jb 0x365c7
cmpl $0x1, %ecx
jne 0x3656a
movl $0x1, %r12d
leaq 0xb(%rsp), %r14
movq 0x30(%rbx), %rax
cmpq %r12, %rax
movq %r12, %r15
cmovbq %rax, %r15
testq %rax, %rax
cmoveq %r12, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *(%rbx)
testq %rax, %rax
je 0x365c2
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x3654a
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *%rax
addq %r15, %r14
addq %r15, 0x28(%rbx)
subq %r15, %r12
jne 0x3650d
movzbl 0xa(%rsp), %ecx
andl $0x3f, %ecx
shll $0x8, %ecx
movzbl 0xb(%rsp), %eax
orl %ecx, %eax
jmp 0x365c7
leaq 0xc(%rsp), %r14
movl $0x4, %r12d
movq 0x30(%rbx), %rax
cmpq %r12, %rax
movq %r12, %r15
cmovbq %rax, %r15
testq %rax, %rax
cmoveq %r12, %r15
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *(%rbx)
testq %rax, %rax
je 0x365c2
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x365ae
movq %rbx, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *%rax
addq %r15, %r14
addq %r15, 0x28(%rbx)
subq %r15, %r12
jne 0x36575
movl 0xc(%rsp), %eax
bswapl %eax
jmp 0x365c7
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbEncodeInteger
int rdbEncodeInteger(long long value, unsigned char *enc) {

    if (value >= -(1<<7) && value <= (1<<7)-1) {
        enc[0] = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_INT8;
        enc[1] = value&0xFF;
        return 2;

    } else if (value >= -(1<<15) && value <= (1<<15)-1) {
        enc[0] = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_INT16;
        enc[1] = value&0xFF;
        enc[2] = (value>>8)&0xFF;
        return 3;

    } else if (value >= -((long long)1<<31) && value <= ((long long)1<<31)-1) {
        enc[0] = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_INT32;
        enc[1] = value&0xFF;
        enc[2] = (value>>8)&0xFF;
        enc[3] = (value>>16)&0xFF;
        enc[4] = (value>>24)&0xFF;
        return 5;

    } else {
        return 0;
    }
}

// Assembly:
movq %rdi, %rcx
movsbq %cl, %rax
cmpq %rdi, %rax
jne 0x365f0
movb $-0x40, (%rsi)
movl $0x2, %eax
movl $0x1, %edx
jmp 0x36638
movswq %cx, %rax
cmpq %rcx, %rax
jne 0x3660f
movb $-0x3f, (%rsi)
movb %cl, 0x1(%rsi)
shrq $0x8, %rcx
movl $0x3, %eax
movl $0x2, %edx
jmp 0x36638
movslq %ecx, %rdx
xorl %eax, %eax
cmpq %rcx, %rdx
jne 0x3663b
movb $-0x3e, (%rsi)
movb %cl, 0x1(%rsi)
movb %ch, 0x2(%rsi)
movl %ecx, %eax
shrl $0x10, %eax
movb %al, 0x3(%rsi)
shrq $0x18, %rcx
movl $0x5, %eax
movl $0x4, %edx
movb %cl, (%rsi,%rdx)
retq
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbLoadIntegerObject
robj *rdbLoadIntegerObject(rio *rdb, int enctype, int encode) {
    unsigned char enc[4];
    long long val;

    // 整数编码
    if (enctype == REDIS_RDB_ENC_INT8) {
        if (rioRead(rdb,enc,1) == 0) return NULL;
        val = (signed char)enc[0];
    } else if (enctype == REDIS_RDB_ENC_INT16) {
        uint16_t v;
        if (rioRead(rdb,enc,2) == 0) return NULL;
        v = enc[0]|(enc[1]<<8);
        val = (int16_t)v;
    } else if (enctype == REDIS_RDB_ENC_INT32) {
        uint32_t v;
        if (rioRead(rdb,enc,4) == 0) return NULL;
        v = enc[0]|(enc[1]<<8)|(enc[2]<<16)|(enc[3]<<24);
        val = (int32_t)v;
    } else {
        val = 0; /* anti-warning */
        redisPanic("Unknown RDB integer encoding type");
    }

    
    if (encode)
        // 整数编码的字符串
        return createStringObjectFromLongLong(val);
    else
        // 未编码
        return createObject(REDIS_STRING,sdsfromlonglong(val));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebx
movq %rdi, %r14
cmpl $0x2, %esi
je 0x36723
cmpl $0x1, %esi
je 0x366c4
testl %esi, %esi
jne 0x367aa
leaq 0x4(%rsp), %r12
movl $0x1, %ebp
xorl %r15d, %r15d
movq 0x30(%r14), %rax
cmpq %rbp, %rax
movq %rbp, %r13
cmovbq %rax, %r13
testq %rax, %rax
cmoveq %rbp, %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *(%r14)
testq %rax, %rax
je 0x36798
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x366ad
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *%rax
addq %r13, %r12
addq %r13, 0x28(%r14)
subq %r13, %rbp
jne 0x3666f
movsbq 0x4(%rsp), %rdi
jmp 0x3677b
leaq 0x4(%rsp), %r12
movl $0x2, %ebp
xorl %r15d, %r15d
movq 0x30(%r14), %rax
cmpq %rbp, %rax
movq %rbp, %r13
cmovbq %rax, %r13
testq %rax, %rax
cmoveq %rbp, %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *(%r14)
testq %rax, %rax
je 0x36798
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x3670f
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *%rax
addq %r13, %r12
addq %r13, 0x28(%r14)
subq %r13, %rbp
jne 0x366d1
movswq 0x4(%rsp), %rdi
jmp 0x3677b
leaq 0x4(%rsp), %r12
movl $0x4, %ebp
xorl %r15d, %r15d
movq 0x30(%r14), %rax
cmpq %rbp, %rax
movq %rbp, %r13
cmovbq %rax, %r13
testq %rax, %rax
cmoveq %rbp, %r13
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *(%r14)
testq %rax, %rax
je 0x36798
movq 0x18(%r14), %rax
testq %rax, %rax
je 0x3676a
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq *%rax
addq %r13, %r12
addq %r13, 0x28(%r14)
subq %r13, %rbp
jne 0x36730
movslq 0x4(%rsp), %rdi
testl %ebx, %ebx
je 0x36786
callq 0x3069e
jmp 0x36795
callq 0x2891b
xorl %edi, %edi
movq %rax, %rsi
callq 0x3059c
movq %rax, %r15
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x622c3(%rip), %rdi     # 0x98a74
leaq 0x622e0(%rip), %rsi     # 0x98a98
movl $0x101, %edx            # imm = 0x101
callq 0x4cae0
movl $0x1, %edi
callq 0x1f3b0
// File: /workspace/github_c_makefile_star2_O3/nilyang[P]redis-tdd-annotation/src/rdb.c
// Function: rdbSaveLzfStringObject
int rdbSaveLzfStringObject(rio *rdb, unsigned char *s, size_t len) {
    size_t comprlen, outlen;
    unsigned char byte;
    int n, nwritten = 0;
    void *out;

    /* We require at least four bytes compression for this to be worth it */
    // 压缩字符串
    if (len <= 4) return 0;
    outlen = len-4;
    if ((out = zmalloc(outlen+1)) == NULL) return 0;
    comprlen = lzf_compress(s, len, out, outlen);
    if (comprlen == 0) {
        zfree(out);
        return 0;
    }

    /* Data compressed! Let's save it on disk 
     *
     * 保存压缩后的字符串到 rdb 。
     */

    // 写入类型，说明这是一个 LZF 压缩字符串
    byte = (REDIS_RDB_ENCVAL<<6)|REDIS_RDB_ENC_LZF;
    if ((n = rdbWriteRaw(rdb,&byte,1)) == -1) goto writeerr;
    nwritten += n;

    // 写入字符串压缩后的长度
    if ((n = rdbSaveLen(rdb,comprlen)) == -1) goto writeerr;
    nwritten += n;
    
    // 写入字符串未压缩时的长度
    if ((n = rdbSaveLen(rdb,len)) == -1) goto writeerr;
    nwritten += n;

    // 写入压缩后的字符串
    if ((n = rdbWriteRaw(rdb,out,comprlen)) == -1) goto writeerr;
    nwritten += n;

    zfree(out);

    return nwritten;

writeerr:
    zfree(out);
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
xorl %ebp, %ebp
cmpq $0x5, %rdx
jb 0x36923
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
leaq -0x3(%rdx), %rdi
callq 0x299b5
testq %rax, %rax
je 0x36923
movq %rax, %rbx
leal -0x4(%r15), %ecx
movq %r12, %rdi
movl %r15d, %esi
movq %rax, %rdx
callq 0x1fce0
testl %eax, %eax
je 0x3690c
movl %eax, %r13d
leaq 0xf(%rsp), %rsi
movb $-0x3d, (%rsi)
movl $0x1, %edx
movq %r14, %rdi
callq 0x361b8
cmpl $-0x1, %eax
je 0x36916
movl %eax, %r12d
movl %r13d, %esi
movq %r14, %rdi
movq %rsi, 0x10(%rsp)
callq 0x363a7
cmpl $-0x1, %eax
je 0x36916
movl %eax, %r13d
movq %r14, %rdi
movl %r15d, %esi
callq 0x363a7
cmpl $-0x1, %eax
je 0x36916
movl %eax, %ebp
movq %r14, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rdx
callq 0x361b8
cmpl $-0x1, %eax
je 0x36916
addl %r12d, %r13d
addl %eax, %ebp
addl %r13d, %ebp
movq %rbx, %rdi
callq 0x29af7
jmp 0x36923
movq %rbx, %rdi
callq 0x29af7
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq