// File: /workspace/github_cpp_makefile_star2_O2/phillip-h[P]todo/src/draw.cpp
// Function: drawTasks(TodoList*, unsigned int)
void drawTasks(TodoList* list, unsigned selected)
{
    auto tasks = list->tasks();
    
    taskWin->clear();    

    if (tasks && tasks->size()){
        xpos = 1;
        ypos = 1;

        unsigned numTasks = height - 2;
        endTask = tasks->size();
        if (endTask > numTasks)
            endTask = numTasks;

        if (numTasks < tasks->size()){
            while (selected > (int) endTask + listOff - 2 && selected != 0)
                listOff++;
            while (selected < (int) startTask + listOff && 
                   selected != list->size() - 1)
                listOff--;
        } else{
            listOff = 0;
        }

        unsigned count = startTask + listOff;

        for (unsigned i = startTask + listOff; i < endTask + listOff &&
                                               i < tasks->size() ; i++){
            Task t = tasks->at(i);
            
            if (showNumbers){
                taskWin->inverse();
                taskWin->color(GUTTER_COLOR_PAIR);
                
                std::string number = std::to_string(count);
                if (!zeroIndexNumbers)
                    number = std::to_string(count + 1);
                while (number.size() < 2)
                    number = "0"+number;
                
                taskWin->print(number + ")", xpos, ypos);
                taskWin->colorOff(GUTTER_COLOR_PAIR);
                taskWin->inverseOff();
                xpos += 5;
            }
           
            if (i == selected){
                std::string tmp = tasks->at(i).task();
                if (tasks->at(i).div()){
                    taskWin->inverse();
                    taskWin->color(SELECT_COLOR_PAIR);
                    drawDivider(tmp.substr(5, tmp.size() - 5), ypos);
                    taskWin->colorOff(SELECT_COLOR_PAIR);
                    taskWin->inverseOff();
                    ypos++;
                    if (showNumbers){
                        xpos -= 5;
                    }
                    continue;
                }

                std::string line = tmp;
                unsigned pad = showNumbers ? 8 : 5;
                if (line.size() >= width - pad) {
                    line = line.substr(0, width - pad - 3) + "...";
                }
                if (highlightWholeLine){
                    for (int k = tmp.size() + xpos; k < width - 2; k++){
                        line += " ";
                    }
                }
                
                std::string mark = line.substr(0, STRING_COMPLETE.size());
                line = line.substr(mark.size());
                
                taskWin->inverse();

                taskWin->color(!t.completed() ? MARK_COLOR_PAIR
                                              : MARK_COLOR_PAIR_DONE); 
                taskWin->print(mark, xpos, ypos);
                taskWin->colorOff(!t.completed() ? MARK_COLOR_PAIR
                                                 : MARK_COLOR_PAIR_DONE);

                taskWin->color(SELECT_COLOR_PAIR);
                taskWin->print(line, xpos + mark.size(), ypos);
                taskWin->colorOff(SELECT_COLOR_PAIR);
                
                taskWin->inverseOff();
            } else{
                std::string tmp = tasks->at(i).task();
                if (tasks->at(i).div()){
                    drawDivider(tmp.substr(5, tmp.size() - 5), ypos);
                    ypos++;
                    if (showNumbers){
                        xpos -= 5;
                    }
                    continue;
                }
                
                std::string text = tmp;
                unsigned pad = showNumbers ? 8 : 5;
                if (text.size() >= width - pad) {
                    text = text.substr(0, width - pad - 3) + "...";
                }

                std::string mark = text.substr(0, STRING_COMPLETE.size());
                text = text.substr(mark.size());

                taskWin->color(!t.completed() ? MARK_COLOR_PAIR
                                              : MARK_COLOR_PAIR_DONE); 
                taskWin->print(mark, xpos, ypos);
                taskWin->colorOff(!t.completed() ? MARK_COLOR_PAIR
                                                 : MARK_COLOR_PAIR_DONE);

                taskWin->print(text, xpos + mark.size(), ypos);
            }
            ypos++;
            if (ypos > numTasks || i >= tasks->size() - 1){
                break;
            }
            if (showNumbers){
                xpos -= 5;
                count++;
            }
        }
    }
    
    taskWin->color(BORDER_COLOR_PAIR, true);
    taskWin->draw();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movl %esi, %r14d
movq %rdi, %rbx
callq 0x7bc2
movq %rax, %r15
movq 0x9288(%rip), %rdi      # 0xf678
callq 0x8ec0
movq %r15, 0x8(%rsp)
testq %r15, %r15
je 0x6b84
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
je 0x6b84
pushq $0x28
popq %rcx
cqto
idivq %rcx
pushq $0x1
popq %rcx
movl %ecx, 0x927a(%rip)      # 0xf6a0
movl %ecx, 0x9278(%rip)      # 0xf6a4
movl 0x926a(%rip), %ecx      # 0xf69c
addl $-0x2, %ecx
cmpl %eax, %ecx
movl %eax, %edx
cmovbl %ecx, %edx
movl %edx, 0x926a(%rip)      # 0xf6ac
movq %rcx, 0x48(%rsp)
cmpq %rcx, %rax
jbe 0x6493
addl $-0x2, %edx
movl 0x925b(%rip), %ecx      # 0xf6b0
leal (%rdx,%rcx), %eax
cmpl %r14d, %eax
jae 0x6484
incl %ecx
movl %ecx, 0x924b(%rip)      # 0xf6b0
jmp 0x6455
movq %rbx, %rdi
callq 0x79aa
decl %eax
movl 0x9239(%rip), %ecx      # 0xf6b0
cmpl %r14d, %eax
je 0x649c
decl %ecx
movl %ecx, 0x922c(%rip)      # 0xf6b0
movl 0x921e(%rip), %eax      # 0xf6a8
addl %ecx, %eax
cmpl %r14d, %eax
ja 0x6467
jmp 0x649c
andl $0x0, 0x9216(%rip)      # 0xf6b0
xorl %ecx, %ecx
movl 0x9206(%rip), %eax      # 0xf6a8
addl %ecx, %eax
leaq 0x50(%rsp), %r12
leaq 0x4081(%rip), %r13      # 0xa531
leaq 0xd8(%rsp), %rbp
leaq 0xb8(%rsp), %rbx
pushq $-0x1
popq %r15
movl %eax, 0x24(%rsp)
movl %r14d, 0x20(%rsp)
addl 0x91d9(%rip), %ecx      # 0xf6ac
cmpl %ecx, %eax
jae 0x6b84
movl %eax, %edi
movl %eax, %esi
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x6b84
movl %edi, 0x14(%rsp)
movq 0x8(%rsp), %rdi
movq %rsi, 0x18(%rsp)
callq 0x51a8
leaq 0x70(%rsp), %rdi
movq %rax, %rsi
callq 0x7046
movq 0x9155(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8f94
movq 0x9147(%rip), %rdi      # 0xf678
pushq $0x2
popq %rsi
xorl %edx, %edx
callq 0x8fe6
movq %r12, %rdi
movl 0x24(%rsp), %esi
callq 0x7064
cmpq $0x1, 0x58(%rsp)
ja 0x6572
movq %rbp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x5c9c
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3360
movq %rbp, %rdi
callq 0x35a8
jmp 0x6547
movq %rbx, %rdi
movq 0x90fc(%rip), %rbx      # 0xf678
movq %r12, %rsi
leaq 0x3eb1(%rip), %rdx      # 0xa437
callq 0x70a3
movl 0x910f(%rip), %edx      # 0xf6a0
movl 0x910d(%rip), %ecx      # 0xf6a4
movq %rbx, %rdi
leaq 0xb8(%rsp), %rbx
movq %rbx, %rsi
callq 0x8fd4
movq %rbx, %rdi
callq 0x35a8
movq 0x90bf(%rip), %rdi      # 0xf678
pushq $0x2
popq %rsi
xorl %edx, %edx
callq 0x8ffa
movq 0x90ae(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8fa6
addl $0x5, 0x90c8(%rip)      # 0xf6a0
movq %r12, %rdi
callq 0x35a8
cmpl %r14d, 0x14(%rsp)
jne 0x66bc
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x51a8
leaq 0xb8(%rsp), %rbx
leaq 0x198(%rsp), %r14
movq %r12, %rdi
movq %rax, %rsi
callq 0x71da
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x51a8
movq %rax, %rdi
callq 0x7404
movb %al, 0x7(%rsp)
cmpb $0x0, 0x7(%rsp)
je 0x6747
movq 0x9036(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8f94
movq 0x9028(%rip), %rdi      # 0xf678
pushq $0x3
popq %rsi
xorl %edx, %edx
callq 0x8fe6
movq 0x58(%rsp), %rcx
addq $-0x5, %rcx
movq %r14, %rdi
movq %r12, %rsi
pushq $0x5
popq %rdx
callq 0x32c0
movl 0x902d(%rip), %esi      # 0xf6a4
movq %r14, %rdi
callq 0x6f03
movq %r14, %rdi
callq 0x35a8
movq 0x8fea(%rip), %rdi      # 0xf678
pushq $0x3
popq %rsi
xorl %edx, %edx
callq 0x8ffa
movq 0x8fd9(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8fa6
incl 0x8ff8(%rip)            # 0xf6a4
addl $-0x5, 0x8fed(%rip)     # 0xf6a0
pushq $0x8
popq %r14
jmp 0x6b0a
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x51a8
movq %r12, %rdi
movq %rax, %rsi
callq 0x71da
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x51a8
movq %rax, %rdi
callq 0x7404
movl %eax, %ebx
testb %al, %al
je 0x67e4
movq 0x58(%rsp), %rcx
addq $-0x5, %rcx
leaq 0x138(%rsp), %rdi
movq %r12, %rsi
pushq $0x5
popq %rdx
callq 0x32c0
movl 0x8f8b(%rip), %esi      # 0xf6a4
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0x6f03
movq %r14, %rdi
callq 0x35a8
incl 0x8f6d(%rip)            # 0xf6a4
addl $-0x5, 0x8f62(%rip)     # 0xf6a0
pushq $0x8
popq %r14
jmp 0x696d
movq %rbp, %rdi
movq %r12, %rsi
callq 0x33b0
movl 0x8f40(%rip), %ecx      # 0xf698
leal -0x8(%rcx), %eax
cmpq %rax, 0xe0(%rsp)
leaq 0x3d75(%rip), %r14      # 0xa4df
jb 0x67ba
addl $-0xb, %ecx
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x32c0
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x3d9d(%rip), %rdx      # 0xa533
callq 0x5c7d
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3360
movq %rbx, %rdi
callq 0x35a8
movq %r15, %rdi
callq 0x35a8
pushq $-0x1
popq %r15
movl 0x8ee0(%rip), %ebx      # 0xf6a0
addl 0x58(%rsp), %ebx
movl 0x8ece(%rip), %eax      # 0xf698
addl $-0x2, %eax
cmpl %eax, %ebx
jge 0x69a7
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3550
incl %ebx
jmp 0x67c4
movq %rbp, %rdi
movq %r12, %rsi
callq 0x33b0
movl 0x8ea3(%rip), %ecx      # 0xf698
leal -0x8(%rcx), %eax
cmpq %rax, 0xe0(%rsp)
jb 0x6850
addl $-0xb, %ecx
leaq 0x98(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x32c0
leaq 0x28(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
leaq 0x3d07(%rip), %rdx      # 0xa533
callq 0x5c7d
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3360
movq %r14, %rdi
callq 0x35a8
movq %r15, %rdi
callq 0x35a8
pushq $-0x1
popq %r15
movq 0x8da1(%rip), %rcx      # 0xf5f8
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x32c0
movq 0x30(%rsp), %rdx
leaq 0x98(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x32c0
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3360
movq %r14, %rdi
callq 0x35a8
movq 0x8ddd(%rip), %r14      # 0xf678
leaq 0x70(%rsp), %rdi
callq 0x744a
movzbl %al, %esi
addl $0x5, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x8fe6
movq 0x8dbc(%rip), %r14      # 0xf678
leaq 0x118(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x33b0
movl 0x8dcc(%rip), %edx      # 0xf6a0
movl 0x8dca(%rip), %ecx      # 0xf6a4
movq %r14, %rdi
leaq 0x118(%rsp), %r14
movq %r14, %rsi
callq 0x8fd4
movq %r14, %rdi
callq 0x35a8
movq 0x8d7c(%rip), %r14      # 0xf678
leaq 0x70(%rsp), %rdi
callq 0x744a
movzbl %al, %esi
addl $0x5, %esi
movq %r14, %rdi
xorl %edx, %edx
callq 0x8ffa
movq 0x8d5b(%rip), %r14      # 0xf678
leaq 0xf8(%rsp), %rdi
movq %rbp, %rsi
callq 0x33b0
movl 0x8d6d(%rip), %edx      # 0xf6a0
addl 0x30(%rsp), %edx
movl 0x8d67(%rip), %ecx      # 0xf6a4
movq %r14, %rdi
leaq 0xf8(%rsp), %r14
movq %r14, %rsi
callq 0x8fd4
movq %r14, %rdi
callq 0x35a8
leaq 0x28(%rsp), %rdi
callq 0x35a8
movq %rbp, %rdi
callq 0x35a8
xorl %r14d, %r14d
movq %r12, %rdi
callq 0x35a8
testb %bl, %bl
leaq 0xb8(%rsp), %rbx
je 0x6b1d
leaq 0x70(%rsp), %rdi
callq 0x35a8
testb $0x7, %r14b
movl 0x20(%rsp), %r14d
movl 0x14(%rsp), %eax
je 0x6b6d
jmp 0x6b84
movq 0x8c4a(%rip), %rcx      # 0xf5f8
leaq 0x28(%rsp), %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x32c0
movq 0x30(%rsp), %rdx
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
movq %rbp, %rsi
movq %r15, %rcx
callq 0x32c0
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x3360
movq %rbx, %rdi
callq 0x35a8
movq 0x8c86(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8f94
movq 0x8c78(%rip), %rbx      # 0xf678
leaq 0x70(%rsp), %rdi
callq 0x744a
movzbl %al, %esi
addl $0x5, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8fe6
movq 0x8c57(%rip), %rbx      # 0xf678
leaq 0x178(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x33b0
movl 0x8c67(%rip), %edx      # 0xf6a0
movl 0x8c65(%rip), %ecx      # 0xf6a4
movq %rbx, %rdi
leaq 0x178(%rsp), %rbx
movq %rbx, %rsi
callq 0x8fd4
movq %rbx, %rdi
callq 0x35a8
movq 0x8c17(%rip), %rbx      # 0xf678
leaq 0x70(%rsp), %rdi
callq 0x744a
movzbl %al, %esi
addl $0x5, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x8ffa
movq 0x8bf6(%rip), %rdi      # 0xf678
pushq $0x3
popq %rsi
xorl %edx, %edx
callq 0x8fe6
movq 0x8be5(%rip), %rbx      # 0xf678
leaq 0x158(%rsp), %rdi
movq %rbp, %rsi
callq 0x33b0
movl 0x8bf7(%rip), %edx      # 0xf6a0
addl 0x30(%rsp), %edx
movl 0x8bf1(%rip), %ecx      # 0xf6a4
movq %rbx, %rdi
leaq 0x158(%rsp), %rbx
movq %rbx, %rsi
callq 0x8fd4
movq %rbx, %rdi
callq 0x35a8
movq 0x8ba3(%rip), %rdi      # 0xf678
pushq $0x3
popq %rsi
xorl %edx, %edx
callq 0x8ffa
movq 0x8b92(%rip), %rdi      # 0xf678
xorl %esi, %esi
callq 0x8fa6
leaq 0x28(%rsp), %rdi
callq 0x35a8
movq %rbp, %rdi
callq 0x35a8
xorl %r14d, %r14d
leaq 0xb8(%rsp), %rbx
movq %r12, %rdi
callq 0x35a8
cmpb $0x0, 0x7(%rsp)
jne 0x6985
movl 0x8b81(%rip), %eax      # 0xf6a4
incl %eax
movl %eax, 0x8b79(%rip)      # 0xf6a4
cmpl 0x48(%rsp), %eax
ja 0x6b7a
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
decq %rax
cmpq 0x18(%rsp), %rax
jbe 0x6b7a
addl $-0x5, 0x8b4a(%rip)     # 0xf6a0
incl 0x24(%rsp)
leaq 0x70(%rsp), %rdi
callq 0x35a8
movl 0x20(%rsp), %r14d
movl 0x14(%rsp), %eax
incl %eax
movl 0x8b3b(%rip), %ecx      # 0xf6b0
jmp 0x64cd
leaq 0x70(%rsp), %rdi
callq 0x35a8
movq 0x8aed(%rip), %rdi      # 0xf678
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x8fe6
movq 0x8adb(%rip), %rdi      # 0xf678
callq 0x8ed6
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6bbb
jmp 0x6c61
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
jmp 0x6c58
jmp 0x6c61
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x6c18
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
jmp 0x6c18
jmp 0x6c50
jmp 0x6c61
jmp 0x6c73
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x6c6c
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x6c18
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x35a8
jmp 0x6c53
jmp 0x6c50
jmp 0x6c61
jmp 0x6c73
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x6c6c
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
jmp 0x6c6c
jmp 0x6c49
jmp 0x6c49
jmp 0x6c49
jmp 0x6c73
jmp 0x6c50
movq %rax, %rbx
jmp 0x6c80
jmp 0x6c73
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x35a8
jmp 0x6c64
jmp 0x6c73
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x35a8
jmp 0x6c76
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x35a8
leaq 0x70(%rsp), %rdi
callq 0x35a8
movq %rbx, %rdi
callq 0x3510