// File: /workspace/github_c_makefile_star2_O3/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
cmpl $0x2, %r14d
jl 0xd3fa
leal -0x1(%r14), %eax
movl %eax, 0xc(%rsp)
leaq 0x3804(%rip), %r15      # 0x10a43
movl $0x1, %r13d
movslq %r13d, %r12
movq (%rbx,%r12,8), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x2370
testl %eax, %eax
je 0xd2e2
movq %rbp, %rdi
leaq 0x37e2(%rip), %rsi      # 0x10a4b
callq 0x2370
testl %eax, %eax
je 0xd2f7
movq %rbp, %rdi
leaq 0x37d9(%rip), %rsi      # 0x10a59
callq 0x2370
testl %eax, %eax
je 0xd2e8
movq %rbp, %rdi
leaq 0x37d0(%rip), %rsi      # 0x10a63
callq 0x2370
testl %eax, %eax
je 0xd306
movq %rbp, %rdi
leaq 0x37c5(%rip), %rsi      # 0x10a6b
callq 0x2370
testl %eax, %eax
je 0xd315
movq %rbp, %rdi
leaq 0x37bc(%rip), %rsi      # 0x10a75
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xd324
testl %eax, %eax
jne 0xd324
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x56e9
movq %rax, 0x7fe3(%rip)      # 0x152c0
jmp 0xd3ee
incl 0x7fc8(%rip)            # 0x152b0
movl $0x1, 0x7fc2(%rip)      # 0x152b4
jmp 0xd3ee
movl $0x0, 0x7f67(%rip)      # 0x15268
jmp 0xd3ee
movl $0x1, 0x7fc0(%rip)      # 0x152d0
jmp 0xd3ee
movl $0x1, 0x7fb5(%rip)      # 0x152d4
jmp 0xd3ee
movq %rbp, %rdi
leaq 0x3750(%rip), %rsi      # 0x10a7e
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xd352
testl %eax, %eax
jne 0xd352
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x7f23(%rip)      # 0x15270
jmp 0xd3ee
movq %rbp, %rdi
leaq 0x372b(%rip), %rsi      # 0x10a87
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xd37d
testl %eax, %eax
jne 0xd37d
incl %r13d
movq 0x8(%rbx,%r12,8), %rax
movq %rax, 0x7f3d(%rip)      # 0x152b8
jmp 0xd3ee
movq %rbp, %rdi
leaq 0x370c(%rip), %rsi      # 0x10a93
callq 0x2370
cmpl 0xc(%rsp), %r13d
je 0xd3b6
testl %eax, %eax
jne 0xd3b6
incl %r13d
movq 0x8(%rbx,%r12,8), %rdi
callq 0x23e0
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
movl %eax, 0x7ec4(%rip)      # 0x15278
jmp 0xd3ee
movq %rbp, %rdi
leaq 0x36df(%rip), %rsi      # 0x10a9f
callq 0x2370
testl %eax, %eax
jne 0xd4c1
movl $0x0, 0x7ea1(%rip)      # 0x15278
movl $0x1, %eax
movl %eax, 0x7eee(%rip)      # 0x152d0
movl %eax, 0x7eec(%rip)      # 0x152d4
movl %eax, 0x7ec6(%rip)      # 0x152b4
incl %r13d
cmpl %r14d, %r13d
jl 0xd245
movl $0x3, %edi
callq 0x20c0
cmpq $0x0, 0x7eb4(%rip)      # 0x152c0
jne 0xd42b
callq 0xd156
cmpq $0x0, 0x7ea5(%rip)      # 0x152c0
jne 0xd42b
leaq 0x37e7(%rip), %rdi      # 0x10c0b
callq 0x23d0
jmp 0xd45b
xorl %edi, %edi
callq 0x2210
movq %rax, 0x7ea7(%rip)      # 0x152e0
xorps %xmm0, %xmm0
movups %xmm0, 0x7ea5(%rip)     # 0x152e8
movl $0x1, %edi
callq 0x90d1
movq %rax, %fs:-0x8
testq %rax, %rax
jne 0xd465
movl $0x1, %edi
callq 0x2300
movups 0x7934(%rip), %xmm0     # 0x14da0
leaq 0x10(%rsp), %rdi
movaps %xmm0, (%rdi)
callq 0x2a2f
leaq 0x36bb(%rip), %rdi      # 0x10b3b
leaq 0x8281(%rip), %rsi      # 0x15708
movl $0x1, %edx
callq 0xc727
movq %rax, 0x8268(%rip)      # 0x15700
leaq 0x36b3(%rip), %rdi      # 0x10b52
leaq 0x828a(%rip), %rsi      # 0x15730
movl $0x1, %edx
callq 0xc727
movq %rax, 0x8271(%rip)      # 0x15728
callq 0xd0a1
callq 0xd124
movq (%rbx), %rsi
leaq 0x35de(%rip), %rdi      # 0x10aa9
xorl %eax, %eax
callq 0x2030
jmp 0xd45b