// File: /workspace/github_c_makefile_star2_O2/Cotix[P]cReddit/src/main.c
// Function: commentScreenDisplay
void commentScreenDisplay(CommentScreen *screen)
{
    int i, screenLines;
    wchar_t *tmpbuf;
    int bufSize, lastLine, bufLen;

    if (screen == NULL)
        return ;

    bufSize = sizeof(wchar_t) * (COLS + 1);
    bufLen = COLS;
    tmpbuf = malloc(bufSize);
    memset(tmpbuf, 0, bufSize);

    for (i = 0; i < bufLen; i++)
        tmpbuf[i] = L' ';

    screenLines = screen->offset + screen->displayed + 1;

    for (i = 0; i < screen->displayed + screen->offset + 1 + screen->commentOpenSize; i++)
        mvaddwstr(i, 0, tmpbuf);

    attron(COLOR_PAIR(1));

    for(i = screen->offset; i < screenLines; i++) {
        if(i == screen->selected)
            attron(COLOR_PAIR(2));

        if (i < screen->lineCount && screen->lines[i]->text != NULL)
            mvaddwstr(i - screen->offset, 0, screen->lines[i]->text);
        else
            mvaddwstr(i - screen->offset, 0, tmpbuf);

        if (i == screen->selected)
            attron(COLOR_PAIR(1));
    }

    if (screen->commentOpen) {
        RedditComment *current;
        lastLine = screenLines - screen->offset;

        for (i = lastLine; i < lastLine + screen->commentOpenSize; i++)
            mvaddwstr(i, 0, tmpbuf);

        for (i = 0; i < bufLen; i++)
            tmpbuf[i] = L'-';

        tmpbuf[bufLen] = (wchar_t)0;
        attron(COLOR_PAIR(2));
        mvaddwstr(lastLine, 0, tmpbuf);

        attron(COLOR_PAIR(1));
        if (screen->lineCount >= screen->selected) {
            current = screen->lines[screen->selected]->comment;
            if (current != NULL) {
                swprintf(tmpbuf, bufLen, L"%s - %d Score - %s", current->author, current->ups, current->created_utc);
                mvaddwstr(lastLine + 1, 0, tmpbuf);
                swprintf(tmpbuf, bufLen, L"-------");
                mvaddwstr(lastLine + 2, 0, tmpbuf);

                mvaddwstr(lastLine + 3, 0, &(current->wbodyEsc[current->advance] ));
            }
        }
    }

    free(tmpbuf);
    refresh();
}

// Assembly:
testq %rdi, %rdi
je 0x2cdf
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %r15
movq 0x5489(%rip), %rax      # 0x7fc8
movslq (%rax), %r14
leal 0x4(,%r14,4), %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x2170
movq %rax, %rbx
xorl %eax, %eax
testl %r14d, %r14d
movl $0x0, %r12d
movq %r14, (%rsp)
cmovgl %r14d, %r12d
cmpq %rax, %r12
je 0x2b7c
movl $0x20, (%rbx,%rax,4)
incq %rax
jmp 0x2b6b
movl 0x18(%r15), %ecx
movl 0x1c(%r15), %eax
leal (%rcx,%rax), %edx
movq %rdx, 0x10(%rsp)
xorl %ebp, %ebp
movq 0x544b(%rip), %r14      # 0x7fe0
pushq $-0x1
popq %r13
addl %ecx, %eax
movl 0x28(%r15), %ecx
addl %ecx, %eax
incl %eax
cmpl %eax, %ebp
jge 0x2bd2
movq (%r14), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2bc6
movq (%r14), %rdi
movq %rbx, %rsi
movl %r13d, %edx
callq 0x22b0
incl %ebp
movl 0x18(%r15), %ecx
movl 0x1c(%r15), %eax
jmp 0x2b99
movq 0x10(%rsp), %rbp
leal 0x1(%rbp), %eax
movq %rax, 0x8(%rsp)
movq (%r14), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x22e0
movslq 0x1c(%r15), %r13
movslq %ebp, %rbp
cmpq %rbp, %r13
jg 0x2c95
cmpl 0x20(%r15), %r13d
jne 0x2c13
movq (%r14), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x22e0
movslq 0x8(%r15), %rax
cmpq %rax, %r13
jge 0x2c52
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rax
cmpq $0x0, (%rax)
movl 0x1c(%r15), %eax
je 0x2c56
movq (%r14), %rdi
movl %r13d, %esi
subl %eax, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2c78
movq (%r14), %rdi
movq 0x10(%r15), %rax
movq (%rax,%r13,8), %rax
movq (%rax), %rsi
jmp 0x2c70
movl 0x1c(%r15), %eax
movq (%r14), %rdi
movl %r13d, %esi
subl %eax, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2c78
movq (%r14), %rdi
movq %rbx, %rsi
pushq $-0x1
popq %rdx
callq 0x22b0
cmpl 0x20(%r15), %r13d
jne 0x2c8d
movq (%r14), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x22e0
incq %r13
jmp 0x2bf5
testb $0x1, 0x2c(%r15)
je 0x2dff
movq 0x8(%rsp), %rax
subl 0x1c(%r15), %eax
movq %rax, %rbp
movl %eax, %r13d
movl 0x28(%r15), %eax
addl %ebp, %eax
cmpl %eax, %r13d
jge 0x2ce0
movq (%r14), %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2cda
movq (%r14), %rdi
movq %rbx, %rsi
pushq $-0x1
popq %rdx
callq 0x22b0
incl %r13d
jmp 0x2caf
retq
xorl %eax, %eax
cmpq %rax, %r12
je 0x2cf3
movl $0x2d, (%rbx,%rax,4)
incq %rax
jmp 0x2ce2
movq (%rsp), %rax
andl $0x0, (%rbx,%rax,4)
movq (%r14), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x22e0
movq (%r14), %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2d29
movq (%r14), %rdi
pushq $-0x1
popq %rdx
movq %rbx, %rsi
callq 0x22b0
movq (%r14), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x22e0
movslq 0x20(%r15), %rax
cmpl %eax, 0x8(%r15)
jl 0x2dff
movq 0x10(%r15), %rcx
movq (%rcx,%rax,8), %rax
movq 0x8(%rax), %r15
testq %r15, %r15
je 0x2dff
movq 0x20(%r15), %rcx
movl 0x50(%r15), %r8d
movq 0x78(%r15), %r9
leaq 0x2652(%rip), %rdx      # 0x53c0
movq %rbx, %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2290
movq (%r14), %rdi
leal 0x1(%rbp), %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2d9c
movq (%r14), %rdi
pushq $-0x1
popq %rdx
movq %rbx, %rsi
callq 0x22b0
leaq 0x2669(%rip), %rdx      # 0x540c
movq %rbx, %rdi
movq (%rsp), %rsi
xorl %eax, %eax
callq 0x2290
movq (%r14), %rdi
leal 0x2(%rbp), %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2dd1
movq (%r14), %rdi
pushq $-0x1
popq %rdx
movq %rbx, %rsi
callq 0x22b0
movq (%r14), %rdi
addl $0x3, %ebp
movl %ebp, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x2dff
movq (%r14), %rdi
movslq 0x84(%r15), %rsi
shlq $0x2, %rsi
addq 0x48(%r15), %rsi
pushq $-0x1
popq %rdx
callq 0x22b0
movq %rbx, %rdi
callq 0x2230
movq (%r14), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220