// File: /workspace/github_c_makefile_star2_O3/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
movl $0x40, %r15d
cmpq $0x0, 0x40(%rdi)
jne 0x7b30e
movl $0x38, %r15d
cmpl $0x0, 0x4(%rdi)
je 0x7b45b
callq 0x2ffce
movq %rax, %r14
movq 0x28(%rbx), %rdi
subq (%rdi,%r15), %r14
cmpq $0x0, 0x10(%rdi)
je 0x7b394
callq 0x2ffce
movq 0x28(%rbx), %rdi
subq 0x20(%rdi), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x7b394
cmpq $0x0, 0x40(%rdi)
je 0x7b394
callq 0x2ffce
movq 0x28(%rbx), %rdi
movq 0x58(%rbx), %rcx
subq 0x40(%rdi), %rax
movq %rcx, %rdx
shrq $0x3f, %rdx
addq %rcx, %rdx
sarq %rdx
cmpq %rdx, %rax
jle 0x7b394
callq 0x2ffce
movq 0x28(%rbx), %rdi
movq 0x58(%rbx), %rcx
subq 0x50(%rdi), %rax
movq %rcx, %rdx
shrq $0x3f, %rdx
addq %rcx, %rdx
sarq %rdx
cmpq %rdx, %rax
jle 0x7b394
movq 0x10(%rdi), %rsi
callq 0x77559
movq 0x28(%rbx), %rdi
cmpq $0x0, 0x18(%rdi)
je 0x7b3ce
callq 0x2ffce
movq 0x28(%rbx), %rcx
subq 0x28(%rcx), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x7b3ce
callq 0x2ffce
movq 0x28(%rbx), %rdi
subq 0x30(%rdi), %rax
cmpq $0x1771, %rax           # imm = 0x1771
jl 0x7b3ce
movq 0x18(%rdi), %rsi
callq 0x77559
cmpq 0x58(%rbx), %r14
jle 0x7b406
testb $0x8, (%rbx)
jne 0x7b455
leaq 0x5204a(%rip), %rsi     # 0xcd42a
leaq 0x51119(%rip), %rcx     # 0xcc500
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x76a24
callq 0x2ffce
movq %rax, 0x48(%rbx)
movl (%rbx), %eax
orl $0x8, %eax
jmp 0x7b453
movl (%rbx), %eax
testb $0x1, %al
je 0x7b42b
cmpl $0x2, 0x68(%rbx)
jne 0x7b42b
callq 0x2ffce
subq 0x70(%rbx), %rax
movl $0x4e20, %ecx           # imm = 0x4E20
addq 0x58(%rbx), %rcx
cmpq %rcx, %rax
jg 0x7b3d4
movl (%rbx), %eax
testb $0x8, %al
je 0x7b455
leaq 0x51ffb(%rip), %rsi     # 0xcd431
leaq 0x510c3(%rip), %rcx     # 0xcc500
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x76a24
movl $0xffffeff7, %eax       # imm = 0xFFFFEFF7
andl (%rbx), %eax
movl %eax, (%rbx)
popq %rbx
popq %r14
popq %r15
retq
xorl %r14d, %r14d
jmp 0x7b31e