// File: /workspace/github_c_makefile_star2_O3/Cotix[P]cReddit/src/main.c
// Function: main
int main(int argc, char *argv[])
{
    RedditUserLogged *user = NULL;
    char *subreddit = NULL;
    char *password = NULL, *username = NULL;
    optParser parser;

    DEBUG_START(DEBUG_FILE, DEBUG_FILENAME);

    memset(&parser, 0, sizeof(optParser));

    parser.argc = argc;
    parser.argv = argv;

    optAddOptions (&parser, mainOptions, MOPT_ARG_COUNT);

    handleArguments(&parser);

    if (mainOptions[MOPT_HELP].isSet) {
        displayHelp(&parser);
        return 0;
    }

    optClearParser(&parser);

    setlocale(LC_CTYPE, "");


    initscr();
    raw();//We want character for character input
    keypad(stdscr,1);//Enable extra keys like arrowkeys
    noecho();
    start_color();
    use_default_colors();
    init_pair(1, -1, -1);
    init_pair(2, COLOR_BLACK, COLOR_WHITE);

    DEBUG_PRINT(L"Starting...\n");

    /* Start libreddit */
    redditGlobalInit();

    globalState = redditStateNew();

    globalState->userAgent = redditCopyString("cReddit/0.0.1");

    redditStateSet(globalState);

    if (mainOptions[MOPT_USERNAME].isSet) {
        username = mainOptions[MOPT_USERNAME].svalue;
        if (!mainOptions[MOPT_PASSWORD].isSet)
            password = getPassword();
        else
            password = mainOptions[MOPT_PASSWORD].svalue;

        user = redditUserLoggedNew();
        redditUserLoggedLogin(user, username, password);

        /* Don't want to leave that important Reddit password in memory */
        memset(password, 0, strlen(password));
        if (!mainOptions[MOPT_PASSWORD].isSet)
            free(password);
    }
    if (mainOptions[MOPT_SUBREDDIT].isSet) {
        subreddit = mainOptions[MOPT_SUBREDDIT].svalue;
        if (!startsWith("/r/", subreddit) && strcmp("/", subreddit) != 0)
            prepend("/r/", subreddit);

    } else {
        subreddit = "/";
    }
    showSubreddit(subreddit);

    redditUserLoggedFree(user);
    redditStateFree(globalState);
    redditGlobalCleanup();
    endwin();

    DEBUG_END(DEBUG_FILE);
    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
subq $0x28, %rsp
xorps %xmm0, %xmm0
movq %rsp, %rbx
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
movq $0x0, 0x20(%rbx)
movl %edi, (%rbx)
movq %rsi, 0x8(%rbx)
leaq 0x5101(%rip), %rsi      # 0x92c0
movq %rbx, %rdi
movl $0x4, %edx
callq 0x4388
movq %rbx, %rdi
callq 0x3ffb
testb $0x1, 0x586a(%rip)      # 0x9a45
jne 0x4298
movq %rsp, %rdi
callq 0x441d
leaq 0x2421(%rip), %rsi      # 0x6611
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x21d0
callq 0x2190
callq 0x20a0
movq 0x4dd6(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x20c0
callq 0x23a0
callq 0x2120
callq 0x21c0
movl $0x1, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2180
movl $0x2, %edi
xorl %esi, %esi
movl $0x7, %edx
callq 0x2180
xorl %eax, %eax
callq 0x2330
xorl %eax, %eax
callq 0x2210
movq %rax, 0x5830(%rip)      # 0x9a90
leaq 0x23ab(%rip), %rdi      # 0x6612
callq 0x2060
movq 0x581d(%rip), %rdi      # 0x9a90
movq %rax, 0x8(%rdi)
callq 0x2130
testb $0x1, 0x53e2(%rip)      # 0x9665
je 0x42ee
testb $0x1, 0x55c9(%rip)      # 0x9855
jne 0x42a5
callq 0x3f9f
movq %rax, %r14
jmp 0x42ac
movq %rsp, %rdi
callq 0x4109
jmp 0x437e
leaq 0x55b0(%rip), %r14      # 0x985c
xorl %eax, %eax
callq 0x2090
movq %rax, %rbx
leaq 0x53af(%rip), %rsi      # 0x966c
movq %rax, %rdi
movq %r14, %rdx
callq 0x2370
movq %r14, %rdi
callq 0x20d0
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2110
testb $0x1, 0x5571(%rip)      # 0x9855
jne 0x42ee
movq %r14, %rdi
callq 0x2230
testb $0x1, 0x5180(%rip)      # 0x9475
jne 0x4300
leaq 0x2324(%rip), %r14      # 0x6622
jmp 0x4356
leaq 0x2319(%rip), %rdi      # 0x6620
leaq 0x516e(%rip), %r14      # 0x947c
movq %r14, %rsi
callq 0x3f1f
testl %eax, %eax
jne 0x4356
cmpw $0x2f, 0x515a(%rip)     # 0x947c
je 0x4356
leaq 0x5151(%rip), %r14      # 0x947c
movq %r14, %rdi
callq 0x20d0
leaq 0x1(%rax), %rdx
leaq 0x5141(%rip), %rdi      # 0x947f
movq %r14, %rsi
callq 0x2310
movw $0x722f, 0x512d(%rip)   # imm = 0x722F
movb $0x2f, 0x5128(%rip)     # 0x947e
movq %r14, %rdi
callq 0x3b5f
movq %rbx, %rdi
callq 0x20b0
movq 0x5723(%rip), %rdi      # 0x9a90
callq 0x2240
xorl %eax, %eax
callq 0x2200
callq 0x2360
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
retq