// File: /workspace/github_c_makefile_star2_O3/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 %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %r14
movsd 0x18(%rsi), %xmm0
subsd 0x10(%rsi), %xmm0
movsd %xmm0, 0x10(%rsp)
movl %r8d, 0xc(%rsp)
movslq %r8d, %rdi
movq %rdi, 0x38(%rsp)
callq 0x382d1
movq %rax, 0x18(%rsp)
movl %ebx, 0x8(%rsp)
testb $0x2, %bl
jne 0x7fcb5
xorpd %xmm0, %xmm0
movsd 0x10(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movapd %xmm1, %xmm0
jne 0x7fcc8
jp 0x7fcc8
movsd 0x40d6d(%rip), %xmm0    # 0xc0a20
jmp 0x7fcc8
movsd 0x10(%rsp), %xmm0
addsd 0x40d5d(%rip), %xmm0    # 0xc0a20
callq 0x264b0
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rsp), %rdi
movl $0x20, %esi
movq 0x38(%rsp), %rbx
movq %rbx, %rdx
callq 0x26110
testl %ebx, %ebx
jle 0x7fe9d
movq 0x20(%rsp), %rax
leal (%rax,%rax,2), %ecx
leal -0x1(%rcx), %edx
movl %edx, 0x2c(%rsp)
notl %eax
movq %rax, 0x50(%rsp)
movq %rcx, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x60(%rsp)
movslq %ebp, %rax
movl 0xc(%rsp), %ecx
movq %rcx, 0x70(%rsp)
shlq $0x4, %rax
movq %rax, 0x48(%rsp)
xorl %r12d, %r12d
movq %r14, 0x40(%rsp)
movq 0x50(%rsp), %rax
addl %r12d, %eax
movl %eax, 0x30(%rsp)
cltq
movq %rax, 0x58(%rsp)
movl %r12d, %eax
notl %eax
addl 0x20(%rsp), %eax
leal (%rax,%rax,2), %eax
negl %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %r14
xorl %r13d, %r13d
xorl %ebx, %ebx
movq 0x8(%r15), %rbp
movsd (%rbp,%r14), %xmm0
subsd 0x10(%r15), %xmm0
testb $0x2, 0x8(%rsp)
je 0x7fd86
addsd 0x40c9f(%rip), %xmm0    # 0xc0a20
callq 0x264b0
cmpl 0x20(%rsp), %r12d
jge 0x7fddc
mulsd 0x60(%rsp), %xmm0
cvttpd2dq %xmm0, %xmm0
cvtdq2pd %xmm0, %xmm0
divsd 0x10(%rsp), %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
jg 0x7fdab
xorl %eax, %eax
cmpl 0x68(%rsp), %eax
jl 0x7fdb5
movl 0x2c(%rsp), %eax
addl 0x34(%rsp), %eax
cmpl $0x2, %eax
ja 0x7fe10
testb $0x1, 0x8(%rsp)
movl %eax, %eax
leaq 0x4f50f(%rip), %rbp     # 0xcf2db
leaq 0x4f50c(%rip), %rcx     # 0xcf2df
cmoveq %rcx, %rbp
addq %rax, %rbp
jmp 0x7fe0b
setg %al
cmpl $0x0, 0x4(%r15)
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x7fe47
movq 0x8(%rbp,%r14), %rbp
testq %rbp, %rbp
je 0x7fe31
movq %rbp, %rdi
callq 0x26500
cmpl %eax, 0x30(%rsp)
jge 0x7fe31
addq 0x58(%rsp), %rbp
movb (%rbp), %cl
jmp 0x7fe23
movl $0x1, %ebx
testb $0x1, 0x8(%rsp)
je 0x7fe31
movb $0x7c, %cl
cmpl $0x2, %eax
jle 0x7fe31
movq 0x18(%rsp), %rax
movb %cl, (%rax,%r13)
movl $0x1, %ebx
incq %r13
addq $0x10, %r14
cmpq %r13, 0x70(%rsp)
jne 0x7fd61
testl %ebx, %ebx
je 0x7fe98
incl %r12d
movq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
movq 0x38(%rsp), %r13
movq %r13, %rdx
callq 0x36ad1
movl $0x1, %edx
movq %rax, %rdi
leaq 0x3f056(%rip), %rsi     # 0xbeec9
callq 0x36ad1
movq %rax, %r14
movq %rbx, %rdi
movl $0x20, %esi
movq %r13, %rdx
callq 0x26110
cmpl $0x0, 0xc(%rsp)
jg 0x7fd2d
jmp 0x7fe9d
movq 0x40(%rsp), %r14
movq 0x18(%rsp), %rdi
callq 0x38413
movq %r14, %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq