// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/fsio/fsio.c
// Function: findMount
static struct mountedFS *findMount(
  char *cmd,
  char *dev,
  uint8_t *unit,
  uint8_t *present,
  char **fname
)
{
  struct mountedFS *fs = &localMount;
  unsigned long unitno = 0;
  uint8_t unitpresent = 0;
  unsigned int i;
  char *endptr, *ptr;
  char origdev[32];

  if ((ptr = strchr(dev, ':')) != NULL) {
    *ptr++ = '\0';

    strncpy(origdev, dev, sizeof(origdev));

    /*
     * Determine validity of the device name and whether a unit number is
     * present.
     */
    for (i = 0; i < strlen(dev); i++)
      if (!isalpha(dev[i])) {
        if (isdigit(dev[i])) {
          unitno = strtoul(&dev[i], &endptr, 8);
          if (*endptr != '\0') {
            fprintf(stderr,
                    "%s: Device \"%s\" unit number invalid\n", cmd, origdev);
            return NULL;
          }

          if (unitno > 0377) {
            fprintf(stderr,
                    "%s: Device \"%s\" unit number too large\n", cmd, origdev);
            return NULL;
          }
          dev[i] ='\0';
          unitpresent = 1;
          break;
        }
        fprintf(stderr,
                "%s: Device \"%s\" contains non-alpha character\n",
                cmd, origdev);
        return NULL;
      }

    /*
     * Search the mounted file system list.
     */
    for (fs = mounts; fs != NULL; fs = fs->next)
      if (strcmp(dev, fs->name) == 0) {
        if ((unitpresent == 0) ||
            ((fs->filesys->flags & FS_UNITVALID) != 0))
          break;
        fprintf(stderr,
                "%s: \"%s\" does not support unit numbers\n", cmd, fs->name);
        return NULL;
      }
  
    if (fs == NULL)
      fprintf(stderr, "%s: Device \"%s\" not mounted\n", cmd, origdev);
  } else {
    if (getenv("FSioForceLocal") != NULL) {
      fprintf(stderr, "Local file system access requires use of \"local:\"\n");
      return NULL;
    }
    ptr = dev;
  }

  /*
   * No device present - assume local file system usage
   */
  *unit = unitno & 0377;
  *present = unitpresent;
  *fname = ptr;
  return fs;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbp
movq %rdi, 0x8(%rsp)
movq %rsi, %rdi
movl $0x3a, %esi
callq 0x3150
testq %rax, %rax
movq %r14, 0x28(%rsp)
movq %r12, 0x20(%rsp)
je 0x6450
movq %rax, %r13
movq %r15, 0x18(%rsp)
movb $0x0, (%rax)
leaq 0x30(%rsp), %rdi
movl $0x20, %edx
movq %rbp, %rsi
callq 0x3090
movq %rbp, %rdi
callq 0x3130
testq %rax, %rax
setne %r15b
je 0x64e6
movq %rax, %rbx
callq 0x32f0
movq (%rax), %rax
movsbq (%rbp), %rcx
movzwl (%rax,%rcx,2), %ecx
btl $0xa, %ecx
jb 0x6478
xorl %r12d, %r12d
jmp 0x649e
leaq 0x9fe5(%rip), %rdi      # 0x1043c
callq 0x3040
testq %rax, %rax
jne 0x65a5
leaq 0x13c4c(%rip), %r12     # 0x1a0b8
xorl %ecx, %ecx
xorl %ebx, %ebx
movq %rbp, %r13
jmp 0x6582
movl $0x1, %edx
movl %edx, %r12d
cmpq %r12, %rbx
seta %r15b
jbe 0x64e6
movsbq (%rbp,%r12), %rcx
movzwl (%rax,%rcx,2), %ecx
leal 0x1(%r12), %edx
btl $0xa, %ecx
jb 0x647d
btl $0xb, %ecx
jae 0x65af
addq %rbp, %r12
leaq 0x50(%rsp), %r14
movq %r12, %rdi
movq %r14, %rsi
movl $0x8, %edx
callq 0x3290
movq (%r14), %rcx
cmpb $0x0, (%rcx)
jne 0x65c2
cmpq $0x100, %rax            # imm = 0x100
jae 0x65d5
movq %rax, 0x10(%rsp)
movb $0x0, (%r12)
movb $0x1, %bl
jmp 0x64f1
movq $0x0, 0x10(%rsp)
xorl %ebx, %ebx
incq %r13
leaq 0x13bb5(%rip), %r12     # 0x1a0b0
movq (%r12), %r12
testq %r12, %r12
je 0x6553
leaq 0x8(%r12), %r14
movq %rbp, %rdi
movq %r14, %rsi
callq 0x31c0
testl %eax, %eax
jne 0x64fb
testb %r15b, %r15b
je 0x6578
movq 0x20(%r12), %rax
testb $0x1, 0x18(%rax)
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %rcx
jne 0x6582
movq 0x11ab7(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9eb4(%rip), %rsi      # 0x103f7
xorl %r12d, %r12d
movq 0x8(%rsp), %rdx
movq %r14, %rcx
jmp 0x65f3
movq 0x11a96(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9ebb(%rip), %rsi      # 0x1041f
xorl %r12d, %r12d
leaq 0x30(%rsp), %rcx
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x31d0
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %rax
movb %cl, (%rax)
movq 0x28(%rsp), %rax
movb %bl, (%rax)
movq %r13, (%r15)
movq %r12, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x36ee
xorl %r12d, %r12d
jmp 0x6593
movq 0x11a3a(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9e09(%rip), %rsi      # 0x103c9
jmp 0x65e6
movq 0x11a27(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9daa(%rip), %rsi      # 0x1037d
jmp 0x65e6
movq 0x11a14(%rip), %rax     # 0x17ff0
movq (%rax), %rdi
leaq 0x9dbc(%rip), %rsi      # 0x103a2
xorl %r12d, %r12d
leaq 0x30(%rsp), %rcx
movq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0x6593