// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/src/server.c
// Function: processCommand
int processCommand(client *c) {
    /* The QUIT command is handled separately. Normal command procs will
     * go through checking for replication and QUIT will cause trouble
     * when FORCE_REPLICATION is enabled and would be implemented in
     * a regular command proc. */
    if (!strcasecmp(c->argv[0]->ptr,"quit")) {
        addReply(c,shared.ok);
        c->flags |= CLIENT_CLOSE_AFTER_REPLY;
        return C_ERR;
    }

    /* Now lookup the command and check ASAP about trivial error conditions
     * such as wrong arity, bad command name and so forth. */
    c->cmd = c->lastcmd = lookupCommand(c->argv[0]->ptr);
    if (!c->cmd) {
        flagTransaction(c);
        addReplyErrorFormat(c,"unknown command '%s'",
            (char*)c->argv[0]->ptr);
        return C_OK;
    } else if ((c->cmd->arity > 0 && c->cmd->arity != c->argc) ||
               (c->argc < -c->cmd->arity)) {
        flagTransaction(c);
        addReplyErrorFormat(c,"wrong number of arguments for '%s' command",
            c->cmd->name);
        return C_OK;
    }

    /* Check if the user is authenticated */
    if (server.requirepass && !c->authenticated && c->cmd->proc != authCommand)
    {
        flagTransaction(c);
        addReply(c,shared.noautherr);
        return C_OK;
    }

    /* If cluster is enabled perform the cluster redirection here.
     * However we don't perform the redirection if:
     * 1) The sender of this command is our master.
     * 2) The command has no key arguments. */
    if (server.cluster_enabled &&
        !(c->flags & CLIENT_MASTER) &&
        !(c->flags & CLIENT_LUA &&
          server.lua_caller->flags & CLIENT_MASTER) &&
        !(c->cmd->getkeys_proc == NULL && c->cmd->firstkey == 0 &&
          c->cmd->proc != execCommand))
    {
        int hashslot;
        int error_code;
        clusterNode *n = getNodeByQuery(c,c->cmd,c->argv,c->argc,
                                        &hashslot,&error_code);
        if (n == NULL || n != server.cluster->myself) {
            if (c->cmd->proc == execCommand) {
                discardTransaction(c);
            } else {
                flagTransaction(c);
            }
            clusterRedirectClient(c,n,hashslot,error_code);
            return C_OK;
        }
    }

    /* Handle the maxmemory directive.
     *
     * First we try to free some memory if possible (if there are volatile
     * keys in the dataset). If there are not the only thing we can do
     * is returning an error. */
    if (server.maxmemory) {
        int retval = freeMemoryIfNeeded();
        /* freeMemoryIfNeeded may flush slave output buffers. This may result
         * into a slave, that may be the active client, to be freed. */
        if (server.current_client == NULL) return C_ERR;

        /* It was impossible to free enough memory, and the command the client
         * is trying to execute is denied during OOM conditions? Error. */
        if ((c->cmd->flags & CMD_DENYOOM) && retval == C_ERR) {
            flagTransaction(c);
            addReply(c, shared.oomerr);
            return C_OK;
        }
    }

    /* Don't accept write commands if there are problems persisting on disk
     * and if this is a master instance. */
    if (((server.stop_writes_on_bgsave_err &&
          server.saveparamslen > 0 &&
          server.lastbgsave_status == C_ERR) ||
          server.aof_last_write_status == C_ERR) &&
        server.masterhost == NULL &&
        (c->cmd->flags & CMD_WRITE ||
         c->cmd->proc == pingCommand))
    {
        flagTransaction(c);
        if (server.aof_last_write_status == C_OK)
            addReply(c, shared.bgsaveerr);
        else
            addReplySds(c,
                sdscatprintf(sdsempty(),
                "-MISCONF Errors writing to the AOF file: %s\r\n",
                strerror(server.aof_last_write_errno)));
        return C_OK;
    }

    /* Don't accept write commands if there are not enough good slaves and
     * user configured the min-slaves-to-write option. */
    if (server.masterhost == NULL &&
        server.repl_min_slaves_to_write &&
        server.repl_min_slaves_max_lag &&
        c->cmd->flags & CMD_WRITE &&
        server.repl_good_slaves_count < server.repl_min_slaves_to_write)
    {
        flagTransaction(c);
        addReply(c, shared.noreplicaserr);
        return C_OK;
    }

    /* Don't accept write commands if this is a read only slave. But
     * accept write commands if this is our master. */
    if (server.masterhost && server.repl_slave_ro &&
        !(c->flags & CLIENT_MASTER) &&
        c->cmd->flags & CMD_WRITE)
    {
        addReply(c, shared.roslaveerr);
        return C_OK;
    }

    /* Only allow SUBSCRIBE and UNSUBSCRIBE in the context of Pub/Sub */
    if (c->flags & CLIENT_PUBSUB &&
        c->cmd->proc != pingCommand &&
        c->cmd->proc != subscribeCommand &&
        c->cmd->proc != unsubscribeCommand &&
        c->cmd->proc != psubscribeCommand &&
        c->cmd->proc != punsubscribeCommand) {
        addReplyError(c,"only (P)SUBSCRIBE / (P)UNSUBSCRIBE / PING / QUIT allowed in this context");
        return C_OK;
    }

    /* Only allow INFO and SLAVEOF when slave-serve-stale-data is no and
     * we are a slave with a broken link with master. */
    if (server.masterhost && server.repl_state != REPL_STATE_CONNECTED &&
        server.repl_serve_stale_data == 0 &&
        !(c->cmd->flags & CMD_STALE))
    {
        flagTransaction(c);
        addReply(c, shared.masterdownerr);
        return C_OK;
    }

    /* Loading DB? Return an error if the command has not the
     * CMD_LOADING flag. */
    if (server.loading && !(c->cmd->flags & CMD_LOADING)) {
        addReply(c, shared.loadingerr);
        return C_OK;
    }

    /* Lua script too slow? Only allow a limited number of commands. */
    if (server.lua_timedout &&
          c->cmd->proc != authCommand &&
          c->cmd->proc != replconfCommand &&
        !(c->cmd->proc == shutdownCommand &&
          c->argc == 2 &&
          tolower(((char*)c->argv[1]->ptr)[0]) == 'n') &&
        !(c->cmd->proc == scriptCommand &&
          c->argc == 2 &&
          tolower(((char*)c->argv[1]->ptr)[0]) == 'k'))
    {
        flagTransaction(c);
        addReply(c, shared.slowscripterr);
        return C_OK;
    }

    /* Exec the command */
    if (c->flags & CLIENT_MULTI &&
        c->cmd->proc != execCommand && c->cmd->proc != discardCommand &&
        c->cmd->proc != multiCommand && c->cmd->proc != watchCommand)
    {
        queueMultiCommand(c);
        addReply(c,shared.queued);
    } else {
        call(c,CMD_CALL_FULL);
        c->woff = server.master_repl_offset;
        if (listLength(server.ready_keys))
            handleClientsBlockedOnLists();
    }
    return C_OK;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rax
movq (%rax), %rax
movq 0x8(%rax), %r14
leaq 0x8a3b5(%rip), %rsi     # 0xc05f8
movq %r14, %rdi
callq 0x26300
testl %eax, %eax
je 0x36298
movq 0xd0632(%rip), %rdi     # 0x106888
movq %r14, %rsi
callq 0x32019
movq %rax, 0x50(%rbx)
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x362b5
movl 0x10(%rax), %edx
testl %edx, %edx
jle 0x36277
cmpl 0x38(%rbx), %edx
jne 0x36280
movl 0x38(%rbx), %ecx
negl %edx
cmpl %edx, %ecx
jge 0x362e6
movq %rbx, %rdi
callq 0x647cc
movq 0x48(%rbx), %rax
movq (%rax), %rdx
leaq 0x8a37c(%rip), %rsi     # 0xc0612
jmp 0x362cf
movq 0xd1019(%rip), %rsi     # 0x1072b8
movq %rbx, %rdi
callq 0x3fc19
orb $0x40, 0x98(%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x362db
movq %rbx, %rdi
callq 0x647cc
movq 0x40(%rbx), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x8a32e(%rip), %rsi     # 0xc05fd
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3fff2
movl %ebp, %eax
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
cmpq $0x0, 0xd05c2(%rip)     # 0x1068b0
je 0x362fd
cmpl $0x0, 0x9c(%rbx)
je 0x3638c
cmpl $0x0, 0xd0ee0(%rip)     # 0x1071e4
je 0x363df
movl 0x98(%rbx), %edx
testb $0x2, %dl
jne 0x363df
btl $0x8, %edx
jae 0x36333
movq 0xd0efa(%rip), %rdx     # 0x107220
testb $0x2, 0x98(%rdx)
jne 0x363df
cmpq $0x0, 0x28(%rax)
jne 0x36344
cmpl $0x0, 0x30(%rax)
je 0x363ce
movq 0x40(%rbx), %rdx
leaq 0xc(%rsp), %r8
leaq 0x8(%rsp), %r9
movq %rbx, %rdi
movq %rax, %rsi
callq 0x705ec
movq %rax, %r14
testq %rax, %rax
je 0x36371
movq 0xd0e8c(%rip), %rax     # 0x1071f8
cmpq (%rax), %r14
je 0x363df
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rax
movq %rbx, %rdi
cmpq 0xcbb8d(%rip), %rax     # 0x101f10
je 0x363b1
callq 0x647cc
jmp 0x363b6
leaq -0x3a5f(%rip), %rdx     # 0x32934
cmpq %rdx, 0x8(%rax)
je 0x362fd
movq %rbx, %rdi
callq 0x647cc
movq 0xd0fd4(%rip), %rsi     # 0x107380
jmp 0x36741
callq 0x646a4
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x709d1
jmp 0x36749
movq 0x8(%rax), %rdx
cmpq 0xcbb37(%rip), %rdx     # 0x101f10
je 0x36344
cmpq $0x0, 0xd0d69(%rip)     # 0x107150
je 0x36439
callq 0x36750
xorl %ebp, %ebp
cmpq $0x0, 0xd0650(%rip)     # 0x106a48
je 0x3642a
movb $0x1, %cl
cmpl $-0x1, %eax
jne 0x36431
movq 0x48(%rbx), %rax
movl 0x20(%rax), %eax
andl $0x4, %eax
je 0x36431
movq %rbx, %rdi
callq 0x647cc
movq 0xd0f7c(%rip), %rsi     # 0x107398
movq %rbx, %rdi
callq 0x3fc19
xorl %ecx, %ecx
xorl %ebp, %ebp
jmp 0x36431
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %ecx, %ecx
testb %cl, %cl
je 0x362db
cmpl $0x0, 0xd0b8c(%rip)     # 0x106fcc
setne %al
cmpl $0x0, 0xd0b3e(%rip)     # 0x106f88
setg %cl
andb %al, %cl
cmpl $-0x1, 0xd0b72(%rip)    # 0x106fc8
sete %al
andb %cl, %al
cmpl $-0x1, 0xd0ad2(%rip)    # 0x106f34
sete %cl
orb %al, %cl
movq 0xd0c02(%rip), %rax     # 0x107070
testq %rax, %rax
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x3649a
movq 0x48(%rbx), %rcx
testb $0x1, 0x20(%rcx)
jne 0x36542
leaq -0x3afa(%rip), %rdx     # 0x32996
cmpq %rdx, 0x8(%rcx)
je 0x36542
testq %rax, %rax
jne 0x364d8
movl 0xd0bab(%rip), %ecx     # 0x107050
testl %ecx, %ecx
je 0x364d8
cmpl $0x0, 0xd0ba4(%rip)     # 0x107054
je 0x364d8
movq 0x48(%rbx), %rdx
testb $0x1, 0x20(%rdx)
je 0x364d8
cmpl %ecx, 0xd0b96(%rip)     # 0x107058
jge 0x364d8
movq %rbx, %rdi
callq 0x647cc
movq 0xd0eb5(%rip), %rsi     # 0x107388
jmp 0x36741
testq %rax, %rax
je 0x364fd
cmpl $0x0, 0xd0be8(%rip)     # 0x1070cc
je 0x364fd
testb $0x2, 0x98(%rbx)
jne 0x364fd
movq 0x48(%rbx), %rcx
testb $0x1, 0x20(%rcx)
jne 0x366c7
movl 0x98(%rbx), %ebp
btl $0x12, %ebp
jb 0x365af
testq %rax, %rax
je 0x36590
cmpl $0xf, 0xd0b7b(%rip)     # 0x107094
je 0x36590
cmpl $0x0, 0xd0ba6(%rip)     # 0x1070c8
jne 0x36590
movq 0x48(%rbx), %rax
testb $0x4, 0x21(%rax)
jne 0x36590
movq %rbx, %rdi
callq 0x647cc
movq 0xd0e2b(%rip), %rsi     # 0x107368
jmp 0x36741
movq %rbx, %rdi
callq 0x647cc
cmpl $0x0, 0xd09e3(%rip)     # 0x106f34
je 0x3667e
callq 0x39222
movq %rax, %r14
movl 0xd09d3(%rip), %edi     # 0x106f38
callq 0x26690
leaq 0x8a0cc(%rip), %rsi     # 0xc063d
xorl %ebp, %ebp
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x39eb7
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3fe4b
jmp 0x362db
cmpl $0x0, 0xd05dd(%rip)     # 0x106b74
je 0x3660f
movq 0x48(%rbx), %rax
testb $0x2, 0x21(%rax)
jne 0x3660f
movq 0xd0da6(%rip), %rsi     # 0x107350
jmp 0x36741
movq 0x48(%rbx), %rcx
movq 0x8(%rcx), %rcx
cmpq 0xcb992(%rip), %rcx     # 0x101f50
je 0x3650d
cmpq 0xcb9d5(%rip), %rcx     # 0x101fa0
je 0x3650d
cmpq 0xcb9b8(%rip), %rcx     # 0x101f90
je 0x3650d
leaq -0x3c4f(%rip), %rdx     # 0x32996
cmpq %rdx, %rcx
je 0x3650d
cmpq 0xcb973(%rip), %rcx     # 0x101f68
je 0x3650d
leaq 0x8a069(%rip), %rsi     # 0xc066b
movq %rbx, %rdi
callq 0x3ffcb
jmp 0x36749
cmpl $0x0, 0xd0c3e(%rip)     # 0x107254
je 0x3663f
movq 0x48(%rbx), %rax
movq 0x8(%rax), %r14
leaq -0x3cf3(%rip), %rax     # 0x32934
cmpq %rax, %r14
sete %al
cmpq 0xcb964(%rip), %r14     # 0x101f98
sete %cl
orb %al, %cl
je 0x366d0
testb $0x8, %bpl
jne 0x3668a
movq %rbx, %rdi
movl $0xf, %esi
callq 0x35f45
movq 0xd09af(%rip), %rax     # 0x107008
movq %rax, 0x198(%rbx)
movq 0xd0b09(%rip), %rax     # 0x107170
xorl %ebp, %ebp
cmpq $0x0, 0x28(%rax)
je 0x362db
callq 0x512ab
jmp 0x362db
movq 0xd0cdb(%rip), %rsi     # 0x107360
jmp 0x36741
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rax
cmpq 0xcb8e7(%rip), %rax     # 0x101f80
je 0x36645
cmpq 0xcb8a6(%rip), %rax     # 0x101f48
je 0x36645
cmpq 0xcb865(%rip), %rax     # 0x101f10
je 0x36645
cmpq 0xcb93c(%rip), %rax     # 0x101ff0
je 0x36645
movq %rbx, %rdi
callq 0x64604
movq 0xd0c4b(%rip), %rsi     # 0x107310
jmp 0x36741
movq 0xd0ca2(%rip), %rsi     # 0x107370
jmp 0x36741
cmpq 0xcb8d1(%rip), %r14     # 0x101fa8
jne 0x36701
cmpl $0x2, 0x38(%rbx)
jne 0x36701
callq 0x269b0
movq (%rax), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movsbq (%rcx), %rcx
cmpl $0x6e, (%rax,%rcx,4)
je 0x3663f
cmpq 0xcb828(%rip), %r14     # 0x101f30
jne 0x36732
cmpl $0x2, 0x38(%rbx)
jne 0x36732
callq 0x269b0
movq (%rax), %rax
movq 0x40(%rbx), %rcx
movq 0x8(%rcx), %rcx
movq 0x8(%rcx), %rcx
movsbq (%rcx), %rcx
cmpl $0x6b, (%rax,%rcx,4)
je 0x3663f
movq %rbx, %rdi
callq 0x647cc
movq 0xd0c17(%rip), %rsi     # 0x107358
movq %rbx, %rdi
callq 0x3fc19
xorl %ebp, %ebp
jmp 0x362db