// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/cluster.c
// Function: clusterUpdateState
void clusterUpdateState(void) {
    int j, new_state;
    int reachable_masters = 0;
    static mstime_t among_minority_time;
    static mstime_t first_call_time = 0;

    server.cluster->todo_before_sleep &= ~CLUSTER_TODO_UPDATE_STATE;

    /* If this is a master node, wait some time before turning the state
     * into OK, since it is not a good idea to rejoin the cluster as a writable
     * master, after a reboot, without giving the cluster a chance to
     * reconfigure this node. Note that the delay is calculated starting from
     * the first call to this function and not since the server start, in order
     * to don't count the DB loading time. */
    if (first_call_time == 0) first_call_time = mstime();
    if (nodeIsMaster(myself) &&
        server.cluster->state == CLUSTER_FAIL &&
        mstime() - first_call_time < CLUSTER_WRITABLE_DELAY) return;

    /* Start assuming the state is OK. We'll turn it into FAIL if there
     * are the right conditions. */
    new_state = CLUSTER_OK;

    /* Check if all the slots are covered. */
    if (server.cluster_require_full_coverage) {
        for (j = 0; j < CLUSTER_SLOTS; j++) {
            if (server.cluster->slots[j] == NULL ||
                server.cluster->slots[j]->flags & (CLUSTER_NODE_FAIL))
            {
                new_state = CLUSTER_FAIL;
                break;
            }
        }
    }

    /* Compute the cluster size, that is the number of master nodes
     * serving at least a single slot.
     *
     * At the same time count the number of reachable masters having
     * at least one slot. */
    {
        dictIterator *di;
        dictEntry *de;

        server.cluster->size = 0;
        di = dictGetSafeIterator(server.cluster->nodes);
        while((de = dictNext(di)) != NULL) {
            clusterNode *node = dictGetVal(de);

            if (nodeIsMaster(node) && node->numslots) {
                server.cluster->size++;
                if ((node->flags & (CLUSTER_NODE_FAIL|CLUSTER_NODE_PFAIL)) == 0)
                    reachable_masters++;
            }
        }
        dictReleaseIterator(di);
    }

    /* If we are in a minority partition, change the cluster state
     * to FAIL. */
    {
        int needed_quorum = (server.cluster->size / 2) + 1;

        if (reachable_masters < needed_quorum) {
            new_state = CLUSTER_FAIL;
            among_minority_time = mstime();
        }
    }

    /* Log a state change */
    if (new_state != server.cluster->state) {
        mstime_t rejoin_delay = server.cluster_node_timeout;

        /* If the instance is a master and was partitioned away with the
         * minority, don't let it accept queries for some time after the
         * partition heals, to make sure there is enough time to receive
         * a configuration update. */
        if (rejoin_delay > CLUSTER_MAX_REJOIN_DELAY)
            rejoin_delay = CLUSTER_MAX_REJOIN_DELAY;
        if (rejoin_delay < CLUSTER_MIN_REJOIN_DELAY)
            rejoin_delay = CLUSTER_MIN_REJOIN_DELAY;

        if (new_state == CLUSTER_OK &&
            nodeIsMaster(myself) &&
            mstime() - among_minority_time < rejoin_delay)
        {
            return;
        }

        /* Change the state and log the event. */
        serverLog(LL_WARNING,"Cluster state changed: %s",
            new_state == CLUSTER_OK ? "ok" : "fail");
        server.cluster->state = new_state;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0xc(%rbp)
leaq 0xf6492(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl 0x60080(%rax), %ecx
andl $-0x3, %ecx
movl %ecx, 0x60080(%rax)
cmpq $0x0, 0x10ae1c(%rip)    # 0x18cb80
jne 0x81d72
callq 0x2ff70
movq %rax, 0x10ae0e(%rip)    # 0x18cb80
movq 0x10ade7(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x81db1
leaq 0xf644d(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
cmpl $0x1, 0x10(%rax)
jne 0x81db1
callq 0x2ff70
subq 0x10addc(%rip), %rax    # 0x18cb80
cmpq $0x7d0, %rax            # imm = 0x7D0
jge 0x81db1
jmp 0x81fce
movl $0x0, -0x8(%rbp)
leaq 0xf6419(%rip), %rax     # 0x1781d8
cmpl $0x0, 0x9c0(%rax)
je 0x81e32
movl $0x0, -0x4(%rbp)
cmpl $0x4000, -0x4(%rbp)     # imm = 0x4000
jge 0x81e30
leaq 0xf63f9(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x4(%rbp), %rcx
cmpq $0x0, 0x40028(%rax,%rcx,8)
je 0x81e1a
leaq 0xf63dc(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movslq -0x4(%rbp), %rcx
movq 0x40028(%rax,%rcx,8), %rax
movl 0x30(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x81e23
movl $0x1, -0x8(%rbp)
jmp 0x81e30
jmp 0x81e25
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x81dcf
jmp 0x81e32
leaq 0xf639f(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl $0x0, 0x14(%rax)
leaq 0xf638a(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movq 0x18(%rax), %rdi
callq 0x2e470
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2e4a0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x81ed0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x81ece
movq -0x28(%rbp), %rax
cmpl $0x0, 0x840(%rax)
je 0x81ece
leaq 0xf6334(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
andl $0xc, %eax
cmpl $0x0, %eax
jne 0x81ecc
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x81ece
jmp 0x81e62
movq -0x18(%rbp), %rdi
callq 0x2e600
leaq 0xf62f8(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl 0x14(%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
movl -0xc(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x81f13
movl $0x1, -0x8(%rbp)
callq 0x2ff70
movq %rax, 0x10ac65(%rip)    # 0x18cb78
movl -0x8(%rbp), %eax
leaq 0xf62bb(%rip), %rcx     # 0x1781d8
movq 0x9b0(%rcx), %rcx
cmpl 0x10(%rcx), %eax
je 0x81fce
leaq 0xf62a4(%rip), %rax     # 0x1781d8
movq 0x9a0(%rax), %rax
movq %rax, -0x38(%rbp)
cmpq $0x1388, -0x38(%rbp)    # imm = 0x1388
jle 0x81f51
movq $0x1388, -0x38(%rbp)    # imm = 0x1388
cmpq $0x1f4, -0x38(%rbp)     # imm = 0x1F4
jge 0x81f63
movq $0x1f4, -0x38(%rbp)     # imm = 0x1F4
cmpl $0x0, -0x8(%rbp)
jne 0x81f8f
movq 0x10abf0(%rip), %rax    # 0x18cb60
movl 0x30(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x81f8f
callq 0x2ff70
subq 0x10abf1(%rip), %rax    # 0x18cb78
cmpq -0x38(%rbp), %rax
jge 0x81f8f
jmp 0x81fce
movl -0x8(%rbp), %ecx
leaq 0xbf80d(%rip), %rdx     # 0x1417a6
leaq 0xc9017(%rip), %rax     # 0x14afb7
cmpl $0x0, %ecx
cmoveq %rax, %rdx
movl $0x3, %edi
leaq 0xc06a2(%rip), %rsi     # 0x142655
movb $0x0, %al
callq 0x2fc60
movl -0x8(%rbp), %ecx
leaq 0xf6214(%rip), %rax     # 0x1781d8
movq 0x9b0(%rax), %rax
movl %ecx, 0x10(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)