// File: dmonaldo[P]simple-network-file-system/Shell.cpp
// Function: Shell::mountNFS(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void Shell::mountNFS(string fs_loc) {
  struct sockaddr_in server;

  // parse filesystem location into array with servername and port
  vector<string> fs_address;
  size_t pos = 0, found;
  while((found = fs_loc.find_first_of(':', pos)) != string::npos) {
    fs_address.push_back(fs_loc.substr(pos, found - pos));
    pos = found+1;
  }
  fs_address.push_back(fs_loc.substr(pos));

  // create the socket
  cs_sock = socket(AF_INET, SOCK_STREAM, 0);
  if (cs_sock < 0) {
    perror("ERROR creating socket");
    exit(0);
  }
  cout << "Socket created\n";

  // construct server address
  server.sin_addr.s_addr = inet_addr(fs_address[0].c_str());
  server.sin_family = AF_INET;
  server.sin_port = htons(stoi(fs_address[1]));

  // connect to remote server
  if (connect(cs_sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("ERROR connection failed");
    exit(0);
  }

  cout << "Connected\n";
  is_mounted = true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rsi, -0xa8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x38(%rbp), %rdi
callq 0xa020
movq $0x0, -0x40(%rbp)
movq -0xa8(%rbp), %rdi
movq -0x40(%rbp), %rdx
movl $0x3a, %esi
callq 0x3230
movq %rax, -0x48(%rbp)
cmpq $-0x1, %rax
je 0x7463
movq -0xa8(%rbp), %rsi
movq -0x40(%rbp), %rdx
movq -0x48(%rbp), %rcx
subq %rdx, %rcx
leaq -0x68(%rbp), %rdi
callq 0x3380
jmp 0x7412
leaq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0xa040
jmp 0x7421
leaq -0x68(%rbp), %rdi
callq 0x3628
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x73d6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x75f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x3628
jmp 0x75f0
movq -0xa8(%rbp), %rsi
movq -0x40(%rbp), %rdx
leaq -0x98(%rbp), %rdi
movq $-0x1, %rcx
callq 0x3380
jmp 0x7483
leaq -0x38(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xa040
jmp 0x7495
leaq -0x98(%rbp), %rdi
callq 0x3628
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x30e0
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, (%rax)
jge 0x74f4
leaq 0x4fd9(%rip), %rdi      # 0xc4a2
callq 0x32e0
jmp 0x74d0
xorl %edi, %edi
callq 0x3410
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3628
jmp 0x75f0
movq 0x8ac5(%rip), %rdi      # 0xffc0
leaq 0x4fb6(%rip), %rsi      # 0xc4b8
callq 0x3340
jmp 0x7509
xorl %eax, %eax
movl %eax, %esi
movq %rsi, -0xb8(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0xa070
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
callq 0x3360
movq -0xc0(%rbp), %rdi
movl %eax, -0x1c(%rbp)
movw $0x2, -0x20(%rbp)
movl $0x1, %esi
callq 0xa070
movq -0xb8(%rbp), %rsi
movq %rax, %rdi
movl $0xa, %edx
callq 0xa090
movl %eax, -0xac(%rbp)
jmp 0x756a
movl -0xac(%rbp), %eax
movzwl %ax, %edi
callq 0x3070
movw %ax, %cx
movq -0xa0(%rbp), %rax
movw %cx, -0x1e(%rbp)
movl (%rax), %edi
leaq -0x20(%rbp), %rsi
movl $0x10, %edx
callq 0x32d0
movl %eax, -0xc4(%rbp)
jmp 0x759e
movl -0xc4(%rbp), %eax
cmpl $0x0, %eax
jge 0x75be
leaq 0x4f18(%rip), %rdi      # 0xc4c8
callq 0x32e0
jmp 0x75b7
xorl %edi, %edi
callq 0x3410
movq 0x89fb(%rip), %rdi      # 0xffc0
leaq 0x4f14(%rip), %rsi      # 0xc4e0
callq 0x3340
jmp 0x75d3
movq -0xa0(%rbp), %rax
movb $0x1, 0x4(%rax)
leaq -0x38(%rbp), %rdi
callq 0xa0d0
addq $0xd0, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0xa0d0
movq -0x70(%rbp), %rdi
callq 0x3560
nopw %cs:(%rax,%rax)