// File: /workspace/github_c_makefile_star2_O1/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 0x5051(%rip), %rsi      # 0x92b0
movq %rbx, %rdi
movl $0x4, %edx
callq 0x4428
movq %rbx, %rdi
callq 0x409b
testb $0x1, 0x57ba(%rip)      # 0x9a35
jne 0x4338
movq %rsp, %rdi
callq 0x44b6
leaq 0x2381(%rip), %rsi      # 0x6611
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x21c0
callq 0x2180
callq 0x20a0
movq 0x4d36(%rip), %rax      # 0x8fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x20c0
callq 0x2390
callq 0x2120
callq 0x21b0
movl $0x1, %edi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0x2170
movl $0x2, %edi
xorl %esi, %esi
movl $0x7, %edx
callq 0x2170
xorl %eax, %eax
callq 0x2320
xorl %eax, %eax
callq 0x2200
movq %rax, 0x5780(%rip)      # 0x9a80
leaq 0x230b(%rip), %rdi      # 0x6612
callq 0x2060
movq 0x576d(%rip), %rdi      # 0x9a80
movq %rax, 0x8(%rdi)
callq 0x2130
testb $0x1, 0x5332(%rip)      # 0x9655
je 0x438e
testb $0x1, 0x5519(%rip)      # 0x9845
jne 0x4345
callq 0x403f
movq %rax, %r14
jmp 0x434c
movq %rsp, %rdi
callq 0x41a9
jmp 0x441e
leaq 0x5500(%rip), %r14      # 0x984c
xorl %eax, %eax
callq 0x2090
movq %rax, %rbx
leaq 0x52ff(%rip), %rsi      # 0x965c
movq %rax, %rdi
movq %r14, %rdx
callq 0x2360
movq %r14, %rdi
callq 0x20d0
movq %r14, %rdi
xorl %esi, %esi
movq %rax, %rdx
callq 0x2110
testb $0x1, 0x54c1(%rip)      # 0x9845
jne 0x438e
movq %r14, %rdi
callq 0x2220
testb $0x1, 0x50d0(%rip)      # 0x9465
jne 0x43a0
leaq 0x2284(%rip), %r14      # 0x6622
jmp 0x43f6
leaq 0x2279(%rip), %rdi      # 0x6620
leaq 0x50be(%rip), %r14      # 0x946c
movq %r14, %rsi
callq 0x3fbf
testl %eax, %eax
jne 0x43f6
cmpw $0x2f, 0x50aa(%rip)     # 0x946c
je 0x43f6
leaq 0x50a1(%rip), %r14      # 0x946c
movq %r14, %rdi
callq 0x20d0
leaq 0x1(%rax), %rdx
leaq 0x5091(%rip), %rdi      # 0x946f
movq %r14, %rsi
callq 0x2300
movw $0x722f, 0x507d(%rip)   # imm = 0x722F
movb $0x2f, 0x5078(%rip)     # 0x946e
movq %r14, %rdi
callq 0x3ba1
movq %rbx, %rdi
callq 0x20b0
movq 0x5673(%rip), %rdi      # 0x9a80
callq 0x2230
xorl %eax, %eax
callq 0x21f0
callq 0x2350
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r14
retq