// File: /workspace/github_c_makefile_star2_O3/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
movl 0x30(%rdi), %eax
testb $0x1, %al
jne 0x34229
leaq 0x965f4(%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 0x2d97c
cmpl $0x2, %eax
jl 0x342d7
movl $0x1, %r13d
leaq 0x639f3(%rip), %r14     # 0x97c32
leaq 0x95d62(%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 0x342aa
movq %rbp, %rdi
leaq 0x6d9ce(%rip), %rsi     # 0xa1c39
callq 0x1f2e0
testl %eax, %eax
je 0x342f9
movq %rbp, %rdi
leaq 0x639bf(%rip), %rsi     # 0x97c41
callq 0x1f2e0
testl %eax, %eax
jne 0x34337
cmpq $0x0, 0x650(%r15)
je 0x342c9
cmpq $0x0, 0x660(%r15)
je 0x342c9
callq 0x3434d
jmp 0x342c9
movq 0x8(%r12,%r13,8), %rsi
movq %rbx, %rdi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x313b2
testl %eax, %eax
jne 0x342ea
movl (%rsp), %eax
movl %eax, 0xfc(%rbx)
addq $0x2, %r13
cmpl %r13d, 0x30(%rbx)
jg 0x34246
leaq 0x96522(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb $0x1, 0x90(%rbx)
je 0x342ea
movq 0x8(%r12,%r13,8), %rdi
movq %rsp, %rsi
callq 0x31271
testl %eax, %eax
jne 0x342ea
movq (%rsp), %rax
cmpq 0xc0(%rbx), %rax
jle 0x34327
movq %rax, 0xc0(%rbx)
movq 0x798(%r15), %rax
movq %rax, 0xc8(%rbx)
jmp 0x342ea
leaq 0x6390a(%rip), %rsi     # 0x97c48
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2dc8a
jmp 0x342ea