// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/sentinel.c
// Function: sentinelCheckSubjectivelyDown
void sentinelCheckSubjectivelyDown(sentinelRedisInstance *ri) {
    mstime_t elapsed = 0;

    if (ri->link->act_ping_time)
        elapsed = mstime() - ri->link->act_ping_time;
    else if (ri->link->disconnected)
        elapsed = mstime() - ri->link->last_avail_time;

    /* Check if we are in need for a reconnection of one of the
     * links, because we are detecting low activity.
     *
     * 1) Check if the command link seems connected, was connected not less
     *    than SENTINEL_MIN_LINK_RECONNECT_PERIOD, but still we have a
     *    pending ping for more than half the timeout. */
    if (ri->link->cc &&
        (mstime() - ri->link->cc_conn_time) >
        SENTINEL_MIN_LINK_RECONNECT_PERIOD &&
        ri->link->act_ping_time != 0 && /* Ther is a pending ping... */
        /* The pending ping is delayed, and we did not received
         * error replies as well. */
        (mstime() - ri->link->act_ping_time) > (ri->down_after_period/2) &&
        (mstime() - ri->link->last_pong_time) > (ri->down_after_period/2))
    {
        instanceLinkCloseConnection(ri->link,ri->link->cc);
    }

    /* 2) Check if the pubsub link seems connected, was connected not less
     *    than SENTINEL_MIN_LINK_RECONNECT_PERIOD, but still we have no
     *    activity in the Pub/Sub channel for more than
     *    SENTINEL_PUBLISH_PERIOD * 3.
     */
    if (ri->link->pc &&
        (mstime() - ri->link->pc_conn_time) >
         SENTINEL_MIN_LINK_RECONNECT_PERIOD &&
        (mstime() - ri->link->pc_last_activity) > (SENTINEL_PUBLISH_PERIOD*3))
    {
        instanceLinkCloseConnection(ri->link,ri->link->pc);
    }

    /* Update the SDOWN flag. We believe the instance is SDOWN if:
     *
     * 1) It is not replying.
     * 2) We believe it is a master, it reports to be a slave for enough time
     *    to meet the down_after_period, plus enough time to get two times
     *    INFO report from the instance. */
    if (elapsed > ri->down_after_period ||
        (ri->flags & SRI_MASTER &&
         ri->role_reported == SRI_SLAVE &&
         mstime() - ri->role_reported_time >
          (ri->down_after_period+SENTINEL_INFO_PERIOD*2)))
    {
        /* Is subjectively down */
        if ((ri->flags & SRI_S_DOWN) == 0) {
            sentinelEvent(LL_WARNING,"+sdown",ri,"%@");
            ri->s_down_since_time = mstime();
            ri->flags |= SRI_S_DOWN;
        }
    } else {
        /* Is subjectively up */
        if (ri->flags & SRI_S_DOWN) {
            sentinelEvent(LL_WARNING,"-sdown",ri,"%@");
            ri->flags &= ~(SRI_S_DOWN|SRI_SCRIPT_KILL_SENT);
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
movq 0x28(%rdi), %rdi
cmpq $0x0, 0x40(%rdi)
je 0x6e997
pushq $0x40
jmp 0x6e9a3
cmpl $0x0, 0x4(%rdi)
je 0x6eae8
pushq $0x38
popq %r15
callq 0x2b8ae
movq %rax, %r14
movq 0x28(%rbx), %rdi
subq (%rdi,%r15), %r14
cmpq $0x0, 0x10(%rdi)
je 0x6ea25
callq 0x2b8ae
movq 0x28(%rbx), %rdi
subq 0x20(%rdi), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x6ea25
cmpq $0x0, 0x40(%rdi)
je 0x6ea25
callq 0x2b8ae
movq %rax, %rcx
movq 0x28(%rbx), %rdi
movq 0x58(%rbx), %rax
subq 0x40(%rdi), %rcx
pushq $0x2
popq %r15
cqto
idivq %r15
cmpq %rax, %rcx
jle 0x6ea25
callq 0x2b8ae
movq %rax, %rcx
movq 0x28(%rbx), %rdi
movq 0x58(%rbx), %rax
subq 0x50(%rdi), %rcx
cqto
idivq %r15
cmpq %rax, %rcx
jle 0x6ea25
movq 0x10(%rdi), %rsi
callq 0x6b1e4
movq 0x28(%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x6ea5f
callq 0x2b8ae
movq 0x28(%rbx), %rcx
subq 0x28(%rcx), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x6ea5f
callq 0x2b8ae
movq 0x28(%rbx), %rdi
subq 0x30(%rdi), %rax
cmpq $0x1771, %rax           # imm = 0x1771
jl 0x6ea5f
movq 0x18(%rdi), %rsi
callq 0x6b1e4
cmpq 0x58(%rbx), %r14
jle 0x6ea95
testb $0x8, (%rbx)
jne 0x6eae2
leaq 0x4f605(%rip), %rsi     # 0xbe076
leaq 0x4e6d4(%rip), %rcx     # 0xbd14c
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6a7bb
callq 0x2b8ae
movq %rax, 0x48(%rbx)
movl (%rbx), %eax
orl $0x8, %eax
jmp 0x6eae0
movl (%rbx), %eax
testb $0x1, %al
je 0x6eaba
cmpl $0x2, 0x68(%rbx)
jne 0x6eaba
callq 0x2b8ae
subq 0x70(%rbx), %rax
movl $0x4e20, %ecx           # imm = 0x4E20
addq 0x58(%rbx), %rcx
cmpq %rcx, %rax
jg 0x6ea65
movl (%rbx), %eax
testb $0x8, %al
je 0x6eae2
leaq 0x4f5b8(%rip), %rsi     # 0xbe07d
leaq 0x4e680(%rip), %rcx     # 0xbd14c
pushq $0x3
popq %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x6a7bb
movl $0xffffeff7, %eax       # imm = 0xFFFFEFF7
andl (%rbx), %eax
movl %eax, (%rbx)
popq %rbx
popq %r14
popq %r15
retq
xorl %r14d, %r14d
jmp 0x6e9b5