// File: /workspace/github_c_makefile_star2_O2/gplessis[P]dotdeb-redis/src/sparkline.c
// Function: sparklineRenderRange
sds sparklineRenderRange(sds output, struct sequence *seq, int rows, int offset, int len, int flags) {
    int j;
    double relmax = seq->max - seq->min;
    int steps = charset_len*rows;
    int row = 0;
    char *chars = zmalloc(len);
    int loop = 1;
    int opt_fill = flags & SPARKLINE_FILL;
    int opt_log = flags & SPARKLINE_LOG_SCALE;

    if (opt_log) {
        relmax = log(relmax+1);
    } else if (relmax == 0) {
        relmax = 1;
    }

    while(loop) {
        loop = 0;
        memset(chars,' ',len);
        for (j = 0; j < len; j++) {
            struct sample *s = &seq->samples[j+offset];
            double relval = s->value - seq->min;
            int step;

            if (opt_log) relval = log(relval+1);
            step = (int) (relval*steps)/relmax;
            if (step < 0) step = 0;
            if (step >= steps) step = steps-1;

            if (row < rows) {
                /* Print the character needed to create the sparkline */
                int charidx = step-((rows-row-1)*charset_len);
                loop = 1;
                if (charidx >= 0 && charidx < charset_len) {
                    chars[j] = opt_fill ? charset_fill[charidx] :
                                          charset[charidx];
                } else if(opt_fill && charidx >= charset_len) {
                    chars[j] = '|';
                }
            } else {
                /* Labels spacing */
                if (seq->labels && row-rows < label_margin_top) {
                    loop = 1;
                    break;
                }
                /* Print the label if needed. */
                if (s->label) {
                    int label_len = strlen(s->label);
                    int label_char = row - rows - label_margin_top;

                    if (label_len > label_char) {
                        loop = 1;
                        chars[j] = s->label[label_char];
                    }
                }
            }
        }
        if (loop) {
            row++;
            output = sdscatlen(output,chars,len);
            output = sdscatlen(output,"\n",1);
        }
    }
    zfree(chars);
    return output;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r9d, %ebx
movl %ecx, %ebp
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movsd 0x18(%rsi), %xmm0
subsd 0x10(%rsi), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
leal (%rdx,%rdx,2), %eax
movq %rax, 0x40(%rsp)
movq %r8, %r14
movslq %r8d, %r15
movq %r15, %rdi
callq 0x327b9
movq %rax, %r13
movl %ebx, 0xc(%rsp)
testb $0x2, %bl
jne 0x72e08
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jne 0x72e1b
jp 0x72e1b
movsd 0x3f5ba(%rip), %xmm0    # 0xb23c0
jmp 0x72e1b
movsd 0x10(%rsp), %xmm0
addsd 0x3f5aa(%rip), %xmm0    # 0xb23c0
callq 0x264b0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rax
notl %eax
movq %rax, 0x58(%rsp)
movq 0x40(%rsp), %rax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x68(%rsp)
decl %eax
movl %eax, 0x34(%rsp)
movslq %ebp, %rax
xorl %ebp, %ebp
testl %r14d, %r14d
cmovlel %ebp, %r14d
movq %r14, 0x70(%rsp)
shlq $0x4, %rax
movq %rax, 0x50(%rsp)
movq %r15, 0x48(%rsp)
movq %r13, 0x20(%rsp)
movq 0x58(%rsp), %rax
addl %ebp, %eax
movl %eax, 0x38(%rsp)
cltq
movq %rax, 0x60(%rsp)
movq %rbp, %rbx
movl %ebp, %eax
notl %eax
addl 0x28(%rsp), %eax
imull $-0x3, %eax, %eax
movl %eax, 0x3c(%rsp)
movq %r13, %rdi
pushq $0x20
popq %rsi
movq %r15, %rdx
callq 0x26110
movq 0x50(%rsp), %r14
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpq %r15, 0x70(%rsp)
je 0x72f88
movq 0x8(%r12), %r13
movsd (%r13,%r14), %xmm0
subsd 0x10(%r12), %xmm0
testb $0x2, 0xc(%rsp)
je 0x72ed4
addsd 0x3f4f1(%rip), %xmm0    # 0xb23c0
callq 0x264b0
cmpl 0x28(%rsp), %ebx
jge 0x72f29
mulsd 0x68(%rsp), %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
jg 0x72ef8
xorl %eax, %eax
cmpl 0x40(%rsp), %eax
jl 0x72f02
movl 0x34(%rsp), %eax
addl 0x3c(%rsp), %eax
cmpl $0x2, %eax
ja 0x72f5f
testb $0x1, 0xc(%rsp)
movl %eax, %eax
leaq 0x4cf8a(%rip), %r13     # 0xbfea3
leaq 0x4cf87(%rip), %rcx     # 0xbfea7
cmoveq %rcx, %r13
addq %rax, %r13
jmp 0x72f59
setg %al
cmpl $0x0, 0x4(%r12)
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x72f8c
movq 0x8(%r13,%r14), %r13
testq %r13, %r13
je 0x72f7c
movq %r13, %rdi
callq 0x26500
cmpl %eax, 0x38(%rsp)
jge 0x72f7c
addq 0x60(%rsp), %r13
movb (%r13), %cl
jmp 0x72f70
pushq $0x1
popq %rbp
testb $0x1, 0xc(%rsp)
je 0x72f7c
movb $0x7c, %cl
cmpl $0x2, %eax
jle 0x72f7c
movq 0x20(%rsp), %rax
movb %cl, (%rax,%r15)
pushq $0x1
popq %rbp
incq %r15
addq $0x10, %r14
jmp 0x72ea2
testl %ebp, %ebp
je 0x72fc7
movq %rbx, %rbp
incl %ebp
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %r13
movq %r13, %rsi
movq 0x48(%rsp), %r15
movq %r15, %rdx
callq 0x31758
movq %rax, %rdi
leaq 0x3de04(%rip), %rsi     # 0xb0db9
pushq $0x1
popq %rdx
callq 0x31758
movq %rax, 0x18(%rsp)
jmp 0x72e66
movq 0x20(%rsp), %rdi
callq 0x328f9
movq 0x18(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq