// File: /workspace/github_c_makefile_star2_O0/antirez[P]stonky/stonky.c
// Function: botHandleRequest
void *botHandleRequest(void *arg) {
    DbHandle = dbInit(0);
    botRequest *br = arg;

    /* Parse the request as a command composed of arguments. */
    int argc;
    sds *argv = sdssplitargs(br->request,&argc);

    if (argc >= 2 && !strcasecmp(argv[0],"$")) {
        if (argc == 2 && !strcasecmp(argv[1],"ls")) {
            /* $$ ls */
            botHandleLsRequest(br);
        } else if (argc == 3 &&
                   AdminPass != NULL &&
                   (!strcasecmp(argv[1],"quit") ||
                    !strcasecmp(argv[1],"exit")) &&
                   !strcasecmp(argv[2],AdminPass))
        {
            /* $$ quit <password> */
            botSendMessage(br->target, "Exiting in 5 seconds. Bye...",0);
            sleep(5); /* Wait for the main thread to likely acknowledge
                         the processing of this message, otherwise the
                         bot will quit again since it will fetch $$ quit
                         again at the next restart. */
            printf("Exiting by user request.\n");
            exit(0);
        } else if (argc == 3 &&
                   AdminPass != NULL &&
                   !strcasecmp(argv[1],"flush-cache") &&
                   !strcasecmp(argv[2],AdminPass))
        {
            /* $$ flush-cache <password> */
            botSendMessage(br->target, "Deleting cached entries...",0);
            sqlQuery("DELETE * FROM KeyValue");
            botSendMessage(br->target, "Cache flushing done.",0);
        } else if (argc == 4 &&
                   AdminPass != NULL &&
                   !strcasecmp(argv[1],"destroy") &&
                   !strcasecmp(argv[3],AdminPass))
        {
            /* $$ destroy <listname> <password> */
            botSendMessage(br->target, "Destroying list...",0);
            dbDestroyList(argv[2]);
        } else if (argc == 2 && !strcasecmp(argv[1],"info")) {
            /* $$ info */
            char buf[1024];
            sds ago = sdsTimeAgo(botStats.start_time);

            snprintf(buf,sizeof(buf),
                "Hey, a few info about me.\n"
                "uptime: %s\n"
                "queries: %llu\n"
                "scanned: %llu\n"
                "active-channels: %d",
                ago,
                (unsigned long long)botStats.queries,
                (unsigned long long)botStats.scanned,
                (int)ActiveChannelsCount);
            sdsfree(ago);
            botSendMessage(br->target,buf,0);
        } else {
            botSendMessage(br->target,
                "Invalid control command or bad password, try $HELP",0);
        }
    } else if (argv[0][sdslen(argv[0])-1] == ':') {
        /* $list: [+... -...] */
        botHandleListRequest(br,argv,argc);
    } else if (argv[0][sdslen(argv[0])-1] == '?') {
        /* $list? [pattern] and $list?? [pattern] */
        if (argv[0][sdslen(argv[0])-2] != '?') {
            botHandleShowPortfolioRequest(br,argc,argv);
        } else {
            botHandleShowProfitLossRequest(br,argc,argv);
        }
    } else if (argc == 1 && !strcasecmp(argv[0],"bigmovers")) {
        /* $bigmovers -- best and worse among stocks in defined lists. */
        botHandleBigMoversRequest(br);
    } else if (argc == 1 && strcasecmp(argv[0],"help")) {
        /* $AAPL */
        botHandlePriceRequest(br,argv[0]);
    } else if (argc == 2 && sdslen(argv[1]) == 2 &&
               isdigit(argv[1][0]) && isalpha(argv[1][1]))
    {
        /* $AAPL 5d */
        botHandleChartRequest(br,argv[0],argv[1]);
    } else if (argc >= 2 && (!strcasecmp(argv[1],"mc") ||
                             !strcasecmp(argv[1],"montecarlo")))
    {
        /* $AAPL mc | montecarlo [options] */
        botHandleMontecarloRequest(br,argv[0],argv+2,argc-2);
    } else if (argc >= 2 && (!strcasecmp(argv[1],"vol") ||
                             !strcasecmp(argv[1],"volatility")))
    {
        /* $AAPL vol | volatility [options] */
        botHandleVolatilityRequest(br,argv[0],argv+2,argc-2);
    } else if (argc >= 2 && !strcasecmp(argv[1],"last")) {
        /* $AAPL last [count] */
        botHandleLastChangesRequest(br,argv[0],argv+2,argc-2);
    } else if (argc == 2 && !strcasecmp(argv[1],"trend")) {
        /* $AAPL trend. */
        botHandleTrendRequest(br,argv[0]);
    } else if (argc == 2 && !strcasecmp(argv[1],"info")) {
        /* $AAPL info. */
        botHandleInfoRequest(br,argv[0]);
    } else if (argc >= 1 && !strcasecmp(argv[0],"help")) {
        /* $HELP */
        botSendMessage(br->target,
"```\n"
"$AAPL                    | Show price for AAPL.\n"
"$AAPL 1d|5d|1m|6m|1y|5y  | Show AAPL price chart for period.\n"
"$AAPL info               | Show general info for the company.\n"
"$mylist: +VMW +AAPL -KO  | Modify the list.\n"
"$mylist:                 | Ask prices of whole list.\n"
"$mylist::                | Like $mylist: but more verbose.\n"
"$mylist: ?               | Show just stock names.\n"
"$AAPL mc                 | Montecarlo simulation.\n"
"$AAPL mc range 60        | Specify Montecarlo range.\n"
"$APPL mc period 5        | Specify Sell/Buy fixed period.\n"
"$APPL trend              | Montecarlo trend analysis.\n"
"$AAPL last [numdays]     | Last N price %% changes (default 10).\n"
"$AAPL vol                | Volatility analysis.\n"
"$AAPL vol range 60       | Volatility anal. last 60 market days.\n"
"$bigmovers               | Best and worse of today.\n"
"$mylist: buy AAPL 10@50  | Add 10 AAPL stocks at 50$ each.\n"
"$mylist: buy AAPL 20     | Add 20 AAPL stocks at current price.\n"
"$mylist: buy AAPL        | Add 1 AAPL stocks at current price.\n"
"$mylist: buy AAPL 10000$ | Add AAPL stocks you can buy with 10k$.\n"
"$mylist: buy V T 500$    | Add AT&T and VISA stocks for 5k$ each.\n"
"$mylist: sell AAPL 10@35 | Sell 10 AAPL stocks at 35$ each.\n"
"$mylist: sell AAPL 10    | Sell 10 AAPL stocks at current price.\n"
"$mylist: sell AAPL       | Sell all AAPL stocks at current price.\n"
"$mylist: rm-sell <id>    | Remove sell with specified ID.\n"
"$mylist? [pattern]       | Show portfolio associated with mylist.\n"
"$mylist?? [pattern]      | Show portfolio profit and loss history.\n"
"$$ ls                    | Show all the available lists.\n"
"$$ info                  | Stop bot internal stats.\n"
"$$ quit <password>       | Stop the bot process.\n"
"$$ destroy <name> <pass> | Destroy the list, portfolio, P/Ls.\n"
"$help                    | Show this help.\n"
"```\n",0);
    } else {
        botSendMessage(br->target,
            "Sorry, I can't understand your request. Try $HELP.",0);
    }

    freeBotRequest(br);
    sdsfreesplitres(argv,argc);
    dbClose();
    return NULL;
}

// Assembly:
subq $0x458, %rsp            # imm = 0x458
movq %rdi, 0x450(%rsp)
xorl %edi, %edi
callq 0xdf80
movq %rax, %rcx
movq %fs:0x0, %rax
leaq -0x8(%rax), %rax
movq %rcx, (%rax)
movq 0x450(%rsp), %rax
movq %rax, 0x448(%rsp)
movq 0x448(%rsp), %rax
movq (%rax), %rdi
leaq 0x444(%rsp), %rsi
callq 0xac10
movq %rax, 0x438(%rsp)
cmpl $0x2, 0x444(%rsp)
jl 0x128b1
movq 0x438(%rsp), %rax
movq (%rax), %rdi
leaq 0x4599(%rip), %rsi      # 0x16b75
callq 0x2270
cmpl $0x0, %eax
jne 0x128b1
cmpl $0x2, 0x444(%rsp)
jne 0x12623
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x46cf(%rip), %rsi      # 0x16cd6
callq 0x2270
cmpl $0x0, %eax
jne 0x12623
movq 0x448(%rsp), %rdi
callq 0x12470
jmp 0x128ac
cmpl $0x3, 0x444(%rsp)
jne 0x126d1
cmpq $0x0, 0x8c7f(%rip)      # 0x1b2b8
je 0x126d1
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4687(%rip), %rsi      # 0x16cd9
callq 0x2270
cmpl $0x0, %eax
je 0x12679
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x466f(%rip), %rsi      # 0x16cde
callq 0x2270
cmpl $0x0, %eax
jne 0x126d1
movq 0x438(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8c2c(%rip), %rsi      # 0x1b2b8
callq 0x2270
cmpl $0x0, %eax
jne 0x126d1
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x463a(%rip), %rsi      # 0x16ce3
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
movl $0x5, %edi
callq 0x2170
leaq 0x463d(%rip), %rdi      # 0x16d00
movb $0x0, %al
callq 0x2030
xorl %edi, %edi
callq 0x22b0
cmpl $0x3, 0x444(%rsp)
jne 0x12772
cmpq $0x0, 0x8bd1(%rip)      # 0x1b2b8
je 0x12772
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x461a(%rip), %rsi      # 0x16d1a
callq 0x2270
cmpl $0x0, %eax
jne 0x12772
movq 0x438(%rsp), %rax
movq 0x10(%rax), %rdi
movq 0x8b9b(%rip), %rsi      # 0x1b2b8
callq 0x2270
cmpl $0x0, %eax
jne 0x12772
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x45ec(%rip), %rsi      # 0x16d26
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
leaq 0x45f7(%rip), %rdi      # 0x16d41
movb $0x0, %al
callq 0xc990
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x45f4(%rip), %rsi      # 0x16d58
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
jmp 0x128a8
cmpl $0x4, 0x444(%rsp)
jne 0x127f2
cmpq $0x0, 0x8b34(%rip)      # 0x1b2b8
je 0x127f2
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x45d4(%rip), %rsi      # 0x16d6d
callq 0x2270
cmpl $0x0, %eax
jne 0x127f2
movq 0x438(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x8b02(%rip), %rsi      # 0x1b2b8
callq 0x2270
cmpl $0x0, %eax
jne 0x127f2
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x45a2(%rip), %rsi      # 0x16d75
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
movq 0x438(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0xec00
jmp 0x128a6
cmpl $0x2, 0x444(%rsp)
jne 0x12888
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4575(%rip), %rsi      # 0x16d88
callq 0x2270
cmpl $0x0, %eax
jne 0x12888
movq 0x8abc(%rip), %rdi      # 0x1b2e0
callq 0x11d70
movq %rax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rcx
movq 0x8aa9(%rip), %r8       # 0x1b2e8
movq 0x8aaa(%rip), %r9       # 0x1b2f0
movl 0x8a8c(%rip), %eax      # 0x1b2d8
movl $0x400, %esi            # imm = 0x400
leaq 0x4535(%rip), %rdx      # 0x16d8d
movl %eax, (%rsp)
movb $0x0, %al
callq 0x23a0
movq 0x28(%rsp), %rdi
callq 0x8750
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x30(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
jmp 0x128a4
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4547(%rip), %rsi      # 0x16de2
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
jmp 0x128a6
jmp 0x128a8
jmp 0x128aa
jmp 0x128ac
jmp 0x12d0d
movq 0x438(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x438(%rsp), %rax
movq (%rax), %rdi
callq 0xfa70
movq %rax, %rcx
movq 0x20(%rsp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3a, %eax
jne 0x12907
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rsi
movl 0x444(%rsp), %edx
callq 0x10c70
jmp 0x12d0b
movq 0x438(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x438(%rsp), %rax
movq (%rax), %rdi
callq 0xfa70
movq %rax, %rcx
movq 0x18(%rsp), %rax
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
jne 0x129b0
movq 0x438(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x438(%rsp), %rax
movq (%rax), %rdi
callq 0xfa70
movq %rax, %rcx
movq 0x10(%rsp), %rax
subq $0x2, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3f, %eax
je 0x1298f
movq 0x448(%rsp), %rdi
movl 0x444(%rsp), %esi
movq 0x438(%rsp), %rdx
callq 0x11770
jmp 0x129ab
movq 0x448(%rsp), %rdi
movl 0x444(%rsp), %esi
movq 0x438(%rsp), %rdx
callq 0x11f80
jmp 0x12d09
cmpl $0x1, 0x444(%rsp)
jne 0x129e8
movq 0x438(%rsp), %rax
movq (%rax), %rdi
leaq 0x4449(%rip), %rsi      # 0x16e15
callq 0x2270
cmpl $0x0, %eax
jne 0x129e8
movq 0x448(%rsp), %rdi
callq 0xfb10
jmp 0x12d07
cmpl $0x1, 0x444(%rsp)
jne 0x12a2b
movq 0x438(%rsp), %rax
movq (%rax), %rdi
leaq 0x3a2f(%rip), %rsi      # 0x16433
callq 0x2270
cmpl $0x0, %eax
je 0x12a2b
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
callq 0xf7e0
jmp 0x12d05
cmpl $0x2, 0x444(%rsp)
jne 0x12aca
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
callq 0xfa70
cmpq $0x2, %rax
jne 0x12aca
callq 0x2260
movq (%rax), %rax
movq 0x438(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x12aca
callq 0x2260
movq (%rax), %rax
movq 0x438(%rsp), %rcx
movq 0x8(%rcx), %rcx
movsbl 0x1(%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x12aca
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdx
callq 0xfdc0
jmp 0x12d03
cmpl $0x2, 0x444(%rsp)
jl 0x12b41
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4338(%rip), %rsi      # 0x16e1f
callq 0x2270
cmpl $0x0, %eax
je 0x12b0e
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x431e(%rip), %rsi      # 0x16e22
callq 0x2270
cmpl $0x0, %eax
jne 0x12b41
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
movq 0x438(%rsp), %rdx
addq $0x10, %rdx
movl 0x444(%rsp), %ecx
subl $0x2, %ecx
callq 0x10190
jmp 0x12d01
cmpl $0x2, 0x444(%rsp)
jl 0x12bb8
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x42cf(%rip), %rsi      # 0x16e2d
callq 0x2270
cmpl $0x0, %eax
je 0x12b85
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x42b6(%rip), %rsi      # 0x16e31
callq 0x2270
cmpl $0x0, %eax
jne 0x12bb8
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
movq 0x438(%rsp), %rdx
addq $0x10, %rdx
movl 0x444(%rsp), %ecx
subl $0x2, %ecx
callq 0x10480
jmp 0x12cff
cmpl $0x2, 0x444(%rsp)
jl 0x12c12
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4267(%rip), %rsi      # 0x16e3c
callq 0x2270
cmpl $0x0, %eax
jne 0x12c12
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
movq 0x438(%rsp), %rdx
addq $0x10, %rdx
movl 0x444(%rsp), %ecx
subl $0x2, %ecx
callq 0x10740
jmp 0x12cfd
cmpl $0x2, 0x444(%rsp)
jne 0x12c56
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4212(%rip), %rsi      # 0x16e41
callq 0x2270
cmpl $0x0, %eax
jne 0x12c56
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
callq 0x10980
jmp 0x12cfb
cmpl $0x2, 0x444(%rsp)
jne 0x12c97
movq 0x438(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4115(%rip), %rsi      # 0x16d88
callq 0x2270
cmpl $0x0, %eax
jne 0x12c97
movq 0x448(%rsp), %rdi
movq 0x438(%rsp), %rax
movq (%rax), %rsi
callq 0xf860
jmp 0x12cf9
cmpl $0x1, 0x444(%rsp)
jl 0x12cdb
movq 0x438(%rsp), %rax
movq (%rax), %rdi
leaq 0x3780(%rip), %rsi      # 0x16433
callq 0x2270
cmpl $0x0, %eax
jne 0x12cdb
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x4177(%rip), %rsi      # 0x16e47
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
jmp 0x12cf7
movq 0x448(%rsp), %rax
movq 0x8(%rax), %rdi
leaq 0x485b(%rip), %rsi      # 0x17549
xorl %eax, %eax
movl %eax, %edx
callq 0xdd70
jmp 0x12cf9
jmp 0x12cfb
jmp 0x12cfd
jmp 0x12cff
jmp 0x12d01
jmp 0x12d03
jmp 0x12d05
jmp 0x12d07
jmp 0x12d09
jmp 0x12d0b
jmp 0x12d0d
movq 0x448(%rsp), %rdi
callq 0xde70
movq 0x438(%rsp), %rdi
movl 0x444(%rsp), %esi
callq 0xa850
callq 0xe080
xorl %eax, %eax
addq $0x458, %rsp            # imm = 0x458
retq
nopl (%rax)