// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
leaq 0x1a9d2(%rip), %rax     # 0x202e8
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movb $0x0, -0x41(%rbp)
movq -0x18(%rbp), %rdi
movl $0x3a, %esi
callq 0x3150
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x5b6d
movq -0x58(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x58(%rbp)
movb $0x0, (%rax)
leaq -0x80(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl $0x20, %edx
callq 0x3080
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq %rax, -0x88(%rbp)
movq -0x18(%rbp), %rdi
callq 0x3130
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x5abd
callq 0x32e0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x48(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x5aad
callq 0x32e0
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movl -0x48(%rbp), %edx
movsbl (%rcx,%rdx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x5a80
movq -0x18(%rbp), %rdi
movl -0x48(%rbp), %eax
addq %rax, %rdi
leaq -0x50(%rbp), %rsi
movl $0x8, %edx
callq 0x3280
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x5a38
movq 0x185e6(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0x129b5(%rip), %rsi     # 0x183d9
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0x5bd7
cmpq $0xff, -0x40(%rbp)
jbe 0x5a6f
movq 0x185af(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0x129a3(%rip), %rsi     # 0x183fe
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0x5bd7
movq -0x18(%rbp), %rax
movl -0x48(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movb $0x1, -0x41(%rbp)
jmp 0x5abd
movq 0x18571(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0x1298c(%rip), %rsi     # 0x18425
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0x5bd7
jmp 0x5aaf
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x596d
movq 0x1a81c(%rip), %rax     # 0x202e0
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x5b44
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
addq $0x8, %rsi
callq 0x31b0
cmpl $0x0, %eax
jne 0x5b35
movzbl -0x41(%rbp), %eax
cmpl $0x0, %eax
je 0x5b02
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movzwl 0x18(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x5b04
jmp 0x5b44
movq 0x184ed(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
movq -0x38(%rbp), %rcx
addq $0x8, %rcx
leaq 0x12932(%rip), %rsi     # 0x18453
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0x5bd7
jmp 0x5b37
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x5ac8
cmpq $0x0, -0x38(%rbp)
jne 0x5b6b
movq 0x184a6(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
leaq -0x80(%rbp), %rcx
leaq 0x12917(%rip), %rsi     # 0x1847b
movb $0x0, %al
callq 0x31c0
jmp 0x5ba9
leaq 0x12924(%rip), %rdi     # 0x18498
callq 0x3030
cmpq $0x0, %rax
je 0x5ba1
movq 0x18472(%rip), %rax     # 0x1dff8
movq (%rax), %rdi
leaq 0x12917(%rip), %rsi     # 0x184a7
movb $0x0, %al
callq 0x31c0
movq $0x0, -0x8(%rbp)
jmp 0x5bd7
movq -0x18(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x40(%rbp), %rax
andq $0xff, %rax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movb -0x41(%rbp), %cl
movq -0x28(%rbp), %rax
movb %cl, (%rax)
movq -0x58(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nop