// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/networking.c
// Function: createClient
client *createClient(int fd) {
    client *c = zmalloc(sizeof(client));

    /* passing -1 as fd it is possible to create a non connected client.
     * This is useful since all the commands needs to be executed
     * in the context of a client. When commands are executed in other
     * contexts (for instance a Lua script) we need a non connected client. */
    if (fd != -1) {
        anetNonBlock(NULL,fd);
        anetEnableTcpNoDelay(NULL,fd);
        if (server.tcpkeepalive)
            anetKeepAlive(NULL,fd,server.tcpkeepalive);
        if (aeCreateFileEvent(server.el,fd,AE_READABLE,
            readQueryFromClient, c) == AE_ERR)
        {
            close(fd);
            zfree(c);
            return NULL;
        }
    }

    selectDb(c,0);
    c->id = server.next_client_id++;
    c->fd = fd;
    c->name = NULL;
    c->bufpos = 0;
    c->querybuf = sdsempty();
    c->querybuf_peak = 0;
    c->reqtype = 0;
    c->argc = 0;
    c->argv = NULL;
    c->cmd = c->lastcmd = NULL;
    c->multibulklen = 0;
    c->bulklen = -1;
    c->sentlen = 0;
    c->flags = 0;
    c->ctime = c->lastinteraction = server.unixtime;
    c->authenticated = 0;
    c->replstate = REPL_STATE_NONE;
    c->repl_put_online_on_ack = 0;
    c->reploff = 0;
    c->repl_ack_off = 0;
    c->repl_ack_time = 0;
    c->slave_listening_port = 0;
    c->slave_ip[0] = '\0';
    c->slave_capa = SLAVE_CAPA_NONE;
    c->reply = listCreate();
    c->reply_bytes = 0;
    c->obuf_soft_limit_reached_time = 0;
    listSetFreeMethod(c->reply,decrRefCountVoid);
    listSetDupMethod(c->reply,dupClientReplyValue);
    c->btype = BLOCKED_NONE;
    c->bpop.timeout = 0;
    c->bpop.keys = dictCreate(&setDictType,NULL);
    c->bpop.target = NULL;
    c->bpop.numreplicas = 0;
    c->bpop.reploffset = 0;
    c->woff = 0;
    c->watched_keys = listCreate();
    c->pubsub_channels = dictCreate(&setDictType,NULL);
    c->pubsub_patterns = listCreate();
    c->peerid = NULL;
    listSetFreeMethod(c->pubsub_patterns,decrRefCountVoid);
    listSetMatchMethod(c->pubsub_patterns,listMatchObjects);
    if (fd != -1) listAddNodeTail(server.clients,c);
    initClientMultiState(c);
    return c;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edi, %ebp
movl $0x41c8, %edi           # imm = 0x41C8
callq 0x3b29d
movq %rax, %rbx
cmpl $-0x1, %ebp
je 0x3f1ef
xorl %edi, %edi
movl %ebp, %esi
callq 0x30779
xorl %edi, %edi
movl %ebp, %esi
callq 0x308ab
leaq 0xc76a0(%rip), %r14     # 0x106858
movl 0x5f0(%r14), %edx
testl %edx, %edx
je 0x3f1cc
xorl %edi, %edi
movl %ebp, %esi
callq 0x3078a
movq 0x40(%r14), %rdi
leaq 0x1ac(%rip), %rcx       # 0x3f383
movl %ebp, %esi
movl $0x1, %edx
movq %rbx, %r8
callq 0x2fee7
cmpl $-0x1, %eax
je 0x3f360
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4554b
leaq 0xc7655(%rip), %r15     # 0x106858
movq 0x310(%r15), %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x310(%r15)
movq %rax, (%rbx)
movl %ebp, 0x8(%rbx)
movq %r12, 0x20(%rbx)
movl %r12d, 0x1c0(%rbx)
callq 0x39222
movq %rax, 0x28(%rbx)
movq %r12, 0x30(%rbx)
movl %r12d, 0x38(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x40(%rbx)
movups %xmm0, 0x50(%rbx)
movq $-0x1, 0x60(%rbx)
movq %r12, 0x78(%rbx)
movl %r12d, 0x98(%rbx)
movq 0x968(%r15), %rax
movq %rax, 0x88(%rbx)
movq %rax, 0x80(%rbx)
movq %r12, 0x9c(%rbx)
movl %r12d, 0xa4(%rbx)
movl %r12d, 0x114(%rbx)
movb $0x0, 0x118(%rbx)
movl %r12d, 0x148(%rbx)
movq %r12, 0xd8(%rbx)
movups %xmm0, 0xc8(%rbx)
callq 0x2e33c
movq %rax, 0x68(%rbx)
movq %r12, 0x70(%rbx)
movq %r12, 0x90(%rbx)
leaq 0x4ee5(%rip), %r13      # 0x4419b
movq %r13, 0x18(%rax)
leaq -0x154(%rip), %rcx      # 0x3f16d
movq %rcx, 0x10(%rax)
movl %r12d, 0x168(%rbx)
movq %r12, 0x170(%rbx)
leaq 0xc6a36(%rip), %r14     # 0x105d10
movq %r14, %rdi
xorl %esi, %esi
callq 0x31774
movq %rax, 0x178(%rbx)
movq %r12, 0x180(%rbx)
movl %r12d, 0x188(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x190(%rbx)
callq 0x2e33c
movq %rax, 0x1a0(%rbx)
movq %r14, %rdi
xorl %esi, %esi
callq 0x31774
movq %rax, 0x1a8(%rbx)
callq 0x2e33c
movq %rax, 0x1b0(%rbx)
movq %r12, 0x1b8(%rbx)
movq %r13, 0x18(%rax)
leaq -0x1c3(%rip), %rcx      # 0x3f17b
movq %rcx, 0x20(%rax)
cmpl $-0x1, %ebp
je 0x3f356
movq 0x1c8(%r15), %rdi
movq %rbx, %rsi
callq 0x2e40f
movq %rbx, %rdi
callq 0x64578
jmp 0x3f371
movl %ebp, %edi
callq 0x26180
movq %rbx, %rdi
callq 0x3b3df
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq