// File: /workspace/github_cpp_makefile_star2_O1/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 0x615f
cmpl $0x101, %edi            # imm = 0x101
jg 0x61bc
addl $-0x71, %edi
cmpl $0x9, %edi
ja 0x67d6
leaq 0x6305(%rip), %rax      # 0xc454
movslq (%rax,%rdi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movb $0x1, %bl
jmp 0x67d8
leal -0x64(%rdi), %eax
cmpl $0x7, %eax
ja 0x61ef
leaq 0x62c2(%rip), %rcx      # 0xc434
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rdi
callq 0x69cc
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9e4c
movq (%r14), %rdi
callq 0x95f2
testl %eax, %eax
je 0x67d6
movl (%rbx), %ebp
movq (%r14), %rdi
callq 0x95f2
cmpl %eax, %ebp
jb 0x67d6
movq (%r14), %rdi
callq 0x95f2
jmp 0x6695
cmpl $0x198, %edi            # imm = 0x198
jg 0x6330
cmpl $0x102, %edi            # imm = 0x102
je 0x65eb
cmpl $0x103, %edi            # imm = 0x103
jne 0x67d6
movl (%rbx), %eax
testl %eax, %eax
jne 0x6695
jmp 0x67d6
cmpl $0xa, %edi
je 0x6649
cmpl $0x20, %edi
jne 0x67d6
movq (%r14), %rdi
callq 0x69cc
leaq 0x158(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x6274(%rip), %rdx      # 0xc490
leaq 0x148(%rsp), %rdi
movq %rdx, %rsi
callq 0x5d4c
leaq 0x20(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x8355
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x626a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x148(%rsp), %rdi
cmpq %r13, %rdi
je 0x6287
movq 0x158(%rsp), %rsi
incq %rsi
callq 0x32b0
cmpq $0x0, 0x50(%rsp)
je 0x67d6
movq (%r14), %rdi
callq 0x95f2
testl %eax, %eax
je 0x62a1
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 0x5cbc
leaq 0x190(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x88dc
movl (%rbx), %edx
leaq 0x190(%rsp), %rsi
movq %r14, %rdi
callq 0x994e
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6312
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x128(%rsp), %rdi
cmpq %r15, %rdi
je 0x67d6
movq 0x138(%rsp), %rsi
jmp 0x67ce
cmpl $0x199, %edi            # imm = 0x199
je 0x661b
cmpl $0x19a, %edi            # imm = 0x19A
jne 0x67d6
callq 0x87d8
callq 0x6ba8
jmp 0x67d6
movq (%r14), %rdi
movl (%rbx), %esi
decl %esi
callq 0x9e8c
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
jmp 0x64d2
movq (%r14), %rdi
callq 0x69cc
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9608
leaq 0x68(%rsp), %rdi
movq %rax, %rsi
callq 0x8c84
leaq 0xf8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe8(%rsp), %rdi
callq 0x5cbc
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
callq 0x8355
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x63e4
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x110(%rsp), %rdx
testq %rdx, %rdx
je 0x6486
leaq 0xd8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x108(%rsp), %rsi
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0x5cbc
leaq 0x20(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x88dc
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9608
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 0x6469
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6486
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x64a7
movq 0x118(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67d6
movq 0x78(%rsp), %rsi
jmp 0x67ce
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9e8c
movl $0x1, %ecx
testb %al, %al
je 0x67d6
addl %ecx, (%rbx)
jmp 0x64ee
movq (%r14), %rdi
callq 0x69cc
movq (%r14), %rdi
callq 0xa038
movq (%r14), %rdi
callq 0x8f8a
jmp 0x67d6
movq %r14, %rdi
callq 0x6a33
jmp 0x67d6
movq (%r14), %rdi
callq 0x69cc
leaq 0xb8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x5f6d(%rip), %rdx      # 0xc490
leaq 0xa8(%rsp), %rdi
movq %rdx, %rsi
callq 0x5d4c
leaq 0x20(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x8355
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
leaq 0x30(%rsp), %r13
cmpq %r13, %rdi
je 0x6571
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0xa8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x658e
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32b0
cmpq $0x0, 0x50(%rsp)
je 0x66ff
leaq 0x5edb(%rip), %rsi      # 0xc47c
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x6aa0
leaq 0x5a53(%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 0x669e
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x66a6
movq (%r14), %rdi
callq 0x95f2
testl %eax, %eax
je 0x67d6
movl (%rbx), %ebp
incl %ebp
movl %ebp, (%rbx)
movq (%r14), %rdi
callq 0x95f2
cmpl %eax, %ebp
jb 0x67d6
movq (%r14), %rdi
callq 0x95f2
jmp 0x6695
leaq 0x20(%rsp), %rdi
callq 0x34c0
testl %eax, %eax
je 0x6670
movl (%rbx), %ebp
incl %ebp
movl %ebp, (%rbx)
movq (%r14), %rdi
callq 0x95f2
cmpl %eax, %ebp
jb 0x67d6
movq (%r14), %rdi
callq 0x95f2
jmp 0x6695
movq (%r14), %rdi
callq 0x95f2
testl %eax, %eax
je 0x67d6
movq (%r14), %rdi
movl (%rbx), %esi
callq 0x9608
movq %rax, %rdi
callq 0x8924
jmp 0x67d6
movl 0x30(%rsp), %eax
testl $0x802, %eax            # imm = 0x802
jne 0x6803
btl $0x10, %eax
setae %cl
movl (%rbx), %eax
testl %eax, %eax
sete %dl
orb %cl, %dl
jne 0x67d6
decl %eax
movl %eax, (%rbx)
jmp 0x67d6
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 0x66e4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x66ff
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32b0
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
movl $0x7, %esi
callq 0x6b28
leaq 0x48(%rsp), %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x3360
movq (%r15), %rdi
cmpq %r13, %rdi
je 0x673a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
movq (%r14), %rdi
callq 0x95f2
testl %eax, %eax
je 0x6748
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 0x5cbc
leaq 0x168(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x88dc
movl (%rbx), %edx
leaq 0x168(%rsp), %rsi
movq %r14, %rdi
callq 0x994e
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x67b9
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x32b0
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x67d6
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32b0
xorl %ebx, %ebx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x67ef
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32b0
movl %ebx, %eax
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
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 0x82dd
jmp 0x67d6
movq %rax, %rbx
leaq 0x1a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6851
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x6851
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r15, %rdi
je 0x69ad
movq 0x138(%rsp), %rsi
jmp 0x699c
jmp 0x6986
jmp 0x69aa
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x689c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x689c
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x68be
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x68be
movq %rax, %rbx
leaq 0x118(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x6989
movq 0x118(%rsp), %rsi
jmp 0x697c
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r13, %rdi
je 0x69ad
movq 0x158(%rsp), %rsi
jmp 0x699c
jmp 0x69aa
movq %rax, %rbx
leaq 0x178(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x692f
movq 0x178(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x692f
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r15, %rdi
je 0x69ad
movq 0x98(%rsp), %rsi
jmp 0x699c
jmp 0x69aa
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x69ad
movq 0xb8(%rsp), %rsi
jmp 0x699c
jmp 0x69aa
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6989
movq 0xf8(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x6989
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x69ad
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32b0
jmp 0x69ad
jmp 0x69aa
jmp 0x69aa
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r12, %rdi
je 0x69c4
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32b0
movq %rbx, %rdi
callq 0x3500