// File: /workspace/github_cpp_makefile_star2_O2/dmonaldo[P]simple-network-file-system/Shell.cpp
// Function: Shell::parse_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Shell::Command Shell::parse_command(string command_str)
{
  // empty command struct returned for errors
  struct Command empty = {"", "", ""};

  // grab each of the tokens (if they exist)
  struct Command command;
  istringstream ss(command_str);
  int num_tokens = 0;
  if (ss >> command.name) {
    num_tokens++;
    if (ss >> command.file_name) {
      num_tokens++;
      if (ss >> command.append_data) {
        num_tokens++;
        string junk;
        if (ss >> junk) {
          num_tokens++;
        }
      }
    }
  }

  // Check for empty command line
  if (num_tokens == 0) {
    return empty;
  }

  // Check for invalid command lines
  if (command.name == "ls" ||
      command.name == "home" ||
      command.name == "quit")
  {
    if (num_tokens != 1) {
      cerr << "Invalid command line: " << command.name;
      cerr << " has improper number of arguments" << endl;
      return empty;
    }
  }
  else if (command.name == "mkdir" ||
      command.name == "cd"    ||
      command.name == "rmdir" ||
      command.name == "create"||
      command.name == "cat"   ||
      command.name == "rm"    ||
      command.name == "stat")
  {
    if (num_tokens != 2) {
      cerr << "Invalid command line: " << command.name;
      cerr << " has improper number of arguments" << endl;
      return empty;
    }
  }
  else if (command.name == "append" || command.name == "head")
  {
    if (num_tokens != 3) {
      cerr << "Invalid command line: " << command.name;
      cerr << " has improper number of arguments" << endl;
      return empty;
    }
  }
  else {
    cerr << "Invalid command line: " << command.name;
    cerr << " is not a command" << endl;
    return empty;
  }

  return command;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x260, %rsp            # imm = 0x260
movq %rdx, %r15
movq %rdi, %rbx
leaq 0x1652(%rip), %rsi      # 0x80ea
leaq 0x80(%rsp), %r14
leaq 0xe0(%rsp), %rdx
movq %r14, %rdi
callq 0x5296
leaq 0xa0(%rsp), %r12
leaq 0x162b(%rip), %rsi      # 0x80ea
movq %rsp, %rdx
movq %r12, %rdi
callq 0x5296
leaq 0xc0(%rsp), %rdi
leaq 0x1611(%rip), %rsi      # 0x80ea
leaq 0x60(%rsp), %rdx
callq 0x5296
leaq 0x10(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x50(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xe0(%rsp), %rdi
pushq $0x8
popq %rdx
movq %r15, %rsi
callq 0x33f0
leaq 0xe0(%rsp), %rdi
movq %rsp, %rsi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x6b4e
movq %r14, %r15
jmp 0x6c1a
leaq 0x20(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x6b72
pushq $0x1
jmp 0x6b98
leaq 0x40(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x6c5a
pushq $0x2
popq %rbp
leaq 0x16c2(%rip), %rsi      # 0x8262
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x6bd9
leaq 0x16a1(%rip), %rsi      # 0x8257
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6bd9
leaq 0x16f2(%rip), %rsi      # 0x82bb
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x6ca2
cmpl $0x1, %ebp
je 0x6c1a
movq 0x440b(%rip), %rdi      # 0xaff0
leaq 0x1690(%rip), %rsi      # 0x827c
callq 0x3270
movq %rsp, %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x16bd(%rip), %rsi      # 0x82c0
movq 0x43e6(%rip), %rdi      # 0xaff0
callq 0x3270
movq %rax, %rdi
callq 0x3160
movq %r14, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6fb0
leaq 0xe0(%rsp), %rdi
callq 0x3150
movq %rsp, %rdi
callq 0x6f90
leaq 0x80(%rsp), %rdi
callq 0x6f90
movq %rbx, %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xe0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x20(%rax,%rcx), %eax
andl $0x5, %eax
xorl %ebp, %ebp
cmpl $0x1, %eax
adcl $0x3, %ebp
leaq 0x60(%rsp), %rdi
callq 0x3498
jmp 0x6b99
leaq 0x15a5(%rip), %rsi      # 0x824e
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x1595(%rip), %rsi      # 0x8254
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x158a(%rip), %rsi      # 0x825c
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x1580(%rip), %rsi      # 0x8265
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x157b(%rip), %rsi      # 0x8273
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x15a8(%rip), %rsi      # 0x82b3
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d2a
leaq 0x1598(%rip), %rsi      # 0x82b6
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x6d38
cmpl $0x2, %ebp
jne 0x6bde
jmp 0x6c1a
leaq 0x152d(%rip), %rsi      # 0x826c
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x6d61
leaq 0x1522(%rip), %rsi      # 0x8277
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x6d6f
cmpl $0x3, %ebp
jne 0x6bde
jmp 0x6c1a
movq 0x427a(%rip), %rdi      # 0xaff0
leaq 0x14ff(%rip), %rsi      # 0x827c
callq 0x3270
movq %rsp, %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x154e(%rip), %rsi      # 0x82e2
jmp 0x6c03
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3498
jmp 0x6dd4
movq %rax, %rbx
jmp 0x6de1
movq %rax, %rbx
movq %r12, %rdi
callq 0x3498
jmp 0x6dbd
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3498
jmp 0x6df6
movq %rax, %rbx
jmp 0x6df6
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x3150
movq %rsp, %rdi
callq 0x6f90
leaq 0x80(%rsp), %rdi
callq 0x6f90
movq %rbx, %rdi
callq 0x3410