// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x73e97(%rip), %rsi     # 0xa5601
callq 0x124e0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x317ce
callq 0x120b0
cmpl $0x2, (%rax)
jne 0x31790
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31d1f
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
callq 0x120b0
movl (%rax), %edi
callq 0x12900
movq -0xe8(%rbp), %rdx
movq %rax, %rcx
movl $0x3, %edi
leaq 0x75a6b(%rip), %rsi     # 0xa7228
movb $0x0, %al
callq 0x18b10
movl $0x1, %edi
callq 0x12870
movq -0x18(%rbp), %rdi
callq 0x12540
movl %eax, %edi
leaq -0xa8(%rbp), %rsi
callq 0x128a0
cmpl $-0x1, %eax
je 0x31806
cmpq $0x0, -0x78(%rbp)
jne 0x31806
movq -0x18(%rbp), %rdi
callq 0x12200
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x31d1f
movl $0x400, -0xb4(%rbp)     # imm = 0x400
movslq -0xb4(%rbp), %rdi
callq 0x20a00
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
movl -0xb4(%rbp), %esi
movq -0x18(%rbp), %rdx
callq 0x12450
cmpq $0x0, %rax
je 0x31c98
movq -0xb0(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x31854
jmp 0x31823
movq -0xb0(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x20390
movq %rax, -0xc8(%rbp)
cmpq $0x0, -0xc8(%rbp)
jne 0x3187d
jmp 0x31ce6
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
leaq 0x759c6(%rip), %rsi     # 0xa7254
callq 0x12070
cmpl $0x0, %eax
jne 0x31928
movl $0x1, -0xb8(%rbp)
movl -0xb8(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jge 0x31911
movq -0xc8(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x7598c(%rip), %rsi     # 0xa7259
callq 0x12070
cmpl $0x0, %eax
jne 0x318d9
jmp 0x318fe
movq -0xc8(%rbp), %rax
movslq -0xb8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl $0x3, %edi
leaq 0x75972(%rip), %rsi     # 0xa7269
movb $0x0, %al
callq 0x18b10
jmp 0x31900
movl -0xb8(%rbp), %eax
addl $0x2, %eax
movl %eax, -0xb8(%rbp)
jmp 0x318a6
movq -0xc8(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x20010
jmp 0x31823
cmpl $0x6, -0xbc(%rbp)
je 0x31936
jmp 0x31ce6
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
callq 0x12230
cmpq $0x28, %rax
je 0x31950
jmp 0x31ce6
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
callq 0x31d30
movq %rax, -0xd0(%rbp)
cmpq $0x0, -0xd0(%rbp)
jne 0x31994
movq -0xc8(%rbp), %rax
movq (%rax), %rdi
xorl %esi, %esi
callq 0x31d90
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
callq 0x31e80
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
movl $0x3a, %esi
callq 0x12300
movq %rax, -0xd8(%rbp)
cmpq $0x0, %rax
jne 0x319bb
jmp 0x31ce6
movq -0xd8(%rbp), %rax
movb $0x0, (%rax)
movq -0xd0(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xf8(%rbp)
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0xf0(%rbp)
movq -0xc8(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x12230
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq %rax, %rdx
addq $0x1, %rdx
callq 0x12500
movq -0xd8(%rbp), %rdi
addq $0x1, %rdi
callq 0x12820
movl %eax, %ecx
movq -0xd0(%rbp), %rax
movl %ecx, 0x80(%rax)
movq -0xc8(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x31c31
movq -0xe0(%rbp), %rdi
movl $0x2c, %esi
callq 0x122a0
movq %rax, -0xd8(%rbp)
cmpq $0x0, -0xd8(%rbp)
je 0x31a85
movq -0xd8(%rbp), %rax
movb $0x0, (%rax)
movq -0xe0(%rbp), %rdi
leaq 0x75804(%rip), %rsi     # 0xa7297
callq 0x12070
cmpl $0x0, %eax
jne 0x31b09
leaq 0x8d644(%rip), %rax     # 0xbf0e8
movq 0x668(%rax), %rax
cmpq $0x0, (%rax)
jne 0x31ab3
jmp 0x31ad5
leaq 0x757e4(%rip), %rdi     # 0xa729e
leaq 0x757fc(%rip), %rsi     # 0xa72bd
movl $0xa5, %edx
callq 0x300b0
movl $0x1, %edi
callq 0x12100
movq -0xd0(%rbp), %rax
leaq 0x8d605(%rip), %rcx     # 0xbf0e8
movq 0x668(%rcx), %rcx
movq %rax, (%rcx)
movq %rax, 0xa1b0c(%rip)     # 0xd3600
movq -0xd0(%rbp), %rax
movl 0x30(%rax), %ecx
orl $0x4, %ecx
movl %ecx, 0x30(%rax)
jmp 0x31c10
movq -0xe0(%rbp), %rdi
leaq 0x757b0(%rip), %rsi     # 0xa72c7
callq 0x12070
cmpl $0x0, %eax
jne 0x31b36
movq -0xd0(%rbp), %rax
movl 0x30(%rax), %ecx
orl $0x1, %ecx
movl %ecx, 0x30(%rax)
jmp 0x31c0e
movq -0xe0(%rbp), %rdi
leaq 0x75789(%rip), %rsi     # 0xa72cd
callq 0x12070
cmpl $0x0, %eax
jne 0x31b76
movq -0xd0(%rbp), %rax
movl 0x30(%rax), %ecx
orl $0x2, %ecx
movl %ecx, 0x30(%rax)
callq 0x18e20
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x31c0c
movq -0xe0(%rbp), %rdi
leaq 0x7574e(%rip), %rsi     # 0xa72d2
callq 0x12070
cmpl $0x0, %eax
jne 0x31ba0
movq -0xd0(%rbp), %rax
movl 0x30(%rax), %ecx
orl $0x8, %ecx
movl %ecx, 0x30(%rax)
jmp 0x31c0a
movq -0xe0(%rbp), %rdi
leaq 0x7572e(%rip), %rsi     # 0xa72dc
callq 0x12070
cmpl $0x0, %eax
jne 0x31bca
movq -0xd0(%rbp), %rax
movl 0x30(%rax), %ecx
orl $0x10, %ecx
movl %ecx, 0x30(%rax)
jmp 0x31c08
movq -0xe0(%rbp), %rdi
leaq 0x7570b(%rip), %rsi     # 0xa72e3
callq 0x12070
cmpl $0x0, %eax
jne 0x31be4
jmp 0x31c06
leaq 0x75700(%rip), %rdi     # 0xa72eb
leaq 0x756cb(%rip), %rsi     # 0xa72bd
movl $0xb4, %edx
callq 0x304a0
movl $0x1, %edi
callq 0x12100
jmp 0x31c08
jmp 0x31c0a
jmp 0x31c0c
jmp 0x31c0e
jmp 0x31c10
cmpq $0x0, -0xd8(%rbp)
je 0x31c2c
movq -0xd8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0x31a4b
movq -0xc8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x12820
cmpl $0x0, %eax
je 0x31c59
callq 0x18e20
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0xc8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x12820
cmpl $0x0, %eax
je 0x31c81
callq 0x18e20
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0xc8(%rbp), %rdi
movl -0xbc(%rbp), %esi
callq 0x20010
jmp 0x31823
leaq 0x8d449(%rip), %rax     # 0xbf0e8
movq 0x668(%rax), %rax
cmpq $0x0, (%rax)
jne 0x31cae
jmp 0x31ce6
movq -0xb0(%rbp), %rdi
callq 0x20ce0
movq -0x18(%rbp), %rdi
callq 0x12200
movq 0xa1936(%rip), %rdx     # 0xd3600
movl $0x2, %edi
leaq 0x75642(%rip), %rsi     # 0xa7318
movb $0x0, %al
callq 0x18b10
movl $0x0, -0x4(%rbp)
jmp 0x31d1f
movl $0x3, %edi
leaq 0x7564b(%rip), %rsi     # 0xa733d
movb $0x0, %al
callq 0x18b10
movq -0xb0(%rbp), %rdi
callq 0x20ce0
cmpq $0x0, -0x18(%rbp)
je 0x31d15
movq -0x18(%rbp), %rdi
callq 0x12200
movl $0x1, %edi
callq 0x12870
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopl (%rax,%rax)