// File: wandernauta[P]ttasks/t.cpp
// Function: main
int main(int argc, char* argv[]) {
  TodoList tl;
  std::vector<std::string> args(argv, argv+argc);

  if (argc == 1) {
    // Called as 't'. Dump the todo list.
    tl.dump();
  } else {
    if (args[1] == "-h") {
      // Called as 't -h': Dump some help info.
      std::cout << "usage: t               # Dump all items." << std::endl;
      std::cout << "       t 3             # Erase the third item." << std::endl;
      std::cout << "       t Walk the dog  # Add an item." << std::endl;
      std::cout << "       t -e            # Open todo.txt in $EDITOR." << std::endl;
      std::cout << "       t -h            # Show this help text." << std::endl;
      std::cout << "       t -c            # Count the amount of items." << std::endl;
      std::cout << "       t -r            # Reorder the items." << std::endl;
      std::cout << std::endl;
      exit(0);
    } else if (args[1] == "-e") {
      // Called as 't -e'. Open todo.txt in $EDITOR.
      tl.edit();
    } else if (args[1] == "-c") {
      // Called as 't -c'. Count the amount of items in the list.
      std::cout << tl.count() << std::endl;
    } else if (args[1] == "-r") {
      // Called as 't -r'. Reorder the items.
      tl.reorder();
    } else if (atoi(argv[1]) != 0) {
      // Called as 't 3' or similar. Erase the task.
      tl.erase(atoi(argv[1]));
    } else if (args[1].find_first_not_of("1234567890. ") == std::string::npos) {
      std::cout << "Say what?" << std::endl;
    } else {
      // Called as 't Walk the dog' or similar.
      // Collect the argument:

      std::ostringstream oss;
      for (std::vector<std::string>::iterator it = args.begin()+1; it < args.end()-1; ++it) {
        oss << *it << " ";
      }
      oss << args.back();
      tl.add(oss.str());
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2d0, %rsp            # imm = 0x2D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x4d70
movq -0x10(%rbp), %rax
movq %rax, -0x260(%rbp)
movslq -0x8(%rbp), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, -0x258(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3b90
movq -0x260(%rbp), %rsi
movq -0x258(%rbp), %rdx
movq -0x250(%rbp), %rcx
leaq -0x78(%rbp), %rdi
callq 0x3bb0
jmp 0x365c
leaq -0x79(%rbp), %rdi
callq 0x3c30
cmpl $0x1, -0x8(%rbp)
jne 0x36b2
leaq -0x60(%rbp), %rdi
callq 0x5760
jmp 0x3676
jmp 0x3b4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x3c30
jmp 0x3b73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x3b6a
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x3c80
movq %rax, %rdi
leaq 0x593a(%rip), %rsi      # 0x9004
callq 0x3c50
movb %al, -0x261(%rbp)
jmp 0x36d7
movb -0x261(%rbp), %al
testb $0x1, %al
jne 0x36e6
jmp 0x3859
movq 0x98e3(%rip), %rdi      # 0xcfd0
leaq 0x5913(%rip), %rsi      # 0x9007
callq 0x3240
movq %rax, -0x270(%rbp)
jmp 0x3702
movq -0x270(%rbp), %rdi
movq 0x98b0(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x3717
movq 0x98b2(%rip), %rdi      # 0xcfd0
leaq 0x590b(%rip), %rsi      # 0x9030
callq 0x3240
movq %rax, -0x278(%rbp)
jmp 0x3733
movq -0x278(%rbp), %rdi
movq 0x987f(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x3748
movq 0x9881(%rip), %rdi      # 0xcfd0
leaq 0x5909(%rip), %rsi      # 0x905f
callq 0x3240
movq %rax, -0x280(%rbp)
jmp 0x3764
movq -0x280(%rbp), %rdi
movq 0x984e(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x3779
movq 0x9850(%rip), %rdi      # 0xcfd0
leaq 0x58fe(%rip), %rsi      # 0x9085
callq 0x3240
movq %rax, -0x288(%rbp)
jmp 0x3795
movq -0x288(%rbp), %rdi
movq 0x981d(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x37aa
movq 0x981f(%rip), %rdi      # 0xcfd0
leaq 0x5900(%rip), %rsi      # 0x90b8
callq 0x3240
movq %rax, -0x290(%rbp)
jmp 0x37c6
movq -0x290(%rbp), %rdi
movq 0x97ec(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x37db
movq 0x97ee(%rip), %rdi      # 0xcfd0
leaq 0x58fd(%rip), %rsi      # 0x90e6
callq 0x3240
movq %rax, -0x298(%rbp)
jmp 0x37f7
movq -0x298(%rbp), %rdi
movq 0x97bb(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x380c
movq 0x97bd(%rip), %rdi      # 0xcfd0
leaq 0x5900(%rip), %rsi      # 0x911a
callq 0x3240
movq %rax, -0x2a0(%rbp)
jmp 0x3828
movq -0x2a0(%rbp), %rdi
movq 0x978a(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x383d
movq 0x978c(%rip), %rdi      # 0xcfd0
movq 0x9775(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x3852
xorl %edi, %edi
callq 0x3300
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x3c80
movq %rax, %rdi
leaq 0x58d5(%rip), %rsi      # 0x9146
callq 0x3c50
movb %al, -0x2a1(%rbp)
jmp 0x387e
movb -0x2a1(%rbp), %al
testb $0x1, %al
jne 0x388a
jmp 0x389a
leaq -0x60(%rbp), %rdi
callq 0x5950
jmp 0x3895
jmp 0x3b48
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x3c80
movq %rax, %rdi
leaq 0x5897(%rip), %rsi      # 0x9149
callq 0x3c50
movb %al, -0x2a2(%rbp)
jmp 0x38bf
movb -0x2a2(%rbp), %al
testb $0x1, %al
jne 0x38cb
jmp 0x3913
leaq -0x60(%rbp), %rdi
callq 0x5830
movq %rax, -0x2b0(%rbp)
jmp 0x38dd
movq -0x2b0(%rbp), %rsi
movq 0x96e5(%rip), %rdi      # 0xcfd0
callq 0x3090
movq %rax, -0x2b8(%rbp)
jmp 0x38f9
movq -0x2b8(%rbp), %rdi
movq 0x96b9(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x390e
jmp 0x3b46
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x3c80
movq %rax, %rdi
leaq 0x5821(%rip), %rsi      # 0x914c
callq 0x3c50
movb %al, -0x2b9(%rbp)
jmp 0x3938
movb -0x2b9(%rbp), %al
testb $0x1, %al
jne 0x3944
jmp 0x3954
leaq -0x60(%rbp), %rdi
callq 0x5850
jmp 0x394f
jmp 0x3b44
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33a0
cmpl $0x0, %eax
je 0x3985
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x33a0
movl %eax, %esi
leaq -0x60(%rbp), %rdi
callq 0x5580
jmp 0x3980
jmp 0x3b42
leaq -0x78(%rbp), %rdi
movl $0x1, %esi
callq 0x3c80
movq %rax, %rdi
leaq 0x57b2(%rip), %rsi      # 0x914f
xorl %eax, %eax
movl %eax, %edx
callq 0x3160
cmpq $-0x1, %rax
jne 0x39e2
movq 0x961d(%rip), %rdi      # 0xcfd0
leaq 0x57a2(%rip), %rsi      # 0x915c
callq 0x3240
movq %rax, -0x2c8(%rbp)
jmp 0x39c8
movq -0x2c8(%rbp), %rdi
movq 0x95ea(%rip), %rsi      # 0xcfc0
callq 0x3290
jmp 0x39dd
jmp 0x3b40
leaq -0x208(%rbp), %rdi
callq 0x3340
jmp 0x39f0
leaq -0x78(%rbp), %rdi
callq 0x3ca0
movq %rax, -0x218(%rbp)
leaq -0x218(%rbp), %rdi
movl $0x1, %esi
callq 0x3cd0
movq %rax, -0x210(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x3d50
movq %rax, -0x228(%rbp)
leaq -0x228(%rbp), %rdi
movl $0x1, %esi
callq 0x3d80
movq %rax, -0x220(%rbp)
leaq -0x210(%rbp), %rdi
leaq -0x220(%rbp), %rsi
callq 0x3d10
testb $0x1, %al
jne 0x3a59
jmp 0x3ab9
leaq -0x210(%rbp), %rdi
callq 0x3dc0
movq %rax, %rsi
leaq -0x208(%rbp), %rdi
callq 0x3230
movq %rax, -0x2d0(%rbp)
jmp 0x3a7d
movq -0x2d0(%rbp), %rdi
leaq 0x56cf(%rip), %rsi      # 0x915a
callq 0x3240
jmp 0x3a92
jmp 0x3a94
leaq -0x210(%rbp), %rdi
callq 0x3de0
jmp 0x3a18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
jmp 0x3b32
leaq -0x78(%rbp), %rdi
callq 0x3e00
movq %rax, %rsi
leaq -0x208(%rbp), %rdi
callq 0x3230
jmp 0x3ad3
leaq -0x248(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x3270
jmp 0x3ae8
leaq -0x60(%rbp), %rdi
leaq -0x248(%rbp), %rsi
callq 0x5220
jmp 0x3afa
leaq -0x248(%rbp), %rdi
callq 0x3190
leaq -0x208(%rbp), %rdi
callq 0x30a0
jmp 0x3b40
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x88(%rbp)
movl %eax, -0x8c(%rbp)
leaq -0x248(%rbp), %rdi
callq 0x3190
leaq -0x208(%rbp), %rdi
callq 0x30a0
jmp 0x3b6a
jmp 0x3b42
jmp 0x3b44
jmp 0x3b46
jmp 0x3b48
jmp 0x3b4a
jmp 0x3b4c
leaq -0x78(%rbp), %rdi
callq 0x3e40
leaq -0x60(%rbp), %rdi
callq 0x3ea0
movl -0x4(%rbp), %eax
addq $0x2d0, %rsp            # imm = 0x2D0
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x3e40
leaq -0x60(%rbp), %rdi
callq 0x3ea0
movq -0x88(%rbp), %rdi
callq 0x3400
nopl (%rax,%rax)