// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x59d0a(%rip), %rsi     # 0xc29f5
callq 0x26af0
testq %rax, %rax
je 0x68d2b
movq %rax, %rbp
movq %rax, %rdi
callq 0x26070
leaq 0x28(%rsp), %rsi
movl %eax, %edi
callq 0x266f0
cmpl $-0x1, %eax
je 0x68d63
cmpq $0x0, 0x58(%rsp)
jne 0x68d63
movq %rbp, %rdi
callq 0x26a20
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x69338
callq 0x26890
movl (%rax), %edi
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $0x2, %edi
je 0x69338
callq 0x26690
leaq 0x618a8(%rip), %rsi     # 0xca5f4
movl $0x3, %edi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x32ea6
jmp 0x693ad
movl $0x200400, %edi         # imm = 0x200400
callq 0x3b29d
movq %rax, %r14
movq %rax, %rdi
movl $0x200400, %esi         # imm = 0x200400
movq %rbp, %rdx
callq 0x26450
testq %rax, %rax
movq %r14, 0x20(%rsp)
je 0x692cc
leaq 0x9dac3(%rip), %r12     # 0x106858
movq %rbp, 0x18(%rsp)
movzbl (%r14), %eax
testl %eax, %eax
je 0x692b3
cmpl $0xa, %eax
je 0x692b3
movq %r14, %rdi
leaq 0x14(%rsp), %rsi
callq 0x3ad85
testq %rax, %rax
je 0x69383
movq %rax, 0x8(%rsp)
movq (%rax), %rbx
movq %rbx, %rdi
leaq 0x61849(%rip), %rsi     # 0xca620
callq 0x26300
movl 0x14(%rsp), %esi
testl %eax, %eax
je 0x691f0
cmpl $0x8, %esi
jl 0x69383
movq %rbx, %rdi
callq 0x693d1
movq %rax, %r13
testq %rax, %rax
jne 0x68e3b
movq 0x8(%rsp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x6941c
movq %rax, %r13
movq 0x9a0(%r12), %rax
movq 0x18(%rax), %rbx
leaq 0x8(%r13), %rdi
movl $0x28, %esi
callq 0x3910c
movq %rbx, %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x31a95
movq 0x8(%rsp), %rbp
movq 0x8(%rbp), %rdi
movl $0x3a, %esi
callq 0x265d0
testq %rax, %rax
je 0x69383
movq %rax, %rbx
movb $0x0, (%rax)
leaq 0x890(%r13), %r15
movq 0x8(%rbp), %r12
movq %r12, %rdi
callq 0x26510
leaq 0x1(%rax), %rdx
movq %r15, %rdi
movq %r12, %rsi
leaq 0x9d9d7(%rip), %r12     # 0x106858
callq 0x26c60
incq %rbx
movq %rbx, %rdi
callq 0x26770
movl %eax, 0x8c0(%r13)
movq 0x10(%rbp), %r15
testq %r15, %r15
je 0x68fd2
movq %r15, %rdi
movl $0x2c, %esi
callq 0x26800
movq %rax, %rbx
testq %rax, %rax
je 0x68ebd
movb $0x0, (%rbx)
movq %r15, %rdi
leaq 0x62748(%rip), %rsi     # 0xcb60f
callq 0x26300
testl %eax, %eax
je 0x68f6a
movq %r15, %rdi
leaq 0x62d3d(%rip), %rsi     # 0xcbc1b
callq 0x26300
testl %eax, %eax
je 0x68f8d
movq %r15, %rdi
leaq 0x62d78(%rip), %rsi     # 0xcbc6d
callq 0x26300
testl %eax, %eax
je 0x68f94
movq %r15, %rdi
leaq 0x6178b(%rip), %rsi     # 0xca697
callq 0x26300
testl %eax, %eax
je 0x68f9b
movq %r15, %rdi
leaq 0x6177a(%rip), %rsi     # 0xca69d
callq 0x26300
testl %eax, %eax
je 0x68fa2
movq %r15, %rdi
leaq 0x5c54f(%rip), %rsi     # 0xc5485
callq 0x26300
testl %eax, %eax
je 0x68fb5
movq %r15, %rdi
leaq 0x61759(%rip), %rsi     # 0xca6a2
callq 0x26300
testl %eax, %eax
je 0x68fbc
movq %r15, %rdi
leaq 0x6174d(%rip), %rsi     # 0xca6a9
callq 0x26300
testl %eax, %eax
je 0x68fc1
jmp 0x693b7
movq 0x9a0(%r12), %rax
cmpq $0x0, (%rax)
jne 0x69361
movq %r13, (%rax)
movq %r13, 0xb224a(%rip)     # 0x11b1d0
orb $0x10, 0x30(%r13)
jmp 0x68fc1
orb $0x1, 0x30(%r13)
jmp 0x68fc1
orb $0x2, 0x30(%r13)
jmp 0x68fc1
orb $0x4, 0x30(%r13)
jmp 0x68fc1
orb $0x8, 0x30(%r13)
callq 0x330c8
movq %rax, 0x868(%r13)
jmp 0x68fc1
orb $0x20, 0x30(%r13)
jmp 0x68fc1
orb $0x40, 0x30(%r13)
leaq 0x1(%rbx), %rax
testq %rbx, %rbx
cmovneq %rax, %r15
jne 0x68ea5
movq 0x8(%rsp), %rbx
movq 0x18(%rbx), %rdi
cmpb $0x2d, (%rdi)
movq 0x18(%rsp), %rbp
je 0x69044
callq 0x693d1
movq %rax, %rbx
testq %rax, %rax
jne 0x6902d
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdi
xorl %esi, %esi
callq 0x6941c
movq %rax, %rbx
movq 0x9a0(%r12), %rax
movq 0x18(%rax), %r15
leaq 0x8(%rbx), %rdi
movl $0x28, %esi
callq 0x3910c
movq %r15, %rdi
movq %rax, %rsi
movq %rbx, %rdx
callq 0x31a95
movq %rbx, 0x850(%r13)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x69521
movq 0x8(%rsp), %rbx
movq 0x20(%rbx), %rdi
callq 0x26770
testl %eax, %eax
je 0x6905d
callq 0x330c8
movq %rax, 0x858(%r13)
movq 0x28(%rbx), %rdi
callq 0x26770
testl %eax, %eax
je 0x69076
callq 0x330c8
movq %rax, 0x860(%r13)
movq 0x30(%rbx), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a80
movq %rax, 0x38(%r13)
movl 0x14(%rsp), %esi
cmpl $0x9, %esi
jl 0x692ab
movl $0x8, %ebp
movq (%rbx,%rbp,8), %rbx
movb (%rbx), %r14b
movq %rbx, %rdi
movl $0x2d, %esi
callq 0x26800
movq %rax, %r15
cmpb $0x5b, %r14b
jne 0x69158
testq %r15, %r15
je 0x6934c
movb $0x0, (%r15)
movb 0x1(%r15), %r14b
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
incq %rdi
callq 0x26770
movl %eax, %ebx
addq $0x3, %r15
movq %r15, %rdi
callq 0x693d1
movq %rax, %r12
testq %rax, %rax
jne 0x69131
movq %r15, %rdi
xorl %esi, %esi
callq 0x6941c
movq %rax, %r12
leaq 0x9d74f(%rip), %rax     # 0x106858
movq 0x9a0(%rax), %rax
movq 0x18(%rax), %r15
leaq 0x8(%r12), %rdi
movl $0x28, %esi
callq 0x3910c
movq %r15, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x31a95
xorl %eax, %eax
cmpb $0x3e, %r14b
setne %al
movslq %ebx, %rcx
shll $0x11, %eax
leaq 0x9d711(%rip), %rdx     # 0x106858
addq 0x9a0(%rdx), %rax
movq %r12, 0x28(%rax,%rcx,8)
movq %rdx, %r12
jmp 0x691cb
testq %r15, %r15
je 0x6917e
movb $0x0, (%r15)
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
callq 0x26770
movl %eax, %ebx
incq %r15
movq %r15, %rdi
callq 0x26770
jmp 0x69188
movq %rbx, %rdi
callq 0x26770
movl %eax, %ebx
movl %eax, %r15d
cmpl %eax, %ebx
jg 0x691cb
movslq %ebx, %r14
incl %r15d
addq $0x8005, %r14           # imm = 0x8005
movq 0x9a0(%r12), %rax
cmpq $0x0, (%rax,%r14,8)
jne 0x691c1
movq %r13, %rdi
movl %ebx, %esi
callq 0x6dccc
movq 0x9a0(%r12), %rax
movq %r13, (%rax,%r14,8)
incq %r14
incl %ebx
cmpl %ebx, %r15d
jne 0x6919c
incq %rbp
movslq 0x14(%rsp), %rsi
cmpq %rsi, %rbp
movq 0x8(%rsp), %rbx
jl 0x6909c
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %r14
jmp 0x692ab
cmpl $0x2, %esi
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rbp
jl 0x692ab
movl $0x1, %r15d
movq %rbx, %r13
movq (%rbx,%r15,8), %rbx
movq %rbx, %rdi
leaq 0x6140b(%rip), %rsi     # 0xca625
callq 0x26300
testl %eax, %eax
je 0x69253
movq %rbx, %rdi
leaq 0x61405(%rip), %rsi     # 0xca632
callq 0x26300
testl %eax, %eax
je 0x69275
movl $0x3, %edi
leaq 0x613fe(%rip), %rsi     # 0xca640
movq %rbx, %rdx
xorl %eax, %eax
callq 0x32ea6
movq 0x8(%rsp), %rbx
jmp 0x6929a
movq 0x8(%r13,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a80
movq 0x9a0(%r12), %rcx
movq %rax, 0x8(%rcx)
movq %r13, %rbx
jmp 0x6929a
movq 0x8(%rsp), %rbx
movq 0x8(%rbx,%r15,8), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x26a80
movq 0x9a0(%r12), %rcx
movq %rax, 0x60078(%rcx)
addq $0x2, %r15
movl 0x14(%rsp), %esi
cmpl %r15d, %esi
jg 0x69209
movq %rbx, %rdi
callq 0x3ab7f
movq %r14, %rdi
movl $0x200400, %esi         # imm = 0x200400
movq %rbp, %rdx
callq 0x26450
testq %rax, %rax
jne 0x68d9a
leaq 0x9d585(%rip), %r14     # 0x106858
movq 0x9a0(%r14), %rax
cmpq $0x0, (%rax)
je 0x69388
movq 0x20(%rsp), %rdi
callq 0x3b3df
movq %rbp, %rdi
callq 0x26a20
movq 0xb1ed3(%rip), %rdx     # 0x11b1d0
addq $0x8, %rdx
leaq 0x613d5(%rip), %rsi     # 0xca6dd
xorl %ebx, %ebx
movl $0x2, %edi
xorl %eax, %eax
callq 0x32ea6
callq 0x695da
movq 0x9a0(%r14), %rcx
cmpq 0x8(%rcx), %rax
jbe 0x69338
callq 0x695da
movq 0x9a0(%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 0x5d399(%rip), %rdi     # 0xc66ec
leaq 0x61333(%rip), %rsi     # 0xca68d
movl $0xe9, %edx
jmp 0x69374
leaq 0x61306(%rip), %rdi     # 0xca66e
leaq 0x6131e(%rip), %rsi     # 0xca68d
movl $0xb3, %edx
callq 0x654e1
movl $0x1, %edi
callq 0x263d0
movq 0x18(%rsp), %rbp
leaq 0x61373(%rip), %rsi     # 0xca702
movl $0x3, %edi
xorl %eax, %eax
callq 0x32ea6
movq 0x20(%rsp), %rdi
callq 0x3b3df
movq %rbp, %rdi
callq 0x26a20
movl $0x1, %edi
callq 0x262d0
leaq 0x612f3(%rip), %rdi     # 0xca6b1
leaq 0x612c8(%rip), %rsi     # 0xca68d
movl $0xc6, %edx
callq 0x6558d
jmp 0x69379