// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/src/cluster.c
// Function: clusterLoadConfig
int clusterLoadConfig(char *filename) {
    FILE *fp = fopen(filename,"r");
    struct stat sb;
    char *line;
    int maxline, j;

    if (fp == NULL) {
        if (errno == ENOENT) {
            return C_ERR;
        } else {
            serverLog(LL_WARNING,
                "Loading the cluster node config from %s: %s",
                filename, strerror(errno));
            exit(1);
        }
    }

    /* Check if the file is zero-length: if so return C_ERR to signal
     * we have to write the config. */
    if (fstat(fileno(fp),&sb) != -1 && sb.st_size == 0) {
        fclose(fp);
        return C_ERR;
    }

    /* Parse the file. */
    maxline = 1024;
    line = zmalloc(maxline);
    while(fgets(line,maxline,fp) != NULL) {
        int argc;
        sds *argv;
        clusterNode *n;
        char *p, *s;

        /* Skip blank lines, they can be created either by users manually
         * editing nodes.conf or by the config writing process if stopped
         * before the truncate() call. */
        if (line[0] == '\n') continue;

        /* Split the line into arguments for processing. */
        argv = sdssplitargs(line,&argc);
        if (argv == NULL) goto fmterr;

        /* Handle the special "vars" line. Don't pretend it is the last
         * line even if it actually is when generated by Discnt. */
        if (strcasecmp(argv[0],"vars") == 0) {
            for (j = 1; j < argc; j += 2) {
                if (strcasecmp(argv[j],"someVarNameHere") == 0) {
                    /* TODO: currently not used. */
                } else {
                    serverLog(LL_WARNING,
                        "Skipping unknown cluster config variable '%s'",
                        argv[j]);
                }
            }
            sdsfreesplitres(argv,argc);
            continue;
        }

        /* Regular config lines have at least eight fields */
        if (argc != 6) goto fmterr;

        /* Create this node if it does not exist */
        if (strlen(argv[0]) != CLUSTER_NAMELEN) goto fmterr;
        n = clusterLookupNode(argv[0]);
        if (!n) {
            n = createClusterNode(argv[0],0);
            clusterAddNode(n);
        }
        /* Address and port */
        if ((p = strrchr(argv[1],':')) == NULL) goto fmterr;
        *p = '\0';
        memcpy(n->ip,argv[1],strlen(argv[1])+1);
        n->port = atoi(p+1);

        /* Parse flags */
        p = s = argv[2];
        while(p) {
            p = strchr(s,',');
            if (p) *p = '\0';
            if (!strcasecmp(s,"myself")) {
                serverAssert(server.cluster->myself == NULL);
                myself = server.cluster->myself = n;
                n->flags |= CLUSTER_NODE_MYSELF;
            } else if (!strcasecmp(s,"fail?")) {
                n->flags |= CLUSTER_NODE_PFAIL;
            } else if (!strcasecmp(s,"fail")) {
                n->flags |= CLUSTER_NODE_FAIL;
                n->fail_time = mstime();
            } else if (!strcasecmp(s,"handshake")) {
                n->flags |= CLUSTER_NODE_HANDSHAKE;
            } else if (!strcasecmp(s,"noaddr")) {
                n->flags |= CLUSTER_NODE_NOADDR;
            } else if (!strcasecmp(s,"noflags")) {
                /* nothing to do */
            } else {
                serverPanic("Unknown flag in discnt cluster config file");
            }
            if (p) s = p+1;
        }

        /* Set ping sent / pong received timestamps */
        if (atoi(argv[3])) n->ping_sent = mstime();
        if (atoi(argv[4])) n->pong_received = mstime();

        sdsfreesplitres(argv,argc);
    }
    /* Config sanity check */
    if (server.cluster->myself == NULL) goto fmterr;

    zfree(line);
    fclose(fp);

    serverLog(LL_NOTICE,"Node configuration loaded, I'm %.40s", myself->name);
    return C_OK;

fmterr:
    serverLog(LL_WARNING,
        "Unrecoverable error: corrupted cluster config file.");
    zfree(line);
    if (fp) fclose(fp);
    exit(1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rdi, %rbx
leaq 0x28cbe(%rip), %rsi     # 0x547f5
callq 0x12500
testq %rax, %rax
je 0x2bb77
movq %rax, %r13
movq %rax, %rdi
callq 0x12560
leaq 0x18(%rsp), %rsi
movl %eax, %edi
callq 0x128a0
cmpl $-0x1, %eax
je 0x2bbaf
cmpq $0x0, 0x48(%rsp)
jne 0x2bbaf
movq %r13, %rdi
callq 0x12220
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2bec2
callq 0x120d0
movl (%rax), %edi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %edi
je 0x2bec2
callq 0x128f0
leaq 0x2ae78(%rip), %rsi     # 0x56a10
movl $0x3, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x19fb1
jmp 0x2bf13
movl $0x400, %edi            # imm = 0x400
callq 0x1fea5
movq %rax, %r14
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdx
callq 0x12470
testq %rax, %rax
je 0x2be82
leaq 0x2aea3(%rip), %r15     # 0x56a7f
movq %r14, 0x10(%rsp)
movq %r13, 0x8(%rsp)
cmpb $0xa, (%r14)
je 0x2be69
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
callq 0x1f99c
testq %rax, %rax
je 0x2bef0
movq %rax, %rbp
movq (%rax), %rbx
movq %rbx, %rdi
leaq 0x2ae26(%rip), %rsi     # 0x56a3c
callq 0x12090
movl 0x4(%rsp), %esi
testl %eax, %eax
je 0x2bc63
cmpl $0x6, %esi
jne 0x2bef0
movq %rbx, %rdi
callq 0x12250
cmpq $0x28, %rax
jne 0x2bef0
leaq 0x43443(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
movq 0x10(%rax), %rdi
movq %rbx, %rsi
callq 0x190de
testq %rax, %rax
je 0x2bcb5
movq 0x8(%rax), %rbx
jmp 0x2bcb7
cmpl $0x2, %esi
leaq 0x2add4(%rip), %r12     # 0x56a41
jl 0x2be5c
movl $0x1, %r14d
movq (%rbp,%r14,8), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x12090
testl %eax, %eax
je 0x2bca3
movl $0x3, %edi
leaq 0x2adb8(%rip), %rsi     # 0x56a51
movq %rbx, %rdx
xorl %eax, %eax
callq 0x19fb1
addq $0x2, %r14
movl 0x4(%rsp), %esi
cmpl %r14d, %esi
jg 0x2bc79
jmp 0x2be5c
xorl %ebx, %ebx
testq %rbx, %rbx
jne 0x2bce7
movq (%rbp), %rdi
xorl %esi, %esi
callq 0x2bf69
movq %rax, %rbx
leaq 0x433b7(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
movq 0x10(%rax), %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x18b97
movq 0x8(%rbp), %rdi
movl $0x3a, %esi
callq 0x12310
testq %rax, %rax
je 0x2bef0
movq %rax, %r12
movb $0x0, (%rax)
leaq 0x50(%rbx), %r13
movq 0x8(%rbp), %r14
movq %r14, %rdi
callq 0x12250
leaq 0x1(%rax), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x12520
incq %r12
movq %r12, %rdi
callq 0x12830
movl %eax, 0x80(%rbx)
movq 0x10(%rbp), %r13
testq %r13, %r13
leaq 0x43346(%rip), %r14     # 0x6f088
je 0x2be27
movq %r13, %rdi
movl $0x2c, %esi
callq 0x122b0
movq %rax, %r12
testq %rax, %rax
je 0x2bd62
movb $0x0, (%r12)
movq %r13, %rdi
movq %r15, %rsi
callq 0x12090
testl %eax, %eax
je 0x2bdd5
movq %r13, %rdi
leaq 0x2ad34(%rip), %rsi     # 0x56aaf
callq 0x12090
testl %eax, %eax
je 0x2bdf6
movq %r13, %rdi
leaq 0x2ad27(%rip), %rsi     # 0x56ab5
callq 0x12090
testl %eax, %eax
je 0x2bdfc
movq %r13, %rdi
leaq 0x2ad19(%rip), %rsi     # 0x56aba
callq 0x12090
testl %eax, %eax
je 0x2be0b
movq %r13, %rdi
leaq 0x2ad10(%rip), %rsi     # 0x56ac4
callq 0x12090
testl %eax, %eax
je 0x2be11
movq %r13, %rdi
leaq 0x2ad04(%rip), %rsi     # 0x56acb
callq 0x12090
testl %eax, %eax
je 0x2be15
jmp 0x2bf1d
movq 0x668(%r14), %rax
cmpq $0x0, (%rax)
jne 0x2bed6
movq %rbx, (%rax)
movq %rbx, 0x577b0(%rip)     # 0x835a0
orb $0x4, 0x30(%rbx)
jmp 0x2be15
orb $0x1, 0x30(%rbx)
jmp 0x2be15
orb $0x2, 0x30(%rbx)
callq 0x1a1d3
movq %rax, 0x48(%rbx)
jmp 0x2be15
orb $0x8, 0x30(%rbx)
jmp 0x2be15
orb $0x10, 0x30(%rbx)
leaq 0x1(%r12), %rax
testq %r12, %r12
cmovneq %rax, %r13
jne 0x2bd48
movq 0x18(%rbp), %rdi
callq 0x12830
testl %eax, %eax
je 0x2be3d
callq 0x1a1d3
movq %rax, 0x38(%rbx)
movq 0x20(%rbp), %rdi
callq 0x12830
testl %eax, %eax
movq 0x8(%rsp), %r13
je 0x2be58
callq 0x1a1d3
movq %rax, 0x40(%rbx)
movl 0x4(%rsp), %esi
movq %rbp, %rdi
callq 0x1f796
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdx
callq 0x12470
testq %rax, %rax
jne 0x2bbe6
leaq 0x431ff(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
cmpq $0x0, (%rax)
je 0x2bef0
movq %r14, %rdi
callq 0x1ffff
movq %r13, %rdi
callq 0x12220
movq 0x576f3(%rip), %rdx     # 0x835a0
leaq 0x2ac4c(%rip), %rsi     # 0x56b00
xorl %ebp, %ebp
movl $0x2, %edi
xorl %eax, %eax
callq 0x19fb1
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2aba9(%rip), %rdi     # 0x56a86
leaq 0x2abc1(%rip), %rsi     # 0x56aa5
movl $0xa5, %edx
callq 0x2a9ff
jmp 0x2bf35
leaq 0x2ac2e(%rip), %rsi     # 0x56b25
movl $0x3, %edi
xorl %eax, %eax
callq 0x19fb1
movq %r14, %rdi
callq 0x1ffff
movq %r13, %rdi
callq 0x12220
movl $0x1, %edi
callq 0x12870
leaq 0x2abaf(%rip), %rdi     # 0x56ad3
leaq 0x2ab7a(%rip), %rsi     # 0x56aa5
movl $0xb4, %edx
callq 0x2ade4
movl $0x1, %edi
callq 0x12120