// File: /workspace/github_c_makefile_star2_O3/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 0x292e6(%rip), %rsi     # 0x5483d
callq 0x124f0
testq %rax, %rax
je 0x2b597
movq %rax, %r13
movq %rax, %rdi
callq 0x12550
leaq 0x18(%rsp), %rsi
movl %eax, %edi
callq 0x12890
cmpl $-0x1, %eax
je 0x2b5cf
cmpq $0x0, 0x48(%rsp)
jne 0x2b5cf
movq %r13, %rdi
callq 0x12220
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2b8d5
callq 0x120d0
movl (%rax), %edi
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x2, %edi
je 0x2b8d5
callq 0x128e0
leaq 0x2b444(%rip), %rsi     # 0x569fc
movl $0x3, %edi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x19c06
jmp 0x2b926
movl $0x400, %edi            # imm = 0x400
callq 0x1fbbd
movq %rax, %r14
movq %rax, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdx
callq 0x12460
testq %rax, %rax
je 0x2b895
leaq 0x2b46f(%rip), %r15     # 0x56a6b
movq %r14, 0x10(%rsp)
movq %r13, 0x8(%rsp)
cmpb $0xa, (%r14)
je 0x2b87c
movq %r14, %rdi
leaq 0x4(%rsp), %rsi
callq 0x1f703
testq %rax, %rax
je 0x2b903
movq %rax, %rbp
movq (%rax), %r12
movq %r12, %rdi
leaq 0x2b3f2(%rip), %rsi     # 0x56a28
callq 0x12090
movl 0x4(%rsp), %ebx
testl %eax, %eax
je 0x2b827
cmpl $0x6, %ebx
jne 0x2b903
movq %r12, %rdi
callq 0x12250
cmpq $0x28, %rax
jne 0x2b903
leaq 0x43a1f(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
movq 0x10(%rax), %rdi
movq %r12, %rsi
callq 0x18d3e
testq %rax, %rax
je 0x2b68a
movq 0x8(%rax), %rbx
testq %rbx, %rbx
jne 0x2b6b5
movq (%rbp), %rdi
xorl %esi, %esi
callq 0x2b97c
movq %rax, %rbx
leaq 0x439e9(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
movq 0x10(%rax), %rdi
movq %rbx, %rsi
movq %rbx, %rdx
callq 0x18802
movq 0x8(%rbp), %rdi
movl $0x3a, %esi
callq 0x12310
testq %rax, %rax
je 0x2b903
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 0x12510
incq %r12
movq %r12, %rdi
callq 0x12820
movl %eax, 0x80(%rbx)
movq 0x10(%rbp), %r12
testq %r12, %r12
leaq 0x43978(%rip), %r14     # 0x6f088
je 0x2b7f0
movq %r12, %rdi
movl $0x2c, %esi
callq 0x122b0
movq %rax, %r13
testq %rax, %rax
je 0x2b730
movb $0x0, (%r13)
movq %r12, %rdi
movq %r15, %rsi
callq 0x12090
testl %eax, %eax
je 0x2b7a3
movq %r12, %rdi
leaq 0x2b352(%rip), %rsi     # 0x56a9b
callq 0x12090
testl %eax, %eax
je 0x2b7c4
movq %r12, %rdi
leaq 0x2b345(%rip), %rsi     # 0x56aa1
callq 0x12090
testl %eax, %eax
je 0x2b7ca
movq %r12, %rdi
leaq 0x2b337(%rip), %rsi     # 0x56aa6
callq 0x12090
testl %eax, %eax
je 0x2b7d9
movq %r12, %rdi
leaq 0x2b32e(%rip), %rsi     # 0x56ab0
callq 0x12090
testl %eax, %eax
je 0x2b7df
movq %r12, %rdi
leaq 0x2b322(%rip), %rsi     # 0x56ab7
callq 0x12090
testl %eax, %eax
je 0x2b7e3
jmp 0x2b930
movq 0x668(%r14), %rax
cmpq $0x0, (%rax)
jne 0x2b8e9
movq %rbx, (%rax)
movq %rbx, 0x57de2(%rip)     # 0x835a0
orb $0x4, 0x30(%rbx)
jmp 0x2b7e3
orb $0x1, 0x30(%rbx)
jmp 0x2b7e3
orb $0x2, 0x30(%rbx)
callq 0x19e27
movq %rax, 0x48(%rbx)
jmp 0x2b7e3
orb $0x8, 0x30(%rbx)
jmp 0x2b7e3
orb $0x10, 0x30(%rbx)
leaq 0x1(%r13), %r12
testq %r13, %r13
jne 0x2b716
movq 0x18(%rbp), %rdi
callq 0x12820
testl %eax, %eax
je 0x2b806
callq 0x19e27
movq %rax, 0x38(%rbx)
movq 0x20(%rbp), %rdi
callq 0x12820
testl %eax, %eax
movq 0x8(%rsp), %r13
je 0x2b821
callq 0x19e27
movq %rax, 0x40(%rbx)
movl 0x4(%rsp), %ebx
jmp 0x2b86d
cmpl $0x2, %ebx
jl 0x2b86d
movl $0x1, %r14d
movq (%rbp,%r14,8), %r12
movq %r12, %rdi
leaq 0x2b1ec(%rip), %rsi     # 0x56a2d
callq 0x12090
testl %eax, %eax
je 0x2b864
movl $0x3, %edi
leaq 0x2b1e7(%rip), %rsi     # 0x56a3d
movq %r12, %rdx
xorl %eax, %eax
callq 0x19c06
movl 0x4(%rsp), %ebx
addq $0x2, %r14
cmpl %r14d, %ebx
jg 0x2b832
movq %rbp, %rdi
movl %ebx, %esi
callq 0x1f4fd
movq 0x10(%rsp), %r14
movq %r14, %rdi
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdx
callq 0x12460
testq %rax, %rax
jne 0x2b606
leaq 0x437ec(%rip), %rax     # 0x6f088
movq 0x668(%rax), %rax
cmpq $0x0, (%rax)
je 0x2b903
movq %r14, %rdi
callq 0x1fd17
movq %r13, %rdi
callq 0x12220
movq 0x57ce0(%rip), %rdx     # 0x835a0
leaq 0x2b225(%rip), %rsi     # 0x56aec
xorl %ebp, %ebp
movl $0x2, %edi
xorl %eax, %eax
callq 0x19c06
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2b182(%rip), %rdi     # 0x56a72
leaq 0x2b19a(%rip), %rsi     # 0x56a91
movl $0xa5, %edx
callq 0x2a46a
jmp 0x2b948
leaq 0x2b207(%rip), %rsi     # 0x56b11
movl $0x3, %edi
xorl %eax, %eax
callq 0x19c06
movq %r14, %rdi
callq 0x1fd17
movq %r13, %rdi
callq 0x12220
movl $0x1, %edi
callq 0x12860
leaq 0x2b188(%rip), %rdi     # 0x56abf
leaq 0x2b153(%rip), %rsi     # 0x56a91
movl $0xb4, %edx
callq 0x2a81d
movl $0x1, %edi
callq 0x12120