// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelFailoverDetectEnd
void sentinelFailoverDetectEnd(sentinelRedisInstance *master) {
    int not_reconfigured = 0, timeout = 0;
    dictIterator *di;
    dictEntry *de;
    mstime_t elapsed = mstime() - master->failover_state_change_time;

    /* We can't consider failover finished if the promoted slave is
     * not reachable. */
    if (master->promoted_slave == NULL ||
        master->promoted_slave->flags & SRI_S_DOWN) return;

    /* The failover terminates once all the reachable slaves are properly
     * configured. */
    di = dictGetIterator(master->slaves);
    while((de = dictNext(di)) != NULL) {
        sentinelRedisInstance *slave = dictGetVal(de);

        if (slave->flags & (SRI_PROMOTED|SRI_RECONF_DONE)) continue;
        if (slave->flags & SRI_S_DOWN) continue;
        not_reconfigured++;
    }
    dictReleaseIterator(di);

    /* Force end of failover on timeout. */
    if (elapsed > master->failover_timeout) {
        not_reconfigured = 0;
        timeout = 1;
        sentinelEvent(LL_WARNING,"+failover-end-for-timeout",master,"%@");
    }

    if (not_reconfigured == 0) {
        sentinelEvent(LL_WARNING,"+failover-end",master,"%@");
        master->failover_state = SENTINEL_FAILOVER_STATE_UPDATE_CONFIG;
        master->failover_state_change_time = mstime();
    }

    /* If I'm the leader it is a good idea to send a best effort SLAVEOF
     * command to all the slaves still not reconfigured to replicate with
     * the new master. */
    if (timeout) {
        dictIterator *di;
        dictEntry *de;

        di = dictGetIterator(master->slaves);
        while((de = dictNext(di)) != NULL) {
            sentinelRedisInstance *slave = dictGetVal(de);
            int retval;

            if (slave->flags & (SRI_RECONF_DONE|SRI_RECONF_SENT)) continue;
            if (slave->link->disconnected) continue;

            retval = sentinelSendSlaveOf(slave,
                    master->promoted_slave->addr->ip,
                    master->promoted_slave->addr->port);
            if (retval == C_OK) {
                sentinelEvent(LL_NOTICE,"+slave-reconf-sent-be",slave,"%@");
                slave->flags |= SRI_RECONF_SENT;
            }
        }
        dictReleaseIterator(di);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0x2ffce
movq %rax, %r14
movq 0x118(%rbx), %rax
testq %rax, %rax
je 0x7bf96
testb $0x8, (%rax)
jne 0x7bf96
subq 0xf8(%rbx), %r14
movq 0x88(%rbx), %rdi
callq 0x2efbb
movq %rax, %r15
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
je 0x7be66
xorl %ebp, %ebp
movl $0x488, %r12d           # imm = 0x488
movq 0x8(%rax), %rax
movl (%rax), %eax
andl %r12d, %eax
cmpl $0x1, %eax
adcl $0x0, %ebp
movq %r15, %rdi
callq 0x2f015
testq %rax, %rax
jne 0x7be2c
movq %r15, %rdi
callq 0x2f0dd
cmpq 0x108(%rbx), %r14
jg 0x7be7b
testl %ebp, %ebp
jne 0x7bf96
jmp 0x7bf63
movq %r15, %rdi
callq 0x2f0dd
cmpq 0x108(%rbx), %r14
jle 0x7bf63
leaq 0x517f7(%rip), %rsi     # 0xcd679
leaq 0x50677(%rip), %r14     # 0xcc500
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x76a24
leaq 0x517f1(%rip), %rsi     # 0xcd693
movl $0x3, %edi
movq %rbx, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x76a24
movl $0x6, 0xf0(%rbx)
callq 0x2ffce
movq %rax, 0xf8(%rbx)
movq 0x88(%rbx), %rdi
callq 0x2efbb
movq %rax, %r14
movq %rax, %rdi
callq 0x2f015
testq %rax, %rax
je 0x7bf4d
leaq 0x517b4(%rip), %r15     # 0xcd6a1
leaq 0x5060c(%rip), %r12     # 0xcc500
movq 0x8(%rax), %r13
testb $0x5, 0x1(%r13)
jne 0x7bf40
movq 0x28(%r13), %rax
cmpl $0x0, 0x4(%rax)
jne 0x7bf40
movq 0x118(%rbx), %rax
movq 0x20(%rax), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r13, %rdi
callq 0x79c10
testl %eax, %eax
jne 0x7bf40
movl $0x2, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x76a24
orb $0x1, 0x1(%r13)
movq %r14, %rdi
callq 0x2f015
testq %rax, %rax
jne 0x7bef4
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2f0dd
leaq 0x51729(%rip), %rsi     # 0xcd693
leaq 0x5058f(%rip), %rcx     # 0xcc500
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x76a24
movl $0x6, 0xf0(%rbx)
callq 0x2ffce
movq %rax, 0xf8(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq