// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
callq 0xa2640
movq %rax, -0x20(%rbp)
callq 0x384f0
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0xa0, -0x14(%rbp)
jge 0xa2221
movq -0x10(%rbp), %rax
movl (%rax), %eax
addl -0x14(%rbp), %eax
movl $0xa0, %ecx
cltd
idivl %ecx
movl %edx, -0x34(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
cmpl $0x0, 0x8(%rax,%rcx,8)
jne 0xa20cf
jmp 0xa2213
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xa20ec
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0xa212e
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
cmpl -0x30(%rbp), %eax
jbe 0xa210c
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
cmpl -0x2c(%rbp), %eax
jae 0xa212c
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
movl %eax, -0x2c(%rbp)
jmp 0xa212e
xorl %eax, %eax
movl %eax, %edi
callq 0x26ce0
movq -0x10(%rbp), %rcx
movslq -0x34(%rbp), %rdx
movslq 0x8(%rcx,%rdx,8), %rcx
subq %rcx, %rax
movl %eax, -0x38(%rbp)
cmpl $0x3c, -0x38(%rbp)
jge 0xa216f
leaq -0x80(%rbp), %rdi
movl -0x38(%rbp), %ecx
movl $0x40, %esi
leaq 0xa6ebb(%rip), %rdx     # 0x14901e
movb $0x0, %al
callq 0x26120
jmp 0xa21f5
cmpl $0xe10, -0x38(%rbp)     # imm = 0xE10
jge 0xa219e
leaq -0x80(%rbp), %rdi
movl -0x38(%rbp), %eax
movl $0x3c, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl $0x40, %esi
leaq 0xa6e8d(%rip), %rdx     # 0x149022
movb $0x0, %al
callq 0x26120
jmp 0xa21f3
cmpl $0x15180, -0x38(%rbp)   # imm = 0x15180
jge 0xa21cd
leaq -0x80(%rbp), %rdi
movl -0x38(%rbp), %eax
movl $0xe10, %ecx            # imm = 0xE10
cltd
idivl %ecx
movl %eax, %ecx
movl $0x40, %esi
leaq 0xa6e62(%rip), %rdx     # 0x149026
movb $0x0, %al
callq 0x26120
jmp 0xa21f1
leaq -0x80(%rbp), %rdi
movl -0x38(%rbp), %eax
movl $0x15180, %ecx          # imm = 0x15180
cltd
idivl %ecx
movl %eax, %ecx
movl $0x40, %esi
leaq 0xa6e40(%rip), %rdx     # 0x14902a
movb $0x0, %al
callq 0x26120
jmp 0xa21f3
jmp 0xa21f5
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl 0xc(%rax,%rcx,8), %eax
cvtsi2sd %rax, %xmm0
leaq -0x80(%rbp), %rsi
callq 0xa2680
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa209a
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0x30(%rbp), %eax
movl %eax, %ecx
movl -0x2c(%rbp), %eax
movl %eax, %r8d
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %r9d
leaq 0xa6de9(%rip), %rsi     # 0x14902e
movb $0x0, %al
callq 0x395b0
movq %rax, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
cmpl $0x50, -0x14(%rbp)
jge 0xa2281
movq -0x28(%rbp), %rdi
leaq 0xa9222(%rip), %rsi     # 0x14b48a
movl $0x1, %edx
callq 0x39040
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xa2257
movq -0x28(%rbp), %rdi
leaq 0x97bad(%rip), %rsi     # 0x139e39
movl $0x1, %edx
callq 0x39040
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl $0x50, %edx
movl $0x4, %ecx
movl $0x1, %r8d
callq 0xa2b30
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0xa27c0
movq -0x28(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)