// File: /workspace/github_c_makefile_star2_O2/Cotix[P]cReddit/src/main.c
// Function: drawScreen
void drawScreen(LinkScreen *screen)
{
    int i, screenLines;
    wchar_t *tmpbuf;
    int bufSize, 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->linkOpenSize; 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->list->linkCount) {
            if (screen->screenLineCount <= i)
                linkScreenRenderLine(screen, i, COLS);

            mvaddwstr(i - screen->offset, 0, screen->screenLines[i]);
        } else {
            mvaddwstr(i - screen->offset, 0, tmpbuf);
        }

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



    if (screen->linkOpen) {
        if (screen->helpOpen == 0)
            linkScreenRenderLinkText(screen, tmpbuf, bufLen, screenLines);
        else
            linkScreenRenderHelpText(screen, tmpbuf, bufLen, screenLines);
    }

    free(tmpbuf);

    refresh();
}

// Assembly:
testq %rdi, %rdi
je 0x34df
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
movq 0x4c5e(%rip), %rax      # 0x7fc8
movl (%rax), %r15d
leal 0x4(,%r15,4), %eax
movslq %eax, %rsi
pushq $0x1
popq %rdi
callq 0x2170
movq %rax, %r14
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
movq %r15, 0x10(%rsp)
cmovgl %r15d, %ecx
cmpq %rax, %rcx
je 0x33a8
movl $0x20, (%r14,%rax,4)
incq %rax
jmp 0x3396
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %eax
leal (%rcx,%rax), %ebp
xorl %r12d, %r12d
movq 0x4c25(%rip), %r15      # 0x7fe0
pushq $-0x1
popq %r13
addl %ecx, %eax
movl 0x28(%rbx), %ecx
addl %ecx, %eax
incl %eax
movq (%r15), %rdi
cmpl %eax, %r12d
jge 0x33f8
movl %r12d, %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x33ed
movq (%r15), %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x22b0
incl %r12d
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %eax
jmp 0x33bf
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x22e0
movslq 0xc(%rbx), %r12
movl %ebp, 0xc(%rsp)
movslq %ebp, %rbp
pushq $-0x1
popq %r13
cmpq %rbp, %r12
jg 0x34bc
cmpl 0x10(%rbx), %r12d
jne 0x3431
movq (%r15), %rdi
movl $0x200, %esi            # imm = 0x200
xorl %edx, %edx
callq 0x22e0
movq (%rbx), %rax
movslq 0x14(%rax), %rax
cmpq %rax, %r12
jge 0x347c
movslq 0x14(%rbx), %rax
cmpq %rax, %r12
jl 0x345a
movq 0x4b7b(%rip), %rax      # 0x7fc8
movl (%rax), %edx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3018
movq (%r15), %rdi
movl %r12d, %esi
subl 0xc(%rbx), %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x349f
movq (%r15), %rdi
movq 0x20(%rbx), %rax
movq (%rax,%r12,8), %rsi
jmp 0x3497
movq (%r15), %rdi
movl %r12d, %esi
subl 0xc(%rbx), %esi
xorl %edx, %edx
callq 0x2160
cmpl $-0x1, %eax
je 0x349f
movq (%r15), %rdi
movq %r14, %rsi
movl %r13d, %edx
callq 0x22b0
cmpl 0x10(%rbx), %r12d
jne 0x34b4
movq (%r15), %rdi
movl $0x100, %esi            # imm = 0x100
xorl %edx, %edx
callq 0x22e0
incq %r12
jmp 0x3413
movb 0x2c(%rbx), %al
testb $0x1, %al
je 0x34ea
movl 0xc(%rsp), %ecx
incl %ecx
movq %rbx, %rdi
movq %r14, %rsi
testb $0x2, %al
jne 0x34e0
movq 0x10(%rsp), %rdx
callq 0x31a1
jmp 0x34ea
retq
movq 0x10(%rsp), %rdx
callq 0x32d8
movq %r14, %rdi
callq 0x2230
movq (%r15), %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2220