// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/networking.c
// Function: freeClient
void freeClient(client *c) {
    listNode *ln;

    /* If it is our master that's beging disconnected we should make sure
     * to cache the state to try a partial resynchronization later.
     *
     * Note that before doing this we make sure that the client is not in
     * some unexpected state, by checking its flags. */
    if (server.master && c->flags & CLIENT_MASTER) {
        serverLog(LL_WARNING,"Connection with master lost.");
        if (!(c->flags & (CLIENT_CLOSE_AFTER_REPLY|
                          CLIENT_CLOSE_ASAP|
                          CLIENT_BLOCKED|
                          CLIENT_UNBLOCKED)))
        {
            replicationCacheMaster(c);
            return;
        }
    }

    /* Log link disconnection with slave */
    if ((c->flags & CLIENT_SLAVE) && !(c->flags & CLIENT_MONITOR)) {
        serverLog(LL_WARNING,"Connection with slave %s lost.",
            replicationGetSlaveName(c));
    }

    /* Free the query buffer */
    sdsfree(c->querybuf);
    c->querybuf = NULL;

    /* Deallocate structures used to block on blocking ops. */
    if (c->flags & CLIENT_BLOCKED) unblockClient(c);
    dictRelease(c->bpop.keys);

    /* UNWATCH all the keys */
    unwatchAllKeys(c);
    listRelease(c->watched_keys);

    /* Unsubscribe from all the pubsub channels */
    pubsubUnsubscribeAllChannels(c,0);
    pubsubUnsubscribeAllPatterns(c,0);
    dictRelease(c->pubsub_channels);
    listRelease(c->pubsub_patterns);

    /* Free data structures. */
    listRelease(c->reply);
    freeClientArgv(c);

    /* Unlink the client: this will close the socket, remove the I/O
     * handlers, and remove references of the client from different
     * places where active clients may be referenced. */
    unlinkClient(c);

    /* Master/slave cleanup Case 1:
     * we lost the connection with a slave. */
    if (c->flags & CLIENT_SLAVE) {
        if (c->replstate == SLAVE_STATE_SEND_BULK) {
            if (c->repldbfd != -1) close(c->repldbfd);
            if (c->replpreamble) sdsfree(c->replpreamble);
        }
        list *l = (c->flags & CLIENT_MONITOR) ? server.monitors : server.slaves;
        ln = listSearchKey(l,c);
        serverAssert(ln != NULL);
        listDelNode(l,ln);
        /* We need to remember the time when we started to have zero
         * attached slaves, as after some time we'll free the replication
         * backlog. */
        if (c->flags & CLIENT_SLAVE && listLength(server.slaves) == 0)
            server.repl_no_slaves_since = server.unixtime;
        refreshGoodSlavesCount();
    }

    /* Master/slave cleanup Case 2:
     * we lost the connection with the master. */
    if (c->flags & CLIENT_MASTER) replicationHandleMasterDisconnection();

    /* If this client was scheduled for async freeing we need to remove it
     * from the queue. */
    if (c->flags & CLIENT_CLOSE_ASAP) {
        ln = listSearchKey(server.clients_to_close,c);
        serverAssert(ln != NULL);
        listDelNode(server.clients_to_close,ln);
    }

    /* Release other dynamically allocated client structure fields,
     * and finally release the client structure itself. */
    if (c->name) decrRefCount(c->name);
    zfree(c->argv);
    freeClientMultiState(c);
    sdsfree(c->peerid);
    zfree(c);
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0xc5d45(%rip), %r15     # 0x106858
cmpq $0x0, 0x828(%r15)
je 0x40b4b
testb $0x2, 0x98(%rbx)
je 0x40b4b
leaq 0x8249a(%rip), %rsi     # 0xc2fc7
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movzwl 0x98(%rbx), %eax
testl $0x4d0, %eax            # imm = 0x4D0
je 0x40d01
movl 0x98(%rbx), %eax
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x40b77
movq %rbx, %rdi
callq 0x47084
leaq 0x8247c(%rip), %rsi     # 0xc2fe4
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x32ea6
movq 0x28(%rbx), %rdi
callq 0x392b6
movq $0x0, 0x28(%rbx)
testb $0x10, 0x98(%rbx)
je 0x40b99
movq %rbx, %rdi
callq 0x806f2
movq 0x178(%rbx), %rdi
callq 0x31ff3
movq %rbx, %rdi
callq 0x646d5
movq 0x1a0(%rbx), %rdi
callq 0x2e360
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63ded
movq %rbx, %rdi
xorl %esi, %esi
callq 0x63ea3
movq 0x1a8(%rbx), %rdi
callq 0x31ff3
movq 0x1b0(%rbx), %rdi
callq 0x2e360
movq 0x68(%rbx), %rdi
callq 0x2e360
movq %rbx, %rdi
callq 0x40e7f
movq %rbx, %rdi
callq 0x40d45
testb $0x1, 0x98(%rbx)
je 0x40c8f
cmpl $0x8, 0xa0(%rbx)
jne 0x40c35
movl 0xa8(%rbx), %edi
cmpl $-0x1, %edi
je 0x40c24
callq 0x26180
movq 0xc0(%rbx), %rdi
testq %rdi, %rdi
je 0x40c35
callq 0x392b6
movl 0x98(%rbx), %eax
andl $0x4, %eax
movq 0x1e0(%r15,%rax,2), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2e653
testq %rax, %rax
je 0x40d0e
movq %r14, %rdi
movq %rax, %rsi
callq 0x2e4f4
testb $0x1, 0x98(%rbx)
je 0x40c8a
movq 0x1e0(%r15), %rax
cmpq $0x0, 0x28(%rax)
jne 0x40c8a
movq 0x968(%r15), %rax
movq %rax, 0x7f0(%r15)
callq 0x47c37
testb $0x2, 0x98(%rbx)
je 0x40c9d
callq 0x49fe4
testb $0x4, 0x99(%rbx)
je 0x40cc9
movq 0x1d0(%r15), %rdi
movq %rbx, %rsi
callq 0x2e653
testq %rax, %rax
je 0x40d23
movq 0x1d0(%r15), %rdi
movq %rax, %rsi
callq 0x2e4f4
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x40cd7
callq 0x440f3
movq 0x40(%rbx), %rdi
callq 0x3b3df
movq %rbx, %rdi
callq 0x6458e
movq 0x1b8(%rbx), %rdi
callq 0x392b6
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3b3df
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x4a3dc
leaq 0x822a7(%rip), %rdi     # 0xc2fbc
leaq 0x821f2(%rip), %rsi     # 0xc2f0e
movl $0x350, %edx            # imm = 0x350
jmp 0x40d36
leaq 0x82292(%rip), %rdi     # 0xc2fbc
leaq 0x821dd(%rip), %rsi     # 0xc2f0e
movl $0x362, %edx            # imm = 0x362
callq 0x654e1
movl $0x1, %edi
callq 0x263d0