// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movl $0x0, 0x64(%rsp)
movl %edi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x48(%rsp)
movq $0x0, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
jmp 0x508b
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
movl $0x28, %edx
callq 0x2110
movl 0x60(%rsp), %eax
movl %eax, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x51e6(%rip), %rsi      # 0xa2a0
movl $0x4, %edx
callq 0x5310
leaq 0x10(%rsp), %rdi
callq 0x4dc0
movb 0x5951(%rip), %al       # 0xaa25
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x50f5
leaq 0x10(%rsp), %rdi
callq 0x4f90
movl $0x0, 0x64(%rsp)
jmp 0x52fb
leaq 0x10(%rsp), %rdi
callq 0x5410
xorl %edi, %edi
leaq 0x2411(%rip), %rsi      # 0x7519
callq 0x21c0
callq 0x2180
callq 0x20a0
movq 0x4ec2(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
movl $0x1, %esi
callq 0x20c0
callq 0x2370
callq 0x2120
callq 0x21b0
movl $0x1, %edi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl %edx, %esi
callq 0x2170
movl $0x2, %edi
xorl %esi, %esi
movl $0x7, %edx
callq 0x2170
jmp 0x515e
movb $0x0, %al
callq 0x2300
movb $0x0, %al
callq 0x2200
movq %rax, 0x58fd(%rip)      # 0xaa70
leaq 0x24dc(%rip), %rdi      # 0x7656
callq 0x2060
movq %rax, %rcx
movq 0x58e7(%rip), %rax      # 0xaa70
movq %rcx, 0x8(%rax)
movq 0x58dc(%rip), %rdi      # 0xaa70
callq 0x2130
movb 0x54a6(%rip), %al       # 0xa645
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x5258
leaq 0x50ec(%rip), %rax      # 0xa2a0
addq $0x1f0, %rax            # imm = 0x1F0
addq $0x1bc, %rax            # imm = 0x1BC
movq %rax, 0x38(%rsp)
movb 0x566a(%rip), %al       # 0xa835
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x51e1
callq 0x4d40
movq %rax, 0x40(%rsp)
jmp 0x51f9
leaq 0x50b8(%rip), %rax      # 0xa2a0
addq $0x3e0, %rax            # imm = 0x3E0
addq $0x1bc, %rax            # imm = 0x1BC
movq %rax, 0x40(%rsp)
movb $0x0, %al
callq 0x2090
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x2340
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x40(%rsp), %rdi
callq 0x20d0
movq 0x8(%rsp), %rdi
movq %rax, %rdx
xorl %esi, %esi
callq 0x2110
movb 0x55f3(%rip), %al       # 0xa835
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x5256
movq 0x40(%rsp), %rdi
callq 0x2220
jmp 0x5258
movb 0x51f7(%rip), %al       # 0xa455
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x52b9
leaq 0x5031(%rip), %rax      # 0xa2a0
addq $0x1bc, %rax            # imm = 0x1BC
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rsi
leaq 0x23de(%rip), %rdi      # 0x7664
callq 0x4c60
cmpl $0x0, %eax
jne 0x52b7
movq 0x48(%rsp), %rsi
leaq 0x23ca(%rip), %rdi      # 0x7666
callq 0x2260
cmpl $0x0, %eax
je 0x52b7
movq 0x48(%rsp), %rsi
leaq 0x23b2(%rip), %rdi      # 0x7664
callq 0x4cd0
jmp 0x52c5
leaq 0x23a6(%rip), %rax      # 0x7666
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rdi
callq 0x46d0
movq 0x50(%rsp), %rdi
callq 0x20b0
movq 0x5790(%rip), %rdi      # 0xaa70
callq 0x2230
movb $0x0, %al
callq 0x21f0
callq 0x2330
jmp 0x52f3
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)
nop