// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelSelectSlave
sentinelRedisInstance *sentinelSelectSlave(sentinelRedisInstance *master) {
    sentinelRedisInstance **instance =
        zmalloc(sizeof(instance[0])*dictSize(master->slaves));
    sentinelRedisInstance *selected = NULL;
    int instances = 0;
    dictIterator *di;
    dictEntry *de;
    mstime_t max_master_down_time = 0;

    if (master->flags & SRI_S_DOWN)
        max_master_down_time += mstime() - master->s_down_since_time;
    max_master_down_time += master->down_after_period * 10;

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

        if (slave->flags & (SRI_S_DOWN|SRI_O_DOWN)) continue;
        if (slave->link->disconnected) continue;
        if (mstime() - slave->link->last_avail_time > SENTINEL_PING_PERIOD*5) continue;
        if (slave->slave_priority == 0) continue;

        /* If the master is in SDOWN state we get INFO for slaves every second.
         * Otherwise we get it with the usual period so we need to account for
         * a larger delay. */
        if (master->flags & SRI_S_DOWN)
            info_validity_time = SENTINEL_PING_PERIOD*5;
        else
            info_validity_time = SENTINEL_INFO_PERIOD*3;
        if (mstime() - slave->info_refresh > info_validity_time) continue;
        if (slave->master_link_down_time > max_master_down_time) continue;
        instance[instances++] = slave;
    }
    dictReleaseIterator(di);
    if (instances) {
        qsort(instance,instances,sizeof(sentinelRedisInstance*),
            compareSlavesForPromotion);
        selected = instance[0];
    }
    zfree(instance);
    return selected;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
addq 0x48(%rax), %rdi
shlq $0x3, %rdi
callq 0x3acd0
movq %rax, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x9aa61
callq 0x2ff70
movq -0x8(%rbp), %rcx
subq 0x48(%rcx), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
imulq $0xa, 0x58(%rax), %rax
addq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rdi
callq 0x2e400
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2e4a0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x9ab60
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %eax
andl $0x18, %eax
cmpl $0x0, %eax
je 0x9aab9
jmp 0x9aa86
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rax
cmpl $0x0, 0x4(%rax)
je 0x9aac9
jmp 0x9aa86
callq 0x2ff70
movq -0x40(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x38(%rcx), %rax
cmpq $0x1388, %rax           # imm = 0x1388
jle 0x9aae4
jmp 0x9aa86
movq -0x40(%rbp), %rax
cmpl $0x0, 0xa8(%rax)
jne 0x9aaf3
jmp 0x9aa86
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x9ab0b
movq $0x1388, -0x48(%rbp)    # imm = 0x1388
jmp 0x9ab13
movq $0x7530, -0x48(%rbp)    # imm = 0x7530
callq 0x2ff70
movq -0x40(%rbp), %rcx
subq 0x60(%rcx), %rax
cmpq -0x48(%rbp), %rax
jle 0x9ab2b
jmp 0x9aa86
movq -0x40(%rbp), %rax
movq 0xa0(%rax), %rax
cmpq -0x38(%rbp), %rax
jle 0x9ab41
jmp 0x9aa86
movq -0x40(%rbp), %rdx
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x1c(%rbp)
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x9aa86
movq -0x28(%rbp), %rdi
callq 0x2e600
cmpl $0x0, -0x1c(%rbp)
je 0x9ab93
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movl $0x8, %edx
leaq 0x107d(%rip), %rcx      # 0x9bc00
callq 0x26890
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3afa0
movq -0x18(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)