// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x40(%rax)
je 0x9b14a
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x40(%rcx), %rax
movq %rax, -0x10(%rbp)
jmp 0x9b16f
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
cmpl $0x0, 0x4(%rax)
je 0x9b16d
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x38(%rcx), %rax
movq %rax, -0x10(%rbp)
jmp 0x9b16f
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x9b22d
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x20(%rcx), %rax
cmpq $0x3a98, %rax           # imm = 0x3A98
jle 0x9b22d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x40(%rax)
je 0x9b22d
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x40(%rcx), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x18(%rbp), %rax
cmpq %rcx, %rax
jle 0x9b22d
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x50(%rcx), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x58(%rax), %rax
movl $0x2, %ecx
cqto
idivq %rcx
movq %rax, %rcx
movq -0x20(%rbp), %rax
cmpq %rcx, %rax
jle 0x9b22d
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x10(%rax), %rsi
callq 0x95940
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x18(%rax)
je 0x9b287
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x28(%rcx), %rax
cmpq $0x3a98, %rax           # imm = 0x3A98
jle 0x9b287
callq 0x2ff70
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
subq 0x30(%rcx), %rax
cmpq $0x1770, %rax           # imm = 0x1770
jle 0x9b287
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rax), %rsi
callq 0x95940
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x58(%rcx), %rax
jg 0x9b2ce
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x9b317
movq -0x8(%rbp), %rax
cmpl $0x2, 0x68(%rax)
jne 0x9b317
callq 0x2ff70
movq -0x8(%rbp), %rcx
subq 0x70(%rcx), %rax
movq -0x8(%rbp), %rcx
movq 0x58(%rcx), %rcx
addq $0x4e20, %rcx           # imm = 0x4E20
cmpq %rcx, %rax
jle 0x9b317
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x9b315
movq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0xabe4a(%rip), %rsi     # 0x147136
leaq 0xaaf19(%rip), %rcx     # 0x14620c
movb $0x0, %al
callq 0x94990
callq 0x2ff70
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
jmp 0x9b353
movq -0x8(%rbp), %rax
movl (%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x9b351
movq -0x8(%rbp), %rdx
movl $0x3, %edi
leaq 0xabe08(%rip), %rsi     # 0x14713d
leaq 0xaaed0(%rip), %rcx     # 0x14620c
movb $0x0, %al
callq 0x94990
movq -0x8(%rbp), %rax
movl (%rax), %ecx
andl $0xffffeff7, %ecx       # imm = 0xFFFFEFF7
movl %ecx, (%rax)
jmp 0x9b353
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)