// File: /workspace/github_c_makefile_star2_O0/antirez[P]stonky/stonky.c
// Function: botHandleVolatilityRequest
void botHandleVolatilityRequest(botRequest *br, sds symbol, sds *argv, int argc) {
    sds reply = sdsempty();
    int range = 253; /* Markets are open a bit more than 253 days per year. */
    ydata *yd = NULL;

    /* Parse arguments. */
    for (int j = 0; j < argc; j++) {
        int moreargs = argc-j-1;
        if (!strcasecmp(argv[j],"range") && moreargs) {
            range = atoi(argv[++j]);
            if (range <= 0) range = 1;
            if (range > 2) {
                /* Adjust for the amount of open market days in 1 year. */
                range = (double)range*5/7.2;
            }
        } else if (!strcasecmp(argv[j],"help")) {
            reply = sdsnew(
                "`$SYMBOL vol [range <days>]`\n"
                "The default range is one year (253 open market days).");
            goto cleanup;
        } else {
            reply = sdsnew("Syntax error. Try $AAPL vol help");
            goto cleanup;
        }
    }

    /* Fetch the data. Sometimes we'll not obtain enough data points. */
    yd = getYahooData(YDATA_TS,symbol,"5y","1d",3600);
    if (yd == NULL || yd->ts_len < range) {
        reply = sdscatprintf(reply,
            "Can't fetch historical data for '%s', use the range option to "
            "limit the amount of history to analyze.",
                             symbol);
        goto cleanup;
    }

    yahooDataToPriceChanges(yd,range);
    range = yd->ts_clen;
    long totdays = yd->pdays + yd->ldays;
    reply = sdscatprintf(reply,
        "%s volatility report:\n"
        "```\n"
        "Reported profits %-3ld times (%.2f%%)\n"
        "Reported loss    %-3ld times (%.2f%%)\n"
        "Average profit   %.2f%%\n"
        "Average loss     %.2f%%\n"
        "Max     profit   %.2f%%\n"
        "Max     loss     %.2f%%"
        "```\n"
        "Data from last %d days (adjusted) range.",
        symbol,
        (long)yd->pdays, (double)yd->pdays/totdays*100,
        (long)yd->ldays, (double)yd->ldays/totdays*100,
        yd->avgp, yd->avgl, yd->maxp, yd->maxl, range);

cleanup:
    if (reply) botSendMessage(br->target,reply,0);
    freeYahooData(yd);
    sdsfree(reply);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq %rdx, 0x30(%rsp)
movl %ecx, 0x2c(%rsp)
callq 0x8610
movq %rax, 0x20(%rsp)
movl $0xfd, 0x1c(%rsp)
movq $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jge 0x105b8
movl 0x2c(%rsp), %eax
subl 0xc(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x8(%rsp)
movq 0x30(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5e90(%rip), %rsi      # 0x1637c
callq 0x2270
cmpl $0x0, %eax
jne 0x1055b
cmpl $0x0, 0x8(%rsp)
je 0x1055b
movq 0x30(%rsp), %rax
movl 0xc(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2380
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jg 0x1052c
movl $0x1, 0x1c(%rsp)
cmpl $0x2, 0x1c(%rsp)
jle 0x10559
cvtsi2sdl 0x1c(%rsp), %xmm0
movsd 0x505f(%rip), %xmm1     # 0x155a0
mulsd %xmm1, %xmm0
movsd 0x504b(%rip), %xmm1     # 0x15598
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x1c(%rsp)
jmp 0x105a6
movq 0x30(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x5ec3(%rip), %rsi      # 0x16433
callq 0x2270
cmpl $0x0, %eax
jne 0x10590
leaq 0x6083(%rip), %rdi      # 0x16604
callq 0x8630
movq %rax, 0x20(%rsp)
jmp 0x10707
leaq 0x60c0(%rip), %rdi      # 0x16657
callq 0x8630
movq %rax, 0x20(%rsp)
jmp 0x10707
jmp 0x105a8
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x104ba
movq 0x38(%rsp), %rsi
movl $0x1, %edi
leaq 0x5d69(%rip), %rdx      # 0x16332
leaq 0x51ae(%rip), %rcx      # 0x1577e
movl $0xe10, %r8d            # imm = 0xE10
callq 0xd200
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0x105f6
movq 0x10(%rsp), %rax
movl 0x78(%rax), %eax
cmpl 0x1c(%rsp), %eax
jge 0x10618
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rdx
leaq 0x5e31(%rip), %rsi      # 0x16438
movb $0x0, %al
callq 0x98c0
movq %rax, 0x20(%rsp)
jmp 0x10707
movq 0x10(%rsp), %rdi
movl 0x1c(%rsp), %esi
callq 0xda40
movq 0x10(%rsp), %rax
movl 0x90(%rax), %eax
movl %eax, 0x1c(%rsp)
movq 0x10(%rsp), %rax
movq 0x98(%rax), %rax
movq 0x10(%rsp), %rcx
addq 0xa0(%rcx), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rdx
movq 0x10(%rsp), %rax
movq 0x98(%rax), %rcx
movq 0x10(%rsp), %rax
cvtsi2sdq 0x98(%rax), %xmm0
cvtsi2sdq (%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0x4ef9(%rip), %xmm1     # 0x15580
mulsd %xmm1, %xmm0
movq 0x10(%rsp), %rax
movq 0xa0(%rax), %r8
movq 0x10(%rsp), %rax
cvtsi2sdq 0xa0(%rax), %xmm1
cvtsi2sdq (%rsp), %xmm2
divsd %xmm2, %xmm1
movsd 0x4ec9(%rip), %xmm2     # 0x15580
mulsd %xmm2, %xmm1
movq 0x10(%rsp), %rax
movsd 0xa8(%rax), %xmm2
movq 0x10(%rsp), %rax
movsd 0xb0(%rax), %xmm3
movq 0x10(%rsp), %rax
movsd 0xb8(%rax), %xmm4
movq 0x10(%rsp), %rax
movsd 0xc0(%rax), %xmm5
movl 0x1c(%rsp), %r9d
leaq 0x5f7d(%rip), %rsi      # 0x16678
movb $0x6, %al
callq 0x98c0
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x20(%rsp)
je 0x10726
movq 0x40(%rsp), %rax
movq 0x8(%rax), %rdi
movq 0x20(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
movq 0x10(%rsp), %rdi
callq 0xd130
movq 0x20(%rsp), %rdi
callq 0x8750
addq $0x48, %rsp
retq
nop