// File: /workspace/github_c_makefile_star2_O2/erikdubbelboer[P]discnt/src/cluster.c
// Function: clusterCommand
void clusterCommand(client *c) {
    if (!strcasecmp(c->argv[1]->ptr,"meet") && c->argc == 4) {
        long long port;

        if (getLongLongFromObject(c->argv[3], &port) != C_OK) {
            addReplyErrorFormat(c,"Invalid TCP port specified: %s",
                                (char*)c->argv[3]->ptr);
            return;
        }

        if (clusterStartHandshake(c->argv[2]->ptr,port) == 0 &&
            errno == EINVAL)
        {
            addReplyErrorFormat(c,"Invalid node address specified: %s:%s",
                            (char*)c->argv[2]->ptr, (char*)c->argv[3]->ptr);
        } else {
            addReply(c,shared.ok);
        }
    } else if (!strcasecmp(c->argv[1]->ptr,"nodes") && c->argc == 2) {
        /* CLUSTER NODES */
        robj *o;
        sds ci = clusterGenNodesDescription(0);

        o = createObject(OBJ_STRING,ci);
        addReplyBulk(c,o);
        decrRefCount(o);
    } else if (!strcasecmp(c->argv[1]->ptr,"myid") && c->argc == 2) {
        /* CLUSTER MYID */
        addReplyBulkCBuffer(c,myself->name, CLUSTER_NAMELEN);
    } else if (!strcasecmp(c->argv[1]->ptr,"info") && c->argc == 2) {
        /* CLUSTER INFO */
        char *statestr[] = {"ok","fail","needhelp"};

        sds info = sdscatprintf(sdsempty(),
            "cluster_state:%s\r\n"
            "cluster_known_nodes:%lu\r\n"
            "cluster_reachable_nodes:%d\r\n"
            "cluster_size:%d\r\n"
            "cluster_stats_messages_sent:%lld\r\n"
            "cluster_stats_messages_received:%lld\r\n"
            , statestr[server.cluster->state],
            dictSize(server.cluster->nodes),
            server.cluster->reachable_nodes_count,
            server.cluster->size,
            server.cluster->stats_bus_messages_sent,
            server.cluster->stats_bus_messages_received
        );
        addReplyBulkSds(c, info);
    } else if (!strcasecmp(c->argv[1]->ptr,"saveconfig") && c->argc == 2) {
        int retval = clusterSaveConfig(1);

        if (retval == 0)
            addReply(c,shared.ok);
        else
            addReplyErrorFormat(c,"error saving the cluster node config: %s",
                strerror(errno));
    } else if (!strcasecmp(c->argv[1]->ptr,"forget") && c->argc == 3) {
        /* CLUSTER FORGET <NODE ID> */
        clusterNode *n;

        if (sdslen(c->argv[2]->ptr) != CLUSTER_NAMELEN) {
            addReplyError(c,"Invalid node identifier");
            return;
        }

        n = clusterLookupNode(c->argv[2]->ptr);

        if (!n) {
            addReplyErrorFormat(c,"Unknown node %s", (char*)c->argv[2]->ptr);
            return;
        } else if (n == myself) {
            addReplyError(c,"I tried hard but I can't forget myself...");
            return;
        }

        if (counterShardsForNode(n) > 0) {
              addReplyErrorFormat(c,"node still has active shards");
              return;
        }

        counterDeleteShards(n);
        clusterBlacklistAddNode(n);
        clusterDelNode(n);
        clusterDoBeforeSleep(CLUSTER_TODO_UPDATE_STATE|
                             CLUSTER_TODO_SAVE_CONFIG);
        addReply(c,shared.ok);
    } else if (!strcasecmp(c->argv[1]->ptr,"reset") &&
               (c->argc == 2 || c->argc == 3))
    {
        /* CLUSTER RESET [SOFT|HARD] */
        int hard = 0;

        /* Parse soft/hard argument. Default is soft. */
        if (c->argc == 3) {
            if (!strcasecmp(c->argv[2]->ptr,"hard")) {
                hard = 1;
            } else if (!strcasecmp(c->argv[2]->ptr,"soft")) {
                hard = 0;
            } else {
                addReply(c,shared.syntaxerr);
                return;
            }
        }

        clusterReset(hard);
        addReply(c,shared.ok);
    } else {
        addReplyError(c,"Wrong CLUSTER subcommand or number of arguments");
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x30(%rdi), %r15
movq 0x8(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x292bf(%rip), %rsi     # 0x50843
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x275ce
cmpl $0x4, 0x28(%rbx)
jne 0x275ce
movq 0x18(%r15), %rdi
leaq 0x10(%rsp), %rsi
callq 0x202ef
movq 0x30(%rbx), %rcx
testl %eax, %eax
je 0x2782c
movq 0x18(%rcx), %rax
movq 0x8(%rax), %rdx
leaq 0x29289(%rip), %rsi     # 0x50848
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1caf6
jmp 0x27885
leaq 0x292b8(%rip), %rsi     # 0x5088d
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x27618
cmpl $0x2, 0x28(%rbx)
jne 0x27618
xorl %edi, %edi
callq 0x2548f
xorl %edi, %edi
movq %rax, %rsi
callq 0x1f928
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1d0d0
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1fb84
leaq 0x29274(%rip), %rsi     # 0x50893
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2764d
cmpl $0x2, 0x28(%rbx)
jne 0x2764d
movq 0x56f68(%rip), %rsi     # 0x7e5a0
pushq $0x28
popq %rdx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d103
leaq 0x24db5(%rip), %rsi     # 0x4c409
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x276cd
cmpl $0x2, 0x28(%rbx)
jne 0x276cd
callq 0x194cc
leaq 0x42a16(%rip), %rcx     # 0x6a088
movq 0x668(%rcx), %rsi
movslq 0x8(%rsi), %rcx
leaq 0x28a54(%rip), %rdi     # 0x500d8
movslq (%rdi,%rcx,4), %rdx
movq 0x10(%rsi), %r8
movq 0x48(%r8), %rcx
addq 0x28(%r8), %rcx
addq %rdi, %rdx
movl 0x38(%rsi), %r8d
movl 0xc(%rsi), %r9d
movups 0x40(%rsi), %xmm0
movups %xmm0, (%rsp)
leaq 0x291f3(%rip), %rsi     # 0x508a1
movq %rax, %rdi
xorl %eax, %eax
callq 0x19db8
movq %rbx, %rdi
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d141
leaq 0x2926e(%rip), %rsi     # 0x50942
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x27720
cmpl $0x2, 0x28(%rbx)
jne 0x27720
pushq $0x1
popq %rdi
callq 0x25374
testl %eax, %eax
je 0x278be
callq 0x120d0
movl (%rax), %edi
callq 0x128e0
leaq 0x29244(%rip), %rsi     # 0x5094d
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1caf6
leaq 0x2924f(%rip), %rsi     # 0x50976
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2779f
cmpl $0x3, 0x28(%rbx)
jne 0x2779f
movq 0x10(%r15), %rax
movq 0x8(%rax), %r14
movq %r14, %rdi
callq 0x2552a
cmpq $0x28, %rax
jne 0x27890
movq %r14, %rdi
callq 0x25290
testq %rax, %rax
je 0x27899
movq %rax, %r14
cmpq 0x56e32(%rip), %rax     # 0x7e5a0
je 0x278db
movq %r14, %rdi
callq 0x2a17a
testl %eax, %eax
jle 0x278e7
leaq 0x29244(%rip), %rsi     # 0x509cf
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1caf6
leaq 0x280e2(%rip), %rsi     # 0x4f888
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x27813
movl 0x28(%rbx), %eax
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x27813
xorl %ebp, %ebp
cmpl $0x3, %eax
jne 0x278b7
movq 0x10(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x281ba(%rip), %rsi     # 0x4f993
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x278b4
leaq 0x291fc(%rip), %rsi     # 0x509ec
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x278b7
leaq 0x42f91(%rip), %rax     # 0x6a798
movq 0x80(%rax), %rsi
jmp 0x278c9
leaq 0x291d7(%rip), %rsi     # 0x509f1
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1cacf
movq 0x10(%rcx), %rax
movq 0x8(%rax), %rdi
movl 0x10(%rsp), %esi
callq 0x26231
testl %eax, %eax
jne 0x27872
callq 0x120d0
cmpl $0x16, (%rax)
jne 0x27872
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rax), %rax
movq 0x8(%rcx), %rdx
movq 0x8(%rax), %rcx
leaq 0x29001(%rip), %rsi     # 0x50867
movq %rbx, %rdi
xorl %eax, %eax
callq 0x1caf6
jmp 0x27885
leaq 0x42f1f(%rip), %rax     # 0x6a798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x1c8e7
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x290e6(%rip), %rsi     # 0x5097d
jmp 0x2781a
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x290e9(%rip), %rsi     # 0x50995
movq %rbx, %rdi
jmp 0x2770f
pushq $0x1
popq %rbp
movl %ebp, %edi
callq 0x259cc
leaq 0x42ed3(%rip), %rax     # 0x6a798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1c8e7
leaq 0x290c3(%rip), %rsi     # 0x509a5
jmp 0x2781a
movq %r14, %rdi
callq 0x2a1f3
movq %r14, %rdi
callq 0x25fd1
movq %r14, %rdi
callq 0x25a7d
leaq 0x42782(%rip), %rax     # 0x6a088
movq 0x668(%rax), %rax
orl $0x3, 0x28(%rax)
jmp 0x278be