// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
xorl %ebp, %ebp
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x260a
movq %r12, %rdi
callq 0x36f9
movq 0x5440(%rip), %r13      # 0x8fe0
leaq 0x14d1(%rip), %r15      # 0x5078
leaq 0x1506(%rip), %r14      # 0x50b4
movq (%r13), %rdi
callq 0x2250
cmpl $0x62, %eax
jg 0x3c12
cmpl $0x49, %eax
jg 0x3ce6
leal -0x31(%rax), %ecx
cmpl $0xe, %ecx
ja 0x3d1c
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movq (%r12), %rdi
cmpl $0x0, 0x10(%rdi)
je 0x3bae
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
xorl %ebp, %ebp
movq %rax, %rdi
movq %rbx, %rsi
xorl %edx, %edx
jmp 0x3eb4
cmpl $0x101, %eax            # imm = 0x101
jg 0x3ca1
leal -0x6a(%rax), %ecx
cmpl $0xb, %ecx
ja 0x3d47
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
callq 0x2050
testl %eax, %eax
jne 0x3c71
leaq 0x294e(%rip), %rdi      # 0x6590
movq %rdi, (%rsp)
movq (%r12), %rax
movq 0x18(%rax), %rax
movslq 0x10(%r12), %rcx
movq (%rax,%rcx,8), %rax
movq 0x20(%rax), %rax
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq %rsp, %rsi
callq 0x21a0
movq (%r12), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movl %ebp, %edx
jmp 0x3eb4
cmpl $0x102, %eax            # imm = 0x102
je 0x3d0f
cmpl $0x157, %eax            # imm = 0x157
je 0x3d25
cmpl $0x103, %eax            # imm = 0x103
jne 0x3bae
movl 0xc(%r12), %eax
movl 0x10(%r12), %ecx
xorl %edx, %edx
testl %ecx, %ecx
setg %dl
subl %edx, %ecx
movl %ecx, 0x10(%r12)
cmpl %eax, %ecx
jge 0x3eea
decl %eax
movl %eax, 0xc(%r12)
jmp 0x3eea
cmpl $0x4a, %eax
je 0x3ee2
cmpl $0x4b, %eax
je 0x3ed8
cmpl $0x4c, %eax
jne 0x3bae
movq (%r12), %rdi
callq 0x2140
jmp 0x3eea
movq %r12, %rdi
callq 0x39b0
jmp 0x3eea
cmpl $0xa, %eax
jne 0x3ef7
movb 0x2c(%r12), %al
testb $0x2, %al
jne 0x3d3b
movq %r12, %rdi
callq 0x3b32
jmp 0x3eea
andb $-0x3, %al
movb %al, 0x2c(%r12)
jmp 0x3eea
cmpl $0x63, %eax
jne 0x3bae
movq (%r12), %rax
movq 0x18(%rax), %rax
movslq 0x10(%r12), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x30c4
jmp 0x3eea
movb 0x2c(%r12), %al
testb $0x1, %al
je 0x3eff
andb $-0x2, %al
movb %al, 0x2c(%r12)
movl 0x8(%r12), %eax
movl 0x28(%r12), %ecx
addl %ecx, %eax
decl %eax
movl %eax, 0x8(%r12)
jmp 0x3eea
movq (%r12), %rdi
cmpl $0x4, 0x10(%rdi)
je 0x3bae
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
movl $0x4, %ebp
movq %rax, %rdi
movq %rbx, %rsi
movl $0x4, %edx
jmp 0x3eb4
movq (%r12), %rdi
cmpl $0x2, 0x10(%rdi)
je 0x3bae
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
movl $0x2, %ebp
movq %rax, %rdi
movq %rbx, %rsi
movl $0x2, %edx
jmp 0x3eb4
movq (%r12), %rdi
cmpl $0x3, 0x10(%rdi)
je 0x3bae
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
movl $0x3, %ebp
movq %rax, %rdi
movq %rbx, %rsi
movl $0x3, %edx
jmp 0x3eb4
movq (%r12), %rdi
callq 0x2100
movq (%r12), %rdi
callq 0x2140
movq $0x0, 0xc(%r12)
jmp 0x3eea
movq (%r12), %rdi
cmpl $0x1, 0x10(%rdi)
je 0x3bae
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
movl $0x1, %edi
movl $0x40, %esi
callq 0x2170
movq %rax, %r12
movl $0x1, %ebp
movq %rax, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x260a
jmp 0x3eea
movb 0x2c(%r12), %al
movl %eax, %ecx
xorb $0x2, %cl
movb %cl, 0x2c(%r12)
testb $0x2, %al
jne 0x3eea
movq %r12, %rdi
callq 0x3aef
jmp 0x3eea
movq %r12, %rdi
callq 0x3a74
jmp 0x3eea
movq %r12, %rdi
callq 0x39ff
movq %r12, %rdi
callq 0x36f9
jmp 0x3bae
testl %eax, %eax
jne 0x3bae
movq (%r12), %rdi
callq 0x20f0
movq %r12, %rdi
callq 0x25c3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq