// File: /workspace/github_c_makefile_star2_O3/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, %r14
leaq 0x5a9de(%rip), %rsi     # 0xbfa5d
callq 0x26ae0
testq %rax, %rax
je 0x650bf
movq %rax, %rbp
movq %rax, %rdi
callq 0x26070
leaq 0x28(%rsp), %rsi
movl %eax, %edi
callq 0x266e0
cmpl $-0x1, %eax
je 0x650f7
cmpq $0x0, 0x58(%rsp)
jne 0x650f7
movq %rbp, %rdi
callq 0x26a10
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x656c8
callq 0x26880
movl (%rax), %edi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x2, %edi
je 0x656c8
callq 0x26680
leaq 0x6259c(%rip), %rsi     # 0xc767c
movl $0x3, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x2fdad
jmp 0x65738
movl $0x200400, %edi         # imm = 0x200400
callq 0x382d1
movq %rax, %r14
movq %rax, %rdi
movl $0x200400, %esi         # imm = 0x200400
movq %rbp, %rdx
callq 0x26440
testq %rax, %rax
movq %r14, 0x10(%rsp)
je 0x6565c
movq %rbp, 0x18(%rsp)
movzbl (%r14), %eax
testl %eax, %eax
je 0x65643
cmpl $0xa, %eax
je 0x65643
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x37e0a
testq %rax, %rax
je 0x65713
movq %rax, %r12
movq (%rax), %rbx
movq %rbx, %rdi
leaq 0x62546(%rip), %rsi     # 0xc76a8
callq 0x262f0
movl 0xc(%rsp), %esi
testl %eax, %eax
je 0x6558e
cmpl $0x8, %esi
jl 0x65713
movq %rbx, %rdi
callq 0x6575c
movq %rax, %r13
testq %rax, %rax
jne 0x651c8
movq (%r12), %rdi
xorl %esi, %esi
callq 0x657a7
movq %rax, %r13
leaq 0x9c707(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %rbx
leaq 0x8(%r13), %rdi
movl $0x28, %esi
callq 0x36178
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x2e9b8
movq 0x8(%r12), %rdi
movl $0x3a, %esi
callq 0x265c0
testq %rax, %rax
je 0x65713
movq %rax, %rbx
movb $0x0, (%rax)
leaq 0x890(%r13), %r15
movq %r12, %rbp
movq 0x8(%r12), %r12
movq %r12, %rdi
callq 0x26500
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %r12, %rsi
leaq 0x63489(%rip), %r12     # 0xc8697
callq 0x26c50
incq %rbx
movq %rbx, %rdi
callq 0x26760
movl %eax, 0x8c0(%r13)
movq %rbp, 0x20(%rsp)
movq 0x10(%rbp), %rbx
testq %rbx, %rbx
je 0x65363
movq %rbx, %rdi
movl $0x2c, %esi
callq 0x267f0
movq %rax, %r15
testq %rax, %rax
je 0x65250
movb $0x0, (%r15)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x262f0
testl %eax, %eax
je 0x652f9
movq %rbx, %rdi
leaq 0x63a36(%rip), %rsi     # 0xc8ca3
callq 0x262f0
testl %eax, %eax
je 0x65322
movq %rbx, %rdi
leaq 0x63a71(%rip), %rsi     # 0xc8cf5
callq 0x262f0
testl %eax, %eax
je 0x65329
movq %rbx, %rdi
leaq 0x62484(%rip), %rsi     # 0xc771f
callq 0x262f0
testl %eax, %eax
je 0x65330
movq %rbx, %rdi
leaq 0x62473(%rip), %rsi     # 0xc7725
callq 0x262f0
testl %eax, %eax
je 0x65337
movq %rbx, %rdi
leaq 0x5d254(%rip), %rsi     # 0xc2519
callq 0x262f0
testl %eax, %eax
je 0x6534a
movq %rbx, %rdi
leaq 0x62452(%rip), %rsi     # 0xc772a
callq 0x262f0
testl %eax, %eax
je 0x65351
movq %rbx, %rdi
leaq 0x62446(%rip), %rsi     # 0xc7731
callq 0x262f0
testl %eax, %eax
je 0x65356
jmp 0x65742
leaq 0x9c5a8(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
cmpq $0x0, (%rax)
jne 0x656f1
movq %r13, (%rax)
movq %r13, 0xb0f15(%rip)     # 0x116230
orb $0x10, 0x30(%r13)
jmp 0x65356
orb $0x1, 0x30(%r13)
jmp 0x65356
orb $0x2, 0x30(%r13)
jmp 0x65356
orb $0x4, 0x30(%r13)
jmp 0x65356
orb $0x8, 0x30(%r13)
callq 0x2ffce
movq %rax, 0x868(%r13)
jmp 0x65356
orb $0x20, 0x30(%r13)
jmp 0x65356
orb $0x40, 0x30(%r13)
leaq 0x1(%r15), %rbx
testq %r15, %r15
jne 0x65237
movq 0x20(%rsp), %r12
movq 0x18(%r12), %rdi
cmpb $0x2d, (%rdi)
movq 0x18(%rsp), %rbp
je 0x653d3
callq 0x6575c
movq %rax, %rbx
testq %rax, %rax
jne 0x653c1
movq 0x18(%r12), %rdi
xorl %esi, %esi
callq 0x657a7
movq %rax, %rbx
leaq 0x9c50e(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %r15
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x36178
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x2e9b8
movq %rbx, 0x850(%r13)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x658ac
movq 0x20(%r12), %rdi
callq 0x26760
testl %eax, %eax
je 0x653ed
callq 0x2ffce
movq %rax, 0x858(%r13)
movq 0x28(%r12), %rdi
callq 0x26760
testl %eax, %eax
je 0x65407
callq 0x2ffce
movq %rax, 0x860(%r13)
movq 0x30(%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a70
movq %rax, 0x38(%r13)
movl 0xc(%rsp), %esi
cmpl $0x9, %esi
jl 0x6563b
movl $0x8, %ebp
movq (%r12,%rbp,8), %rbx
movb (%rbx), %r14b
movq %rbx, %rdi
movl $0x2d, %esi
callq 0x267f0
movq %rax, %r15
cmpb $0x5b, %r14b
jne 0x654ea
testq %r15, %r15
je 0x656dc
movb $0x0, (%r15)
movb 0x1(%r15), %r14b
movq (%r12,%rbp,8), %rdi
incq %rdi
callq 0x26760
movl %eax, %ebx
addq $0x3, %r15
movq %r15, %rdi
callq 0x6575c
movq %rax, %r12
testq %rax, %rax
jne 0x654be
movq %r15, %rdi
xorl %esi, %esi
callq 0x657a7
movq %rax, %r12
leaq 0x9c412(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %r15
leaq 0x8(%r12), %rdi
movl $0x28, %esi
callq 0x36178
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x2e9b8
xorl %eax, %eax
cmpb $0x3e, %r14b
setne %al
movslq %ebx, %rcx
shll $0x11, %eax
leaq 0x9c3d4(%rip), %rdx     # 0x1018a8
addq 0x9b0(%rdx), %rax
movq %r12, 0x28(%rax,%rcx,8)
movq 0x20(%rsp), %r12
jmp 0x6556e
testq %r15, %r15
je 0x65512
movb $0x0, (%r15)
movq (%r12,%rbp,8), %rdi
callq 0x26760
movl %eax, %ebx
incq %r15
movq %r15, %rdi
callq 0x26760
cmpl %eax, %ebx
jg 0x6556e
movl %eax, %r15d
jmp 0x6551f
movq %rbx, %rdi
callq 0x26760
movl %eax, %r15d
movl %eax, %ebx
movslq %ebx, %r14
incl %r15d
leaq 0x9c37c(%rip), %rax     # 0x1018a8
movq 0x9b0(%rax), %rax
addq $0x8005, %r14           # imm = 0x8005
cmpq $0x0, (%rax,%r14,8)
jne 0x65564
movq %r13, %rdi
movl %ebx, %esi
callq 0x6a187
leaq 0x9c356(%rip), %rcx     # 0x1018a8
movq 0x9b0(%rcx), %rax
movq %r13, (%rax,%r14,8)
movq 0x9b0(%rcx), %rax
incq %r14
incl %ebx
cmpl %ebx, %r15d
jne 0x6553a
incq %rbp
movslq 0xc(%rsp), %rsi
cmpq %rsi, %rbp
jl 0x6542e
movq 0x18(%rsp), %rbp
movq 0x10(%rsp), %r14
jmp 0x6563b
cmpl $0x2, %esi
jl 0x6563b
movl $0x1, %r15d
movq (%r12,%r15,8), %rbx
movq %rbx, %rdi
leaq 0x62102(%rip), %rsi     # 0xc76ad
callq 0x262f0
testl %eax, %eax
je 0x655df
movq %rbx, %rdi
leaq 0x620fc(%rip), %rsi     # 0xc76ba
callq 0x262f0
testl %eax, %eax
je 0x65604
movl $0x3, %edi
leaq 0x620f5(%rip), %rsi     # 0xc76c8
movq %rbx, %rdx
xorl %eax, %eax
callq 0x2fdad
jmp 0x6562a
movq 0x8(%r12,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a70
leaq 0x9c2b1(%rip), %rcx     # 0x1018a8
movq 0x9b0(%rcx), %rcx
movq %rax, 0x8(%rcx)
jmp 0x6562a
movq 0x8(%r12,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a70
leaq 0x9c28c(%rip), %rcx     # 0x1018a8
movq 0x9b0(%rcx), %rcx
movq %rax, 0x60078(%rcx)
addq $0x2, %r15
movl 0xc(%rsp), %esi
cmpl %r15d, %esi
jg 0x6559d
movq %r12, %rdi
callq 0x37c04
movq %r14, %rdi
movl $0x200400, %esi         # imm = 0x200400
movq %rbp, %rdx
callq 0x26440
testq %rax, %rax
jne 0x65127
leaq 0x9c245(%rip), %r14     # 0x1018a8
movq 0x9b0(%r14), %rax
cmpq $0x0, (%rax)
je 0x65713
movq 0x10(%rsp), %rdi
callq 0x38413
movq %rbp, %rdi
callq 0x26a10
movq 0xb0ba3(%rip), %rdx     # 0x116230
addq $0x8, %rdx
leaq 0x620cd(%rip), %rsi     # 0xc7765
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x2fdad
callq 0x6595e
movq 0x9b0(%r14), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x656c8
callq 0x6595e
movq 0x9b0(%r14), %rcx
movq %rax, 0x8(%rcx)
movl %ebx, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5e089(%rip), %rdi     # 0xc376c
leaq 0x6202b(%rip), %rsi     # 0xc7715
movl $0xe8, %edx
jmp 0x65704
leaq 0x61ffe(%rip), %rdi     # 0xc76f6
leaq 0x62016(%rip), %rsi     # 0xc7715
movl $0xb2, %edx
callq 0x61908
movl $0x1, %edi
callq 0x263c0
leaq 0x62070(%rip), %rsi     # 0xc778a
movl $0x3, %edi
xorl %eax, %eax
callq 0x2fdad
movq 0x10(%rsp), %rdi
callq 0x38413
movq %rbp, %rdi
callq 0x26a10
movl $0x1, %edi
callq 0x262c0
leaq 0x61ff0(%rip), %rdi     # 0xc7739
leaq 0x61fc5(%rip), %rsi     # 0xc7715
movl $0xc5, %edx
callq 0x619b4
jmp 0x65709