// File: /workspace/github_cpp_makefile_star2_O2/64Mega[P]todo-cli/src/todo.cpp
// Function: process_todos(std::queue<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::deque<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>>*, bool)
void process_todos(std::queue<std::string>* command_list, bool local_mode) {
    static bool local = local_mode;

    // Recursion guard
    if(command_list->empty()) { 
        return; 
    }
    
    std::string command = command_list->front();
    std::transform(command.begin(), command.end(), command.begin(), ::tolower);    
    command_list->pop();

    // Pretty straightforward state-changes where necessary. Some of the functions "eat" the remainder
    // of the command inputs (if any) to make sure there aren't multiple triggerings of, for instance,
    // the usage() function.
    if(match_one_or_more(command, "global")) {
        local = false;        
        if(command_list->empty()) {
            read_todos(local);
        }
    } else
    if(match_one_or_more(command, "init")) {
        todo_init(local);
    } else 
    if(match_one_or_more(command, "add")) {
        if(command_list->empty()) {
            ccout << "No todo body provided." << std::endl;
        } else {
            write_todo(concat_remainder(command_list), local);
        }
    } else
    if(match_one_or_more(command, "complete")) {
        if(command_list->empty()) {
            ccout << "No todo ID provided." << std::endl;
        } else {
            unsigned int idx = atoi(command_list->front().c_str());
            command_list->pop();
            complete_todo(idx, local);
        }
    } else
    if(match_one_or_more(command, "sweep")) {
        sweep_todos(local);
    } else
    if(match_one_or_more(command, "delete")) {
        if(command_list->empty()) {
            ccout << "No todo ID provided." << std::endl;          
        } else {
            unsigned int idx = atoi(command_list->front().c_str());
            command_list->pop();
            delete_todo(idx, local);
        }
    } else 
    if(match_one_or_more(command, "purge")) {
        purge_todos(local);
    } else
    if(match_one_or_more(command, "version")) {
        ccout << "todo-cli version " << VERSION << std::endl;       
        while(!command_list->empty()) { command_list->pop(); }
    } else
    if(match_one_or_more(command, "help")) {
        while(!command_list->empty()) { command_list->pop(); }
        usage();
    } else {
        while(!command_list->empty()) { command_list->pop(); }
        // usage();
        ccout << "Invalid command. Run 'todo help' for usage information" << std::endl;
    }
    
    process_todos(command_list);    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x290, %rsp            # imm = 0x290
movq %rdi, %rbx
movb 0xe01b0(%rip), %al      # 0xf5550
testb %al, %al
je 0x15900
movq 0x10(%rbx), %rsi
cmpq %rsi, 0x30(%rbx)
je 0x15757
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x88fc0
movq (%r14), %r15
movq 0x8(%r14), %r14
xorl %r12d, %r12d
cmpq %r12, %r14
je 0x153e5
movsbl (%r15,%r12), %edi
callq 0x12530
movb %al, (%r15,%r12)
incq %r12
jmp 0x153cd
movq %rbx, %rdi
callq 0x16d1a
leaq 0x270(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4f3c(%rip), %rsi     # 0xba342
leaq 0x250(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x270(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x250(%rsp), %rdi
callq 0x86830
leaq 0x270(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x1546f
movb $0x0, 0xe00f4(%rip)     # 0xf5549
movq 0x30(%rbx), %rax
cmpq 0x10(%rbx), %rax
jne 0x15743
xorl %edi, %edi
callq 0x151b1
jmp 0x15743
leaq 0x230(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4ec1(%rip), %rsi     # 0xba349
leaq 0x210(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x230(%rsp), %rdi
leaq 0x210(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x210(%rsp), %rdi
callq 0x86830
leaq 0x230(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x154e1
movzbl 0xe0072(%rip), %edi     # 0xf5549
callq 0x15c1c
jmp 0x15743
leaq 0x1f0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4e54(%rip), %rsi     # 0xba34e
leaq 0x1d0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x1f0(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x1d0(%rsp), %rdi
callq 0x86830
leaq 0x1f0(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x15586
movq 0x30(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x1568c
leaq 0x1b0(%rsp), %rdi
movq %rbx, %rsi
callq 0x15de8
movzbl 0xdffe2(%rip), %esi     # 0xf5549
leaq 0x1b0(%rsp), %rdi
callq 0x15e57
leaq 0x1b0(%rsp), %rdi
callq 0x86830
jmp 0x15743
leaq 0x190(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4dca(%rip), %rsi     # 0xba369
leaq 0x170(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x190(%rsp), %rdi
leaq 0x170(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x170(%rsp), %rdi
callq 0x86830
leaq 0x190(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x1561a
movq 0x10(%rbx), %rax
cmpq %rax, 0x30(%rbx)
je 0x15725
movq (%rax), %rdi
callq 0x12420
movl %eax, %ebp
movq %rbx, %rdi
callq 0x16d1a
movzbl 0xdff3b(%rip), %esi     # 0xf5549
movl %ebp, %edi
callq 0x16012
jmp 0x15743
leaq 0x150(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4d54(%rip), %rsi     # 0xba387
leaq 0x130(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x150(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x130(%rsp), %rdi
callq 0x86830
leaq 0x150(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x15698
movzbl 0xdfec7(%rip), %edi     # 0xf5549
callq 0x16200
jmp 0x15743
leaq 0xa4cbf(%rip), %r14     # 0xba352
jmp 0x1572c
leaq 0x110(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4cdc(%rip), %rsi     # 0xba38d
leaq 0xf0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x110(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0xf0(%rsp), %rdi
callq 0x86830
leaq 0x110(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x15767
movq 0x10(%rbx), %rax
cmpq %rax, 0x30(%rbx)
je 0x15725
movq (%rax), %rdi
callq 0x12420
movl %eax, %ebp
movq %rbx, %rdi
callq 0x16d1a
movzbl 0xdfe2d(%rip), %esi     # 0xf5549
movl %ebp, %edi
callq 0x16105
jmp 0x15743
leaq 0xa4c46(%rip), %r14     # 0xba372
leaq 0xe0d2d(%rip), %rdi     # 0xf6460
movq %r14, %rsi
callq 0x80460
movq %rax, %rdi
callq 0x7fd40
movq %rbx, %rdi
xorl %esi, %esi
callq 0x15388
leaq 0x10(%rsp), %rdi
callq 0x86830
addq $0x290, %rsp            # imm = 0x290
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4c14(%rip), %rsi     # 0xba394
leaq 0xb0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0xb0(%rsp), %rdi
callq 0x86830
leaq 0xd0(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x157d9
movzbl 0xdfd7a(%rip), %edi     # 0xf5549
callq 0x1631e
jmp 0x15743
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4ba8(%rip), %rsi     # 0xba39a
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x90(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x70(%rsp), %rdi
callq 0x86830
leaq 0x90(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x15874
leaq 0xe0c28(%rip), %rdi     # 0xf6460
leaq 0xa4b63(%rip), %rsi     # 0xba3a2
callq 0x80460
leaq 0xa4b69(%rip), %rsi     # 0xba3b4
movq %rax, %rdi
callq 0x80460
movq %rax, %rdi
callq 0x7fd40
jmp 0x15865
movq %rbx, %rdi
callq 0x16d1a
movq 0x30(%rbx), %rax
cmpq 0x10(%rbx), %rax
jne 0x1585d
jmp 0x15743
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x88fc0
leaq 0xa4b30(%rip), %rsi     # 0xba3ba
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x16450
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x15b81
movl %eax, %ebp
leaq 0x30(%rsp), %rdi
callq 0x86830
leaq 0x50(%rsp), %rdi
callq 0x86830
testb %bpl, %bpl
je 0x158d7
movq 0x30(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x158f6
movq %rbx, %rdi
callq 0x16d1a
jmp 0x158c3
leaq 0xa4ae1(%rip), %r14     # 0xba3bf
movq 0x30(%rbx), %rax
cmpq 0x10(%rbx), %rax
je 0x1572c
movq %rbx, %rdi
callq 0x16d1a
jmp 0x158de
callq 0x15a7c
jmp 0x15743
movl %esi, %ebp
leaq 0xdfc47(%rip), %rdi     # 0xf5550
callq 0x17cc0
testl %eax, %eax
je 0x153a8
movb %bpl, 0xdfc2c(%rip)     # 0xf5549
leaq 0xdfc2c(%rip), %rdi     # 0xf5550
callq 0x17dd0
jmp 0x153a8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x86830
jmp 0x15940
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x86830
jmp 0x1595c
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0x15a60
jmp 0x15a67
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x86830
jmp 0x15983
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x86830
jmp 0x159a5
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
jmp 0x15a60
jmp 0x15a67
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x86830
jmp 0x159cc
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x1b0(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
callq 0x86830
jmp 0x159fb
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x1d0(%rsp), %rdi
callq 0x86830
jmp 0x15a1a
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x210(%rsp), %rdi
callq 0x86830
jmp 0x15a39
movq %rax, %rbx
leaq 0x230(%rsp), %rdi
jmp 0x15a60
movq %rax, %rbx
leaq 0x250(%rsp), %rdi
callq 0x86830
jmp 0x15a58
movq %rax, %rbx
leaq 0x270(%rsp), %rdi
callq 0x86830
jmp 0x15a6a
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x86830
movq %rbx, %rdi
callq 0xb7920