// File: /workspace/github_c_makefile_star2_O1/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 0x3131
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r15
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x22f0
movq %rax, %rbx
movq 0x10(%r15), %rdi
callq 0x2060
movq %rax, 0x10(%rbx)
movq %rbx, %rdi
callq 0x2330
testl %eax, %eax
je 0x3132
movq %rbx, %rdi
callq 0x2040
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x271e
retq
movq (%rbx), %rax
cmpl $0x0, (%rax)
je 0x32df
movl $0x30, %edi
callq 0x2250
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movq 0x5e60(%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 0x5e39(%rip), %rax      # 0x8fc8
movl (%rax), %eax
movl %eax, 0x24(%r14)
movq %r14, %rdi
callq 0x2935
movq %r14, %rdi
callq 0x2b82
movq 0x5e34(%rip), %r15      # 0x8fe0
leaq 0x1e9d(%rip), %r12      # 0x5050
movq (%r15), %rdi
callq 0x2240
cmpl $0x101, %eax            # imm = 0x101
jg 0x3203
cmpl $0x4a, %eax
jle 0x3224
leal -0x68(%rax), %ecx
cmpl $0x9, %ecx
ja 0x3299
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movb 0x2c(%r14), %al
testb $0x1, %al
je 0x3116
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 0x32d2
cmpl $0x151, %eax            # imm = 0x151
jle 0x324c
cmpl $0x152, %eax            # imm = 0x152
je 0x3285
cmpl $0x153, %eax            # imm = 0x153
je 0x328f
cmpl $0x157, %eax            # imm = 0x157
je 0x323f
jmp 0x32d2
cmpl $0xa, %eax
je 0x323f
cmpl $0x4a, %eax
jne 0x32ca
movq %r14, %rdi
callq 0x2a8a
jmp 0x32d2
movq %r14, %rdi
callq 0x30c2
jmp 0x32d2
cmpl $0x102, %eax            # imm = 0x102
je 0x327b
cmpl $0x103, %eax            # imm = 0x103
jne 0x32d2
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 0x32d2
decl %eax
movl %eax, 0x1c(%r14)
jmp 0x32d2
movq %r14, %rdi
callq 0x29a6
jmp 0x32d2
movq %r14, %rdi
callq 0x29d6
jmp 0x32d2
movq %r14, %rdi
callq 0x2a20
jmp 0x32d2
cmpl $0x4b, %eax
jne 0x32d2
movq %r14, %rdi
callq 0x2b02
jmp 0x32d2
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 0x2935
jmp 0x32d2
testl %eax, %eax
je 0x3116
movq %r14, %rdi
callq 0x2b82
jmp 0x31b3
xorl %r14d, %r14d
jmp 0x3116