// File: /workspace/github_c_makefile_star2_O1/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 0x28bab(%rip), %rsi     # 0x5716f
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e60e
cmpl $0x4, 0x28(%rbx)
jne 0x2e60e
movq 0x18(%r15), %rdi
leaq 0x10(%rsp), %rsi
callq 0x26612
movq 0x30(%rbx), %rcx
testl %eax, %eax
je 0x2e83c
movq 0x18(%rcx), %rax
movq 0x8(%rax), %rdx
leaq 0x28b75(%rip), %rsi     # 0x57174
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22331
jmp 0x2e895
leaq 0x28ba4(%rip), %rsi     # 0x571b9
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e658
cmpl $0x2, 0x28(%rbx)
jne 0x2e658
xorl %edi, %edi
callq 0x2c218
xorl %edi, %edi
movq %rax, %rsi
callq 0x25a2c
movq %rax, %r14
movq %rbx, %rdi
movq %rax, %rsi
callq 0x22a4a
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x25d25
leaq 0x28b60(%rip), %rsi     # 0x571bf
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e68f
cmpl $0x2, 0x28(%rbx)
jne 0x2e68f
movq 0x54f28(%rip), %rsi     # 0x835a0
movl $0x28, %edx
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22a7d
leaq 0x23e03(%rip), %rsi     # 0x52499
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e70f
cmpl $0x2, 0x28(%rbx)
jne 0x2e70f
callq 0x1de3f
leaq 0x409d4(%rip), %rcx     # 0x6f088
movq 0x668(%rcx), %rsi
movslq 0x8(%rsi), %rcx
leaq 0x2833e(%rip), %rdi     # 0x56a04
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 0x28add(%rip), %rsi     # 0x571cd
movq %rax, %rdi
xorl %eax, %eax
callq 0x1eace
movq %rbx, %rdi
movq %rax, %rsi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22abd
leaq 0x28b58(%rip), %rsi     # 0x5726e
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e764
cmpl $0x2, 0x28(%rbx)
jne 0x2e764
movl $0x1, %edi
callq 0x2c028
testl %eax, %eax
je 0x2e94c
callq 0x120d0
movl (%rax), %edi
callq 0x128f0
leaq 0x28b2c(%rip), %rsi     # 0x57279
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22331
leaq 0x28b37(%rip), %rsi     # 0x572a2
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e7af
cmpl $0x3, 0x28(%rbx)
jne 0x2e7af
movq 0x10(%r15), %rax
movq 0x8(%rax), %rsi
movzbl -0x1(%rsi), %eax
movl %eax, %ecx
andl $0x7, %ecx
cmpl $0x4, %ecx
ja 0x2e8b7
leaq 0x281da(%rip), %rdx     # 0x56978
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
shrl $0x3, %eax
jmp 0x2e8b9
leaq 0x278d2(%rip), %rsi     # 0x56088
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
jne 0x2e823
movl 0x28(%rbx), %eax
movl %eax, %ecx
andl $-0x2, %ecx
cmpl $0x2, %ecx
jne 0x2e823
xorl %ebp, %ebp
cmpl $0x3, %eax
jne 0x2e945
movq 0x10(%r15), %rax
movq 0x8(%rax), %r14
leaq 0x279aa(%rip), %rsi     # 0x56193
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x2e940
leaq 0x28b18(%rip), %rsi     # 0x57318
movq %r14, %rdi
callq 0x12090
testl %eax, %eax
je 0x2e945
leaq 0x40f81(%rip), %rax     # 0x6f798
movq 0x80(%rax), %rsi
jmp 0x2e957
leaq 0x28af3(%rip), %rsi     # 0x5731d
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2230a
movq 0x10(%rcx), %rax
movq 0x8(%rax), %rdi
movl 0x10(%rsp), %esi
callq 0x2d0b3
testl %eax, %eax
jne 0x2e882
callq 0x120d0
cmpl $0x16, (%rax)
jne 0x2e882
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rcx
movq 0x18(%rax), %rax
movq 0x8(%rcx), %rdx
movq 0x8(%rax), %rcx
leaq 0x2891d(%rip), %rsi     # 0x57193
movq %rbx, %rdi
xorl %eax, %eax
callq 0x22331
jmp 0x2e895
leaq 0x40f0f(%rip), %rax     # 0x6f798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x21f58
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq -0x11(%rsi), %rax
jmp 0x2e8b9
movzwl -0x5(%rsi), %eax
jmp 0x2e8b9
movl -0x9(%rsi), %eax
jmp 0x2e8b9
movzbl -0x3(%rsi), %eax
jmp 0x2e8b9
xorl %eax, %eax
cmpq $0x28, %rax
jne 0x2e8e1
leaq 0x407c2(%rip), %r15     # 0x6f088
movq 0x668(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x190de
testq %rax, %rax
je 0x2e8ed
movq 0x8(%rax), %r14
jmp 0x2e8f0
leaq 0x289c1(%rip), %rsi     # 0x572a9
jmp 0x2e82a
xorl %r14d, %r14d
testq %r14, %r14
je 0x2e925
cmpq 0x54ca4(%rip), %r14     # 0x835a0
je 0x2e969
movq %r14, %rdi
callq 0x316bd
testl %eax, %eax
jle 0x2e975
leaq 0x289ea(%rip), %rsi     # 0x572fb
movq %rbx, %rdi
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22331
movq 0x30(%rbx), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdx
leaq 0x28989(%rip), %rsi     # 0x572c1
movq %rbx, %rdi
jmp 0x2e753
movl $0x1, %ebp
movl %ebp, %edi
callq 0x2c761
leaq 0x40e45(%rip), %rax     # 0x6f798
movq 0x8(%rax), %rsi
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x21f58
leaq 0x28961(%rip), %rsi     # 0x572d1
jmp 0x2e82a
movq %r14, %rdi
callq 0x31743
movq %r14, %rdi
callq 0x2cde8
movq %r14, %rdi
callq 0x2c827
movq 0x668(%r15), %rax
orl $0x3, 0x28(%rax)
jmp 0x2e94c