// File: /workspace/github_c_makefile_star2_O3/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 0x3115
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 0x3116
movq %rbx, %rdi
callq 0x2040
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2701
retq
movq (%rbx), %rax
cmpl $0x0, (%rax)
je 0x32ba
movl $0x1, %edi
movl $0x30, %esi
callq 0x2170
movq %rax, %r14
movq 0x5e85(%rip), %rax      # 0x8fc0
movl (%rax), %eax
decl %eax
movl %eax, 0x18(%r14)
cltq
imulq $0x66666667, %rax, %rax # imm = 0x66666667
movq %rax, %rcx
shrq $0x3f, %rcx
shrq $0x21, %rax
addl %ecx, %eax
shll $0x2, %eax
movl %eax, 0x28(%r14)
movq %rbx, (%r14)
movq 0x5e5e(%rip), %rax      # 0x8fc8
movl (%rax), %eax
movl %eax, 0x24(%r14)
movq %r14, %rdi
callq 0x2917
movq %r14, %rdi
callq 0x2b6d
movq 0x5e59(%rip), %r15      # 0x8fe0
leaq 0x1ec2(%rip), %r12      # 0x5050
movq (%r15), %rdi
callq 0x2250
cmpl $0x101, %eax            # imm = 0x101
jg 0x31de
cmpl $0x4a, %eax
jle 0x31ff
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
ja 0x3274
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movb 0x2c(%r14), %al
testb $0x1, %al
je 0x30fa
andb $-0x2, %al
movb %al, 0x2c(%r14)
movl 0x18(%r14), %eax
movl 0x28(%r14), %ecx
addl %ecx, %eax
decl %eax
movl %eax, 0x18(%r14)
jmp 0x32ad
cmpl $0x151, %eax            # imm = 0x151
jle 0x3227
cmpl $0x152, %eax            # imm = 0x152
je 0x3260
cmpl $0x153, %eax            # imm = 0x153
je 0x326a
cmpl $0x157, %eax            # imm = 0x157
je 0x321a
jmp 0x32ad
cmpl $0xa, %eax
je 0x321a
cmpl $0x4a, %eax
jne 0x32a5
movq %r14, %rdi
callq 0x2a63
jmp 0x32ad
movq %r14, %rdi
callq 0x30a6
jmp 0x32ad
cmpl $0x102, %eax            # imm = 0x102
je 0x3256
cmpl $0x103, %eax            # imm = 0x103
jne 0x32ad
movl 0x1c(%r14), %eax
movl 0x20(%r14), %ecx
xorl %edx, %edx
testl %ecx, %ecx
setg %dl
subl %edx, %ecx
movl %ecx, 0x20(%r14)
cmpl %eax, %ecx
jge 0x32ad
decl %eax
movl %eax, 0x1c(%r14)
jmp 0x32ad
movq %r14, %rdi
callq 0x297f
jmp 0x32ad
movq %r14, %rdi
callq 0x29af
jmp 0x32ad
movq %r14, %rdi
callq 0x29f9
jmp 0x32ad
cmpl $0x4b, %eax
jne 0x32ad
movq %r14, %rdi
callq 0x2ae2
jmp 0x32ad
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 0x2917
jmp 0x32ad
testl %eax, %eax
je 0x30fa
movq %r14, %rdi
callq 0x2b6d
jmp 0x318e
xorl %r14d, %r14d
jmp 0x30fa