// File: /workspace/github_c_makefile_star2_O0/erikdubbelboer[P]discnt/src/counter.c
// Function: countersCron
void countersCron(void) {
    int history_last_index;
    dictIterator *it;
    dictEntry *de;
    mstime_t now = mstime();

    history_last_index = server.history_index;
    server.history_index = (server.history_index + 1) % server.history_size;

    it = dictGetIterator(server.counters);
    while ((de = dictNext(it)) != NULL) {
        long double rvalue, elapsed, diff, change;
        counter *cntr;
        int miss;

        cntr = dictGetVal(de);

        counterPubSub(cntr, now);

        if (cntr->myshard == NULL) {
            continue;
        }

        change = counterHistoryChange(cntr, now, history_last_index);

        if (cntr->myshard->predict_time > 0) {
            miss = 0;

            /* When our shard doesn't change anymore we should make sure it's predicted value
             * matches the actual value otherwise we never have a mis-prediction and
             * other instances will keep using our wrongly predicted value */
            if (change == 0 && (cntr->myshard->predict_change != 0 || cntr->myshard->predict_value != cntr->myshard->value)) {
                miss = 1;

                serverLog(LL_DEBUG,"Counter %s needs a final prediction (%Lf != %Lf)",
                      cntr->name, cntr->myshard->predict_value, cntr->myshard->value);
            } else {
                elapsed = (now - cntr->myshard->predict_time);
                rvalue = cntr->myshard->predict_value + (elapsed * cntr->myshard->predict_change);
                diff = fabsl(rvalue - cntr->myshard->value);

                if (diff > cntr->precision) {
                    miss = 1;

                    serverLog(LL_DEBUG,"Counter %s needs new prediction (%Lf <= %f)",
                        cntr->name, diff, cntr->precision);
                }
            }

            if (miss == 0) {
                /* It's still up to date, check if we need to resend our last prediction. */
                counterMaybeResend(cntr);

                /* Only count hits for when something actually changed but
                 * is still within our last prediction. */
                if (cntr->history[history_last_index] != cntr->myshard->value) {
                    server.stat_hits++;
                    cntr->hits++;
                }

                counterHistoryUpdate(cntr);

                continue;
            }
        }

        /* Make a new prediction. */

        server.stat_misses++;
        cntr->misses++;
        cntr->revision++;

        counterPredict(cntr, now, change);
        clusterSendShard(cntr);

        counterHistoryUpdate(cntr);

        cntr->updated = mstime();
    }
    dictReleaseIterator(it);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
callq 0x18e20
movq %rax, -0x20(%rbp)
leaq 0x8468d(%rip), %rax     # 0xbf0e8
movl 0x62c(%rax), %eax
movl %eax, -0x4(%rbp)
leaq 0x8467d(%rip), %rax     # 0xbf0e8
movl 0x62c(%rax), %eax
addl $0x1, %eax
leaq 0x8466d(%rip), %rcx     # 0xbf0e8
xorl %edx, %edx
divl 0x628(%rcx)
leaq 0x8465e(%rip), %rax     # 0xbf0e8
movl %edx, 0x62c(%rax)
leaq 0x84651(%rip), %rax     # 0xbf0e8
movq 0x618(%rax), %rdi
callq 0x17300
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x173a0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x3acfc
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x399b0
movq -0x68(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x3aae4
jmp 0x3aaa7
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x4(%rbp), %edx
callq 0x39470
fstpt -0x60(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x40(%rax)
jle 0x3ac90
movl $0x0, -0x6c(%rbp)
fldt -0x60(%rbp)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x3ab8d
jp 0x3ab8d
jmp 0x3ab22
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
fldt 0x60(%rax)
fldz
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x3ab55
jp 0x3ab55
jmp 0x3ab3b
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
fldt 0x50(%rax)
fldt 0x30(%rax)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x3ab55
jp 0x3ab55
jmp 0x3ab8d
movl $0x1, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rdx
movq 0x10(%rax), %rax
fldt 0x50(%rax)
fldt 0x30(%rax)
xorl %eax, %eax
movq %rsp, %rax
fstpt 0x10(%rax)
fstpt (%rax)
leaq 0x6e832(%rip), %rsi     # 0xa93b0
xorl %edi, %edi
movb %dil, %al
callq 0x18b10
jmp 0x3ac1e
movq -0x20(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq 0x40(%rcx), %rcx
subq %rcx, %rax
movq %rax, -0x78(%rbp)
fildll -0x78(%rbp)
fstpt -0x40(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
fldt 0x50(%rax)
fldt -0x40(%rbp)
fldt 0x60(%rax)
fmulp %st, %st(1)
faddp %st, %st(1)
fstpt -0x30(%rbp)
fldt -0x30(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
fldt 0x30(%rax)
fsubrp %st, %st(1)
fabs
fstpt -0x50(%rbp)
fldt -0x50(%rbp)
movq -0x68(%rbp), %rax
fldl 0x50(%rax)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jbe 0x3ac1c
jmp 0x3abeb
movl $0x1, -0x6c(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rdx
fldt -0x50(%rbp)
movq -0x68(%rbp), %rax
movsd 0x50(%rax), %xmm0
xorl %eax, %eax
movq %rsp, %rax
fstpt (%rax)
leaq 0x6e7ce(%rip), %rsi     # 0xa93e1
xorl %edi, %edi
movb $0x1, %al
callq 0x18b10
jmp 0x3ac1e
cmpl $0x0, -0x6c(%rbp)
jne 0x3ac8e
movq -0x68(%rbp), %rdi
callq 0x3a950
movq -0x68(%rbp), %rcx
movq 0x10(%rcx), %rax
movq 0x30(%rcx), %rcx
movslq -0x4(%rbp), %rdx
shlq $0x4, %rdx
fldt (%rcx,%rdx)
fldt 0x30(%rax)
fxch %st(1)
fucompi %st(1), %st
fstp %st(0)
jne 0x3ac53
jp 0x3ac53
jmp 0x3ac80
leaq 0x8448e(%rip), %rax     # 0xbf0e8
movq 0x3c0(%rax), %rcx
addq $0x1, %rcx
leaq 0x8447c(%rip), %rax     # 0xbf0e8
movq %rcx, 0x3c0(%rax)
movq -0x68(%rbp), %rax
movl 0x58(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x58(%rax)
movq -0x68(%rbp), %rdi
callq 0x39440
jmp 0x3aaa7
jmp 0x3ac90
leaq 0x84451(%rip), %rax     # 0xbf0e8
movq 0x3c8(%rax), %rcx
incq %rcx
movq %rcx, 0x3c8(%rax)
movq -0x68(%rbp), %rax
movl 0x5c(%rax), %ecx
incl %ecx
movl %ecx, 0x5c(%rax)
movq -0x68(%rbp), %rax
movl 0x38(%rax), %ecx
incl %ecx
movl %ecx, 0x38(%rax)
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rsi
fldt -0x60(%rbp)
movq %rsp, %rax
fstpt (%rax)
callq 0x394c0
movq -0x68(%rbp), %rdi
callq 0x35ca0
movq -0x68(%rbp), %rdi
callq 0x39440
callq 0x18e20
movq %rax, %rcx
movq -0x68(%rbp), %rax
movq %rcx, 0x48(%rax)
jmp 0x3aaa7
movq -0x10(%rbp), %rdi
callq 0x17510
addq $0xa0, %rsp
popq %rbp
retq
nop