// File: /workspace/github_c_makefile_star2_O3/gplessis[P]dotdeb-redis/src/latency.c
// Function: latencyCommandGenSparkeline
sds latencyCommandGenSparkeline(char *event, struct latencyTimeSeries *ts) {
    int j;
    struct sequence *seq = createSparklineSequence();
    sds graph = sdsempty();
    uint32_t min = 0, max = 0;

    for (j = 0; j < LATENCY_TS_LEN; j++) {
        int i = (ts->idx + j) % LATENCY_TS_LEN;
        int elapsed;
        char buf[64];

        if (ts->samples[i].time == 0) continue;
        /* Update min and max. */
        if (seq->length == 0) {
            min = max = ts->samples[i].latency;
        } else {
            if (ts->samples[i].latency > max) max = ts->samples[i].latency;
            if (ts->samples[i].latency < min) min = ts->samples[i].latency;
        }
        /* Use as label the number of seconds / minutes / hours / days
         * ago the event happened. */
        elapsed = time(NULL) - ts->samples[i].time;
        if (elapsed < 60)
            snprintf(buf,sizeof(buf),"%ds",elapsed);
        else if (elapsed < 3600)
            snprintf(buf,sizeof(buf),"%dm",elapsed/60);
        else if (elapsed < 3600*24)
            snprintf(buf,sizeof(buf),"%dh",elapsed/3600);
        else
            snprintf(buf,sizeof(buf),"%dd",elapsed/(3600*24));
        sparklineSequenceAddSample(seq,ts->samples[i].latency,buf);
    }

    graph = sdscatprintf(graph,
        "%s - high %lu ms, low %lu ms (all time high %lu ms)\n", event,
        (unsigned long) max, (unsigned long) min, (unsigned long) ts->max);
    for (j = 0; j < LATENCY_GRAPH_COLS; j++)
        graph = sdscatlen(graph,"-",1);
    graph = sdscatlen(graph,"\n",1);
    graph = sparklineRender(graph,seq,LATENCY_GRAPH_COLS,4,SPARKLINE_FILL);
    freeSparklineSequence(seq);
    return graph;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
callq 0x7fb4c
movq %rax, 0x8(%rsp)
callq 0x3628d
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movl (%r15), %eax
addl %r14d, %eax
cltq
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rdx
shrq $0x3f, %rdx
sarq $0x26, %rcx
addl %edx, %ecx
shll $0x5, %ecx
leal (%rcx,%rcx,4), %ecx
subl %ecx, %eax
movslq %eax, %rbp
cmpl $0x0, 0x8(%r15,%rbp,8)
je 0x7f875
movq 0x8(%rsp), %rax
cmpl $0x0, (%rax)
movl 0xc(%r15,%rbp,8), %eax
je 0x7f7b9
cmpl %r13d, %eax
cmoval %eax, %r13d
cmpl %r12d, %eax
cmovbl %eax, %r12d
jmp 0x7f7bf
movl %eax, %r12d
movl %eax, %r13d
xorl %edi, %edi
callq 0x26cd0
subl 0x8(%r15,%rbp,8), %eax
cmpl $0x3b, %eax
jg 0x7f7e8
movl $0x40, %esi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x4fa72(%rip), %rdx     # 0xcf256
movl %eax, %ecx
jmp 0x7f854
cmpl $0xe0f, %eax            # imm = 0xE0F
leaq 0x20(%rsp), %rdi
ja 0x7f811
movzwl %ax, %eax
imull $0x8889, %eax, %ecx     # imm = 0x8889
shrl $0x15, %ecx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x4fa4b(%rip), %rdx     # 0xcf25a
jmp 0x7f854
movl %eax, %ecx
cmpl $0x1517f, %eax          # imm = 0x1517F
ja 0x7f838
movl $0x91a2b3c5, %eax       # imm = 0x91A2B3C5
imulq %rax, %rcx
shrq $0x2b, %rcx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x4fa28(%rip), %rdx     # 0xcf25e
jmp 0x7f854
movl $0xc22e4507, %eax       # imm = 0xC22E4507
imulq %rax, %rcx
shrq $0x30, %rcx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x4fa0e(%rip), %rdx     # 0xcf262
xorl %eax, %eax
callq 0x26120
movl 0xc(%r15,%rbp,8), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x7fb67
incl %r14d
cmpl $0xa0, %r14d
jne 0x7f767
movl %r13d, %ecx
movl %r12d, %r8d
movl 0x4(%r15), %r9d
leaq 0x4f9d0(%rip), %rsi     # 0xcf266
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x36f2d
movl $0x50, %ebp
leaq 0x51c73(%rip), %r14     # 0xd1526
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x36ad1
decl %ebp
jne 0x7f8b3
leaq 0x3f5fb(%rip), %rsi     # 0xbeec9
movl $0x1, %edx
movq %rax, %rdi
callq 0x36ad1
movq %rax, %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movl $0x50, %edx
movl $0x4, %ecx
movl $0x1, %r8d
callq 0x7feb9
movq %rax, %r14
movq %rbx, %rdi
callq 0x7fbff
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq