// File: /workspace/github_c_makefile_star2_O2/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 0x3207a
leaq 0x957a3(%rip), %rax     # 0xc7800
movq 0x80(%rax), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2c10d
pushq $0x1
popq %r13
leaq 0x5bb71(%rip), %r14     # 0x8dbf6
leaq 0x94f1c(%rip), %r15     # 0xc6fa8
cltq
cmpq %rax, %r13
jge 0x32122
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 0x320f7
movq %rbp, %rdi
leaq 0x65b0d(%rip), %rsi     # 0x97bc9
callq 0x1f2e0
testl %eax, %eax
je 0x32137
movq %rbp, %rdi
leaq 0x5bb36(%rip), %rsi     # 0x8dc05
callq 0x1f2e0
testl %eax, %eax
jne 0x32175
cmpq $0x0, 0x650(%r15)
je 0x32116
cmpq $0x0, 0x660(%r15)
je 0x32116
callq 0x32198
jmp 0x32116
movq 0x8(%r12,%r13,8), %rsi
movq %rbx, %rdi
movq %rsp, %rdx
xorl %ecx, %ecx
callq 0x2f672
testl %eax, %eax
jne 0x32189
movl (%rsp), %eax
movl %eax, 0xfc(%rbx)
addq $0x2, %r13
movl 0x30(%rbx), %eax
jmp 0x3208c
leaq 0x956d7(%rip), %rax     # 0xc7800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x32189
testb $0x1, 0x90(%rbx)
je 0x32189
movq 0x8(%r12,%r13,8), %rdi
movq %rsp, %rsi
callq 0x2f540
testl %eax, %eax
jne 0x32189
movq (%rsp), %rax
cmpq 0xc0(%rbx), %rax
jle 0x32165
movq %rax, 0xc0(%rbx)
movq 0x798(%r15), %rax
movq %rax, 0xc8(%rbx)
jmp 0x32189
leaq 0x5ba90(%rip), %rsi     # 0x8dc0c
movq %rbx, %rdi
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2c301
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq