// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/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 0xc415e(%rip), %r15     # 0x1018a8
cmpq $0x0, 0x838(%r15)
sete %cl
movl 0x98(%rdi), %eax
testb $0x2, %al
sete %dl
orb %cl, %dl
jne 0x3d788
leaq 0x828a4(%rip), %rsi     # 0xc000f
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movl 0x98(%rbx), %eax
testl $0x4d0, %eax            # imm = 0x4D0
je 0x3d93d
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x3d7ae
movq %rbx, %rdi
callq 0x43e7c
leaq 0x8288d(%rip), %rsi     # 0xc002c
movl $0x3, %edi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2fdad
movq 0x28(%rbx), %rdi
callq 0x36330
movq $0x0, 0x28(%rbx)
testb $0x10, 0x98(%rbx)
je 0x3d7d0
movq %rbx, %rdi
callq 0x7cca6
movq 0x178(%rbx), %rdi
callq 0x2eef3
movq %rbx, %rdi
callq 0x60ae5
movq 0x1a0(%rbx), %rdi
callq 0x2b19c
movq %rbx, %rdi
xorl %esi, %esi
callq 0x60201
movq %rbx, %rdi
xorl %esi, %esi
callq 0x602b7
movq 0x1a8(%rbx), %rdi
callq 0x2eef3
movq 0x1b0(%rbx), %rdi
callq 0x2b19c
movq 0x68(%rbx), %rdi
callq 0x2b19c
movq %rbx, %rdi
callq 0x3dac3
movq %rbx, %rdi
callq 0x3d981
movl 0x98(%rbx), %eax
testb $0x1, %al
je 0x3d8cd
cmpl $0x8, 0xa0(%rbx)
jne 0x3d86d
movl 0xa8(%rbx), %edi
cmpl $-0x1, %edi
je 0x3d85c
callq 0x26180
movq 0xc0(%rbx), %rdi
testq %rdi, %rdi
je 0x3d86d
callq 0x36330
movl 0x98(%rbx), %eax
andl $0x4, %eax
movq 0x1e0(%r15,%rax,2), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2b470
testq %rax, %rax
je 0x3d94a
movq %r14, %rdi
movq %rax, %rsi
callq 0x2b331
testb $0x1, 0x98(%rbx)
je 0x3d8c2
movq 0x1e0(%r15), %rax
cmpq $0x0, 0x28(%rax)
jne 0x3d8c2
movq 0x978(%r15), %rax
movq %rax, 0x800(%r15)
callq 0x44a2b
movl 0x98(%rbx), %eax
testb $0x2, %al
je 0x3d8dc
callq 0x46d01
movl 0x98(%rbx), %eax
btl $0xa, %eax
jae 0x3d905
movq 0x1d0(%r15), %rdi
movq %rbx, %rsi
callq 0x2b470
testq %rax, %rax
je 0x3d95f
movq 0x1d0(%r15), %rdi
movq %rax, %rsi
callq 0x2b331
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x3d913
callq 0x40c8f
movq 0x40(%rbx), %rdi
callq 0x38413
movq %rbx, %rdi
callq 0x6099e
movq 0x1b8(%rbx), %rdi
callq 0x36330
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x38413
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x470fa
leaq 0x826b3(%rip), %rdi     # 0xc0004
leaq 0x825fe(%rip), %rsi     # 0xbff56
movl $0x350, %edx            # imm = 0x350
jmp 0x3d972
leaq 0x8269e(%rip), %rdi     # 0xc0004
leaq 0x825e9(%rip), %rsi     # 0xbff56
movl $0x362, %edx            # imm = 0x362
callq 0x61908
movl $0x1, %edi
callq 0x263c0