// File: /workspace/github_c_makefile_star2_O1/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replconfCommand
void replconfCommand(redisClient *c) {
    int j;

    if ((c->argc % 2) == 0) {
        /* Number of arguments must be odd to make sure that every
         * option has a corresponding value. */
        addReply(c,shared.syntaxerr);
        return;
    }

    /* Process every option-value pair. */
    for (j = 1; j < c->argc; j+=2) {

        // 从服务器发来 REPLCONF listening-port <port> 命令
        // 主服务器将从服务器监听的端口号记录下来
        // 也即是 INFO replication 中的 slaveN ..., port = xxx 这一项
        if (!strcasecmp(c->argv[j]->ptr,"listening-port")) {
            long port;

            if ((getLongFromObjectOrReply(c,c->argv[j+1],
                    &port,NULL) != REDIS_OK))
                return;
            c->slave_listening_port = port;

        // 从服务器发来 REPLCONF ACK <offset> 命令
        // 告知主服务器，从服务器已处理的复制流的偏移量
        } else if (!strcasecmp(c->argv[j]->ptr,"ack")) {
            /* REPLCONF ACK is used by slave to inform the master the amount
             * of replication stream that it processed so far. It is an
             * internal only command that normal clients should never use. */
            // 从服务器使用 REPLCONF ACK 告知主服务器，
            // 从服务器目前已处理的复制流的偏移量
            // 主服务器更新它的记录值
            // 也即是 INFO replication 中的  slaveN ..., offset = xxx 这一项
            long long offset;

            if (!(c->flags & REDIS_SLAVE)) return;
            if ((getLongLongFromObject(c->argv[j+1], &offset) != REDIS_OK))
                return;
            // 如果 offset 已改变，那么更新
            if (offset > c->repl_ack_off)
                c->repl_ack_off = offset;
            // 更新最后一次发送 ack 的时间
            c->repl_ack_time = server.unixtime;
            /* Note: this command does not reply anything! */
            return;
        } else if (!strcasecmp(c->argv[j]->ptr,"getack")) {
            /* REPLCONF GETACK is used in order to request an ACK ASAP
             * to the slave. */
            if (server.masterhost && server.master) replicationSendAck();
            /* Note: this command does not reply anything! */
        } else {
            addReplyErrorFormat(c,"Unrecognized REPLCONF option: %s",
                (char*)c->argv[j]->ptr);
            return;
        }
    }
    addReply(c,shared.ok);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testb $0x1, 0x30(%rdi)
jne 0x33def
leaq 0x96a2e(%rip), %rax     # 0xca800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2d6f0
cmpl $0x2, 0x30(%rbx)
jl 0x33e9e
movl $0x1, %r13d
leaq 0x63dbc(%rip), %r14     # 0x97bc2
leaq 0x9619b(%rip), %r15     # 0xc9fa8
movq 0x38(%rbx), %r12
movq (%r12,%r13,8), %rax
movq 0x8(%rax), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x1f2e0
testl %eax, %eax
je 0x33e71
movq %rbp, %rdi
leaq 0x6dd77(%rip), %rsi     # 0xa1ba9
callq 0x1f2e0
testl %eax, %eax
je 0x33ec0
movq %rbp, %rdi
leaq 0x63d88(%rip), %rsi     # 0x97bd1
callq 0x1f2e0
testl %eax, %eax
jne 0x33efe
cmpq $0x0, 0x650(%r15)
je 0x33e90
cmpq $0x0, 0x660(%r15)
je 0x33e90
callq 0x33f14
jmp 0x33e90
movq 0x8(%r12,%r13,8), %rsi
movq %rbx, %rdi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x310df
testl %eax, %eax
jne 0x33eb1
movl (%rsp), %eax
movl %eax, 0xfc(%rbx)
addq $0x2, %r13
cmpl %r13d, 0x30(%rbx)
jg 0x33e0d
leaq 0x9695b(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, 0x90(%rbx)
je 0x33eb1
movq 0x8(%r12,%r13,8), %rdi
movq %rsp, %rsi
callq 0x30f9e
testl %eax, %eax
jne 0x33eb1
movq (%rsp), %rax
cmpq 0xc0(%rbx), %rax
jle 0x33eee
movq %rax, 0xc0(%rbx)
movq 0x798(%r15), %rax
movq %rax, 0xc8(%rbx)
jmp 0x33eb1
leaq 0x63cd3(%rip), %rsi     # 0x97bd8
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2d9fe
jmp 0x33eb1