// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %ecx, %r12d
movq %rdx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, 0x10(%rsp)
callq 0x4ee9
movq %rax, (%rsp)
movslq %r12d, %r15
decl %r12d
movl $0xfd, %ebx
xorl %r14d, %r14d
leaq 0x3e60(%rip), %rbp      # 0xd1f4
cmpq %r15, %r14
jge 0x93ee
movq (%r13,%r14,8), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x22b0
cmpq %r14, %r12
je 0x943b
testl %eax, %eax
jne 0x943b
movq 0x8(%r13,%r14,8), %rdi
callq 0x23e0
cmpl $0x2, %eax
pushq $0x1
popq %rcx
cmovll %ecx, %eax
cvtsi2sd %eax, %xmm0
mulsd 0x3017(%rip), %xmm0     # 0xc3f0
divsd 0x3017(%rip), %xmm0     # 0xc3f8
cvttsd2si %xmm0, %ebx
cmovlel %eax, %ebx
addq $0x2, %r14
jmp 0x9394
leaq 0x3db5(%rip), %rdx      # 0xd1aa
leaq 0x31fa(%rip), %rcx      # 0xc5f6
pushq $0x1
popq %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
movl $0xe10, %r8d            # imm = 0xE10
callq 0x7676
movq %rax, %r12
testq %rax, %rax
je 0x9421
cmpl %ebx, 0x78(%r12)
jge 0x946e
leaq 0x3e88(%rip), %rsi      # 0xd2b0
movq (%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x5814
jmp 0x94f8
leaq 0x3e69(%rip), %rsi      # 0xd2ab
movq %rbx, %rdi
callq 0x22b0
testl %eax, %eax
je 0x9457
leaq 0x407a(%rip), %rdi      # 0xd4cf
jmp 0x945e
leaq 0x401e(%rip), %rdi      # 0xd47c
callq 0x4ef7
movq %rax, %rbx
xorl %r12d, %r12d
jmp 0x94fb
movq %r12, %rdi
movl %ebx, %esi
callq 0x7b35
movq 0x98(%r12), %rcx
movq 0xa0(%r12), %r8
leaq (%r8,%rcx), %rax
cvtsi2sd %rcx, %xmm0
cvtsi2sd %rax, %xmm2
movl 0x90(%r12), %r9d
divsd %xmm2, %xmm0
movsd 0x2f1e(%rip), %xmm3     # 0xc3c8
mulsd %xmm3, %xmm0
cvtsi2sd %r8, %xmm1
divsd %xmm2, %xmm1
mulsd %xmm3, %xmm1
movsd 0xa8(%r12), %xmm2
movsd 0xb0(%r12), %xmm3
movsd 0xb8(%r12), %xmm4
movsd 0xc0(%r12), %xmm5
leaq 0x4006(%rip), %rsi      # 0xd4f0
movq (%rsp), %rdi
movq %r14, %rdx
movb $0x6, %al
callq 0x5814
movq %rax, %rbx
testq %rbx, %rbx
je 0x9513
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x7cae
movq %r12, %rdi
callq 0x75e4
movq %rbx, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4f65