// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationResurrectCachedMaster
void replicationResurrectCachedMaster(int newfd) {
    
    // 设置 master
    server.master = server.cached_master;
    server.cached_master = NULL;

    server.master->fd = newfd;

    server.master->flags &= ~(REDIS_CLOSE_AFTER_REPLY|REDIS_CLOSE_ASAP);

    server.master->authenticated = 1;
    server.master->lastinteraction = server.unixtime;

    // 回到已连接状态
    server.repl_state = REDIS_REPL_CONNECTED;

    /* Re-add to the list of clients. */
    // 将 master 重新加入到客户端列表中
    listAddNodeTail(server.clients,server.master);
    // 监听 master 的读事件
    if (aeCreateFileEvent(server.el, newfd, AE_READABLE,
                          readQueryFromClient, server.master)) {
        redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
        freeClientAsync(server.master); /* Close ASAP. */
    }

    /* We may also need to install the write handler as well if there is
     * pending data in the write buffers. */
    if (server.master->bufpos || listLength(server.master->reply)) {
        if (aeCreateFileEvent(server.el, newfd, AE_WRITABLE,
                          sendReplyToClient, server.master)) {
            redisLog(REDIS_WARNING,"Error resurrecting the cached master, impossible to add the writable handler: %s", strerror(errno));
            freeClientAsync(server.master); /* Close ASAP. */
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movl %edi, -0x4(%rbp)
leaq 0xd22b6(%rip), %rax     # 0x1138f8
movq 0x668(%rax), %rcx
leaq 0xd22a8(%rip), %rax     # 0x1138f8
movq %rcx, 0x660(%rax)
leaq 0xd229a(%rip), %rax     # 0x1138f8
movq $0x0, 0x668(%rax)
movl -0x4(%rbp), %ecx
leaq 0xd2285(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movl %ecx, (%rax)
leaq 0xd2275(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movl 0x90(%rax), %ecx
andl $0xfffffbbf, %ecx       # imm = 0xFFFFFBBF
movl %ecx, 0x90(%rax)
leaq 0xd2255(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movl $0x1, 0x94(%rax)
leaq 0xd223d(%rip), %rax     # 0x1138f8
movq 0x798(%rax), %rcx
leaq 0xd222f(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movq %rcx, 0x80(%rax)
leaq 0xd221a(%rip), %rax     # 0x1138f8
movl $0x5, 0x674(%rax)
leaq 0xd2209(%rip), %rax     # 0x1138f8
movq 0x1b0(%rax), %rdi
leaq 0xd21fb(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rsi
callq 0x1ff90
leaq 0xd21e8(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movl -0x4(%rbp), %esi
leaq 0xd21da(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %r8
movl $0x1, %edx
leaq -0xca81(%rip), %rcx     # 0x34cb0
callq 0x20a80
cmpl $0x0, %eax
je 0x41770
callq 0x1f820
movl (%rax), %edi
callq 0x1f630
movq %rax, %rdx
movl $0x3, %edi
leaq 0xa112a(%rip), %rsi     # 0xe2880
movb $0x0, %al
callq 0x24fb0
leaq 0xd2194(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rdi
callq 0x37000
leaq 0xd2181(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
cmpl $0x0, 0x170(%rax)
jne 0x417a0
leaq 0xd216a(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rax
movq 0x60(%rax), %rax
cmpq $0x0, 0x28(%rax)
je 0x41809
leaq 0xd2151(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movl -0x4(%rbp), %esi
leaq 0xd2143(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %r8
movl $0x2, %edx
leaq -0xc788(%rip), %rcx     # 0x35040
callq 0x20a80
cmpl $0x0, %eax
je 0x41807
callq 0x1f820
movl (%rax), %edi
callq 0x1f630
movq %rax, %rdx
movl $0x3, %edi
leaq 0xa10e4(%rip), %rsi     # 0xe28d1
movb $0x0, %al
callq 0x24fb0
leaq 0xd20fd(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rdi
callq 0x37000
jmp 0x41809
addq $0x10, %rsp
popq %rbp
retq
nop