// File: /workspace/github_c_makefile_star2_O1/zhou-yuxin[P]redis-aof-no-cow/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), %rax
movl $0x40, %r15d
cmpq $0x0, 0x40(%rax)
jne 0x7edd8
movl $0x38, %r15d
cmpl $0x0, 0x4(%rax)
je 0x7ef27
callq 0x330c8
movq %rax, %r14
movq 0x28(%rbx), %rax
subq (%rax,%r15), %r14
movq 0x28(%rbx), %rax
cmpq $0x0, 0x10(%rax)
je 0x7ee5e
callq 0x330c8
movq 0x28(%rbx), %rcx
subq 0x20(%rcx), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x7ee5e
cmpq $0x0, 0x40(%rcx)
je 0x7ee5e
callq 0x330c8
movq 0x28(%rbx), %rcx
movq 0x58(%rbx), %rdx
subq 0x40(%rcx), %rax
movq %rdx, %rcx
shrq $0x3f, %rcx
addq %rdx, %rcx
sarq %rcx
cmpq %rcx, %rax
jle 0x7ee5e
callq 0x330c8
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 0x7ee5e
movq 0x10(%rdi), %rsi
callq 0x7b040
movq 0x28(%rbx), %rax
cmpq $0x0, 0x18(%rax)
je 0x7ee9c
callq 0x330c8
movq 0x28(%rbx), %rcx
subq 0x28(%rcx), %rax
cmpq $0x3a99, %rax           # imm = 0x3A99
jl 0x7ee9c
callq 0x330c8
movq 0x28(%rbx), %rdi
subq 0x30(%rdi), %rax
cmpq $0x1771, %rax           # imm = 0x1771
jl 0x7ee9c
movq 0x18(%rdi), %rsi
callq 0x7b040
cmpq 0x58(%rbx), %r14
jle 0x7eed4
testb $0x8, (%rbx)
jne 0x7ef21
leaq 0x5147c(%rip), %rsi     # 0xd032a
leaq 0x5054b(%rip), %rcx     # 0xcf400
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7a50c
callq 0x330c8
movq %rax, 0x48(%rbx)
movl (%rbx), %eax
orl $0x8, %eax
jmp 0x7ef1f
testb $0x1, (%rbx)
je 0x7eef6
cmpl $0x2, 0x68(%rbx)
jne 0x7eef6
callq 0x330c8
subq 0x70(%rbx), %rax
movl $0x4e20, %ecx           # imm = 0x4E20
addq 0x58(%rbx), %rcx
cmpq %rcx, %rax
jg 0x7eea2
testb $0x8, (%rbx)
je 0x7ef21
leaq 0x5142f(%rip), %rsi     # 0xd0331
leaq 0x504f7(%rip), %rcx     # 0xcf400
movl $0x3, %edi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x7a50c
movl $0xffffeff7, %eax       # imm = 0xFFFFEFF7
andl (%rbx), %eax
movl %eax, (%rbx)
popq %rbx
popq %r14
popq %r15
retq
xorl %r14d, %r14d
jmp 0x7ede8