// File: /workspace/github_c_makefile_star2_O2/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 0xc2372(%rip), %r15     # 0xf98a8
cmpq $0x0, 0x838(%r15)
sete %cl
movl 0x98(%rdi), %eax
testb $0x2, %al
sete %dl
orb %cl, %dl
jne 0x37571
leaq 0x7a45c(%rip), %rsi     # 0xb19b3
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movl 0x98(%rbx), %eax
testw $0x4d0, %ax             # imm = 0x4D0
je 0x37721
andl $0x5, %eax
cmpl $0x1, %eax
jne 0x37595
movq %rbx, %rdi
callq 0x3cc38
leaq 0x7a448(%rip), %rsi     # 0xb19d0
pushq $0x3
popq %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2b699
movq 0x28(%rbx), %rdi
callq 0x311c8
andq $0x0, 0x28(%rbx)
testb $0x10, 0x98(%rbx)
je 0x375b4
movq %rbx, %rdi
callq 0x70160
movq 0x178(%rbx), %rdi
callq 0x2a8da
movq %rbx, %rdi
callq 0x56ece
movq 0x1a0(%rbx), %rdi
callq 0x26e2a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x566fe
movq %rbx, %rdi
xorl %esi, %esi
callq 0x567ab
movq 0x1a8(%rbx), %rdi
callq 0x2a8da
movq 0x1b0(%rbx), %rdi
callq 0x26e2a
movq 0x68(%rbx), %rdi
callq 0x26e2a
movq %rbx, %rdi
callq 0x37899
movq %rbx, %rdi
callq 0x37763
movl 0x98(%rbx), %eax
testb $0x1, %al
je 0x376b1
cmpl $0x8, 0xa0(%rbx)
jne 0x37651
movl 0xa8(%rbx), %edi
cmpl $-0x1, %edi
je 0x37640
callq 0x26180
movq 0xc0(%rbx), %rdi
testq %rdi, %rdi
je 0x37651
callq 0x311c8
movl 0x98(%rbx), %eax
andl $0x4, %eax
movq 0x1e0(%r15,%rax,2), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x270cf
testq %rax, %rax
je 0x3772e
movq %r14, %rdi
movq %rax, %rsi
callq 0x26fa8
testb $0x1, 0x98(%rbx)
je 0x376a6
movq 0x1e0(%r15), %rax
cmpq $0x0, 0x28(%rax)
jne 0x376a6
movq 0x978(%r15), %rax
movq %rax, 0x800(%r15)
callq 0x3d779
movl 0x98(%rbx), %eax
testb $0x2, %al
je 0x376c0
callq 0x3f75a
movl 0x98(%rbx), %eax
btl $0xa, %eax
jae 0x376e9
movq 0x1d0(%r15), %rdi
movq %rbx, %rsi
callq 0x270cf
testq %rax, %rax
je 0x37743
movq 0x1d0(%r15), %rdi
movq %rax, %rsi
callq 0x26fa8
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x376f7
callq 0x3a265
movq 0x40(%rbx), %rdi
callq 0x328f9
movq %rbx, %rdi
callq 0x56da0
movq 0x1b8(%rbx), %rdi
callq 0x311c8
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x328f9
movq %rbx, %rdi
popq %rbx
popq %r14
popq %r15
jmp 0x3fb19
leaq 0x7a273(%rip), %rdi     # 0xb19a8
leaq 0x7a1be(%rip), %rsi     # 0xb18fa
movl $0x350, %edx            # imm = 0x350
jmp 0x37756
leaq 0x7a25e(%rip), %rdi     # 0xb19a8
leaq 0x7a1a9(%rip), %rsi     # 0xb18fa
movl $0x362, %edx            # imm = 0x362
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0