// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/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. Note that single lines of the cluster config file can
     * be really long as they include all the hash slots of the node.
     * This means in the worst possible case, half of the Redis slots will be
     * present in a single line, possibly in importing or migrating state, so
     * together with the node ID of the sender/receiver.
     *
     * To simplify we allocate 1024+CLUSTER_SLOTS*128 bytes per line. */
    maxline = 1024+CLUSTER_SLOTS*128;
    line = zmalloc(maxline);
    while(fgets(line,maxline,fp) != NULL) {
        int argc;
        sds *argv;
        clusterNode *n, *master;
        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' || line[0] == '\0') 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 Redis. */
        if (strcasecmp(argv[0],"vars") == 0) {
            for (j = 1; j < argc; j += 2) {
                if (strcasecmp(argv[j],"currentEpoch") == 0) {
                    server.cluster->currentEpoch =
                            strtoull(argv[j+1],NULL,10);
                } else if (strcasecmp(argv[j],"lastVoteEpoch") == 0) {
                    server.cluster->lastVoteEpoch =
                            strtoull(argv[j+1],NULL,10);
                } 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 < 8) goto fmterr;

        /* Create this node if it does not exist */
        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,"master")) {
                n->flags |= CLUSTER_NODE_MASTER;
            } else if (!strcasecmp(s,"slave")) {
                n->flags |= CLUSTER_NODE_SLAVE;
            } 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 redis cluster config file");
            }
            if (p) s = p+1;
        }

        /* Get master if any. Set the master and populate master's
         * slave list. */
        if (argv[3][0] != '-') {
            master = clusterLookupNode(argv[3]);
            if (!master) {
                master = createClusterNode(argv[3],0);
                clusterAddNode(master);
            }
            n->slaveof = master;
            clusterNodeAddSlave(master,n);
        }

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

        /* Set configEpoch for this node. */
        n->configEpoch = strtoull(argv[6],NULL,10);

        /* Populate hash slots served by this instance. */
        for (j = 8; j < argc; j++) {
            int start, stop;

            if (argv[j][0] == '[') {
                /* Here we handle migrating / importing slots */
                int slot;
                char direction;
                clusterNode *cn;

                p = strchr(argv[j],'-');
                serverAssert(p != NULL);
                *p = '\0';
                direction = p[1]; /* Either '>' or '<' */
                slot = atoi(argv[j]+1);
                p += 3;
                cn = clusterLookupNode(p);
                if (!cn) {
                    cn = createClusterNode(p,0);
                    clusterAddNode(cn);
                }
                if (direction == '>') {
                    server.cluster->migrating_slots_to[slot] = cn;
                } else {
                    server.cluster->importing_slots_from[slot] = cn;
                }
                continue;
            } else if ((p = strchr(argv[j],'-')) != NULL) {
                *p = '\0';
                start = atoi(argv[j]);
                stop = atoi(p+1);
            } else {
                start = stop = atoi(argv[j]);
            }
            while(start <= stop) clusterAddSlot(n, start++);
        }

        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);

    /* Something that should never happen: currentEpoch smaller than
     * the max epoch found in the nodes configuration. However we handle this
     * as some form of protection against manual editing of critical files. */
    if (clusterGetMaxEpoch() > server.cluster->currentEpoch) {
        server.cluster->currentEpoch = clusterGetMaxEpoch();
    }
    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 $0xb8, %rsp
movq %rdi, %rbx
leaq 0x56ac2(%rip), %rsi     # 0xb1695
callq 0x26ae0
testq %rax, %rax
je 0x5ac0b
movq %rax, %r14
movq %rax, %rdi
callq 0x26070
leaq 0x28(%rsp), %rsi
movl %eax, %edi
callq 0x266e0
cmpl $-0x1, %eax
je 0x5ac32
cmpq $0x0, 0x58(%rsp)
jne 0x5ac32
movq %r14, %rdi
callq 0x26a10
jmp 0x5ac1b
callq 0x26880
movl (%rax), %edi
cmpl $0x2, %edi
jne 0x5b1a1
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x200400, %edi         # imm = 0x200400
callq 0x327b9
movq %rax, %rbx
leaq 0x9ec62(%rip), %r13     # 0xf98a8
movq %r14, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
movl $0x200400, %esi         # imm = 0x200400
movq %r14, %rdx
callq 0x26440
testq %rax, %rax
je 0x5b0ba
movzbl (%rbx), %eax
testl %eax, %eax
je 0x5ac50
cmpl $0xa, %eax
je 0x5ac50
movq %rbx, %rdi
leaq 0x14(%rsp), %rsi
callq 0x32388
testq %rax, %rax
je 0x5b159
movq %rax, 0x8(%rsp)
movq (%rax), %rbx
movq %rbx, %rdi
leaq 0x5d9f3(%rip), %rsi     # 0xb8690
callq 0x262f0
testl %eax, %eax
je 0x5aff4
cmpl $0x8, 0x14(%rsp)
movq 0x8(%rsp), %r15
jl 0x5b159
movq %rbx, %rdi
callq 0x5b1bf
movq %rax, %rbp
testq %rax, %rax
jne 0x5acdf
movq (%r15), %rdi
xorl %esi, %esi
callq 0x5b208
movq %rax, %rbp
movq %rax, %rdi
callq 0x5b2c3
movq 0x8(%r15), %rdi
pushq $0x3a
popq %rsi
callq 0x265c0
testq %rax, %rax
je 0x5b159
movq %rax, %rbx
movb $0x0, (%rax)
leaq 0x890(%rbp), %r14
movq 0x8(%r15), %r12
movq %r12, %rdi
callq 0x26500
leaq 0x1(%rax), %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x26c50
incq %rbx
movq %rbx, %rdi
callq 0x26760
movl %eax, 0x8c0(%rbp)
movq 0x10(%r15), %r14
movq %r14, %r12
pushq $0x2c
popq %rbx
testq %r14, %r14
je 0x5ae5e
movq %r12, %rdi
movl %ebx, %esi
callq 0x267f0
movq %rax, %r14
testq %rax, %rax
je 0x5ad56
movb $0x0, (%r14)
movq %r12, %rdi
leaq 0x5e91f(%rip), %rsi     # 0xb967f
callq 0x262f0
testl %eax, %eax
je 0x5adff
movq %r12, %rdi
leaq 0x5ef14(%rip), %rsi     # 0xb9c8b
callq 0x262f0
testl %eax, %eax
je 0x5ae20
movq %r12, %rdi
leaq 0x5ef4f(%rip), %rsi     # 0xb9cdd
callq 0x262f0
testl %eax, %eax
je 0x5ae26
movq %r12, %rdi
leaq 0x5d962(%rip), %rsi     # 0xb8707
callq 0x262f0
testl %eax, %eax
je 0x5ae2c
movq %r12, %rdi
leaq 0x5d955(%rip), %rsi     # 0xb870d
callq 0x262f0
testl %eax, %eax
je 0x5ae32
movq %r12, %rdi
leaq 0x58e9e(%rip), %rsi     # 0xb3c69
callq 0x262f0
testl %eax, %eax
je 0x5ae44
movq %r12, %rdi
leaq 0x5d934(%rip), %rsi     # 0xb8712
callq 0x262f0
testl %eax, %eax
je 0x5ae4a
movq %r12, %rdi
leaq 0x5d928(%rip), %rsi     # 0xb8719
callq 0x262f0
testl %eax, %eax
je 0x5ae4e
jmp 0x5b187
movq 0x9b0(%r13), %rax
cmpq $0x0, (%rax)
jne 0x5b139
movq %rbp, (%rax)
movq %rbp, 0xb3416(%rip)     # 0x10e230
orb $0x10, 0x30(%rbp)
jmp 0x5ae4e
orb $0x1, 0x30(%rbp)
jmp 0x5ae4e
orb $0x2, 0x30(%rbp)
jmp 0x5ae4e
orb $0x4, 0x30(%rbp)
jmp 0x5ae4e
orb $0x8, 0x30(%rbp)
callq 0x2b8ae
movq %rax, 0x868(%rbp)
jmp 0x5ae4e
orb $0x20, 0x30(%rbp)
jmp 0x5ae4e
orb $0x40, 0x30(%rbp)
leaq 0x1(%r14), %rax
testq %r14, %r14
cmovneq %rax, %r12
jmp 0x5ad37
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rdi
cmpb $0x2d, (%rdi)
je 0x5aeab
callq 0x5b1bf
movq %rax, %rbx
testq %rax, %rax
jne 0x5ae94
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
xorl %esi, %esi
callq 0x5b208
movq %rax, %rbx
movq %rax, %rdi
callq 0x5b2c3
movq %rbx, 0x850(%rbp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5b306
movq 0x8(%rsp), %rbx
movq 0x20(%rbx), %rdi
callq 0x26760
testl %eax, %eax
je 0x5aec4
callq 0x2b8ae
movq %rax, 0x858(%rbp)
movq 0x28(%rbx), %rdi
callq 0x26760
testl %eax, %eax
je 0x5aedd
callq 0x2b8ae
movq %rax, 0x860(%rbp)
movq 0x30(%rbx), %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x26a70
movq %rax, 0x38(%rbp)
pushq $0x8
popq %r15
movslq 0x14(%rsp), %rsi
cmpq %rsi, %r15
jge 0x5afe5
movq (%rbx,%r15,8), %rbx
movb (%rbx), %r12b
movq %rbx, %rdi
pushq $0x2d
popq %rsi
callq 0x267f0
movq %rax, %r14
cmpb $0x5b, %r12b
jne 0x5af97
testq %r14, %r14
je 0x5b124
movb $0x0, (%r14)
movb 0x1(%r14), %al
movb %al, 0x7(%rsp)
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rdi
incq %rdi
callq 0x26760
movl %eax, %r12d
addq $0x3, %r14
movq %r14, %rdi
callq 0x5b1bf
movq %rax, %rbx
testq %rax, %rax
jne 0x5af6e
movq %r14, %rdi
xorl %esi, %esi
callq 0x5b208
movq %rax, %rbx
movq %rax, %rdi
callq 0x5b2c3
xorl %eax, %eax
cmpb $0x3e, 0x7(%rsp)
setne %al
movslq %r12d, %rcx
shll $0x11, %eax
addq 0x9b0(%r13), %rax
movq %rbx, 0x28(%rax,%rcx,8)
incq %r15
movq 0x8(%rsp), %rbx
jmp 0x5aef3
testq %r14, %r14
je 0x5afbe
movb $0x0, (%r14)
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rdi
callq 0x26760
movl %eax, %r12d
incq %r14
movq %r14, %rdi
callq 0x26760
jmp 0x5afc9
movq %rbx, %rdi
callq 0x26760
movl %eax, %r12d
movl %eax, %ebx
cmpl %ebx, %r12d
jg 0x5af8a
leal 0x1(%r12), %r14d
movq %rbp, %rdi
movl %r12d, %esi
callq 0x5b377
movl %r14d, %r12d
jmp 0x5afcb
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %rbx
jmp 0x5b0ab
pushq $0x1
popq %r14
leaq 0x5d696(%rip), %r12     # 0xb8695
pushq $0xa
popq %rbp
movq 0x8(%rsp), %rbx
movslq 0x14(%rsp), %rsi
cmpq %rsi, %r14
jge 0x5b0a1
movq %rbx, %r15
movq (%rbx,%r14,8), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x262f0
testl %eax, %eax
je 0x5b059
movq %rbx, %rdi
leaq 0x5d66d(%rip), %rsi     # 0xb86a2
callq 0x262f0
testl %eax, %eax
je 0x5b077
pushq $0x3
popq %rdi
leaq 0x5d668(%rip), %rsi     # 0xb86b0
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2b699
movq 0x8(%rsp), %rbx
jmp 0x5b098
movq 0x8(%r15,%r14,8), %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x26a70
movq 0x9b0(%r13), %rcx
movq %rax, 0x8(%rcx)
movq %r15, %rbx
jmp 0x5b098
movq 0x8(%rsp), %rbx
movq 0x8(%rbx,%r14,8), %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x26a70
movq 0x9b0(%r13), %rcx
movq %rax, 0x60078(%rcx)
addq $0x2, %r14
jmp 0x5b007
movq 0x18(%rsp), %rbx
movq 0x20(%rsp), %r14
movq 0x8(%rsp), %rdi
callq 0x321be
jmp 0x5ac50
movq 0x9b0(%r13), %rax
cmpq $0x0, (%rax)
je 0x5b15e
movq %rbx, %rdi
callq 0x328f9
movq %r14, %rdi
callq 0x26a10
movq 0xb314e(%rip), %rdx     # 0x10e230
addq $0x8, %rdx
leaq 0x5d660(%rip), %rsi     # 0xb874d
xorl %ebx, %ebx
pushq $0x2
popq %rdi
xorl %eax, %eax
callq 0x2b699
callq 0x5b3bf
movq 0x9b0(%r13), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x5ac1e
callq 0x5b3bf
movq 0x9b0(%r13), %rcx
movq %rax, 0x8(%rcx)
jmp 0x5ac1e
leaq 0x59abd(%rip), %rdi     # 0xb4be8
leaq 0x5d5cb(%rip), %rsi     # 0xb86fd
movl $0xe8, %edx
jmp 0x5b14c
leaq 0x5d59e(%rip), %rdi     # 0xb86de
leaq 0x5d5b6(%rip), %rsi     # 0xb86fd
movl $0xb2, %edx
callq 0x57ac8
pushq $0x1
popq %rdi
callq 0x263c0
movq 0x18(%rsp), %rbx
leaq 0x5d60d(%rip), %rsi     # 0xb8772
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x2b699
movq %rbx, %rdi
callq 0x328f9
movq %r14, %rdi
callq 0x26a10
pushq $0x1
popq %rdi
callq 0x262c0
leaq 0x5d593(%rip), %rdi     # 0xb8721
leaq 0x5d568(%rip), %rsi     # 0xb86fd
movl $0xc5, %edx
callq 0x57b45
jmp 0x5b151
callq 0x26680
leaq 0x5d4b7(%rip), %rsi     # 0xb8664
pushq $0x3
popq %rdi
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2b699
jmp 0x5b17f