// File: /workspace/github_c_makefile_star2_O2/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 0x2b8ae
movq %rax, %r14
movq 0x118(%rbx), %rax
testq %rax, %rax
je 0x6f4f5
testb $0x8, (%rax)
jne 0x6f4f5
subq 0xf8(%rbx), %r14
movq 0x88(%rbx), %rdi
callq 0x2a99f
movq %rax, %r15
xorl %ebp, %ebp
movq %r15, %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x6f40e
movq 0x8(%rax), %rax
movzwl (%rax), %eax
andl $0x488, %eax            # imm = 0x488
cmpw $0x1, %ax
adcl $0x0, %ebp
jmp 0x6f3ec
movq %r15, %rdi
callq 0x2aa94
movq 0x108(%rbx), %r15
cmpq %r15, %r14
jle 0x6f43f
leaq 0x4ee9c(%rip), %rsi     # 0xbe2c5
leaq 0x4dd1c(%rip), %rcx     # 0xbd14c
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6a7bb
jmp 0x6f447
testl %ebp, %ebp
jne 0x6f4f5
leaq 0x4ee91(%rip), %rsi     # 0xbe2df
leaq 0x4dcf7(%rip), %rcx     # 0xbd14c
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6a7bb
movl $0x6, 0xf0(%rbx)
callq 0x2b8ae
movq %rax, 0xf8(%rbx)
cmpq %r15, %r14
jle 0x6f4f5
movq 0x88(%rbx), %rdi
callq 0x2a99f
movq %rax, %r14
leaq 0x4ee5a(%rip), %r15     # 0xbe2ed
leaq 0x4dcb2(%rip), %r12     # 0xbd14c
pushq $0x2
popq %rbp
movq %r14, %rdi
callq 0x2a9d3
testq %rax, %rax
je 0x6f504
movq 0x8(%rax), %r13
testb $0x5, 0x1(%r13)
jne 0x6f49d
movq 0x28(%r13), %rax
cmpl $0x0, 0x4(%rax)
jne 0x6f49d
movq 0x118(%rbx), %rax
movq 0x20(%rax), %rax
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r13, %rdi
callq 0x6d3ed
testl %eax, %eax
jne 0x6f49d
movl %ebp, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
xorl %eax, %eax
callq 0x6a7bb
orb $0x1, 0x1(%r13)
jmp 0x6f49d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2aa94