// File: /workspace/github_c_makefile_star2_O1/antirez[P]stonky/stonky.c
// Function: main
int main(int argc, char **argv) {
    srand(time(NULL));

    /* Parse options. */
    for (int j = 1; j < argc; j++) {
        int morearg = argc-j-1;
        if (!strcmp(argv[j],"--debug")) {
            DebugMode++;
            VerboseMode = 1;
        } else if (!strcmp(argv[j],"--noautolists")) {
            AutoListsMode = 0;
        } else if (!strcmp(argv[j],"--verbose")) {
            VerboseMode = 1;
        } else if (!strcmp(argv[j],"--cache")) {
            CacheYahoo = 1;
        } else if (!strcmp(argv[j],"--noevict")) {
            NoEvictMode = 1;
        } else if (!strcmp(argv[j],"--apikey") && morearg) {
            BotApiKey = sdsnew(argv[++j]);
        } else if (!strcmp(argv[j],"--dbfile") && morearg) {
            DbFile = argv[++j];
        } else if (!strcmp(argv[j],"--adminpass") && morearg) {
            AdminPass = argv[++j];
        } else if (!strcmp(argv[j],"--scanpause") && morearg) {
            ScanPause = atoi(argv[++j]);
            if (ScanPause < 0) ScanPause = 0;
        } else if (!strcmp(argv[j],"--refresh")) {
            /* This is just an alias for
             * --cache --noevict --scanpause 0 --verbose
             * And is useful in order to scan the local DB of stocks
             * and apply a modified algorithm for the autolists
             * tothemoon:, evenbetter:, penny:, ... */
            ScanPause = 0;
            CacheYahoo = 1;
            NoEvictMode = 1;
            VerboseMode = 1;
        } else {
            printf(
            "Usage: %s [--apikey <apikey>] [--debug] [--verbose] "
            "[--noautolists] [--dbfile <filename>] [--scanpause <usec>] "
            "[--cache] [--noevict] [--refresh]"
            "\n",argv[0]);
            exit(1);
        }
    }

    /* Initializations. Note that we don't redefine the SQLite allocator,
     * since SQLite errors are always handled by Stonky anyway. */
    curl_global_init(CURL_GLOBAL_DEFAULT);
    if (BotApiKey == NULL) readApiKeyFromFile();
    if (BotApiKey == NULL) {
        printf("Provide a bot API key via --apikey or storing a file named "
               "apikey.txt in the bot working directory.\n");
        exit(1);
    }
    resetBotStats();
    DbHandle = dbInit(1);
    if (DbHandle == NULL) exit(1);
    cJSON_Hooks jh = {.malloc_fn = xmalloc, .free_fn = xfree};
    cJSON_InitHooks(&jh);
    Symbols = loadFile("marketdata/symbols.txt",&NumSymbols,1);
    Fortune = loadFile("fortune.txt",&NumFortune,1);
    startBackgroundTasks();

    /* Enter the infinite loop handling the bot. */
    botMain();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movl %edi, %r14d
xorl %edi, %edi
callq 0x2200
movl %eax, %edi
callq 0x2230
cmpl $0x2, %r14d
jl 0xd74a
leal -0x1(%r14), %eax
movl %eax, 0xc(%rsp)
leaq 0x34d4(%rip), %r15      # 0x10a63
movl $0x1, %r13d
movslq %r13d, %r12
movq (%rbx,%r12,8), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2360
testl %eax, %eax
je 0xd632
movq %rbp, %rdi
leaq 0x34b2(%rip), %rsi      # 0x10a6b
callq 0x2360
testl %eax, %eax
je 0xd647
movq %rbp, %rdi
leaq 0x34a9(%rip), %rsi      # 0x10a79
callq 0x2360
testl %eax, %eax
je 0xd638
movq %rbp, %rdi
leaq 0x34a0(%rip), %rsi      # 0x10a83
callq 0x2360
testl %eax, %eax
je 0xd656
movq %rbp, %rdi
leaq 0x3495(%rip), %rsi      # 0x10a8b
callq 0x2360
testl %eax, %eax
je 0xd665
movq %rbp, %rdi
leaq 0x348c(%rip), %rsi      # 0x10a95
callq 0x2360
cmpl 0xc(%rsp), %r13d
je 0xd674
testl %eax, %eax
jne 0xd674
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x58ac
movq %rax, 0x7c93(%rip)      # 0x152c0
jmp 0xd73e
incl 0x7c78(%rip)            # 0x152b0
movl $0x1, 0x7c72(%rip)      # 0x152b4
jmp 0xd73e
movl $0x0, 0x7c0f(%rip)      # 0x15260
jmp 0xd73e
movl $0x1, 0x7c70(%rip)      # 0x152d0
jmp 0xd73e
movl $0x1, 0x7c65(%rip)      # 0x152d4
jmp 0xd73e
movq %rbp, %rdi
leaq 0x3420(%rip), %rsi      # 0x10a9e
callq 0x2360
cmpl 0xc(%rsp), %r13d
je 0xd6a2
testl %eax, %eax
jne 0xd6a2
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x7bcb(%rip)      # 0x15268
jmp 0xd73e
movq %rbp, %rdi
leaq 0x33fb(%rip), %rsi      # 0x10aa7
callq 0x2360
cmpl 0xc(%rsp), %r13d
je 0xd6cd
testl %eax, %eax
jne 0xd6cd
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x7bed(%rip)      # 0x152b8
jmp 0xd73e
movq %rbp, %rdi
leaq 0x33dc(%rip), %rsi      # 0x10ab3
callq 0x2360
cmpl 0xc(%rsp), %r13d
je 0xd706
testl %eax, %eax
jne 0xd706
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x23d0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x7b6c(%rip)      # 0x15270
jmp 0xd73e
movq %rbp, %rdi
leaq 0x33af(%rip), %rsi      # 0x10abf
callq 0x2360
testl %eax, %eax
jne 0xd811
movl $0x0, 0x7b49(%rip)      # 0x15270
movl $0x1, %eax
movl %eax, 0x7b9e(%rip)      # 0x152d0
movl %eax, 0x7b9c(%rip)      # 0x152d4
movl %eax, 0x7b76(%rip)      # 0x152b4
incl %r13d
cmpl %r14d, %r13d
jl 0xd595
movl $0x3, %edi
callq 0x20c0
cmpq $0x0, 0x7b64(%rip)      # 0x152c0
jne 0xd763
callq 0xd4a6
cmpq $0x0, 0x7b55(%rip)      # 0x152c0
jne 0xd77b
leaq 0x34b7(%rip), %rdi      # 0x10c2b
callq 0x23c0
jmp 0xd7ab
xorl %edi, %edi
callq 0x2200
movq %rax, 0x7b57(%rip)      # 0x152e0
xorps %xmm0, %xmm0
movups %xmm0, 0x7b55(%rip)     # 0x152e8
movl $0x1, %edi
callq 0x936c
movq %rax, %fs:-0x8
testq %rax, %rax
jne 0xd7b5
movl $0x1, %edi
callq 0x22f0
movups 0x75e4(%rip), %xmm0     # 0x14da0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
callq 0x2a5b
leaq 0x338b(%rip), %rdi      # 0x10b5b
leaq 0x7f31(%rip), %rsi      # 0x15708
movl $0x1, %edx
callq 0xca1f
movq %rax, 0x7f18(%rip)      # 0x15700
leaq 0x3383(%rip), %rdi      # 0x10b72
leaq 0x7f3a(%rip), %rsi      # 0x15730
movl $0x1, %edx
callq 0xca1f
movq %rax, 0x7f21(%rip)      # 0x15728
callq 0xd3f1
callq 0xd474
movq (%rbx), %rsi
leaq 0x32ae(%rip), %rdi      # 0x10ac9
xorl %eax, %eax
callq 0x2030
jmp 0xd7ab