// File: /workspace/github_c_makefile_star2_O2/Cotix[P]cReddit/src/main.c
// Function: showThread
void showThread(RedditLink *link)
{
    CommentScreen *screen = NULL;
    RedditCommentList *list = NULL;
    RedditErrno err;

    if (link == NULL)
        return ;

    list = redditCommentListNew();
    list->permalink = redditCopyString(link->permalink);

    err = redditGetCommentList(list);
    if (err != REDDIT_SUCCESS || list->baseComment->replyCount == 0)
        goto cleanup;

    /*screen = getCommentScreenFromCommentList(list, COLS); */
    screen = commentScreenNew();

    screen->offset = 0;
    screen->selected = 0;
    screen->displayed = LINES - 1;
    screen->commentOpenSize = (screen->displayed / 5) * 4;
    screen->list = list;
    screen->width = COLS;

    commentScreenRenderLines(screen);
    commentScreenDisplay(screen);
    int c;
    while((c = wgetch(stdscr))) {
        switch(c) {
            case 'j': case KEY_DOWN:
                commentScreenDown(screen);
                break;
            case 'k': case KEY_UP:
                commentScreenUp(screen);
                break;
                
            case KEY_NPAGE:
                commentScreenLevelDown(screen);
                break;
            case KEY_PPAGE:
                commentScreenLevelUp(screen);
                break;

            case 'J':
                commentScreenCommentScrollDown(screen);
                break;
            case 'K':
                commentScreenCommentScrollUp(screen);
                break;

            case 'l': case '\n': case KEY_ENTER:
                commentScreenToggleComment(screen);
                break;
            case 'm':
                redditGetCommentChildren(screen->list, screen->lines[screen->selected]->comment);
                commentScreenRenderLines(screen);
                break;

            case 'q': case 'h':
                if (screen->commentOpen) {
                    commentScreenCloseComment(screen);
                } else {
                    goto cleanup;
                }
                break;
        }
        commentScreenDisplay(screen);
    }

cleanup:;
    redditCommentListFree(list);
    commentScreenFree(screen);
    return ;
}

// Assembly:
testq %rdi, %rdi
je 0x2ec0
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x2300
movq %rax, %rbx
movq 0x10(%r15), %rdi
callq 0x2060
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x2340
testl %eax, %eax
je 0x2ec1
movq %rbx, %rdi
callq 0x2040
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x26d2
retq
movq (%rbx), %rax
cmpl $0x0, (%rax)
je 0x3010
callq 0x2686
movq %rax, %r14
andq $0x0, 0x1c(%rax)
movq 0x50df(%rip), %rax      # 0x7fc0
movl (%rax), %eax
decl %eax
movl %eax, 0x18(%r14)
pushq $0x5
popq %rcx
cltd
idivl %ecx
shll $0x2, %eax
movl %eax, 0x28(%r14)
movq %rbx, (%r14)
movq 0x50c8(%rip), %rax      # 0x7fc8
movl (%rax), %eax
movl %eax, 0x24(%r14)
movq %r14, %rdi
callq 0x28da
movq %r14, %rdi
callq 0x2b1e
movq 0x50c3(%rip), %r15      # 0x7fe0
leaq 0x10e0(%rip), %r12      # 0x4004
movq (%r15), %rdi
callq 0x2250
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
jbe 0x2f7f
cmpl $0xa, %eax
je 0x2f9d
cmpl $0x4a, %eax
je 0x2fe7
cmpl $0x4b, %eax
je 0x2ff1
cmpl $0x102, %eax            # imm = 0x102
je 0x2fa7
cmpl $0x103, %eax            # imm = 0x103
je 0x2fb1
cmpl $0x152, %eax            # imm = 0x152
je 0x2fdd
cmpl $0x153, %eax            # imm = 0x153
je 0x2ffb
cmpl $0x157, %eax            # imm = 0x157
je 0x2f9d
testl %eax, %eax
jne 0x3003
jmp 0x2ea5
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
testb $0x1, 0x2c(%r14)
je 0x2ea5
movq %r14, %rdi
callq 0x2e46
jmp 0x3003
movq %r14, %rdi
callq 0x2e60
jmp 0x3003
movq %r14, %rdi
callq 0x2934
jmp 0x3003
movq %r14, %rdi
callq 0x29fc
jmp 0x3003
movq (%r14), %rdi
movq 0x10(%r14), %rax
movslq 0x20(%r14), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rsi
callq 0x2080
movq %r14, %rdi
callq 0x28da
jmp 0x3003
movq %r14, %rdi
callq 0x2964
jmp 0x3003
movq %r14, %rdi
callq 0x2a18
jmp 0x3003
movq %r14, %rdi
callq 0x2a95
jmp 0x3003
movq %r14, %rdi
callq 0x29ae
movq %r14, %rdi
callq 0x2b1e
jmp 0x2f24
xorl %r14d, %r14d
jmp 0x2ea5