// File: /workspace/github_c_makefile_star2_O0/nilyang[P]redis-tdd-annotation/src/networking.c
// Function: clientCommand
void clientCommand(redisClient *c) {
    listNode *ln;
    listIter li;
    redisClient *client;

    // CLIENT list
    if (!strcasecmp(c->argv[1]->ptr,"list") && c->argc == 2) {
        sds o = getAllClientsInfoString();
        addReplyBulkCBuffer(c,o,sdslen(o));
        sdsfree(o);

    // CLIENT kill
    } else if (!strcasecmp(c->argv[1]->ptr,"kill") && c->argc == 3) {

        // 遍历客户端链表，并杀死指定地址的客户端
        listRewind(server.clients,&li);
        while ((ln = listNext(&li)) != NULL) {
            char *peerid;

            client = listNodeValue(ln);
            peerid = getClientPeerId(client);
            if (strcmp(peerid,c->argv[2]->ptr) == 0) {
                addReply(c,shared.ok);
                if (c == client) {
                    client->flags |= REDIS_CLOSE_AFTER_REPLY;
                } else {
                    freeClient(client);
                }
                return;
            }
        }
        addReplyError(c,"No such client");

    // CLIENT setname 设置客户端名字
    } else if (!strcasecmp(c->argv[1]->ptr,"setname") && c->argc == 3) {
        int j, len = sdslen(c->argv[2]->ptr);
        char *p = c->argv[2]->ptr;

        /* Setting the client name to an empty string actually removes
         * the current name. */
        // 名字为空时，清空客户端的名字
        if (len == 0) {
            if (c->name) decrRefCount(c->name);
            c->name = NULL;
            addReply(c,shared.ok);
            return;
        }

        /* Otherwise check if the charset is ok. We need to do this otherwise
         * CLIENT LIST format will break. You should always be able to
         * split by space to get the different fields. */
        for (j = 0; j < len; j++) {
            if (p[j] < '!' || p[j] > '~') { /* ASCII is assumed. */
                addReplyError(c,
                    "Client names cannot contain spaces, "
                    "newlines or special characters.");
                return;
            }
        }
        if (c->name) decrRefCount(c->name);
        c->name = c->argv[2];
        incrRefCount(c->name);
        addReply(c,shared.ok);

    // CLIENT getname 获取客户端的名字
    } else if (!strcasecmp(c->argv[1]->ptr,"getname") && c->argc == 2) {
        if (c->name)
            addReplyBulk(c,c->name);
        else
            addReply(c,shared.nullbulk);
    } else if (!strcasecmp(c->argv[1]->ptr,"pause") && c->argc == 3) {
        long long duration;

        if (getTimeoutFromObjectOrReply(c,c->argv[2],&duration,UNIT_MILLISECONDS)
                                        != REDIS_OK) return;
        pauseClients(duration);
        addReply(c,shared.ok);
    } else {
        addReplyError(c, "Syntax error, try CLIENT (LIST | KILL ip:port | GETNAME | SETNAME connection-name)");
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa9145(%rip), %rsi     # 0xe15c8
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x384d7
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x384d7
callq 0x383c0
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rdi
callq 0x34800
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq %rax, %rdx
callq 0x36670
movq -0x30(%rbp), %rdi
callq 0x2c160
jmp 0x387f6
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa8cff(%rip), %rsi     # 0xe11ed
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x385c6
movq -0x8(%rbp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x385c6
leaq 0xdb3e7(%rip), %rax     # 0x1138f8
movq 0x1b0(%rax), %rdi
leaq -0x20(%rbp), %rsi
callq 0x202b0
leaq -0x20(%rbp), %rdi
callq 0x20310
movq %rax, -0x10(%rbp)
cmpq $0x0, %rax
je 0x385b1
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x38330
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rsi
callq 0x1f890
cmpl $0x0, %eax
jne 0x385ac
movq -0x8(%rbp), %rdi
leaq 0xdbbda(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
movq -0x8(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x3859e
movq -0x28(%rbp), %rax
movl 0x90(%rax), %ecx
orl $0x40, %ecx
movl %ecx, 0x90(%rax)
jmp 0x385a7
movq -0x28(%rbp), %rdi
callq 0x36a80
jmp 0x387f6
jmp 0x38521
movq -0x8(%rbp), %rdi
leaq 0xa8c36(%rip), %rsi     # 0xe11f2
callq 0x35d40
jmp 0x387f4
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa8c24(%rip), %rsi     # 0xe1201
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x3870d
movq -0x8(%rbp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x3870d
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdi
callq 0x34800
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
cmpl $0x0, -0x40(%rbp)
jne 0x38668
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x38643
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3aaa0
movq -0x8(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x8(%rbp), %rdi
leaq 0xdbaf6(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
jmp 0x387f6
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x40(%rbp), %eax
jge 0x386bb
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x21, %eax
jl 0x38699
movq -0x48(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
jle 0x386ae
movq -0x8(%rbp), %rdi
leaq 0xa8b65(%rip), %rsi     # 0xe1209
callq 0x35d40
jmp 0x387f6
jmp 0x386b0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3866f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x386d3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3aaa0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x3a3f0
movq -0x8(%rbp), %rdi
leaq 0xdba51(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
jmp 0x387f2
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xa8b29(%rip), %rsi     # 0xe124d
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x3876f
movq -0x8(%rbp), %rax
cmpl $0x2, 0x30(%rax)
jne 0x3876f
movq -0x8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x38756
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x36620
jmp 0x3876a
movq -0x8(%rbp), %rdi
leaq 0xdb9ef(%rip), %rax     # 0x114150
movq 0x50(%rax), %rsi
callq 0x35a70
jmp 0x387f0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax), %rdi
leaq 0xb335a(%rip), %rsi     # 0xebae0
callq 0x1f2f0
cmpl $0x0, %eax
jne 0x387de
movq -0x8(%rbp), %rax
cmpl $0x3, 0x30(%rax)
jne 0x387de
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rax), %rsi
leaq -0x50(%rbp), %rdx
movl $0x1, %ecx
callq 0x81d90
cmpl $0x0, %eax
je 0x387bf
jmp 0x387f6
movq -0x50(%rbp), %rdi
callq 0x38800
movq -0x8(%rbp), %rdi
leaq 0xdb97d(%rip), %rax     # 0x114150
movq 0x8(%rax), %rsi
callq 0x35a70
jmp 0x387ee
movq -0x8(%rbp), %rdi
leaq 0xa8a6c(%rip), %rsi     # 0xe1255
callq 0x35d40
jmp 0x387f0
jmp 0x387f2
jmp 0x387f4
jmp 0x387f6
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax)