// File: /workspace/github_c_makefile_star2_O2/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 0x2210
movl %eax, %edi
callq 0x2240
leal -0x1(%r14), %eax
movl %eax, 0xc(%rsp)
pushq $0x1
popq %r13
leaq 0x2cbc(%rip), %r15      # 0xe6ab
cmpl %r14d, %r13d
jge 0xbba1
movslq %r13d, %r12
movq (%rbx,%r12,8), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2370
testl %eax, %eax
je 0xba95
movq %rbp, %rdi
leaq 0x2c97(%rip), %rsi      # 0xe6b3
callq 0x2370
testl %eax, %eax
je 0xbaaa
movq %rbp, %rdi
leaq 0x2c8e(%rip), %rsi      # 0xe6c1
callq 0x2370
testl %eax, %eax
je 0xba9b
movq %rbp, %rdi
leaq 0x2c85(%rip), %rsi      # 0xe6cb
callq 0x2370
testl %eax, %eax
je 0xbab6
movq %rbp, %rdi
leaq 0x2c7a(%rip), %rsi      # 0xe6d3
callq 0x2370
testl %eax, %eax
je 0xbac5
movq %rbp, %rdi
leaq 0x2c71(%rip), %rsi      # 0xe6dd
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xbad4
testl %eax, %eax
jne 0xbad4
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x4ef7
movq %rax, 0x7830(%rip)      # 0x132c0
jmp 0xbb99
incl 0x7815(%rip)            # 0x132b0
movl $0x1, 0x780f(%rip)      # 0x132b4
jmp 0xbb99
andl $0x0, 0x77b7(%rip)      # 0x13268
jmp 0xbb99
movl $0x1, 0x7810(%rip)      # 0x132d0
jmp 0xbb99
movl $0x1, 0x7805(%rip)      # 0x132d4
jmp 0xbb99
movq %rbp, %rdi
leaq 0x2c08(%rip), %rsi      # 0xe6e6
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xbb02
testl %eax, %eax
jne 0xbb02
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x7773(%rip)      # 0x13270
jmp 0xbb99
movq %rbp, %rdi
leaq 0x2be3(%rip), %rsi      # 0xe6ef
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xbb2d
testl %eax, %eax
jne 0xbb2d
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x778d(%rip)      # 0x132b8
jmp 0xbb99
movq %rbp, %rdi
leaq 0x2bc4(%rip), %rsi      # 0xe6fb
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xbb66
testl %eax, %eax
jne 0xbb66
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x23e0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x7714(%rip)      # 0x13278
jmp 0xbb99
movq %rbp, %rdi
leaq 0x2b97(%rip), %rsi      # 0xe707
callq 0x2370
testl %eax, %eax
jne 0xbc4c
andl $0x0, 0x76f4(%rip)      # 0x13278
pushq $0x1
popq %rax
movl %eax, 0x7743(%rip)      # 0x132d0
movl %eax, 0x7741(%rip)      # 0x132d4
movl %eax, 0x771b(%rip)      # 0x132b4
incl %r13d
jmp 0xb9ef
pushq $0x3
popq %rdi
callq 0x20c0
cmpq $0x0, 0x770f(%rip)      # 0x132c0
jne 0xbbd0
callq 0xb90c
cmpq $0x0, 0x7700(%rip)      # 0x132c0
jne 0xbbd0
leaq 0x2caa(%rip), %rdi      # 0xe873
callq 0x23d0
jmp 0xbbeb
callq 0xb99f
pushq $0x1
popq %rdi
callq 0x7e27
movq %rax, %fs:-0x8
testq %rax, %rax
jne 0xbbf3
pushq $0x1
popq %rdi
callq 0x2300
movups 0x71ae(%rip), %xmm0     # 0x12da8
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
callq 0x2949
leaq 0x2b95(%rip), %rdi      # 0xe7a3
leaq 0x7af3(%rip), %rsi      # 0x13708
pushq $0x1
popq %rbx
movl %ebx, %edx
callq 0xaf72
movq %rax, 0x7ada(%rip)      # 0x13700
leaq 0x2b8d(%rip), %rdi      # 0xe7ba
leaq 0x7afc(%rip), %rsi      # 0x13730
movl %ebx, %edx
callq 0xaf72
movq %rax, 0x7ae6(%rip)      # 0x13728
callq 0xb85b
callq 0xb8dc
movq (%rbx), %rsi
leaq 0x2abb(%rip), %rdi      # 0xe711
xorl %eax, %eax
callq 0x2030
jmp 0xbbeb