// File: /workspace/github_c_makefile_star2_O3/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 0x2916c(%rip), %rsi     # 0x5715b
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e039
cmpl $0x4, 0x28(%rbx)
jne 0x2e039
movq 0x18(%r15), %rdi
leaq 0x10(%rsp), %rsi
callq 0x2620f
movq 0x30(%rbx), %rcx
testl %eax, %eax
je 0x2e25c
movq 0x18(%rcx), %rax
movq 0x8(%rax), %rdx
leaq 0x29136(%rip), %rsi     # 0x57160
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22033
jmp 0x2e2b5
leaq 0x29165(%rip), %rsi     # 0x571a5
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e083
cmpl $0x2, 0x28(%rbx)
jne 0x2e083
xorl %edi, %edi
callq 0x2bc2d
xorl %edi, %edi
movq %rax, %rsi
callq 0x2564c
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22748
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x25945
leaq 0x29121(%rip), %rsi     # 0x571ab
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e0ba
cmpl $0x2, 0x28(%rbx)
jne 0x2e0ba
movq 0x554fd(%rip), %rsi     # 0x835a0
movl $0x28, %edx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2277b
leaq 0x24428(%rip), %rsi     # 0x524e9
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e13a
cmpl $0x2, 0x28(%rbx)
jne 0x2e13a
callq 0x1db82
leaq 0x40fa9(%rip), %rcx     # 0x6f088
movq 0x668(%rcx), %rsi
movslq 0x8(%rsi), %rcx
leaq 0x288ff(%rip), %rdi     # 0x569f0
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 0x2909e(%rip), %rsi     # 0x571b9
movq %rax, %rdi
xorl %eax, %eax
callq 0x1e826
movq %rbx, %rdi
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x227bb
leaq 0x29119(%rip), %rsi     # 0x5725a
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e183
cmpl $0x2, 0x28(%rbx)
jne 0x2e183
movl $0x1, %edi
callq 0x2ba3b
testl %eax, %eax
je 0x2e371
callq 0x120d0
movl (%rax), %edi
callq 0x128e0
leaq 0x290ed(%rip), %rsi     # 0x57265
movq %rbx, %rdi
movq %rax, %rdx
jmp 0x2e354
leaq 0x29104(%rip), %rsi     # 0x5728e
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e1cf
cmpl $0x3, 0x28(%rbx)
jne 0x2e1cf
movq 0x10(%r15), %rax
movq 0x8(%rax), %rsi
movzbl -0x1(%rsi), %eax
andl $0x7, %eax
decl %eax
cmpl $0x3, %eax
ja 0x2e332
leaq 0x287ab(%rip), %rcx     # 0x56968
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl -0x3(%rsi), %eax
jmp 0x2e2cf
leaq 0x27e9a(%rip), %rsi     # 0x56070
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e243
movl 0x28(%rbx), %eax
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x2e243
xorl %ebp, %ebp
cmpl $0x3, %eax
jne 0x2e36a
movq 0x10(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x27f72(%rip), %rsi     # 0x5617b
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x2e365
leaq 0x290e4(%rip), %rsi     # 0x57304
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x2e36a
leaq 0x41561(%rip), %rax     # 0x6f798
movq 0x80(%rax), %rsi
jmp 0x2e37c
leaq 0x290bf(%rip), %rsi     # 0x57309
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2200c
movq 0x10(%rcx), %rax
movq 0x8(%rax), %rdi
movl 0x10(%rsp), %esi
callq 0x2caca
testl %eax, %eax
jne 0x2e2a2
callq 0x120d0
cmpl $0x16, (%rax)
jne 0x2e2a2
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rax), %rax
movq 0x8(%rcx), %rdx
movq 0x8(%rax), %rcx
leaq 0x28ee9(%rip), %rsi     # 0x5717f
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22033
jmp 0x2e2b5
leaq 0x414ef(%rip), %rax     # 0x6f798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x21c5a
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl -0x9(%rsi), %eax
jmp 0x2e2cf
movq -0x11(%rsi), %rax
jmp 0x2e2cf
movzwl -0x5(%rsi), %eax
cmpq $0x28, %rax
jne 0x2e332
leaq 0x40dac(%rip), %r15     # 0x6f088
movq 0x668(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x18d3e
testq %rax, %rax
je 0x2e33e
movq 0x8(%rax), %r14
testq %r14, %r14
je 0x2e33e
cmpq 0x5529f(%rip), %r14     # 0x835a0
je 0x2e38e
movq %r14, %rdi
callq 0x31105
testl %eax, %eax
jle 0x2e39a
leaq 0x28fc9(%rip), %rsi     # 0x572e7
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22033
leaq 0x28f5c(%rip), %rsi     # 0x57295
jmp 0x2e24a
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x28f5c(%rip), %rsi     # 0x572ad
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22033
movl $0x1, %ebp
movl %ebp, %edi
callq 0x2c176
leaq 0x41420(%rip), %rax     # 0x6f798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x21c5a
leaq 0x28f28(%rip), %rsi     # 0x572bd
jmp 0x2e24a
movq %r14, %rdi
callq 0x3118b
movq %r14, %rdi
callq 0x2c7f9
movq %r14, %rdi
callq 0x2c23c
movq 0x668(%r15), %rax
orl $0x3, 0x28(%rax)
jmp 0x2e371