// File: /workspace/github_c_makefile_star2_O0/antirez[P]stonky/stonky.c
// Function: yahooDataToPriceChanges
void yahooDataToPriceChanges(ydata *yd, int range) {
    if (range >= yd->ts_len) range = yd->ts_len-1;
    if (range <= 0) return;

    /* Intialize the result set. */
    yd->pdays = 0;
    yd->ldays = 0;
    yd->avgp = 0;
    yd->avgl = 0;
    yd->maxp = 0;
    yd->maxl = 0;

    double pval = 0; /* Previous sample value. */
    /* Analyze from the first to the last day in the range. */
    for (int j = range; j >= 0; j--) {
        double val = yd->ts_data[yd->ts_len-j-1];
        if (j == range) { /* First iteration. */
            pval = val;
            continue;
        } else {
            /* Handle broken data: the Yahoo API returns zero samples for
             * certain data points of less known stocks. */
            if (val == 0 || pval == 0) {
                if (val != 0) pval = val;
                yd->ts_data[yd->ts_len-j-1] = -1.0/0;
                continue;
            }
        }

        /* Compute the PL percentage between the previous and current
         * day of trading. */
        double pl = ((val/pval)-1)*100;
        yd->ts_data[yd->ts_len-j-1] = pl;
        if (pl > 0) {
            yd->pdays++;
            yd->avgp += pl;
            if (pl > yd->maxp) yd->maxp = pl;
        } else {
            yd->ldays++;
            yd->avgl += pl;
            if (pl < yd->maxl) yd->maxl = pl;
        }
        pval = val;
    }
    if (yd->pdays) yd->avgp /= yd->pdays;
    if (yd->ldays) yd->avgl /= yd->ldays;
    yd->ts_clen = range;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movl -0xc(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x78(%rcx), %eax
jl 0xda66
movq -0x8(%rsp), %rax
movl 0x78(%rax), %eax
subl $0x1, %eax
movl %eax, -0xc(%rsp)
cmpl $0x0, -0xc(%rsp)
jg 0xda72
jmp 0xdd64
movq -0x8(%rsp), %rax
movq $0x0, 0x98(%rax)
movq -0x8(%rsp), %rax
movq $0x0, 0xa0(%rax)
movq -0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xa8(%rax)
movq -0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xb0(%rax)
movq -0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xb8(%rax)
movq -0x8(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0xc0(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rsp)
movl -0xc(%rsp), %eax
movl %eax, -0x1c(%rsp)
cmpl $0x0, -0x1c(%rsp)
jl 0xdce9
movq -0x8(%rsp), %rax
movq 0x80(%rax), %rax
movq -0x8(%rsp), %rcx
movl 0x78(%rcx), %ecx
subl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss (%rax,%rcx,4), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, -0x28(%rsp)
movl -0x1c(%rsp), %eax
cmpl -0xc(%rsp), %eax
jne 0xdb36
movsd -0x28(%rsp), %xmm0
movsd %xmm0, -0x18(%rsp)
jmp 0xdcd9
movsd -0x28(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdb49
jp 0xdb49
jmp 0xdb5a
movsd -0x18(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdba9
jp 0xdba9
movsd -0x28(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xdb6d
jp 0xdb6d
jmp 0xdb79
movsd -0x28(%rsp), %xmm0
movsd %xmm0, -0x18(%rsp)
movq -0x8(%rsp), %rax
movq 0x80(%rax), %rax
movq -0x8(%rsp), %rcx
movl 0x78(%rcx), %ecx
subl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss 0x7ac5(%rip), %xmm0     # 0x15664
movss %xmm0, (%rax,%rcx,4)
jmp 0xdcd9
jmp 0xdbab
movsd -0x28(%rsp), %xmm0
divsd -0x18(%rsp), %xmm0
movsd 0x79c9(%rip), %xmm1     # 0x15588
subsd %xmm1, %xmm0
movsd 0x79b5(%rip), %xmm1     # 0x15580
mulsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rsp)
movsd -0x30(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
movq -0x8(%rsp), %rax
movq 0x80(%rax), %rax
movq -0x8(%rsp), %rcx
movl 0x78(%rcx), %ecx
subl -0x1c(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movss %xmm0, (%rax,%rcx,4)
movsd -0x30(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xdc6d
movq -0x8(%rsp), %rax
movq 0x98(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x98(%rax)
movsd -0x30(%rsp), %xmm0
movq -0x8(%rsp), %rax
addsd 0xa8(%rax), %xmm0
movsd %xmm0, 0xa8(%rax)
movsd -0x30(%rsp), %xmm0
movq -0x8(%rsp), %rax
ucomisd 0xb8(%rax), %xmm0
jbe 0xdc6b
movsd -0x30(%rsp), %xmm0
movq -0x8(%rsp), %rax
movsd %xmm0, 0xb8(%rax)
jmp 0xdccd
movq -0x8(%rsp), %rax
movq 0xa0(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0xa0(%rax)
movsd -0x30(%rsp), %xmm0
movq -0x8(%rsp), %rax
addsd 0xb0(%rax), %xmm0
movsd %xmm0, 0xb0(%rax)
movsd -0x30(%rsp), %xmm1
movq -0x8(%rsp), %rax
movsd 0xc0(%rax), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xdccb
movsd -0x30(%rsp), %xmm0
movq -0x8(%rsp), %rax
movsd %xmm0, 0xc0(%rax)
jmp 0xdccd
movsd -0x28(%rsp), %xmm0
movsd %xmm0, -0x18(%rsp)
movl -0x1c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0xdae3
movq -0x8(%rsp), %rax
cmpq $0x0, 0x98(%rax)
je 0xdd1f
movq -0x8(%rsp), %rax
cvtsi2sdq 0x98(%rax), %xmm1
movq -0x8(%rsp), %rax
movsd 0xa8(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xa8(%rax)
movq -0x8(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0xdd55
movq -0x8(%rsp), %rax
cvtsi2sdq 0xa0(%rax), %xmm1
movq -0x8(%rsp), %rax
movsd 0xb0(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0xb0(%rax)
movl -0xc(%rsp), %ecx
movq -0x8(%rsp), %rax
movl %ecx, 0x90(%rax)
retq
nopw %cs:(%rax,%rax)