// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r14
pushq %rbx
subq $0x30, %rsp
xorps %xmm0, %xmm0
movq %rsp, %rbx
andq $0x0, 0x20(%rbx)
movaps %xmm0, (%rbx)
movaps %xmm0, 0x10(%rbx)
movl %edi, (%rbx)
movq %rsi, 0x8(%rbx)
leaq 0x4697(%rip), %rsi      # 0x82c0
pushq $0x4
popq %rdx
movq %rbx, %rdi
callq 0x3dcc
movq %rbx, %rdi
callq 0x3a73
testb $0x1, 0x4e02(%rip)      # 0x8a45
jne 0x3cf4
movq %rsp, %rdi
callq 0x3e65
leaq 0x196d(%rip), %rsi      # 0x55c5
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x21d0
callq 0x2190
callq 0x20a0
movq 0x436e(%rip), %rax      # 0x7fe0
movq (%rax), %rdi
pushq $0x1
popq %rbp
movl %ebp, %esi
callq 0x20c0
callq 0x23a0
callq 0x2120
callq 0x21c0
pushq $-0x1
popq %rdx
movl %ebp, %edi
movl %edx, %esi
callq 0x2180
pushq $0x2
popq %rdi
pushq $0x7
popq %rdx
xorl %esi, %esi
callq 0x2180
xorl %eax, %eax
callq 0x2330
xorl %eax, %eax
callq 0x2210
movq %rax, 0x4dd4(%rip)      # 0x8a90
leaq 0x1903(%rip), %rdi      # 0x55c6
callq 0x2060
movq 0x4dc1(%rip), %rdi      # 0x8a90
movq %rax, 0x8(%rdi)
callq 0x2130
testb $0x1, 0x4986(%rip)      # 0x8665
je 0x3d4a
testb $0x1, 0x4b6d(%rip)      # 0x8855
jne 0x3d01
callq 0x3a17
movq %rax, %r14
jmp 0x3d08
movq %rsp, %rdi
callq 0x3b81
jmp 0x3dbe
leaq 0x4b54(%rip), %r14      # 0x885c
xorl %eax, %eax
callq 0x2090
movq %rax, %rbx
leaq 0x4953(%rip), %rsi      # 0x866c
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, 0x4b15(%rip)      # 0x8855
jne 0x3d4a
movq %r14, %rdi
callq 0x2230
testb $0x1, 0x4724(%rip)      # 0x8475
jne 0x3d5c
leaq 0x187c(%rip), %r14      # 0x55d6
jmp 0x3d96
leaq 0x1871(%rip), %rdi      # 0x55d4
leaq 0x4712(%rip), %r14      # 0x847c
movq %r14, %rsi
callq 0x3997
testl %eax, %eax
jne 0x3d96
cmpw $0x2f, 0x46fe(%rip)     # 0x847c
je 0x3d96
leaq 0x184d(%rip), %rdi      # 0x55d4
leaq 0x46ee(%rip), %r14      # 0x847c
movq %r14, %rsi
callq 0x39d9
movq %r14, %rdi
callq 0x36a4
movq %rbx, %rdi
callq 0x20b0
movq 0x4ce3(%rip), %rdi      # 0x8a90
callq 0x2240
xorl %eax, %eax
callq 0x2200
callq 0x2360
xorl %eax, %eax
addq $0x30, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)