// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %r15
movq 0x8(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x5fa04(%rip), %rsi     # 0x8d4be
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2daf4
cmpl $0x2, 0x30(%rbx)
jne 0x2daf4
callq 0x2da10
movq %rax, %r14
movslq -0x8(%rax), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2c87d
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x271f7
leaq 0x5f5f8(%rip), %rsi     # 0x8d0f3
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2db84
cmpl $0x3, 0x30(%rbx)
jne 0x2db84
leaq 0x99494(%rip), %rax     # 0xc6fa8
movq 0x1b0(%rax), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0x1ffac
movq %r14, %rdi
callq 0x1ffc6
testq %rax, %rax
je 0x2dc80
movq 0x10(%rax), %r15
movq %r15, %rdi
callq 0x2d9c6
movq 0x38(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdi
callq 0x1f880
testl %eax, %eax
jne 0x2db26
leaq 0x99c9e(%rip), %rax     # 0xc7800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
cmpq %rbx, %r15
je 0x2dcf1
movq %r15, %rdi
callq 0x2cb56
jmp 0x2dcf9
leaq 0x5f57c(%rip), %rsi     # 0x8d107
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2dbdd
cmpl $0x3, 0x30(%rbx)
jne 0x2dbdd
movq 0x10(%r15), %rdi
movq 0x8(%rdi), %rax
movl -0x8(%rax), %ecx
testl %ecx, %ecx
je 0x2dc91
xorl %edx, %edx
testl %ecx, %ecx
cmovlel %edx, %ecx
cmpq %rdx, %rcx
je 0x2dca6
movb (%rax,%rdx), %sil
addb $-0x7f, %sil
incq %rdx
cmpb $-0x5f, %sil
ja 0x2dbb7
leaq 0x5f537(%rip), %rsi     # 0x8d10f
jmp 0x2dc6f
leaq 0x5f56f(%rip), %rsi     # 0x8d153
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2dc14
cmpl $0x2, 0x30(%rbx)
jne 0x2dc14
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x2dcd5
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2c84a
leaq 0x69cf5(%rip), %rsi     # 0x97910
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2dc68
cmpl $0x3, 0x30(%rbx)
jne 0x2dc68
movq 0x10(%r15), %rsi
movq %rsp, %rdx
pushq $0x1
popq %rcx
movq %rbx, %rdi
callq 0x5b94c
testl %eax, %eax
jne 0x2dcf9
movq (%rsp), %rdi
callq 0x2dd03
leaq 0x99ba9(%rip), %rax     # 0xc7800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2c10d
jmp 0x2dcf9
leaq 0x5f4ec(%rip), %rsi     # 0x8d15b
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2c2da
leaq 0x5f471(%rip), %rsi     # 0x8d0f8
movq %rbx, %rdi
callq 0x2c2da
jmp 0x2dcf9
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2dc9f
callq 0x2ee1f
andq $0x0, 0x18(%rbx)
jmp 0x2dcc8
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x2dcbf
movq %rax, %rdi
callq 0x2ee1f
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0x2eacc
leaq 0x99b31(%rip), %rax     # 0xc7800
movq 0x8(%rax), %rsi
jmp 0x2dce0
leaq 0x99b24(%rip), %rax     # 0xc7800
movq 0x50(%rax), %rsi
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2c10d
orb $0x40, 0x90(%r15)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq