// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/fsio.c
// Function: doMount
static void doMount(void)
{
  struct FSdef *filesys;
  FILE *container;
  int status;
  char *mode = SWISSET('r') ? "r" : "r+";

  if (checkDev(words[0]) != 0) { 
    if (lookupDev(words[0]) == NULL) {
      if ((filesys = lookupFS(words[2])) != NULL) {
        if (filesys->mount == NULL) {
          fprintf(stderr,
                  "mount: \"%s\" is not a mountable filesystem\n", words[2]);
          return;
        }

        if ((container = fopen(words[1], mode)) != NULL) {
          struct mountedFS *mount;

          if ((mount = malloc(sizeof(struct mountedFS))) != NULL) {
            memset(mount, 0, sizeof(struct mountedFS));

            strcpy(mount->name, words[0]);
            mount->filesys = filesys;
            mount->blocksz = filesys->blocksz;
            mount->flags = SWISSET('r') ? FS_READONLY : 0;
#ifdef DEBUG
            if (SWISSET('d')) {
              mount->flags |= FS_DEBUG;

              if (DEBUGout == NULL) {
                char *dbg = getenv("FSioDebugLog");

                if (dbg != NULL)
                  DEBUGout = fopen(dbg, "a");
              }

              if (DEBUGout == NULL)
                DEBUGout = stdout;
            }
#endif
            mount->container = container;
            mount->skip = 0;

            /*
             * Verify that the container holds a valid file system
             */
            if ((status = (*filesys->mount)(mount)) > 0) {
              mount->next = mounts;
              mounts = mount;
              return;
            }
            free(mount);
            if (status == 0)
              fprintf(stderr,
                      "mount: \"%s\" does not contain a valid file system\n",
                      words[1]);
          } else fprintf(stderr, "mount: out of memory\n");
          fclose(container);
        } else fprintf(stderr, "mount: failed to open \"%s\"\n", words[1]);
      } else fprintf(stderr, "mount: \"%s\" is not a supported file system type\n", words[2]);
    } else fprintf(stderr, "mount: \"%s\" already mounted\n", words[0]);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
btl $0x11, 0x14bbc(%rip)    # 0x17fd8
leaq 0xbcd1(%rip), %rax      # 0xf0f4
leaq 0xd1c9(%rip), %rbx      # 0x105f3
cmovaeq %rax, %rbx
movq 0x14c83(%rip), %rax     # 0x180b8
movq (%rax), %rdi
callq 0x4d45
testl %eax, %eax
je 0x3568
movq 0x14c6c(%rip), %r12     # 0x180b8
movq (%r12), %r14
movq %r14, %rdi
callq 0x4dc2
testq %rax, %rax
jne 0x3593
movq 0x10(%r12), %r15
movq %r15, %rdi
callq 0x4df3
testq %rax, %rax
je 0x35a9
movq %rax, %r14
cmpq $0x0, 0x28(%rax)
je 0x35bc
movq 0x8(%r12), %rdi
movq %rbx, %rsi
callq 0x3280
testq %rax, %rax
je 0x35d2
movq %rax, %rbx
pushq $0x1
popq %rdi
movl $0x958, %esi            # imm = 0x958
callq 0x31c0
testq %rax, %rax
je 0x35fd
movq %rax, %r15
movq %rax, %rdi
addq $0x8, %rdi
movq 0x14bf3(%rip), %rax     # 0x180b8
movq (%rax), %rsi
callq 0x30c0
movq %r14, 0x20(%r15)
movq 0x20(%r14), %rax
movq %rax, 0x28(%r15)
movl 0x14af9(%rip), %ecx     # 0x17fd8
movl %ecx, %eax
shrl $0x11, %eax
andl $0x1, %eax
movw %ax, 0x30(%r15)
testb $0x8, %cl
je 0x3543
movzwl %ax, %eax
orl $0x2, %eax
movw %ax, 0x30(%r15)
cmpq $0x0, 0x14ac4(%rip)     # 0x17fc8
jne 0x3543
leaq 0xbc15(%rip), %rdi      # 0xf122
callq 0x3040
testq %rax, %rax
je 0x3532
leaq 0xbc11(%rip), %rsi      # 0xf12f
movq %rax, %rdi
callq 0x3280
movq %rax, 0x14a9b(%rip)     # 0x17fc8
testq %rax, %rax
jne 0x3543
movq 0x13a87(%rip), %rax     # 0x16fc0
movq (%rax), %rax
movq %rax, 0x14a85(%rip)     # 0x17fc8
movq %rbx, 0x38(%r15)
andq $0x0, 0x40(%r15)
movq %r15, %rdi
callq *0x28(%r14)
testl %eax, %eax
jle 0x3571
movq 0x15b62(%rip), %rax     # 0x190c0
movq %rax, (%r15)
movq %r15, 0x15b58(%rip)     # 0x190c0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %ebp
movq %r15, %rdi
callq 0x3050
testl %ebp, %ebp
je 0x361e
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3110
movq 0x13a5e(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xbc22(%rip), %rsi      # 0xf1c6
movq %r14, %rdx
jmp 0x35ee
movq 0x13a48(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xbbdb(%rip), %rsi      # 0xf195
jmp 0x35cd
movq 0x13a35(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xbb2a(%rip), %rsi      # 0xf0f7
movq %r15, %rdx
jmp 0x35ee
movq 0x13a1f(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x14ad5(%rip), %rax     # 0x180b8
movq 0x8(%rax), %rdx
leaq 0xbb8b(%rip), %rsi      # 0xf179
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x31e0
movq 0x139f4(%rip), %rax     # 0x16ff8
movq (%rax), %rcx
leaq 0xbb55(%rip), %rdi      # 0xf163
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
jmp 0x3583
movq 0x139d3(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x14a89(%rip), %rax     # 0x180b8
movq 0x8(%rax), %rdx
leaq 0xbaf7(%rip), %rsi      # 0xf131
xorl %eax, %eax
callq 0x31e0
jmp 0x3583