// File: /workspace/github_c_makefile_star2_O3/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 0x67f07(%rip), %rsi     # 0x974ca
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f5fd
cmpl $0x2, 0x30(%rbx)
jne 0x2f5fd
callq 0x2f513
movq %rax, %r14
movslq -0x8(%rax), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2e237
movq %r14, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2850d
leaq 0x67b1f(%rip), %rsi     # 0x97123
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f68d
cmpl $0x3, 0x30(%rbx)
jne 0x2f68d
leaq 0x9a98b(%rip), %rax     # 0xc9fa8
movq 0x1b0(%rax), %rdi
movq %rsp, %r14
movq %r14, %rsi
callq 0x20637
movq %r14, %rdi
callq 0x20654
testq %rax, %rax
je 0x2f7cd
movq 0x10(%rax), %r15
movq %r15, %rdi
callq 0x2f4c0
movq 0x38(%rbx), %rcx
movq 0x10(%rcx), %rcx
movq 0x8(%rcx), %rsi
movq %rax, %rdi
callq 0x1f880
testl %eax, %eax
jne 0x2f62f
leaq 0x9b195(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
cmpq %rbx, %r15
je 0x2f822
movq %r15, %rdi
callq 0x2e517
jmp 0x2f82a
leaq 0x67aa3(%rip), %rsi     # 0x97137
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f701
cmpl $0x3, 0x30(%rbx)
jne 0x2f701
movq 0x10(%r15), %rdi
movq 0x8(%rdi), %rax
movl -0x8(%rax), %ecx
testq %rcx, %rcx
je 0x2f7e3
testl %ecx, %ecx
jle 0x2f6da
xorl %edx, %edx
movb (%rax,%rdx), %sil
addb $-0x7f, %sil
cmpb $-0x5f, %sil
jbe 0x2f834
incq %rdx
cmpq %rdx, %rcx
jne 0x2f6c0
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x2f6f3
movq %rax, %rdi
callq 0x30b0c
movq 0x38(%rbx), %rax
movq 0x10(%rax), %rdi
movq %rdi, 0x18(%rbx)
callq 0x306f3
jmp 0x2f7f9
leaq 0x67a7b(%rip), %rsi     # 0x97183
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f738
cmpl $0x2, 0x30(%rbx)
jne 0x2f738
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x2f806
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2e204
leaq 0x72241(%rip), %rsi     # 0xa1980
movq %r14, %rdi
callq 0x1f2e0
testl %eax, %eax
jne 0x2f7b0
cmpl $0x3, 0x30(%rbx)
jne 0x2f7b0
movq 0x10(%r15), %rsi
movq %rsp, %rdx
movq %rbx, %rdi
movl $0x1, %ecx
callq 0x60858
testl %eax, %eax
jne 0x2f82a
movq (%rsp), %rcx
leaq 0x9a830(%rip), %rax     # 0xc9fa8
cmpl $0x0, 0x1d8(%rax)
je 0x2f78a
cmpq %rcx, 0x1e0(%rax)
jge 0x2f791
movq %rcx, 0x1e0(%rax)
movl $0x1, 0x1d8(%rax)
leaq 0x9b05e(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x2d97c
jmp 0x2f82a
leaq 0x679d4(%rip), %rsi     # 0x9718b
movl $0x52, %edx
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2dc1d
leaq 0x67954(%rip), %rsi     # 0x97128
movl $0xe, %edx
movq %rbx, %rdi
callq 0x2dc1d
jmp 0x2f82a
movq 0x18(%rbx), %rdi
testq %rdi, %rdi
je 0x2f7f1
callq 0x30b0c
movq $0x0, 0x18(%rbx)
leaq 0x9b000(%rip), %rax     # 0xca800
movq 0x8(%rax), %rsi
jmp 0x2f811
leaq 0x9aff3(%rip), %rax     # 0xca800
movq 0x50(%rax), %rsi
movq %rbx, %rdi
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
jmp 0x2d97c
orb $0x40, 0x90(%r15)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
leaq 0x67904(%rip), %rsi     # 0x9713f
movl $0x43, %edx
jmp 0x2f7bc