// File: /workspace/github_cpp_makefile_star2_O1/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 0x53cd(%rip), %r15      # 0xa0ea
leaq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r15, %rdx
callq 0x5d16
leaq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r15, %rsi
movq %r15, %rdx
callq 0x5d16
leaq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x538f(%rip), %rdx      # 0xa0ea
movq %rdx, %rsi
callq 0x5d16
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
xorl %r14d, %r14d
testb $0x5, 0x20(%rax,%rcx)
jne 0x4e98
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 0x4e98
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 0x4e98
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 0x4e98
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
testl %r14d, %r14d
je 0x521a
leaq 0x53ba(%rip), %rsi      # 0xa262
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5024
leaq 0x5396(%rip), %rsi      # 0xa257
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5024
leaq 0x53e1(%rip), %rsi      # 0xa2bb
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x5024
leaq 0x535b(%rip), %rsi      # 0xa24e
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x5348(%rip), %rsi      # 0xa254
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x5337(%rip), %rsi      # 0xa25c
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x5327(%rip), %rsi      # 0xa265
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x531c(%rip), %rsi      # 0xa273
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x5343(%rip), %rsi      # 0xa2b3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x532d(%rip), %rsi      # 0xa2b6
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x50a7
leaq 0x52ca(%rip), %rsi      # 0xa26c
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x53c2
leaq 0x52bc(%rip), %rsi      # 0xa277
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x53c2
movq 0x801c(%rip), %rdi      # 0xcff0
leaq 0x52a1(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7ffa(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7fee(%rip), %rdi      # 0xcff0
leaq 0x52d9(%rip), %rsi      # 0xa2e2
movl $0x11, %edx
callq 0x3310
movq 0x7fd6(%rip), %rdi      # 0xcff0
callq 0x3170
jmp 0x541e
cmpl $0x1, %r14d
je 0x50b1
movq 0x7fbb(%rip), %rdi      # 0xcff0
leaq 0x5240(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7f99(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7f8d(%rip), %r14      # 0xcff0
leaq 0x5256(%rip), %rsi      # 0xa2c0
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 0x7f5b(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x521a
cmpl $0x2, %r14d
jne 0x51a6
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x68(%rsp), %rcx
cmpq %rbp, %rcx
je 0x50d0
movq %rcx, (%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x50d7
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 0x511a
movq %rcx, 0x20(%rbx)
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x5122
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 0x5171
movq %rcx, 0x40(%rbx)
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x5179
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 0x52ec
movq 0x7e43(%rip), %rdi      # 0xcff0
leaq 0x50c8(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7e21(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7e15(%rip), %r14      # 0xcff0
leaq 0x50de(%rip), %rsi      # 0xa2c0
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 0x7de3(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %rdx
cmpq %rdx, %rcx
je 0x523e
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x5244
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 0x5286
movq %rcx, 0x20(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x528c
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 0x52c9
movq %rcx, 0x40(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x52d0
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 0x7ccd(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x532a
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x5347
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x535e
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x5375
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5391
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x53ad
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 $0x3, %r14d
je 0x50b1
movq 0x7c1d(%rip), %rdi      # 0xcff0
leaq 0x4ea2(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x7bfb(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x7bef(%rip), %rdi      # 0xcff0
leaq 0x4eb8(%rip), %rsi      # 0xa2c0
movl $0x21, %edx
callq 0x3310
movq 0x7bd7(%rip), %rdi      # 0xcff0
callq 0x3170
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5b5c
jmp 0x52ec
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x54a4
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x54a4
movq %rax, %rbx
jmp 0x54c5
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x5483
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x5483
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x54d9
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x54d9
movq %rax, %rbx
movq 0x7b15(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x68(%rsp), %rdi
callq 0x5b0e
leaq 0x8(%rsp), %rdi
callq 0x5b0e
movq %rbx, %rdi
callq 0x3440
nop