// File: /workspace/github_cpp_makefile_star2_O2/dmonaldo[P]simple-network-file-system/FileSys.cpp
// Function: FileSys::parse_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
FileSys::Command FileSys::parse_command(string command_str)
{
  //cout << "Running command: " << command_str << endl;

  // empty command struct returned for errors
  struct FileSys::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 0x3674(%rip), %rsi      # 0x80ea
leaq 0x80(%rsp), %r14
leaq 0xe0(%rsp), %rdx
movq %r14, %rdi
callq 0x5296
leaq 0xa0(%rsp), %r12
leaq 0x364d(%rip), %rsi      # 0x80ea
movq %rsp, %rdx
movq %r12, %rdi
callq 0x5296
leaq 0xc0(%rsp), %rdi
leaq 0x3633(%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 0x4b2c
movq %r14, %r15
jmp 0x4bf8
leaq 0x20(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x4b50
pushq $0x1
jmp 0x4b76
leaq 0x40(%rsp), %rsi
leaq 0xe0(%rsp), %rdi
callq 0x3300
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x4c38
pushq $0x2
popq %rbp
leaq 0x36e4(%rip), %rsi      # 0x8262
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x4bb7
leaq 0x36c3(%rip), %rsi      # 0x8257
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4bb7
leaq 0x3714(%rip), %rsi      # 0x82bb
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x4c80
cmpl $0x1, %ebp
je 0x4bf8
movq 0x642d(%rip), %rdi      # 0xaff0
leaq 0x36b2(%rip), %rsi      # 0x827c
callq 0x3270
movq %rsp, %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x36df(%rip), %rsi      # 0x82c0
movq 0x6408(%rip), %rdi      # 0xaff0
callq 0x3270
movq %rax, %rdi
callq 0x3160
movq %r14, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x52fe
leaq 0xe0(%rsp), %rdi
callq 0x3150
movq %rsp, %rdi
callq 0x52de
leaq 0x80(%rsp), %rdi
callq 0x52de
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 0x4b77
leaq 0x35c7(%rip), %rsi      # 0x824e
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x35b7(%rip), %rsi      # 0x8254
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x35ac(%rip), %rsi      # 0x825c
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x35a2(%rip), %rsi      # 0x8265
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x359d(%rip), %rsi      # 0x8273
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x35ca(%rip), %rsi      # 0x82b3
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d08
leaq 0x35ba(%rip), %rsi      # 0x82b6
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x4d16
cmpl $0x2, %ebp
jne 0x4bbc
jmp 0x4bf8
leaq 0x354f(%rip), %rsi      # 0x826c
movq %rsp, %r15
movq %r15, %rdi
callq 0x52d1
testb %al, %al
jne 0x4d3f
leaq 0x3544(%rip), %rsi      # 0x8277
movq %rsp, %rdi
callq 0x52d1
testb %al, %al
je 0x4d4d
cmpl $0x3, %ebp
jne 0x4bbc
jmp 0x4bf8
movq 0x629c(%rip), %rdi      # 0xaff0
leaq 0x3521(%rip), %rsi      # 0x827c
callq 0x3270
movq %rsp, %rsi
movq %rax, %rdi
callq 0x3250
leaq 0x3570(%rip), %rsi      # 0x82e2
jmp 0x4be1
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x3498
jmp 0x4db2
movq %rax, %rbx
jmp 0x4dbf
movq %rax, %rbx
movq %r12, %rdi
callq 0x3498
jmp 0x4d9b
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x3498
jmp 0x4dd4
movq %rax, %rbx
jmp 0x4dd4
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x3150
movq %rsp, %rdi
callq 0x52de
leaq 0x80(%rsp), %rdi
callq 0x52de
movq %rbx, %rdi
callq 0x3410