// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x28, %rsp
movl $0x0, 0x24(%rsp)
movl %edi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
xorl %eax, %eax
movl %eax, %edi
callq 0x21e0
movl %eax, %edi
callq 0x2210
movl $0x1, 0x14(%rsp)
movl 0x14(%rsp), %eax
cmpl 0x20(%rsp), %eax
jge 0x14609
movl 0x20(%rsp), %eax
subl 0x14(%rsp), %eax
subl $0x1, %eax
movl %eax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3586(%rip), %rsi      # 0x178e5
callq 0x2320
cmpl $0x0, %eax
jne 0x14387
movl 0x6f41(%rip), %eax      # 0x1b2b0
addl $0x1, %eax
movl %eax, 0x6f38(%rip)      # 0x1b2b0
movl $0x1, 0x6f32(%rip)      # 0x1b2b4
jmp 0x145f7
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3551(%rip), %rsi      # 0x178ed
callq 0x2320
cmpl $0x0, %eax
jne 0x143b5
movl $0x0, 0x6e90(%rip)      # 0x1b240
jmp 0x145f5
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3531(%rip), %rsi      # 0x178fb
callq 0x2320
cmpl $0x0, %eax
jne 0x143e3
movl $0x1, 0x6ed6(%rip)      # 0x1b2b4
jmp 0x145f3
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x350d(%rip), %rsi      # 0x17905
callq 0x2320
cmpl $0x0, %eax
jne 0x14411
movl $0x1, 0x6ec4(%rip)      # 0x1b2d0
jmp 0x145f1
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x34e7(%rip), %rsi      # 0x1790d
callq 0x2320
cmpl $0x0, %eax
jne 0x1443f
movl $0x1, 0x6e9a(%rip)      # 0x1b2d4
jmp 0x145ef
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x34c3(%rip), %rsi      # 0x17917
callq 0x2320
cmpl $0x0, %eax
jne 0x1448d
cmpl $0x0, 0x10(%rsp)
je 0x1448d
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x8630
movq %rax, 0x6e38(%rip)      # 0x1b2c0
jmp 0x145ed
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x347e(%rip), %rsi      # 0x17920
callq 0x2320
cmpl $0x0, %eax
jne 0x144d6
cmpl $0x0, 0x10(%rsp)
je 0x144d6
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x6d77(%rip)      # 0x1b248
jmp 0x145eb
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x343e(%rip), %rsi      # 0x17929
callq 0x2320
cmpl $0x0, %eax
jne 0x1451f
cmpl $0x0, 0x10(%rsp)
je 0x1451f
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x6d9e(%rip)      # 0x1b2b8
jmp 0x145e9
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x3401(%rip), %rsi      # 0x17935
callq 0x2320
cmpl $0x0, %eax
jne 0x1457c
cmpl $0x0, 0x10(%rsp)
je 0x1457c
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rsp)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2380
movl %eax, 0x6ce9(%rip)      # 0x1b250
cmpl $0x0, 0x6ce2(%rip)      # 0x1b250
jge 0x1457a
movl $0x0, 0x6cd6(%rip)      # 0x1b250
jmp 0x145e7
movq 0x18(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x33b0(%rip), %rsi      # 0x17941
callq 0x2320
cmpl $0x0, %eax
jne 0x145c5
movl $0x0, 0x6cab(%rip)      # 0x1b250
movl $0x1, 0x6d21(%rip)      # 0x1b2d0
movl $0x1, 0x6d1b(%rip)      # 0x1b2d4
movl $0x1, 0x6cf1(%rip)      # 0x1b2b4
jmp 0x145e5
movq 0x18(%rsp), %rax
movq (%rax), %rsi
leaq 0x3377(%rip), %rdi      # 0x1794b
movb $0x0, %al
callq 0x2030
movl $0x1, %edi
callq 0x22b0
jmp 0x145e7
jmp 0x145e9
jmp 0x145eb
jmp 0x145ed
jmp 0x145ef
jmp 0x145f1
jmp 0x145f3
jmp 0x145f5
jmp 0x145f7
jmp 0x145f9
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x1432d
movl $0x3, %edi
callq 0x20a0
cmpq $0x0, 0x6ca5(%rip)      # 0x1b2c0
jne 0x14622
callq 0x14220
cmpq $0x0, 0x6c96(%rip)      # 0x1b2c0
jne 0x14644
leaq 0x33aa(%rip), %rdi      # 0x179dd
movb $0x0, %al
callq 0x2030
movl $0x1, %edi
callq 0x22b0
callq 0x142d0
movl $0x1, %edi
callq 0xdf80
movq %rax, %rcx
movq %fs:0x0, %rax
leaq -0x8(%rax), %rax
movq %rcx, (%rax)
movq %fs:0x0, %rax
leaq -0x8(%rax), %rax
cmpq $0x0, (%rax)
jne 0x14689
movl $0x1, %edi
callq 0x22b0
movq 0x6718(%rip), %rax      # 0x1ada8
movq %rax, (%rsp)
movq 0x6715(%rip), %rax      # 0x1adb0
movq %rax, 0x8(%rsp)
movq %rsp, %rdi
callq 0x2b80
leaq 0x3393(%rip), %rdi      # 0x17a42
leaq 0x7052(%rip), %rsi      # 0x1b708
movl $0x1, %edx
callq 0x131e0
movq %rax, 0x7039(%rip)      # 0x1b700
leaq 0x338b(%rip), %rdi      # 0x17a59
leaq 0x705b(%rip), %rsi      # 0x1b730
movl $0x1, %edx
callq 0x131e0
movq %rax, 0x7042(%rip)      # 0x1b728
callq 0x14110
callq 0x141d0
xorl %eax, %eax
addq $0x28, %rsp
retq