// File: /workspace/github_cpp_makefile_star2_O3/phillip-h[P]todo/src/core.cpp
// Function: Core::handleInput(int, TodoList*&, unsigned int&)
bool Core::handleInput(int c, TodoList *&todoList, unsigned &position)
{
    std::string newTask;
    
    switch(c){
        case EXIT_KEY:
            return true;
        
        case TOGGLE_CHECK_KEY:
            if (todoList->size() != 0){
                todoList->at(position).toggleComplete();
            }
            break;
        
        case NEW_KEY:
            backup(todoList);
            newTask = Draw::getInput();
            if (!newTask.empty()){
                if (todoList->size() != 0){
                    position++;
                }
                todoList->add(Task(newTask), position);
            }
            break;
       
        case EDIT_KEY:
            {
            backup(todoList);
            string base = todoList->at(position).raw();
            string editTask = Draw::getInput(base);
            if (!editTask.empty())
                todoList->at(position) = Task(editTask);
            break;
            }

        case REMOVE_KEY:
            backup(todoList);
            todoList->remove(position);
            if (todoList->size() != 0){
                if (position >= todoList->size()){
                    position = todoList->size() - 1;
                }
            }
            break;

        case UNDO_KEY:
            restore(todoList); 
            break;

        case MOVE_UP_KEY:
            if (todoList->swap(position - 1)){
                --position;
                if (autoSave){
                    todoList->save();
                }
            }
            break;

        case MOVE_DOWN_KEY:
            if(todoList->swap(position)){
                ++position;
                if (autoSave){
                    todoList->save();
                }
            }
            break;

        case DIV_KEY:
            backup(todoList);
            newTask = Draw::getInput();
            if (!newTask.empty()){
                newTask ="[" + newTask + "]";
            }
            newTask = DIV_CODE + newTask;
            if (todoList->size() != 0){
                position++;
            }
            todoList->add(Task(newTask), position);
            break;

        case UP_KEY:
            if (position != 0){
                --position;
            }
            break;
        
        case DOWN_KEY:
	        if (todoList->size() != 0){
                ++position;
                if (position >= todoList->size()){
                    position = todoList->size() - 1;
                }
	        }
	        break;

        case SORT_KEY:
            backup(todoList);
            todoList->sort();
            if (autoSave){
                todoList->save();
            }
            break;

        case KEY_RESIZE:
            Draw::stop();
            Draw::init();
            break;
    
        case KEY_MOUSE:
            MEVENT event;
            if (getmouse(&event) == OK){ 
                if (event.bstate & BUTTON1_PRESSED){
                    Draw::mouse(event, todoList, position, false);  
                } else if (event.bstate & BUTTON3_PRESSED){
                    Draw::mouse(event, todoList, position, true);  
                } else if (event.bstate & BUTTON4_PRESSED){
                    if (position != 0){
                        --position;
                    }
                }
            } else {          // ncurses is weird and returns ERR
                ++position;   // on mouse wheel down events
                if (position >= todoList->size()){
                    position = todoList->size() - 1;
                }
            }
            break;
    }
    
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
movq %rdx, %rbx
movq %rsi, %r14
leaq 0x58(%rsp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
movb $0x0, (%r12)
cmpl $0x70, %edi
jle 0x6069
cmpl $0x101, %edi            # imm = 0x101
jg 0x60c6
addl $-0x71, %edi
cmpl $0x9, %edi
ja 0x66f0
leaq 0x63fb(%rip), %rax      # 0xc454
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movb $0x1, %al
jmp 0x6709
leal -0x64(%rdi), %eax
cmpl $0x7, %eax
ja 0x60f9
leaq 0x63b8(%rip), %rcx      # 0xc434
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
callq 0x68d7
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9d22
movq (%r14), %rdi
callq 0x94b2
testl %eax, %eax
je 0x66f0
movl (%rbx), %ebp
movq (%r14), %rdi
callq 0x94b2
cmpl %eax, %ebp
jb 0x66f0
movq (%r14), %rdi
callq 0x94b2
jmp 0x6551
cmpl $0x198, %edi            # imm = 0x198
jg 0x623a
cmpl $0x102, %edi            # imm = 0x102
je 0x64f5
cmpl $0x103, %edi            # imm = 0x103
jne 0x66f0
movl (%rbx), %eax
testl %eax, %eax
jne 0x6551
jmp 0x66f0
cmpl $0xa, %edi
je 0x655a
cmpl $0x20, %edi
jne 0x66f0
movq (%r14), %rdi
callq 0x68d7
leaq 0x158(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x636a(%rip), %rdx      # 0xc490
leaq 0x148(%rsp), %rdi
movq %rdx, %rsi
callq 0x5c8a
leaq 0x20(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x8230
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6174
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x148(%rsp), %rdi
cmpq %r13, %rdi
je 0x6191
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x32b0
cmpq $0x0, 0x50(%rsp)
je 0x66f0
movq (%r14), %rdi
callq 0x94b2
testl %eax, %eax
je 0x61ab
incl (%rbx)
movq (%r14), %r14
leaq 0x138(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0x128(%rsp), %rdi
callq 0x5bf4
leaq 0x190(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x87bc
movl (%rbx), %edx
leaq 0x190(%rsp), %rsi
movq %r14, %rdi
callq 0x980e
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x621c
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x128(%rsp), %rdi
cmpq %r15, %rdi
je 0x66f0
movq 0x138(%rsp), %rsi
jmp 0x66e8
cmpl $0x199, %edi            # imm = 0x199
je 0x6525
cmpl $0x19a, %edi            # imm = 0x19A
jne 0x66f0
callq 0x86b9
callq 0x6ab4
jmp 0x66f0
movq (%r14), %rdi
movl (%rbx), %esi
decl %esi
callq 0x9d62
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x63dc
movq (%r14), %rdi
callq 0x68d7
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x94c8
leaq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x8b46
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x5bf4
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x8230
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x62ee
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x110(%rsp), %rdx
testq %rdx, %rdx
je 0x6390
leaq 0xd8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x108(%rsp), %rsi
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x5bf4
leaq 0x20(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x87bc
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x94c8
movq %rax, %rbx
leaq 0x20(%rsp), %r14
movq %rax, %rdi
movq %r14, %rsi
callq 0x3360
movb 0x20(%r14), %al
movb %al, 0x20(%rbx)
movq (%r14), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x6373
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6390
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x63b1
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66f0
movq 0x78(%rsp), %rsi
jmp 0x66e8
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9d62
movl $0x1, %ecx
testb %al, %al
je 0x66f0
addl %ecx, (%rbx)
jmp 0x63f8
movq (%r14), %rdi
callq 0x68d7
movq (%r14), %rdi
callq 0x9ed6
movq (%r14), %rdi
callq 0x8e4a
jmp 0x66f0
movq %r14, %rdi
callq 0x693e
jmp 0x66f0
movq (%r14), %rdi
callq 0x68d7
leaq 0xb8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x6063(%rip), %rdx      # 0xc490
leaq 0xa8(%rsp), %rdi
movq %rdx, %rsi
callq 0x5c8a
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x8230
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
leaq 0x30(%rsp), %r13
cmpq %r13, %rdi
je 0x647b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xa8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6498
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32b0
cmpq $0x0, 0x50(%rsp)
je 0x6619
leaq 0x5fd1(%rip), %rsi      # 0xc47c
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x69ab
leaq 0x5b49(%rip), %rsi      # 0xc00a
leaq 0x68(%rsp), %rdi
callq 0x3560
movq %r13, 0x20(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x65b8
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x65c0
movq (%r14), %rdi
callq 0x94b2
testl %eax, %eax
je 0x66f0
movl (%rbx), %ebp
incl %ebp
movl %ebp, (%rbx)
movq (%r14), %rdi
callq 0x94b2
cmpl %eax, %ebp
jb 0x66f0
movq (%r14), %rdi
callq 0x94b2
jmp 0x6551
leaq 0x20(%rsp), %rdi
callq 0x34c0
testl %eax, %eax
je 0x6581
movl (%rbx), %ebp
incl %ebp
movl %ebp, (%rbx)
movq (%r14), %rdi
callq 0x94b2
cmpl %eax, %ebp
jb 0x66f0
movq (%r14), %rdi
callq 0x94b2
decl %eax
movl %eax, (%rbx)
jmp 0x66f0
movq (%r14), %rdi
callq 0x94b2
testl %eax, %eax
je 0x66f0
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x94c8
movq %rax, %rdi
callq 0x8804
jmp 0x66f0
movl 0x30(%rsp), %eax
testl $0x802, %eax            # imm = 0x802
je 0x671b
xorl %edx, %edx
testb $0x2, %al
sete %dl
movq (%r14), %rdi
movl 0x30(%rsp), %eax
movl %eax, 0x10(%rsp)
movups 0x20(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbx, %rsi
callq 0x81b8
jmp 0x66f0
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %r15
movq %rdx, 0x8(%r15)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x48(%rsp), %rdi
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
cmpq %r13, %rdi
je 0x65fe
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6619
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movl $0x7, %esi
callq 0x6a33
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
cmpq %r13, %rdi
je 0x6654
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq (%r14), %rdi
callq 0x94b2
testl %eax, %eax
je 0x6662
incl (%rbx)
movq (%r14), %r14
leaq 0x98(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x5bf4
leaq 0x168(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x87bc
movl (%rbx), %edx
leaq 0x168(%rsp), %rsi
movq %r14, %rdi
callq 0x980e
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66d3
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x66f0
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x6707
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32b0
xorl %eax, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
btl $0x10, %eax
setae %cl
movl (%rbx), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
je 0x6551
jmp 0x66f0
movq %rax, %rbx
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x675c
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x675c
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r15, %rdi
je 0x68b8
movq 0x138(%rsp), %rsi
jmp 0x68a7
jmp 0x6891
jmp 0x68b5
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67a7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x67a7
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x67c9
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x67c9
movq %rax, %rbx
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6894
movq 0x118(%rsp), %rsi
jmp 0x6887
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r13, %rdi
je 0x68b8
movq 0x158(%rsp), %rsi
jmp 0x68a7
jmp 0x68b5
movq %rax, %rbx
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x683a
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x683a
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x68b8
movq 0x98(%rsp), %rsi
jmp 0x68a7
jmp 0x68b5
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x68b8
movq 0xb8(%rsp), %rsi
jmp 0x68a7
jmp 0x68b5
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6894
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x6894
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68b8
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x68b8
jmp 0x68b5
jmp 0x68b5
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x68cf
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3500