// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x268, %rsp            # imm = 0x268
movq %rdx, %r14
movq %rdi, %rbx
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x5399(%rip), %r15      # 0xa136
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x5d7e
leaq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rsi
movq %r15, %rdx
callq 0x5d7e
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x535b(%rip), %rdx      # 0xa136
movq %rdx, %rsi
callq 0x5d7e
leaq 0x78(%rsp), %rbp
movq %rbp, -0x10(%rbp)
xorl %eax, %eax
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
leaq 0x98(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rax, -0x8(%r12)
movb %al, (%r12)
leaq 0xb8(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x3420
leaq 0xe8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x3340
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x4e7f
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %rdx
cmpq %rdx, %rcx
je 0x50bf
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x50c5
leaq 0x88(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x3340
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl $0x1, %r14d
testb $0x5, 0x20(%rax,%rcx)
jne 0x4f3c
leaq 0xa8(%rsp), %rsi
leaq 0xe8(%rsp), %rdi
callq 0x3340
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl $0x2, %r14d
testb $0x5, 0x20(%rax,%rcx)
jne 0x4f3c
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0xe8(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3340
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movb 0x20(%rax,%rcx), %al
andb $0x5, %al
xorl %r14d, %r14d
cmpb $0x1, %al
adcl $0x3, %r14d
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x4f3c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
leaq 0x536b(%rip), %rsi      # 0xa2ae
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5243
leaq 0x5347(%rip), %rsi      # 0xa2a3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5243
leaq 0x5392(%rip), %rsi      # 0xa307
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5243
leaq 0x530c(%rip), %rsi      # 0xa29a
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52f9(%rip), %rsi      # 0xa2a0
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52e8(%rip), %rsi      # 0xa2a8
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52d8(%rip), %rsi      # 0xa2b1
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52cd(%rip), %rsi      # 0xa2bf
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52f4(%rip), %rsi      # 0xa2ff
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x52de(%rip), %rsi      # 0xa302
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x52c6
leaq 0x527b(%rip), %rsi      # 0xa2b8
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x543e
leaq 0x526d(%rip), %rsi      # 0xa2c3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x543e
movq 0x7f81(%rip), %rdi      # 0xcff0
leaq 0x5252(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7f5f(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7f53(%rip), %rdi      # 0xcff0
leaq 0x528a(%rip), %rsi      # 0xa32e
movl $0x11, %edx
callq 0x3310
movq 0x7f3b(%rip), %rdi      # 0xcff0
callq 0x3170
jmp 0x549a
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %rdx, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x20(%rbx)
movq 0x28(%rsp), %rcx
leaq 0x38(%rsp), %rdx
cmpq %rdx, %rcx
je 0x5107
movq %rcx, 0x20(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x510d
movups (%rdx), %xmm0
movups %xmm0, (%rax)
movq 0x30(%rsp), %rax
movq %rax, 0x28(%rbx)
movq %rdx, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x40(%rbx)
movq 0x48(%rsp), %rcx
cmpq %r15, %rcx
je 0x514a
movq %rcx, 0x40(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x5151
movups (%r15), %xmm0
movups %xmm0, (%rax)
movq 0x50(%rsp), %rax
movq %rax, 0x48(%rbx)
movq %r15, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq 0x7e4c(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x51ab
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x51c8
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x51df
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x51f6
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5212
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x522e
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x32c0
movq %rbx, %rax
addq $0x268, %rsp            # imm = 0x268
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x1, %r14d
je 0x52d0
movq 0x7d9c(%rip), %rdi      # 0xcff0
leaq 0x506d(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7d7a(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7d6e(%rip), %r14      # 0xcff0
leaq 0x5083(%rip), %rsi      # 0xa30c
movl $0x21, %edx
movq %r14, %rdi
callq 0x3310
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0x7d3c(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x4e54
cmpl $0x2, %r14d
jne 0x53c5
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x68(%rsp), %rcx
cmpq %rbp, %rcx
je 0x52ef
movq %rcx, (%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x52f6
movups (%rbp), %xmm0
movups %xmm0, (%rax)
movq 0x70(%rsp), %rax
movq %rax, 0x8(%rbx)
movq %rbp, 0x68(%rsp)
movq $0x0, 0x70(%rsp)
movb $0x0, 0x78(%rsp)
leaq 0x30(%rbx), %rax
movq %rax, 0x20(%rbx)
movq 0x88(%rsp), %rcx
cmpq %r12, %rcx
je 0x5339
movq %rcx, 0x20(%rbx)
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x5341
movups (%r12), %xmm0
movups %xmm0, (%rax)
movq 0x90(%rsp), %rax
movq %rax, 0x28(%rbx)
movq %r12, 0x88(%rsp)
movq $0x0, 0x90(%rsp)
movb $0x0, 0x98(%rsp)
leaq 0x50(%rbx), %rax
movq %rax, 0x40(%rbx)
movq 0xa8(%rsp), %rcx
cmpq %r13, %rcx
je 0x5390
movq %rcx, 0x40(%rbx)
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x5398
movups (%r13), %xmm0
movups %xmm0, (%rax)
movq 0xb0(%rsp), %rax
movq %rax, 0x48(%rbx)
movq %r13, 0xa8(%rsp)
movq $0x0, 0xb0(%rsp)
movb $0x0, 0xb8(%rsp)
jmp 0x516d
movq 0x7c24(%rip), %rdi      # 0xcff0
leaq 0x4ef5(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7c02(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7bf6(%rip), %r14      # 0xcff0
leaq 0x4f0b(%rip), %rsi      # 0xa30c
movl $0x21, %edx
movq %r14, %rdi
callq 0x3310
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0x7bc4(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x4e54
cmpl $0x3, %r14d
je 0x52d0
movq 0x7ba1(%rip), %rdi      # 0xcff0
leaq 0x4e72(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7b7f(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7b73(%rip), %rdi      # 0xcff0
leaq 0x4e88(%rip), %rsi      # 0xa30c
movl $0x21, %edx
callq 0x3310
movq 0x7b5b(%rip), %rdi      # 0xcff0
callq 0x3170
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5bbe
jmp 0x516d
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x5520
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x5520
movq %rax, %rbx
jmp 0x5541
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x54ff
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x54ff
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x5555
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x5555
movq %rax, %rbx
movq 0x7a99(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x68(%rsp), %rdi
callq 0x5b70
leaq 0x8(%rsp), %rdi
callq 0x5b70
movq %rbx, %rdi
callq 0x3440
nop