// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movl 0x30(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x400ac
movq -0x8(%rbp), %rdi
leaq 0xd40b5(%rip), %rax     # 0x114150
movq 0x80(%rax), %rsi
callq 0x35a70
jmp 0x4026d
movl $0x1, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x30(%rcx), %eax
jge 0x40259
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xa1c20(%rip), %rsi     # 0xe1cfe
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x4012d
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq -0x18(%rbp), %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x3b960
cmpl $0x0, %eax
je 0x40118
jmp 0x4026d
movq -0x18(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xfc(%rax)
jmp 0x40249
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xabc51(%rip), %rsi     # 0xebd99
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x401cf
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x40169
jmp 0x4026d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x20(%rbp), %rsi
callq 0x3b780
cmpl $0x0, %eax
je 0x40191
jmp 0x4026d
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0xc0(%rcx), %rax
jle 0x401b1
movq -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xc0(%rax)
leaq 0xd3740(%rip), %rax     # 0x1138f8
movq 0x798(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xc8(%rax)
jmp 0x4026d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdi
leaq 0xa1b23(%rip), %rsi     # 0xe1d0d
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x4021d
leaq 0xd36fd(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x650(%rax)
je 0x4021b
leaq 0xd36ec(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x660(%rax)
je 0x4021b
callq 0x40280
jmp 0x40245
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0xc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rdx
leaq 0xa1ad8(%rip), %rsi     # 0xe1d14
movb $0x0, %al
callq 0x35d80
jmp 0x4026d
jmp 0x40247
jmp 0x40249
jmp 0x4024b
movl -0xc(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xc(%rbp)
jmp 0x400b3
movq -0x8(%rbp), %rdi
leaq 0xd3eec(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)