// File: /workspace/github_cpp_makefile_star2_O3/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 0x1e29(%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 0x1deb(%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 0x83ef
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x8(%rsp), %rcx
leaq 0x18(%rsp), %rdx
cmpq %rdx, %rcx
je 0x862f
movq %rcx, (%rbx)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x8635
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 0x84ac
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 0x84ac
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 0x84ac
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
leaq 0x1dfb(%rip), %rsi      # 0xa2ae
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x87b3
leaq 0x1dd7(%rip), %rsi      # 0xa2a3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x87b3
leaq 0x1e22(%rip), %rsi      # 0xa307
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x87b3
leaq 0x1d9c(%rip), %rsi      # 0xa29a
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d89(%rip), %rsi      # 0xa2a0
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d78(%rip), %rsi      # 0xa2a8
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d68(%rip), %rsi      # 0xa2b1
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d5d(%rip), %rsi      # 0xa2bf
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d84(%rip), %rsi      # 0xa2ff
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d6e(%rip), %rsi      # 0xa302
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x8836
leaq 0x1d0b(%rip), %rsi      # 0xa2b8
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x89ae
leaq 0x1cfd(%rip), %rsi      # 0xa2c3
leaq 0x68(%rsp), %rdi
callq 0x30d0
testl %eax, %eax
je 0x89ae
movq 0x4a11(%rip), %rdi      # 0xcff0
leaq 0x1ce2(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x49ef(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x49e3(%rip), %rdi      # 0xcff0
leaq 0x1d1a(%rip), %rsi      # 0xa32e
movl $0x11, %edx
callq 0x3310
movq 0x49cb(%rip), %rdi      # 0xcff0
callq 0x3170
jmp 0x8a0a
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 0x8677
movq %rcx, 0x20(%rbx)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x867d
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 0x86ba
movq %rcx, 0x40(%rbx)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x86c1
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 0x48dc(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
movq 0xa8(%rsp), %rdi
cmpq %r13, %rdi
je 0x871b
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x88(%rsp), %rdi
cmpq %r12, %rdi
je 0x8738
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x68(%rsp), %rdi
cmpq %rbp, %rdi
je 0x874f
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x8766
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8782
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x879e
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 0x8840
movq 0x482c(%rip), %rdi      # 0xcff0
leaq 0x1afd(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x480a(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x47fe(%rip), %r14      # 0xcff0
leaq 0x1b13(%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 0x47cc(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x83c4
cmpl $0x2, %r14d
jne 0x8935
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq 0x68(%rsp), %rcx
cmpq %rbp, %rcx
je 0x885f
movq %rcx, (%rbx)
movq 0x78(%rsp), %rax
movq %rax, 0x10(%rbx)
jmp 0x8866
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 0x88a9
movq %rcx, 0x20(%rbx)
movq 0x98(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x88b1
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 0x8900
movq %rcx, 0x40(%rbx)
movq 0xb8(%rsp), %rax
movq %rax, 0x50(%rbx)
jmp 0x8908
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 0x86dd
movq 0x46b4(%rip), %rdi      # 0xcff0
leaq 0x1985(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x4692(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x4686(%rip), %r14      # 0xcff0
leaq 0x199b(%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 0x4654(%rip), %rdi      # 0xcff0
callq 0x3040
movq %rax, %rdi
callq 0x31e0
jmp 0x83c4
cmpl $0x3, %r14d
je 0x8840
movq 0x4631(%rip), %rdi      # 0xcff0
leaq 0x1902(%rip), %rsi      # 0xa2c8
movl $0x16, %edx
callq 0x3310
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x460f(%rip), %rdi      # 0xcff0
callq 0x3310
movq 0x4603(%rip), %rdi      # 0xcff0
leaq 0x1918(%rip), %rsi      # 0xa30c
movl $0x21, %edx
callq 0x3310
movq 0x45eb(%rip), %rdi      # 0xcff0
callq 0x3170
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x8c02
jmp 0x86dd
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
leaq 0xd8(%rsp), %rax
cmpq %rax, %rdi
je 0x8a90
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8a90
movq %rax, %rbx
jmp 0x8ab1
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x8a6f
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8a6f
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x8ac5
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x32c0
jmp 0x8ac5
movq %rax, %rbx
movq 0x4529(%rip), %rsi      # 0xcfc0
leaq 0xe8(%rsp), %rdi
callq 0x3390
leaq 0x160(%rsp), %rdi
callq 0x3120
leaq 0x68(%rsp), %rdi
callq 0x8bb4
leaq 0x8(%rsp), %rdi
callq 0x8bb4
movq %rbx, %rdi
callq 0x3440
nop