// File: /workspace/github_c_makefile_star2_O1/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 0x68193(%rip), %rsi     # 0x9746a
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f311
cmpl $0x2, 0x30(%rbx)
jne 0x2f311
callq 0x2f227
movq %rax, %r14
movslq -0x8(%rax), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2dfa7
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x28204
leaq 0x67dab(%rip), %rsi     # 0x970c3
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f3a1
cmpl $0x3, 0x30(%rbx)
jne 0x2f3a1
leaq 0x9ac77(%rip), %rax     # 0xc9fa8
movq 0x1b0(%rax), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0x205d2
movq %r14, %rdi
callq 0x205ef
testq %rax, %rax
je 0x2f4de
movq 0x10(%rax), %r15
movq %r15, %rdi
callq 0x2f1cd
movq 0x38(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdi
callq 0x1f880
testl %eax, %eax
jne 0x2f343
leaq 0x9b481(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
cmpq %rbx, %r15
je 0x2f533
movq %r15, %rdi
callq 0x2e287
jmp 0x2f53b
leaq 0x67d2f(%rip), %rsi     # 0x970d7
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f412
cmpl $0x3, 0x30(%rbx)
jne 0x2f412
movq 0x10(%r15), %rax
movq 0x8(%rax), %rax
movl -0x8(%rax), %ecx
testq %rcx, %rcx
je 0x2f4f4
testl %ecx, %ecx
jle 0x2f3ee
xorl %edx, %edx
movb (%rax,%rdx), %sil
addb $-0x7f, %sil
cmpb $-0x5f, %sil
jbe 0x2f545
incq %rdx
cmpq %rdx, %rcx
jne 0x2f3d4
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2f3fc
callq 0x30834
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0x3041b
jmp 0x2f50a
leaq 0x67d0a(%rip), %rsi     # 0x97123
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f449
cmpl $0x2, 0x30(%rbx)
jne 0x2f449
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x2f517
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2df74
leaq 0x724a0(%rip), %rsi     # 0xa18f0
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f4c1
cmpl $0x3, 0x30(%rbx)
jne 0x2f4c1
movq 0x10(%r15), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0x60d78
testl %eax, %eax
jne 0x2f53b
movq (%rsp), %rcx
leaq 0x9ab1f(%rip), %rax     # 0xc9fa8
cmpl $0x0, 0x1d8(%rax)
je 0x2f49b
cmpq %rcx, 0x1e0(%rax)
jge 0x2f4a2
movq %rcx, 0x1e0(%rax)
movl $0x1, 0x1d8(%rax)
leaq 0x9b34d(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d6f0
jmp 0x2f53b
leaq 0x67c63(%rip), %rsi     # 0x9712b
movl $0x52, %edx
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2d991
leaq 0x67be3(%rip), %rsi     # 0x970c8
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2d991
jmp 0x2f53b
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2f502
callq 0x30834
movq $0x0, 0x18(%rbx)
leaq 0x9b2ef(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
jmp 0x2f522
leaq 0x9b2e2(%rip), %rax     # 0xca800
movq 0x50(%rax), %rsi
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2d6f0
orb $0x40, 0x90(%r15)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x67b93(%rip), %rsi     # 0x970df
movl $0x43, %edx
jmp 0x2f4cd