// File: /workspace/github_c_makefile_star2_O0/Cotix[P]cReddit/src/main.c
// Function: showSubreddit
void showSubreddit(const char *subreddit)
{
    LinkScreen *screen;
    RedditListType listType = REDDIT_HOT; // Default RedditListType for screen is 'hot'

    DEBUG_PRINT(L"Loading Subreddit %s\n", subreddit);
    screen = linkScreenNew();

    linkScreenSetup(screen, subreddit, listType);

    drawScreen(screen); //And print the screen!

    int c;
    while((c = wgetch(stdscr))) {
        switch(c) {
            case 'k': case KEY_UP:
                linkScreenUp(screen);
                drawScreen(screen);
                break;

            case 'j': case KEY_DOWN:
                linkScreenDown(screen);
                drawScreen(screen);
                break;
            case 'K':
                linkScreenTextScrollUp(screen);
                drawScreen(screen);
                break;
            case 'J':
                linkScreenTextScrollDown(screen);
                drawScreen(screen);
                break;
            case 'q':
                if (screen->linkOpen) {
                    linkScreenCloseLink(screen);
                    drawScreen(screen);
                } else {
                    goto cleanup;
                }
                break;
            case 'u':
                redditLinkListFreeLinks(screen->list);
                redditGetListing(screen->list);
                screen->offset = 0;
                screen->selected = 0;
                drawScreen(screen);
                break;
            case 'l': case '\n': case KEY_ENTER:
                if (screen->helpOpen)
                    linkScreenCloseHelp(screen);
                else
                    linkScreenToggleLink(screen);
                drawScreen(screen);
                break;
            case 'o':
                if (fork() == 0) {
                    char* const argv[]= {"xdg-open", 
                                        screen->list->links[screen->selected]->url,
                                        NULL};
                    execvp("xdg-open", argv);
                }

                redditLinkListFree(screen->list);
                linkScreenFree(screen);

                screen = linkScreenNew();
                linkScreenSetup(screen, subreddit, listType);

                drawScreen(screen);
                break;
            case 'L':
                redditGetListing(screen->list);
                drawScreen(screen);
                break;
            case 'c':
                showThread(screen->list->links[screen->selected]);
                drawScreen(screen);
                break;
            case '?':
                linkScreenToggleHelp(screen);
                if (screen->helpOpen)
                    linkScreenOpenLink(screen);
                drawScreen(screen);
                break;
            case '1':
                if (screen->list->type != REDDIT_HOT)
                {
                    listType = REDDIT_HOT;
                    redditLinkListFree(screen->list);
                    linkScreenFree(screen);

                    screen = linkScreenNew();
                    linkScreenSetup(screen, subreddit, listType);

                    drawScreen(screen);
                }
                break;
            case '2':
                if (screen->list->type != REDDIT_NEW)
                {
                    listType = REDDIT_NEW;
                    redditLinkListFree(screen->list);
                    linkScreenFree(screen);

                    screen = linkScreenNew();
                    linkScreenSetup(screen, subreddit, listType);

                    drawScreen(screen);
                }
                break;
            case '3':
                if (screen->list->type != REDDIT_RISING)
                {
                    listType = REDDIT_RISING;
                    redditLinkListFree(screen->list);
                    linkScreenFree(screen);

                    screen = linkScreenNew();
                    linkScreenSetup(screen, subreddit, listType);

                    drawScreen(screen);
                }
                break;
            case '4':
                if (screen->list->type != REDDIT_CONTR)
                {
                    listType = REDDIT_CONTR;
                    redditLinkListFree(screen->list);
                    linkScreenFree(screen);

                    screen = linkScreenNew();
                    linkScreenSetup(screen, subreddit, listType);

                    drawScreen(screen);
                }
                break;
            case '5':
                if (screen->list->type != REDDIT_TOP)
                {
                    listType = REDDIT_TOP;
                    redditLinkListFree(screen->list);
                    linkScreenFree(screen);

                    screen = linkScreenNew();
                    linkScreenSetup(screen, subreddit, listType);

                    drawScreen(screen);
                }
                break;
        }
    }

cleanup:;
    redditLinkListFree(screen->list);
    linkScreenFree(screen);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movl $0x0, 0x34(%rsp)
jmp 0x46e3
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
movq 0x58cf(%rip), %rax      # 0x9fe0
movq (%rax), %rdi
callq 0x2240
movl %eax, 0x30(%rsp)
cmpl $0x0, %eax
je 0x4c34
movl 0x30(%rsp), %eax
movl %eax, 0xc(%rsp)
subl $0xa, %eax
je 0x492a
jmp 0x4739
movl 0xc(%rsp), %eax
subl $0x31, %eax
je 0x4a78
jmp 0x4748
movl 0xc(%rsp), %eax
subl $0x32, %eax
je 0x4ad1
jmp 0x4757
movl 0xc(%rsp), %eax
subl $0x33, %eax
je 0x4b2a
jmp 0x4766
movl 0xc(%rsp), %eax
subl $0x34, %eax
je 0x4b83
jmp 0x4775
movl 0xc(%rsp), %eax
subl $0x35, %eax
je 0x4bd9
jmp 0x4784
movl 0xc(%rsp), %eax
subl $0x3f, %eax
je 0x4a41
jmp 0x4793
movl 0xc(%rsp), %eax
subl $0x4a, %eax
je 0x489e
jmp 0x47a2
movl 0xc(%rsp), %eax
subl $0x4b, %eax
je 0x4885
jmp 0x47b1
movl 0xc(%rsp), %eax
subl $0x4c, %eax
je 0x49f8
jmp 0x47c0
movl 0xc(%rsp), %eax
subl $0x63, %eax
je 0x4a14
jmp 0x47cf
movl 0xc(%rsp), %eax
subl $0x6a, %eax
je 0x486c
jmp 0x47de
movl 0xc(%rsp), %eax
subl $0x6b, %eax
je 0x4853
jmp 0x47e9
movl 0xc(%rsp), %eax
subl $0x6c, %eax
je 0x492a
jmp 0x47f8
movl 0xc(%rsp), %eax
subl $0x6f, %eax
je 0x4963
jmp 0x4807
movl 0xc(%rsp), %eax
subl $0x71, %eax
je 0x48b7
jmp 0x4816
movl 0xc(%rsp), %eax
subl $0x75, %eax
je 0x48e9
jmp 0x4825
movl 0xc(%rsp), %eax
subl $0x102, %eax            # imm = 0x102
je 0x486c
jmp 0x4832
movl 0xc(%rsp), %eax
subl $0x103, %eax            # imm = 0x103
je 0x4853
jmp 0x483f
movl 0xc(%rsp), %eax
subl $0x157, %eax            # imm = 0x157
je 0x492a
jmp 0x4c2f
movq 0x38(%rsp), %rdi
callq 0x4330
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rdi
callq 0x4290
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rdi
callq 0x4460
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rdi
callq 0x4380
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movb 0x2c(%rax), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x48df
movq 0x38(%rsp), %rdi
callq 0x45f0
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x48e4
jmp 0x4c36
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x2100
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x2140
movq 0x38(%rsp), %rax
movl $0x0, 0xc(%rax)
movq 0x38(%rsp), %rax
movl $0x0, 0x10(%rax)
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movb 0x2c(%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x494a
movq 0x38(%rsp), %rdi
callq 0x4680
jmp 0x4954
movq 0x38(%rsp), %rdi
callq 0x4630
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
callq 0x2050
cmpl $0x0, %eax
jne 0x49b5
leaq 0x2b24(%rip), %rax      # 0x7498
movq %rax, 0x10(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x10(%rsp), %rsi
leaq 0x2ae8(%rip), %rdi      # 0x7498
callq 0x2190
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x2140
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax), %rax
movq 0x38(%rsp), %rcx
movslq 0x10(%rcx), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3740
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rdi
callq 0x46a0
movq 0x38(%rsp), %rax
movb 0x2c(%rax), %al
shrb %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
je 0x4a69
movq 0x38(%rsp), %rdi
callq 0x4570
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x4acc
movl $0x0, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpl $0x1, 0x10(%rax)
je 0x4b25
movl $0x1, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpl $0x2, 0x10(%rax)
je 0x4b7e
movl $0x2, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpl $0x3, 0x10(%rax)
je 0x4bd7
movl $0x3, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
movq 0x38(%rsp), %rax
movq (%rax), %rax
cmpl $0x4, 0x10(%rax)
je 0x4c2d
movl $0x4, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
callq 0x2670
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movl 0x34(%rsp), %edx
callq 0x2710
movq 0x38(%rsp), %rdi
callq 0x3fb0
jmp 0x4c2f
jmp 0x470a
jmp 0x4c36
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x20f0
movq 0x38(%rsp), %rdi
callq 0x26a0
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)