LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq $0x0, -0x38(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x3ce5f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3bdc0
movq -0x48(%rbp), %rdi
movq %rax, %rsi
callq 0x3a2e0
movq %rax, -0x30(%rbp)
jmp 0x3cf23
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x2, %eax
jne 0x3ce86
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3a3f0
jmp 0x3cf21
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x4, %eax
jne 0x3cebf
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3a3f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
callq 0x3a3f0
jmp 0x3cf1f
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
cmpl $0x3, %eax
jne 0x3cefb
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x3a3f0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
fldl (%rax)
movq %rsp, %rax
fstpt (%rax)
callq 0x3a410
movq %rax, -0x38(%rbp)
jmp 0x3cf1d
leaq 0xa4798(%rip), %rdi     # 0xe169a
leaq 0xa5bfc(%rip), %rsi     # 0xe2b05
movl $0x267, %edx            # imm = 0x267
callq 0x63d40
movl $0x1, %edi
callq 0x1f3b0
jmp 0x3cf1f
jmp 0x3cf21
jmp 0x3cf23
movq -0x20(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x1ff90
cmpq $0x0, -0x38(%rbp)
je 0x3cf44
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x1ff90
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
callq 0x1f820
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x28(%rbp), %rsi
movl $0xa, %edx
callq 0x1fbc0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
callq 0x1f530
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x2000, %eax           # imm = 0x2000
cmpl $0x0, %eax
jne 0x3cfc9
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0x3cfc9
callq 0x1f820
cmpl $0x22, (%rax)
jne 0x3cfe2
movq -0x10(%rbp), %rdi
leaq 0xa46eb(%rip), %rsi     # 0xe16bf
callq 0x35d40
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x3cfe9
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3bed0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3d8dd
leaq 0xa3ea1(%rip), %rax     # 0xe1778
movq %rax, -0x18(%rbp)
jmp 0x3d953
movq -0x10(%rbp), %rax
movl (%rax), %eax
andl $0xf, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x4, %eax
ja 0x3d946
movq -0x20(%rbp), %rax
leaq 0xa3d40(%rip), %rcx     # 0xe163c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xae28c(%rip), %rax     # 0xebb98
movq %rax, -0x18(%rbp)
jmp 0x3d951
leaq 0xa3caf(%rip), %rax     # 0xe15c8
movq %rax, -0x18(%rbp)
jmp 0x3d951
leaq 0xa1c30(%rip), %rax     # 0xdf556
movq %rax, -0x18(%rbp)
jmp 0x3d951
leaq 0xa3e4a(%rip), %rax     # 0xe177d
movq %rax, -0x18(%rbp)
jmp 0x3d951
leaq 0xa3e42(%rip), %rax     # 0xe1782
movq %rax, -0x18(%rbp)
jmp 0x3d951
leaq 0xa3c9f(%rip), %rax     # 0xe15ec
movq %rax, -0x18(%rbp)
jmp 0x3d953
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x35f30
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jle 0x3d9a9
movq -0x8(%rbp), %rdi
leaq 0xd67b8(%rip), %rax     # 0x114150
movq 0x80(%rax), %rsi
callq 0x35a70
jmp 0x3da7c
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x3da28
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa3dbd(%rip), %rsi     # 0xe1787
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x3d9df
movl -0xc(%rbp), %eax
orl $0x2, %eax
movl %eax, -0xc(%rbp)
jmp 0x3da26
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa4303(%rip), %rsi     # 0xe1cf9
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x3da0b
movl -0xc(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3da24
movq -0x8(%rbp), %rdi
leaq 0xd673a(%rip), %rax     # 0x114150
movq 0x80(%rax), %rsi
callq 0x35a70
jmp 0x3da7c
jmp 0x3da26
jmp 0x3da28
jmp 0x3da2a
leaq 0xd5ec7(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x2f0(%rax)
jne 0x3da4a
leaq 0xd5eb7(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x84(%rax)
je 0x3da56
movl -0xc(%rbp), %eax
andl $-0x2, %eax
orl $0x2, %eax
movl %eax, -0xc(%rbp)
movl -0xc(%rbp), %edi
movb $0x0, %al
callq 0x29980
cmpl $0x0, %eax
jne 0x3da6c
xorl %edi, %edi
callq 0x1f2c0
movq -0x8(%rbp), %rdi
leaq 0xa3d17(%rip), %rsi     # 0xe178e
callq 0x35d40
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq 0x48(%rcx), %rax
cmpq $0x0, %rax
je 0x3dd2d
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x23aa0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x3dd37
movq $-0x1, -0x8(%rbp)
jmp 0x3dd8a
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x23aa0
cmpq $0x0, %rax
je 0x3dd53
jmp 0x3dd7e
movq -0x18(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0xa3a8d(%rip), %rdx     # 0xe17ef
leaq 0xa4d9c(%rip), %rcx     # 0xe2b05
movl $0x465, %r8d            # imm = 0x465
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x23aa0
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x3ddd5
jmp 0x3de00
movq -0x10(%rbp), %rsi
xorl %eax, %eax
movl %eax, %edi
leaq 0xa3a2f(%rip), %rdx     # 0xe1813
leaq 0xa4d1a(%rip), %rcx     # 0xe2b05
movl $0x449, %r8d            # imm = 0x449
callq 0x648b0
movl $0x1, %edi
callq 0x1f3b0
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
callq 0x23be0
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0xd6109(%rip), %rax     # 0x114150
movq 0x128(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3a3f0
movq -0x18(%rbp), %rdi
callq 0x3a3f0
leaq 0xd5885(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x4d0(%rax)
je 0x3e09f
leaq 0xd5875(%rip), %rax     # 0x1138f8
movq 0x318(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x30(%rax), %esi
leaq -0x20(%rbp), %rdx
movl $0x2, %ecx
callq 0x5f700
leaq 0xd5852(%rip), %rax     # 0x1138f8
movq 0x1c0(%rax), %rdi
movq -0x8(%rbp), %rax
movl 0x30(%rax), %esi
leaq -0x20(%rbp), %rdx
movl $0x2, %ecx
callq 0x3f180
movq -0x20(%rbp), %rdi
callq 0x3aaa0
movq -0x18(%rbp), %rdi
callq 0x3aaa0
addq $0x20, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq $-0x1, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3bed0
cmpq $0x0, %rax
jne 0x3e43b
movq -0x8(%rbp), %rdi
movq $-0x2, %rsi
callq 0x36480
jmp 0x3e4e1
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3dce0
movq %rax, -0x18(%rbp)
cmpq $-0x1, -0x18(%rbp)
je 0x3e48b
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
callq 0x252e0
movq %rax, %rcx
movq -0x28(%rbp), %rax
subq %rcx, %rax
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jge 0x3e489
movq $0x0, -0x20(%rbp)
jmp 0x3e48b
cmpq $-0x1, -0x20(%rbp)
jne 0x3e4a4
movq -0x8(%rbp), %rdi
movq $-0x1, %rsi
callq 0x36480
jmp 0x3e4e1
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x3e4bc
movq -0x20(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x3e4d4
movq -0x20(%rbp), %rax
addq $0x1f4, %rax            # imm = 0x1F4
movl $0x3e8, %ecx            # imm = 0x3E8
cqto
idivq %rcx
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x36480
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x23aa0
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0x3e57d
movq -0x8(%rbp), %rdi
leaq 0xd5bde(%rip), %rax     # 0x114150
movq 0x20(%rax), %rsi
callq 0x35a70
jmp 0x3e5e7
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x3c350
cmpl $0x0, %eax
je 0x3e5d1
movq -0x8(%rbp), %rdi
leaq 0xd5baa(%rip), %rax     # 0x114150
movq 0x28(%rax), %rsi
callq 0x35a70
leaq 0xd5342(%rip), %rax     # 0x1138f8
movq 0x560(%rax), %rcx
addq $0x1, %rcx
leaq 0xd5330(%rip), %rax     # 0x1138f8
movq %rcx, 0x560(%rax)
jmp 0x3e5e5
movq -0x8(%rbp), %rdi
leaq 0xd5b74(%rip), %rax     # 0x114150
movq 0x20(%rax), %rsi
callq 0x35a70
jmp 0x3e5e7
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x30(%rax)
jne 0x3e62f
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x3e6db
movq -0x10(%rbp), %rax
movl 0x34(%rax), %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0x3e648
movl -0x1c(%rbp), %eax
addl -0x34(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
subl 0x30(%rcx), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2e130
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x3e6ca
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x3e681
jmp 0x3e6a3
leaq 0xa31ab(%rip), %rdi     # 0xe1833
leaq 0xa4476(%rip), %rsi     # 0xe2b05
movl $0x596, %edx            # imm = 0x596
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
movl -0x2c(%rbp), %edx
movq -0x40(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0x3e66f
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: createReplicationBacklog
void createReplicationBacklog(void) {

    redisAssert(server.repl_backlog == NULL);

    // backlog
    server.repl_backlog = zmalloc(server.repl_backlog_size);
    // 数据长度
    server.repl_backlog_histlen = 0;
    // 索引值，增加数据时使用
    server.repl_backlog_idx = 0;
    /* When a new backlog buffer is created, we increment the replication
     * offset by one to make sure we'll not be able to PSYNC with any
     * previous slave. This is needed because we avoid incrementing the
     * master_repl_offset if no backlog exists nor slaves are attached. */
    // 每次创建 backlog 时都将 master_repl_offset 增一
    // 这是为了防止之前使用过 backlog 的从服务器引发错误的 PSYNC 请求
    server.master_repl_offset++;

    /* We don't have any data inside our buffer, but virtually the first
     * byte we have is the next byte that will be generated for the
     * replication stream. */
    // 尽管没有任何数据，
    // 但 backlog 第一个字节的逻辑位置应该是 repl_offset 后的第一个字节
    server.repl_backlog_off = server.master_repl_offset+1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
leaq 0xd4bad(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x600(%rax)
jne 0x3ed57
jmp 0x3ed79
leaq 0xa2ade(%rip), %rdi     # 0xe183c
leaq 0xa2af3(%rip), %rsi     # 0xe1858
movl $0x33, %edx
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
leaq 0xd4b78(%rip), %rax     # 0x1138f8
movq 0x608(%rax), %rdi
callq 0x2e130
movq %rax, %rcx
leaq 0xd4b62(%rip), %rax     # 0x1138f8
movq %rcx, 0x600(%rax)
leaq 0xd4b54(%rip), %rax     # 0x1138f8
movq $0x0, 0x610(%rax)
leaq 0xd4b42(%rip), %rax     # 0x1138f8
movq $0x0, 0x618(%rax)
leaq 0xd4b30(%rip), %rax     # 0x1138f8
movq 0x5f0(%rax), %rcx
addq $0x1, %rcx
leaq 0xd4b1e(%rip), %rax     # 0x1138f8
movq %rcx, 0x5f0(%rax)
leaq 0xd4b10(%rip), %rax     # 0x1138f8
movq 0x5f0(%rax), %rcx
addq $0x1, %rcx
leaq 0xd4afe(%rip), %rax     # 0x1138f8
movq %rcx, 0x620(%rax)
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: resizeReplicationBacklog
void resizeReplicationBacklog(long long newsize) {

    // 不能小于最小大小
    if (newsize < REDIS_REPL_BACKLOG_MIN_SIZE)
        newsize = REDIS_REPL_BACKLOG_MIN_SIZE;

    // 大小和目前大小相等
    if (server.repl_backlog_size == newsize) return;

    // 设置新大小
    server.repl_backlog_size = newsize;
    if (server.repl_backlog != NULL) {
        /* What we actually do is to flush the old buffer and realloc a new
         * empty one. It will refill with new data incrementally.
         * The reason is that copying a few gigabytes adds latency and even
         * worse often we need to alloc additional space before freeing the
         * old buffer. */
        // 释放 backlog
        zfree(server.repl_backlog);
        // 按新大小创建新 backlog
        server.repl_backlog = zmalloc(server.repl_backlog_size);
        server.repl_backlog_histlen = 0;
        server.repl_backlog_idx = 0;
        /* Next byte we have is... the next since the buffer is emtpy. */
        server.repl_backlog_off = server.master_repl_offset+1;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
cmpq $0x4000, -0x8(%rbp)     # imm = 0x4000
jge 0x3ee2e
movq $0x4000, -0x8(%rbp)     # imm = 0x4000
leaq 0xd4ac3(%rip), %rax     # 0x1138f8
movq 0x608(%rax), %rax
cmpq -0x8(%rbp), %rax
jne 0x3ee47
jmp 0x3eee5
movq -0x8(%rbp), %rcx
leaq 0xd4aa6(%rip), %rax     # 0x1138f8
movq %rcx, 0x608(%rax)
leaq 0xd4a98(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x600(%rax)
je 0x3eee5
leaq 0xd4a87(%rip), %rax     # 0x1138f8
movq 0x600(%rax), %rdi
callq 0x2e3a0
leaq 0xd4a74(%rip), %rax     # 0x1138f8
movq 0x608(%rax), %rdi
callq 0x2e130
movq %rax, %rcx
leaq 0xd4a5e(%rip), %rax     # 0x1138f8
movq %rcx, 0x600(%rax)
leaq 0xd4a50(%rip), %rax     # 0x1138f8
movq $0x0, 0x610(%rax)
leaq 0xd4a3e(%rip), %rax     # 0x1138f8
movq $0x0, 0x618(%rax)
leaq 0xd4a2c(%rip), %rax     # 0x1138f8
movq 0x5f0(%rax), %rcx
addq $0x1, %rcx
leaq 0xd4a1a(%rip), %rax     # 0x1138f8
movq %rcx, 0x620(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0xf, %eax
cmpl $0x1, %eax
jne 0x3f143
leaq -0x20(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdx
movl $0x15, %esi
callq 0x39660
cltq
movq %rax, -0x30(%rbp)
leaq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3f160
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3ed00
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3ef60
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x1c(%rbp)
leaq 0xd3cb2(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x638(%rax)
je 0x3fc5f
leaq 0xd3ca2(%rip), %rax     # 0x1138f8
cmpl $0x0, 0x63c(%rax)
jne 0x3fc64
jmp 0x3fcf6
leaq 0xd3c8d(%rip), %rax     # 0x1138f8
movq 0x1c0(%rax), %rdi
leaq -0x10(%rbp), %rsi
callq 0x202b0
leaq -0x10(%rbp), %rdi
callq 0x20310
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x3fce6
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
leaq 0xd3c57(%rip), %rax     # 0x1138f8
movq 0x798(%rax), %rax
movq -0x28(%rbp), %rcx
subq 0xc8(%rcx), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x9, 0x98(%rax)
jne 0x3fce4
movq -0x30(%rbp), %rax
leaq 0xd3c29(%rip), %rcx     # 0x1138f8
movslq 0x63c(%rcx), %rcx
cmpq %rcx, %rax
jg 0x3fce4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3fc7b
movl -0x1c(%rbp), %ecx
leaq 0xd3c08(%rip), %rax     # 0x1138f8
movl %ecx, 0x640(%rax)
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0xd3669(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
je 0x4030f
movq -0x8(%rbp), %rax
movl 0x90(%rax), %ecx
orl $0x2000, %ecx           # imm = 0x2000
movl %ecx, 0x90(%rax)
movq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x364f0
movq -0x8(%rbp), %rdi
leaq 0x9e5cc(%rip), %rsi     # 0xde89c
callq 0x36330
movq -0x8(%rbp), %rdi
leaq 0x9e5c8(%rip), %rsi     # 0xde8a8
callq 0x36330
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0xb8(%rax), %rsi
callq 0x366c0
movq -0x8(%rbp), %rax
movl 0x90(%rax), %ecx
andl $0xffffdfff, %ecx       # imm = 0xFFFFDFFF
movl %ecx, 0x90(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
leaq 0xd302d(%rip), %rax     # 0x1138f8
cmpl $0x4, 0x674(%rax)
jne 0x408d6
jmp 0x408f8
leaq 0xa15be(%rip), %rdi     # 0xe1e9b
leaq 0xa0f74(%rip), %rsi     # 0xe1858
movl $0x38d, %edx            # imm = 0x38D
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
leaq 0xd2ff9(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
leaq 0xd2fee(%rip), %rax     # 0x1138f8
movl 0x690(%rax), %esi
movl $0x1, %edx
callq 0x20c60
leaq 0xd2fd7(%rip), %rax     # 0x1138f8
movl 0x690(%rax), %edi
callq 0x1f170
leaq 0xd2fc5(%rip), %rax     # 0x1138f8
movl 0x694(%rax), %edi
callq 0x1f170
leaq 0xd2fb3(%rip), %rax     # 0x1138f8
movq 0x698(%rax), %rdi
callq 0x1f3a0
leaq 0xd2fa0(%rip), %rax     # 0x1138f8
movq 0x698(%rax), %rdi
callq 0x2e3a0
leaq 0xd2f8d(%rip), %rax     # 0x1138f8
movl $0x1, 0x674(%rax)
popq %rbp
retq
nopw (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
leaq 0xd232d(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x668(%rax)
jne 0x415d7
jmp 0x4162c
movl $0x2, %edi
leaq 0xa1272(%rip), %rsi     # 0xe2855
movb $0x0, %al
callq 0x24fb0
leaq 0xd2307(%rip), %rax     # 0x1138f8
movq 0x668(%rax), %rax
movl 0x90(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x90(%rax)
leaq 0xd22ea(%rip), %rax     # 0x1138f8
movq 0x668(%rax), %rdi
callq 0x36a80
leaq 0xd22d7(%rip), %rax     # 0x1138f8
movq $0x0, 0x668(%rax)
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0xd1b09(%rip), %rax     # 0x1138f8
movq 0x650(%rax), %rsi
leaq 0xd1afb(%rip), %rax     # 0x1138f8
movl 0x658(%rax), %edx
xorl %eax, %eax
movl %eax, %edi
callq 0x22270
movl %eax, -0x8(%rbp)
cmpl $-0x1, -0x8(%rbp)
jne 0x41e43
callq 0x1f820
movl (%rax), %edi
callq 0x1f630
movq %rax, %rdx
movl $0x3, %edi
leaq 0xa0819(%rip), %rsi     # 0xe2649
movb $0x0, %al
callq 0x24fb0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41ed4
leaq 0xd1aae(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movl -0x8(%rbp), %esi
movl $0x3, %edx
leaq -0x64d(%rip), %rcx      # 0x41810
xorl %eax, %eax
movl %eax, %r8d
callq 0x20a80
cmpl $-0x1, %eax
jne 0x41e90
movl -0x8(%rbp), %edi
callq 0x1f170
movl $0x3, %edi
leaq 0xa07e9(%rip), %rsi     # 0xe2669
movb $0x0, %al
callq 0x24fb0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x41ed4
leaq 0xd1a61(%rip), %rax     # 0x1138f8
movq 0x798(%rax), %rcx
leaq 0xd1a53(%rip), %rax     # 0x1138f8
movq %rcx, 0x6a0(%rax)
movl -0x8(%rbp), %ecx
leaq 0xd1a42(%rip), %rax     # 0x1138f8
movl %ecx, 0x690(%rax)
leaq 0xd1a35(%rip), %rax     # 0x1138f8
movl $0x2, 0x674(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0xd1a09(%rip), %rax     # 0x1138f8
movl 0x690(%rax), %eax
movl %eax, -0x4(%rbp)
leaq 0xd19f9(%rip), %rax     # 0x1138f8
cmpl $0x2, 0x674(%rax)
je 0x41f18
leaq 0xd19e9(%rip), %rax     # 0x1138f8
cmpl $0x3, 0x674(%rax)
jne 0x41f1a
jmp 0x41f3c
leaq 0xa076d(%rip), %rdi     # 0xe268e
leaq 0x9f930(%rip), %rsi     # 0xe1858
movl $0x615, %edx            # imm = 0x615
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
leaq 0xd19b5(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movl -0x4(%rbp), %esi
movl $0x3, %edx
callq 0x20c60
movl -0x4(%rbp), %edi
callq 0x1f170
leaq 0xd1995(%rip), %rax     # 0x1138f8
movl $0xffffffff, 0x690(%rax) # imm = 0xFFFFFFFF
leaq 0xd1984(%rip), %rax     # 0x1138f8
movl $0x1, 0x674(%rax)
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
leaq 0xd1959(%rip), %rax     # 0x1138f8
cmpl $0x4, 0x674(%rax)
jne 0x41faf
callq 0x408c0
jmp 0x41fe1
leaq 0xd1942(%rip), %rax     # 0x1138f8
cmpl $0x2, 0x674(%rax)
je 0x41fcf
leaq 0xd1932(%rip), %rax     # 0x1138f8
cmpl $0x3, 0x674(%rax)
jne 0x41fd6
callq 0x41ee0
jmp 0x41fdf
movl $0x0, -0x4(%rbp)
jmp 0x41fe8
jmp 0x41fe1
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq 0xd18e2(%rip), %rax     # 0x1138f8
movq 0x650(%rax), %rdi
callq 0x2c160
movq -0x8(%rbp), %rdi
callq 0x2c0e0
movq %rax, %rcx
leaq 0xd18c3(%rip), %rax     # 0x1138f8
movq %rcx, 0x650(%rax)
movl -0xc(%rbp), %ecx
leaq 0xd18b2(%rip), %rax     # 0x1138f8
movl %ecx, 0x658(%rax)
leaq 0xd18a5(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x660(%rax)
je 0x42070
leaq 0xd1894(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rdi
callq 0x36a80
callq 0x36a30
callq 0x415c0
callq 0x3eef0
callq 0x41f90
leaq 0xd186d(%rip), %rax     # 0x1138f8
movl $0x1, 0x674(%rax)
leaq 0xd185c(%rip), %rax     # 0x1138f8
movq $0x0, 0x5f0(%rax)
leaq 0xd184a(%rip), %rax     # 0x1138f8
movq $0x0, 0x6b0(%rax)
addq $0x10, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
leaq 0xd144d(%rip), %rax     # 0x1138f8
movl $0x2710, 0x708(%rax)    # imm = 0x2710
leaq 0xd05d4(%rip), %rdi     # 0x112a90
xorl %eax, %eax
movl %eax, %esi
callq 0x231a0
movq %rax, %rcx
leaq 0xd1429(%rip), %rax     # 0x1138f8
movq %rcx, 0x6f8(%rax)
callq 0x1fdb0
movq %rax, %rcx
leaq 0xd1413(%rip), %rax     # 0x1138f8
movq %rcx, 0x700(%rax)
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x24(%rbp)
leaq 0xd126e(%rip), %rax     # 0x1138f8
movq 0x1c0(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x202b0
leaq -0x18(%rbp), %rdi
callq 0x20310
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x426e4
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
cmpl $0x9, 0x98(%rax)
je 0x426c8
jmp 0x4269a
movq -0x30(%rbp), %rax
movq 0xc0(%rax), %rax
cmpq -0x8(%rbp), %rax
jl 0x426e2
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x4269a
movl -0x24(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x148(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rsi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x42732
jmp 0x427f3
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x10(%rbp), %rdx
movl $0x1, %ecx
callq 0x81d90
cmpl $0x0, %eax
je 0x4275a
jmp 0x427f3
movq -0x8(%rbp), %rax
movq 0x148(%rax), %rdi
callq 0x42670
cltq
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x18(%rbp), %rax
jge 0x4278c
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x4279b
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x36480
jmp 0x427f3
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x120(%rax)
movq -0x28(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x140(%rax)
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x138(%rax)
leaq 0xd1128(%rip), %rax     # 0x1138f8
movq 0x710(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x1ff90
movq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x81e30
callq 0x42650
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)
// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpl $0x40, -0x14(%rbp)
jae 0x431a3
movl -0x14(%rbp), %eax
andl $0xff, %eax
orl $0x0, %eax
movb %al, -0x16(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x16(%rbp), %rsi
movl $0x1, %edx
callq 0x42f30
cmpl $-0x1, %eax
jne 0x43196
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43252
movq $0x1, -0x20(%rbp)
jmp 0x4324b
cmpl $0x4000, -0x14(%rbp)    # imm = 0x4000
jae 0x431f2
movl -0x14(%rbp), %eax
shrl $0x8, %eax
andl $0xff, %eax
orl $0x40, %eax
movb %al, -0x16(%rbp)
movl -0x14(%rbp), %eax
andl $0xff, %eax
movb %al, -0x15(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x16(%rbp), %rsi
movl $0x2, %edx
callq 0x42f30
cmpl $-0x1, %eax
jne 0x431e8
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43252
movq $0x2, -0x20(%rbp)
jmp 0x43249
movb $-0x80, -0x16(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x16(%rbp), %rsi
movl $0x1, %edx
callq 0x42f30
cmpl $-0x1, %eax
jne 0x43216
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43252
movl -0x14(%rbp), %edi
callq 0x1fab0
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0x42f30
cmpl $-0x1, %eax
jne 0x43241
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43252
movq $0x5, -0x20(%rbp)
jmp 0x4324b
movq -0x20(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)
// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x43281
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0x1, %edx
callq 0x42fc0
cmpq $0x0, %rax
jne 0x432a5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43355
movzbl -0x1a(%rbp), %eax
andl $0xc0, %eax
sarl $0x6, %eax
movl %eax, -0x24(%rbp)
cmpl $0x3, -0x24(%rbp)
jne 0x432d7
cmpq $0x0, -0x18(%rbp)
je 0x432cb
movq -0x18(%rbp), %rax
movl $0x1, (%rax)
movzbl -0x1a(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x4(%rbp)
jmp 0x43355
cmpl $0x0, -0x24(%rbp)
jne 0x432e9
movzbl -0x1a(%rbp), %eax
andl $0x3f, %eax
movl %eax, -0x4(%rbp)
jmp 0x43355
cmpl $0x1, -0x24(%rbp)
jne 0x43329
movq -0x10(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
addq $0x1, %rsi
movl $0x1, %edx
callq 0x42fc0
cmpq $0x0, %rax
jne 0x43314
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43355
movzbl -0x1a(%rbp), %eax
andl $0x3f, %eax
shll $0x8, %eax
movzbl -0x19(%rbp), %ecx
orl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x43355
movq -0x10(%rbp), %rdi
leaq -0x20(%rbp), %rsi
movl $0x4, %edx
callq 0x42fc0
cmpq $0x0, %rax
jne 0x4334a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43355
movl -0x20(%rbp), %edi
callq 0x1f5a0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop
// File: /workspace/github_c_makefile_star2_O0/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:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
cmpq $-0x80, -0x10(%rbp)
jl 0x433a0
cmpq $0x7f, -0x10(%rbp)
jg 0x433a0
movq -0x18(%rbp), %rax
movb $-0x40, (%rax)
movq -0x10(%rbp), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movl $0x2, -0x4(%rbp)
jmp 0x43474
cmpq $-0x8000, -0x10(%rbp)   # imm = 0x8000
jl 0x433f1
cmpq $0x7fff, -0x10(%rbp)    # imm = 0x7FFF
jg 0x433f1
movq -0x18(%rbp), %rax
movb $-0x3f, (%rax)
movq -0x10(%rbp), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
sarq $0x8, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movl $0x3, -0x4(%rbp)
jmp 0x43474
cmpq $-0x80000000, -0x10(%rbp) # imm = 0x80000000
jl 0x4346d
cmpq $0x7fffffff, -0x10(%rbp) # imm = 0x7FFFFFFF
jg 0x4346d
movq -0x18(%rbp), %rax
movb $-0x3e, (%rax)
movq -0x10(%rbp), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
sarq $0x8, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x2(%rax)
movq -0x10(%rbp), %rax
sarq $0x10, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x3(%rax)
movq -0x10(%rbp), %rax
sarq $0x18, %rax
andq $0xff, %rax
movb %al, %cl
movq -0x18(%rbp), %rax
movb %cl, 0x4(%rax)
movl $0x5, -0x4(%rbp)
jmp 0x43474
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax)