// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/replication.c
// Function: replicationCacheMaster
void replicationCacheMaster(redisClient *c) {
    listNode *ln;

    redisAssert(server.master != NULL && server.cached_master == NULL);
    redisLog(REDIS_NOTICE,"Caching the disconnected master state.");

    /* Remove from the list of clients, we don't want this client to be
     * listed by CLIENT LIST or processed in any way by batch operations. */
    // 从客户端链表中移除主服务器
    ln = listSearchKey(server.clients,c);
    redisAssert(ln != NULL);
    listDelNode(server.clients,ln);

    /* Save the master. Server.master will be set to null later by
     * replicationHandleMasterDisconnection(). */
    // 缓存 master
    server.cached_master = server.master;

    /* Remove the event handlers and close the socket. We'll later reuse
     * the socket of the new connection with the master during PSYNC. */
    // 删除事件监视，关闭 socket
    aeDeleteFileEvent(server.el,c->fd,AE_READABLE);
    aeDeleteFileEvent(server.el,c->fd,AE_WRITABLE);
    close(c->fd);

    /* Set fd to -1 so that we can safely call freeClient(c) later. */
    c->fd = -1;

    /* Invalidate the Peer ID cache. */
    if (c->peerid) {
        sdsfree(c->peerid);
        c->peerid = NULL;
    }

    /* Caching the master happens instead of the actual freeClient() call,
     * so make sure to adjust the replication state. This function will
     * also set server.master to NULL. */
    // 重置复制状态，并将 server.master 设为 NULL
    // 并强制断开这个服务器的所有从服务器，让它们执行 resync 
    replicationHandleMasterDisconnection();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
leaq 0xd15b5(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x660(%rax)
je 0x42360
leaq 0xd15a4(%rip), %rax     # 0x1138f8
cmpq $0x0, 0x668(%rax)
jne 0x42360
jmp 0x42382
leaq 0xa0491(%rip), %rdi     # 0xe27f8
leaq 0x9f4ea(%rip), %rsi     # 0xe1858
movl $0x6e0, %edx            # imm = 0x6E0
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
movl $0x2, %edi
leaq 0xa04a0(%rip), %rsi     # 0xe282e
movb $0x0, %al
callq 0x24fb0
leaq 0xd155c(%rip), %rax     # 0x1138f8
movq 0x1b0(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x20480
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x423b9
jmp 0x423db
leaq 0xa0cb9(%rip), %rdi     # 0xe3079
leaq 0x9f491(%rip), %rsi     # 0xe1858
movl $0x6e7, %edx            # imm = 0x6E7
callq 0x63ca0
movl $0x1, %edi
callq 0x1f3b0
leaq 0xd1516(%rip), %rax     # 0x1138f8
movq 0x1b0(%rax), %rdi
movq -0x10(%rbp), %rsi
callq 0x20170
leaq 0xd14ff(%rip), %rax     # 0x1138f8
movq 0x660(%rax), %rcx
leaq 0xd14f1(%rip), %rax     # 0x1138f8
movq %rcx, 0x668(%rax)
leaq 0xd14e3(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %esi
movl $0x1, %edx
callq 0x20c60
leaq 0xd14c8(%rip), %rax     # 0x1138f8
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movl (%rax), %esi
movl $0x2, %edx
callq 0x20c60
movq -0x8(%rbp), %rax
movl (%rax), %edi
callq 0x1f170
movq -0x8(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
cmpq $0x0, 0x168(%rax)
je 0x42486
movq -0x8(%rbp), %rax
movq 0x168(%rax), %rdi
callq 0x2c160
movq -0x8(%rbp), %rax
movq $0x0, 0x168(%rax)
callq 0x36f40
addq $0x10, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)