// File: /workspace/github_c_makefile_star2_O1/erikdubbelboer[P]discnt/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 *label;
        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));
        label = zstrdup(buf);
        sparklineSequenceAddSample(seq,ts->samples[i].latency,label);
    }

    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, 0x10(%rsp)
callq 0x30da8
movq %rax, %rbx
callq 0x1de3f
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %rbx, 0x18(%rsp)
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 0x30aed
cmpl $0x0, (%rbx)
movl 0xc(%r15,%rbp,8), %eax
je 0x30a25
cmpl %r13d, %eax
cmoval %eax, %r13d
cmpl %r12d, %eax
cmovbl %eax, %r12d
jmp 0x30a2b
movl %eax, %r13d
movl %eax, %r12d
xorl %edi, %edi
callq 0x12550
subl 0x8(%r15,%rbp,8), %eax
cmpl $0x3b, %eax
jg 0x30a54
movl $0x40, %esi
leaq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0x27dbe(%rip), %rdx     # 0x5880e
movl %eax, %ecx
jmp 0x30ac1
movl %eax, %ecx
cmpl $0xe0f, %eax            # imm = 0xE0F
leaq 0x20(%rsp), %rdi
jg 0x30a80
movl $0x88888889, %eax       # imm = 0x88888889
imulq %rax, %rcx
shrq $0x25, %rcx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x27d94(%rip), %rdx     # 0x58812
jmp 0x30ac1
cmpl $0x1517f, %eax          # imm = 0x1517F
jg 0x30aa5
movl $0x91a2b3c5, %eax       # imm = 0x91A2B3C5
imulq %rax, %rcx
shrq $0x2b, %rcx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x27d73(%rip), %rdx     # 0x58816
jmp 0x30ac1
movl $0xc22e4507, %eax       # imm = 0xC22E4507
imulq %rax, %rcx
shrq $0x30, %rcx
movl $0x40, %esi
movq %rdi, %rbx
leaq 0x27d59(%rip), %rdx     # 0x5881a
xorl %eax, %eax
callq 0x122d0
movq %rbx, %rdi
callq 0x20041
movl 0xc(%r15,%rbp,8), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
movq %rax, %rsi
callq 0x30dc3
incl %r14d
cmpl $0xa0, %r14d
jne 0x309d8
movl %r13d, %ecx
movl %r12d, %r8d
movl 0x4(%r15), %r9d
leaq 0x27d10(%rip), %rsi     # 0x5881e
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x1eace
movl $0x50, %ebp
leaq 0x25d54(%rip), %r14     # 0x5687f
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x1e66d
decl %ebp
jne 0x30b2b
leaq 0x23242(%rip), %rsi     # 0x53d88
movl $0x1, %edx
movq %rax, %rdi
callq 0x1e66d
movq %rax, %rdi
movq %rbx, %rsi
movl $0x50, %edx
movl $0x4, %ecx
movl $0x1, %r8d
callq 0x31119
movq %rax, %r14
movq %rbx, %rdi
callq 0x30e3f
movq %r14, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq