// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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 0x330c8
movq %rax, %r14
movq 0x118(%rbx), %rax
testq %rax, %rax
je 0x7fa02
testb $0x8, (%rax)
jne 0x7fa02
subq 0xf8(%rbx), %r14
movq 0x88(%rbx), %rdi
callq 0x320bb
movq %rax, %r15
movq %rax, %rdi
callq 0x32116
xorl %ebp, %ebp
testq %rax, %rax
je 0x7f8f6
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 0x32116
testq %rax, %rax
jne 0x7f8da
movq %r15, %rdi
callq 0x321d3
movq 0x108(%rbx), %r15
cmpq %r15, %r14
jle 0x7f929
leaq 0x50c68(%rip), %rsi     # 0xd0579
leaq 0x4fae8(%rip), %rcx     # 0xcf400
xorl %ebp, %ebp
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7a50c
testl %ebp, %ebp
jne 0x7f960
leaq 0x50c5f(%rip), %rsi     # 0xd0593
leaq 0x4fac5(%rip), %rcx     # 0xcf400
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7a50c
movl $0x6, 0xf0(%rbx)
callq 0x330c8
movq %rax, 0xf8(%rbx)
cmpq %r15, %r14
jle 0x7fa02
movq 0x88(%rbx), %rdi
callq 0x320bb
movq %rax, %r14
movq %rax, %rdi
callq 0x32116
testq %rax, %rax
je 0x7f9ec
leaq 0x50c15(%rip), %r15     # 0xd05a1
leaq 0x4fa6d(%rip), %r12     # 0xcf400
movq 0x8(%rax), %r13
testb $0x5, 0x1(%r13)
jne 0x7f9df
movq 0x28(%r13), %rax
cmpl $0x0, 0x4(%rax)
jne 0x7f9df
movq 0x118(%rbx), %rax
movq 0x20(%rax), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r13, %rdi
callq 0x7d6ce
testl %eax, %eax
jne 0x7f9df
movl $0x2, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x7a50c
orb $0x1, 0x1(%r13)
movq %r14, %rdi
callq 0x32116
testq %rax, %rax
jne 0x7f993
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x321d3
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq