// File: /workspace/github_cpp_makefile_star2_O1/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 %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 0x1e23(%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 0x1de5(%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 0x8442
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 0x8442
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 0x8442
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 0x8442
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
testl %r14d, %r14d
je 0x87c4
leaq 0x1e10(%rip), %rsi      # 0xa262
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x85ce
leaq 0x1dec(%rip), %rsi      # 0xa257
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x85ce
leaq 0x1e37(%rip), %rsi      # 0xa2bb
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x85ce
leaq 0x1db1(%rip), %rsi      # 0xa24e
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d9e(%rip), %rsi      # 0xa254
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d8d(%rip), %rsi      # 0xa25c
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d7d(%rip), %rsi      # 0xa265
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d72(%rip), %rsi      # 0xa273
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d99(%rip), %rsi      # 0xa2b3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d83(%rip), %rsi      # 0xa2b6
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8651
leaq 0x1d20(%rip), %rsi      # 0xa26c
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x896c
leaq 0x1d12(%rip), %rsi      # 0xa277
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x896c
movq 0x4a72(%rip), %rdi      # 0xcff0
leaq 0x1cf7(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x4a50(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x4a44(%rip), %rdi      # 0xcff0
leaq 0x1d2f(%rip), %rsi      # 0xa2e2
movl $0x11, %edx
callq 0x3310
movq 0x4a2c(%rip), %rdi      # 0xcff0
callq 0x3170
jmp 0x89c8
cmpl $0x1, %r14d
je 0x865b
movq 0x4a11(%rip), %rdi      # 0xcff0
leaq 0x1c96(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x49ef(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x49e3(%rip), %r14      # 0xcff0
leaq 0x1cac(%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 0x49b1(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x87c4
cmpl $0x2, %r14d
jne 0x8750
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x68(%rsp), %rcx
cmpq %rbp, %rcx
je 0x867a
movq %rcx, (%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x8681
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 0x86c4
movq %rcx, 0x20(%rbx)
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x86cc
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 0x871b
movq %rcx, 0x40(%rbx)
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x8723
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 0x8896
movq 0x4899(%rip), %rdi      # 0xcff0
leaq 0x1b1e(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x4877(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x486b(%rip), %r14      # 0xcff0
leaq 0x1b34(%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 0x4839(%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 0x87e8
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x87ee
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 0x8830
movq %rcx, 0x20(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x8836
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 0x8873
movq %rcx, 0x40(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x887a
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 0x4723(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x88d4
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x88f1
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x8908
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x891f
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x893b
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8957
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 0x865b
movq 0x4673(%rip), %rdi      # 0xcff0
leaq 0x18f8(%rip), %rsi      # 0xa27c
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x4651(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x4645(%rip), %rdi      # 0xcff0
leaq 0x190e(%rip), %rsi      # 0xa2c0
movl $0x21, %edx
callq 0x3310
movq 0x462d(%rip), %rdi      # 0xcff0
callq 0x3170
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x8bbe
jmp 0x8896
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x8a4e
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8a4e
movq %rax, %rbx
jmp 0x8a6f
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8a2d
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8a2d
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8a83
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8a83
movq %rax, %rbx
movq 0x456b(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x68(%rsp), %rdi
callq 0x8b70
leaq 0x8(%rsp), %rdi
callq 0x8b70
movq %rbx, %rdi
callq 0x3440
nop