// File: /workspace/github_c_makefile_star2_O0/gplessis[P]dotdeb-redis/src/latency.c
// Function: analyzeLatencyForEvent
void analyzeLatencyForEvent(char *event, struct latencyStats *ls) {
    struct latencyTimeSeries *ts = dictFetchValue(server.latency_events,event);
    int j;
    uint64_t sum;

    ls->all_time_high = ts ? ts->max : 0;
    ls->avg = 0;
    ls->min = 0;
    ls->max = 0;
    ls->mad = 0;
    ls->samples = 0;
    ls->period = 0;
    if (!ts) return;

    /* First pass, populate everything but the MAD. */
    sum = 0;
    for (j = 0; j < LATENCY_TS_LEN; j++) {
        if (ts->samples[j].time == 0) continue;
        ls->samples++;
        if (ls->samples == 1) {
            ls->min = ls->max = ts->samples[j].latency;
        } else {
            if (ls->min > ts->samples[j].latency)
                ls->min = ts->samples[j].latency;
            if (ls->max < ts->samples[j].latency)
                ls->max = ts->samples[j].latency;
        }
        sum += ts->samples[j].latency;

        /* Track the oldest event time in ls->period. */
        if (ls->period == 0 || ts->samples[j].time < ls->period)
            ls->period = ts->samples[j].time;
    }

    /* So far avg is actually the sum of the latencies, and period is
     * the oldest event time. We need to make the first an average and
     * the second a range of seconds. */
    if (ls->samples) {
        ls->avg = sum / ls->samples;
        ls->period = time(NULL) - ls->period;
        if (ls->period == 0) ls->period = 1;
    }

    /* Second pass, compute MAD. */
    sum = 0;
    for (j = 0; j < LATENCY_TS_LEN; j++) {
        int64_t delta;

        if (ts->samples[j].time == 0) continue;
        delta = (int64_t)ls->avg - ts->samples[j].latency;
        if (delta < 0) delta = -delta;
        sum += delta;
    }
    if (ls->samples) ls->mad = sum / ls->samples;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0xd6da1(%rip), %rax     # 0x1781d8
movq 0xa20(%rax), %rdi
movq -0x8(%rbp), %rsi
callq 0x2e280
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xa145e
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
jmp 0xa1465
xorl %eax, %eax
movl %eax, -0x34(%rbp)
jmp 0xa1465
movl -0x34(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x14(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x18(%rax)
cmpq $0x0, -0x18(%rbp)
jne 0xa14bd
jmp 0xa16b3
movq $0x0, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xa0, -0x1c(%rbp)
jge 0xa15cd
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpl $0x0, 0x8(%rax,%rcx,8)
jne 0xa14ed
jmp 0xa15bf
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jne 0xa1520
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0xa1572
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
cmpl 0xc(%rcx,%rdx,8), %eax
jbe 0xa1548
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
cmpl 0xc(%rcx,%rdx,8), %eax
jae 0xa1570
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0xa1572
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xa15a8
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movslq 0x8(%rax,%rcx,8), %rax
movq -0x10(%rbp), %rcx
cmpq 0x18(%rcx), %rax
jge 0xa15bd
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movslq 0x8(%rax,%rcx,8), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0xa15bf
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa14cc
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0xa1625
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4(%rax)
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
movq %rax, %rcx
movq -0x10(%rbp), %rax
subq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xa1623
movq -0x10(%rbp), %rax
movq $0x1, 0x18(%rax)
jmp 0xa1625
movq $0x0, -0x28(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0xa0, -0x1c(%rbp)
jge 0xa1690
movq -0x18(%rbp), %rax
movslq -0x1c(%rbp), %rcx
cmpl $0x0, 0x8(%rax,%rcx,8)
jne 0xa164e
jmp 0xa1685
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movl 0xc(%rcx,%rdx,8), %ecx
subq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jge 0xa1679
xorl %eax, %eax
subq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa1634
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0xa16b3
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
xorl %edx, %edx
divq %rcx
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)