// File: dmonaldo[P]simple-network-file-system/Shell.cpp
// Function: Shell::execute_command(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool Shell::execute_command(string command_str)
{
  // parse the command line
  struct Command command = parse_command(command_str);

  // look for the matching command
  if (command.name == "") {
    return false;
  }
  else if (command.name == "mkdir") {
    mkdir_rpc(command.file_name);
  }
  else if (command.name == "cd") {
    cd_rpc(command.file_name);
  }
  else if (command.name == "home") {
    home_rpc();
  }
  else if (command.name == "rmdir") {
    rmdir_rpc(command.file_name);
  }
  else if (command.name == "ls") {
    ls_rpc();
  }
  else if (command.name == "create") {
    create_rpc(command.file_name);
  }
  else if (command.name == "append") {
    append_rpc(command.file_name, command.append_data);
  }
  else if (command.name == "cat") {
    cat_rpc(command.file_name);
  }
  else if (command.name == "head") {
    errno = 0;
    unsigned long n = strtoul(command.append_data.c_str(), NULL, 0);
    if (0 == errno) {
      head_rpc(command.file_name, n);
    } else {
      cerr << "Invalid command line: " << command.append_data;
      cerr << " is not a valid number of bytes" << endl;
      return false;
    }
  }
  else if (command.name == "rm") {
    rm_rpc(command.file_name);
  }
  else if (command.name == "stat") {
    stat_rpc(command.file_name);
  }
  else if (command.name == "quit") {
    return true;
  }

  return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x200(%rbp)
leaq -0x98(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x31a0
movq -0x200(%rbp), %rsi
movq -0x1f8(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x97a0
jmp 0x8e2a
leaq -0x98(%rbp), %rdi
callq 0x3628
leaq 0x32ad(%rip), %rsi      # 0xc0ea
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x201(%rbp)
jmp 0x8e4e
movb -0x201(%rbp), %al
testb $0x1, %al
jne 0x8e5a
jmp 0x8ea7
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa8(%rbp)
jmp 0x94be
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3628
jmp 0x94de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x94d5
leaq 0x33a0(%rip), %rsi      # 0xc24e
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x202(%rbp)
jmp 0x8ebf
movb -0x202(%rbp), %al
testb $0x1, %al
jne 0x8ecb
jmp 0x8f26
leaq -0x58(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x31a0
jmp 0x8edd
movq -0x200(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x7650
jmp 0x8ef2
leaq -0xc8(%rbp), %rdi
callq 0x3628
jmp 0x94ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x3327(%rip), %rsi      # 0xc254
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x203(%rbp)
jmp 0x8f3e
movb -0x203(%rbp), %al
testb $0x1, %al
jne 0x8f4a
jmp 0x8fa5
leaq -0x58(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x31a0
jmp 0x8f5c
movq -0x200(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x7b10
jmp 0x8f71
leaq -0xe8(%rbp), %rdi
callq 0x3628
jmp 0x94ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x32ab(%rip), %rsi      # 0xc257
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x204(%rbp)
jmp 0x8fbd
movb -0x204(%rbp), %al
testb $0x1, %al
jne 0x8fc9
jmp 0x8fdc
movq -0x200(%rbp), %rdi
callq 0x7d10
jmp 0x8fd7
jmp 0x94aa
leaq 0x3279(%rip), %rsi      # 0xc25c
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x205(%rbp)
jmp 0x8ff4
movb -0x205(%rbp), %al
testb $0x1, %al
jne 0x9000
jmp 0x905b
leaq -0x58(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x31a0
jmp 0x9012
movq -0x200(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x7f10
jmp 0x9027
leaq -0x108(%rbp), %rdi
callq 0x3628
jmp 0x94a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x3200(%rip), %rsi      # 0xc262
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x206(%rbp)
jmp 0x9073
movb -0x206(%rbp), %al
testb $0x1, %al
jne 0x907f
jmp 0x9092
movq -0x200(%rbp), %rdi
callq 0x8110
jmp 0x908d
jmp 0x94a6
leaq 0x31cc(%rip), %rsi      # 0xc265
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x207(%rbp)
jmp 0x90aa
movb -0x207(%rbp), %al
testb $0x1, %al
jne 0x90b6
jmp 0x9111
leaq -0x58(%rbp), %rsi
leaq -0x128(%rbp), %rdi
callq 0x31a0
jmp 0x90c8
movq -0x200(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x8310
jmp 0x90dd
leaq -0x128(%rbp), %rdi
callq 0x3628
jmp 0x94a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x3154(%rip), %rsi      # 0xc26c
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x208(%rbp)
jmp 0x9129
movb -0x208(%rbp), %al
testb $0x1, %al
jne 0x9135
jmp 0x91b3
leaq -0x58(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x31a0
jmp 0x9147
leaq -0x38(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x31a0
jmp 0x9159
movq -0x200(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x8510
leaq -0x168(%rbp), %rdi
callq 0x3628
leaq -0x148(%rbp), %rdi
callq 0x3628
jmp 0x94a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x30b9(%rip), %rsi      # 0xc273
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x209(%rbp)
jmp 0x91cb
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0x91d7
jmp 0x9232
leaq -0x58(%rbp), %rsi
leaq -0x188(%rbp), %rdi
callq 0x31a0
jmp 0x91e9
movq -0x200(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x8530
jmp 0x91fe
leaq -0x188(%rbp), %rdi
callq 0x3628
jmp 0x94a0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x303e(%rip), %rsi      # 0xc277
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x20a(%rbp)
jmp 0x924a
movb -0x20a(%rbp), %al
testb $0x1, %al
jne 0x9259
jmp 0x936c
callq 0x3060
movl $0x0, (%rax)
leaq -0x78(%rbp), %rdi
addq $0x40, %rdi
callq 0x3190
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x3130
movq %rax, -0x190(%rbp)
callq 0x3060
movq %rax, %rcx
xorl %eax, %eax
cmpl (%rcx), %eax
jne 0x92f5
leaq -0x58(%rbp), %rsi
leaq -0x1b0(%rbp), %rdi
callq 0x31a0
jmp 0x92a6
movq -0x200(%rbp), %rdi
movl -0x190(%rbp), %edx
leaq -0x1b0(%rbp), %rsi
callq 0x8730
jmp 0x92c1
leaq -0x1b0(%rbp), %rdi
callq 0x3628
jmp 0x9367
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x3628
jmp 0x94d5
movq 0x6cf4(%rip), %rdi      # 0xfff0
leaq 0x2f79(%rip), %rsi      # 0xc27c
callq 0x3340
movq %rax, -0x218(%rbp)
jmp 0x9311
movq -0x218(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3310
jmp 0x9323
movq 0x6cc6(%rip), %rdi      # 0xfff0
leaq 0x2f62(%rip), %rsi      # 0xc293
callq 0x3340
movq %rax, -0x220(%rbp)
jmp 0x933f
movq -0x220(%rbp), %rdi
movq 0x6c5b(%rip), %rsi      # 0xffa8
callq 0x3390
jmp 0x9354
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa8(%rbp)
jmp 0x94be
jmp 0x949e
leaq 0x2f40(%rip), %rsi      # 0xc2b3
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x221(%rbp)
jmp 0x9384
movb -0x221(%rbp), %al
testb $0x1, %al
jne 0x9390
jmp 0x93eb
leaq -0x58(%rbp), %rsi
leaq -0x1d0(%rbp), %rdi
callq 0x31a0
jmp 0x93a2
movq -0x200(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x89d0
jmp 0x93b7
leaq -0x1d0(%rbp), %rdi
callq 0x3628
jmp 0x949c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x2ec4(%rip), %rsi      # 0xc2b6
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x222(%rbp)
jmp 0x9403
movb -0x222(%rbp), %al
testb $0x1, %al
jne 0x940f
jmp 0x9464
leaq -0x58(%rbp), %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x31a0
jmp 0x9421
movq -0x200(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x8bd0
jmp 0x9436
leaq -0x1f0(%rbp), %rdi
callq 0x3628
jmp 0x949a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x1f0(%rbp), %rdi
callq 0x3628
jmp 0x94d5
leaq 0x2e50(%rip), %rsi      # 0xc2bb
leaq -0x78(%rbp), %rdi
callq 0x6a60
movb %al, -0x223(%rbp)
jmp 0x947c
movb -0x223(%rbp), %al
testb $0x1, %al
jne 0x9488
jmp 0x9498
movb $0x1, -0x1(%rbp)
movl $0x1, -0xa8(%rbp)
jmp 0x94be
jmp 0x949a
jmp 0x949c
jmp 0x949e
jmp 0x94a0
jmp 0x94a2
jmp 0x94a4
jmp 0x94a6
jmp 0x94a8
jmp 0x94aa
jmp 0x94ac
jmp 0x94ae
jmp 0x94b0
movb $0x0, -0x1(%rbp)
movl $0x1, -0xa8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0xa480
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0xa480
movq -0xa0(%rbp), %rdi
callq 0x3560
nopw (%rax,%rax)