// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/fsio/os8.c
// Function: os8Mount
static int os8Mount(
  struct mountedFS *mount
)
{
  struct OS8data *data = &mount->os8data;
  struct stat stat;
  uint8_t valid = 0;
  uint16_t files[8], freeblks[8], extra[8];

  memset(files, 0, sizeof(files));
  memset(freeblks, 0, sizeof(freeblks));
  memset(extra, 0, sizeof(extra));

  /*
   * Allow access to all filesystems for validation
   */
  data->device = NULL;
  data->valid = 0xFF;

  if (fstat(fileno(mount->container), &stat) == 0) {
    data->blocks = stat.st_size / OS8_BLOCKSIZE;

    if (SWISSET('t')) {
      struct OS8device *dev = OS8Devices;

      while (dev->name != NULL) {
        if (strcmp(SWGETVAL('t'), dev->name) == 0) {
          uint8_t i, count = 0;

          mount->skip = dev->skip;
          data->device = dev;

          /*
           * Validate all possible file systems.
           */
          for (i = 0; i < dev->filesys; i++)
            if (validate(mount, i, &files[i], &freeblks[i], &extra[i]) != 0) {
              count++;
              valid |= 1 << i;
            }

          if (valid != 0) {
            if (!quiet)
              printf("%s: successfully mounted (%d file system%s)\n\n",
                     mount->name, count, count == 1 ? "" : "s");

            for (i = 0; i < dev->filesys; i++)
              if ((valid & 1 << i) != 0) {
                printf("%s%o:\n", mount->name, i);
                printf("  Total Blocks: %4d, Free Blocks: %4d\n"
                       "  Files: %4d\n"
                       "  Extra words/directory entry: %d\n",
                       dev->blocks[i], freeblks[i], files[i], extra[i]);
              }
          }

          data->valid = valid;
          return valid != 0 ? 1 : 0;
        }
        dev++;
      }
      fprintf(stderr, "mount: unknown disk type - \"%s\"\n",
              SWGETVAL('t'));
      return -1;
    } else {
      fprintf(stderr, "mount: unable to determine disk type,"
              " use \"-t type\"\n");
      return -1;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movq $0x0, 0x50(%rdi)
movb $-0x1, 0x59(%rdi)
movq 0x38(%rdi), %rdi
callq 0x3200
leaq 0x68(%rsp), %rsi
movl %eax, %edi
callq 0x32e0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0xf054
movq 0x98(%rsp), %rax
leaq 0xff(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
shrq $0x8, %rcx
movl %ecx, 0x48(%rbx)
leaq 0xa2ba(%rip), %rax      # 0x18fc8
testb $0x8, 0x2(%rax)
je 0xf066
movq 0xa0a1(%rip), %rsi      # 0x18dc0
testq %rsi, %rsi
je 0xed52
leaq 0xa2a5(%rip), %rax      # 0x18fd0
movq 0x98(%rax), %r14
leaq 0xa087(%rip), %r15      # 0x18dc0
movq %r14, %rdi
callq 0x31c0
testl %eax, %eax
je 0xed5c
movq 0x48(%r15), %rsi
addq $0x48, %r15
testq %rsi, %rsi
jne 0xed39
callq 0x4a3a
jmp 0xf06b
movq 0x18(%r15), %rax
movq %rax, 0x40(%rbx)
movq %r15, 0x50(%rbx)
xorl %esi, %esi
cmpb $0x0, 0x8(%r15)
movq %r15, 0x18(%rsp)
je 0xef91
xorl %ebp, %ebp
xorl %edi, %edi
xorl %edx, %edx
xorl %ecx, %ecx
movl %edi, 0x24(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x8(%rsp)
movl %esi, 0x13(%rsp)
movl %esi, 0x10(%rsp)
movzbl %bpl, %r14d
movl $0x1, %r15d
movl %r15d, %r12d
cmpb $0x0, 0x10(%rsp,%r12)
je 0xedc3
xorl %r13d, %r13d
testb %r13b, %r13b
je 0xef53
testl %r15d, %r15d
jne 0xeda2
jmp 0xef53
movq 0x50(%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq *0x30(%rax)
testl %eax, %eax
je 0xedad
xorl %r13d, %r13d
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0xd979
testl %eax, %eax
je 0xedb0
movb $0x1, 0x10(%rsp,%r12)
movzwl 0x64(%rbx), %edi
movl %edi, %eax
negl %eax
movl $0xfff, %ecx            # imm = 0xFFF
andl %ecx, %eax
cmpl $0x1, %r15d
jne 0xee13
movw %ax, 0x30(%rsp,%rbp,2)
movw %ax, 0x6(%rsp)
cmpw %ax, 0x6(%rsp)
setne %cl
cmpw $0x40, %ax
setae %dl
orb %cl, %dl
jne 0xedad
movzwl 0x5c(%rbx), %edx
xorl %ecx, %ecx
subw %dx, %cx
movl $0xfff, %edx            # imm = 0xFFF
andl %edx, %ecx
movzwl 0x62(%rbx), %edx
testl $0xfff, %edx            # imm = 0xFFF
setne %sil
notl %edx
testl $0x300, %edx            # imm = 0x300
setne %dl
andb %sil, %dl
testw %cx, %cx
sete %sil
orb %dl, %sil
jne 0xedad
movzwl %ax, %esi
movzwl %cx, %r8d
leal 0x7(%rsi), %r9d
xorl %r13d, %r13d
movl $0x100, %eax            # imm = 0x100
xorl %edx, %edx
divl %r9d
addl %eax, %eax
cmpl %r8d, %eax
jb 0xedb0
movl %edi, %eax
movl $0xfff, %edx            # imm = 0xFFF
andl %edx, %eax
andl $0x800, %edi            # imm = 0x800
addl %edi, %edi
subl %eax, %edi
addl $0x5, %edi
movzwl 0x5e(%rbx), %eax
andl %edx, %eax
addl $0x4, %esi
movzwl %di, %edx
movq 0x50(%rbx), %rdi
movzwl 0x20(%rdi,%rbp,2), %edi
movl $0x5, %r9d
leaq 0x40(%rsp), %r13
movzwl %r9w, %r8d
movzwl 0x5c(%rbx,%r8,2), %r9d
testl $0xfff, %r9d            # imm = 0xFFF
je 0xeef5
leal (%rsi,%r8), %r9d
movzwl 0x5c(%rbx,%r9,2), %r9d
xorl %r11d, %r11d
subw %r9w, %r11w
andl $0xfff, %r11d           # imm = 0xFFF
movw $0x1, %r10w
leaq 0x50(%rsp), %r12
movl %edx, %r9d
jmp 0xef18
movl %r8d, %r9d
movzwl 0x5e(%rbx,%r9,2), %r9d
xorl %r10d, %r10d
subw %r9w, %r10w
andl $0xfff, %r10d           # imm = 0xFFF
movl $0x2, %r9d
movq %r13, %r12
movl %r10d, %r11d
addw %r10w, (%r12,%rbp,2)
movzwl %r11w, %r10d
addl %eax, %r10d
cmpw %di, %r10w
ja 0xedad
movl %r10d, %eax
addl %r8d, %r9d
decw %cx
jne 0xeebb
movzwl 0x60(%rbx), %r15d
andl $0xfff, %r15d           # imm = 0xFFF
cmpw $0x7, %r15w
setb %r13b
jmp 0xedb0
movl $0x1, %eax
movl 0x24(%rsp), %ecx
shll %cl, %eax
testb %r13b, %r13b
movl $0x0, %esi
cmovel %esi, %eax
movq 0x8(%rsp), %rcx
orb %al, %cl
movq 0x28(%rsp), %rdx
addb %r13b, %dl
incq %rbp
movq 0x18(%rsp), %rax
movzbl 0x8(%rax), %eax
movl %ebp, %edi
cmpq %rax, %rbp
jb 0xed82
jmp 0xef95
xorl %ecx, %ecx
xorl %edx, %edx
movq %rcx, 0x8(%rsp)
testb %cl, %cl
je 0xf045
leaq 0xa00b(%rip), %rax      # 0x18fb4
cmpl $0x0, (%rax)
jne 0xefd8
leaq 0x8(%rbx), %rsi
movzbl %dl, %edx
cmpb $0x1, %dl
leaq 0x3ac1(%rip), %rax      # 0x12a80
leaq 0x30b5(%rip), %rcx      # 0x1207b
cmoveq %rax, %rcx
leaq 0x3a82(%rip), %rdi      # 0x12a53
xorl %eax, %eax
callq 0x3160
movq 0x18(%rsp), %rax
cmpb $0x0, 0x8(%rax)
je 0xf045
movzbl 0x8(%rsp), %ebp
leaq 0x8(%rbx), %r14
leaq 0x3a8e(%rip), %r15      # 0x12a81
xorl %r13d, %r13d
movq 0x18(%rsp), %r12
btl %r13d, %ebp
jae 0xf037
leaq 0x3207(%rip), %rdi      # 0x1220f
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3160
movzwl 0x20(%r12,%r13,2), %esi
movzwl 0x40(%rsp,%r13,2), %edx
movzwl 0x50(%rsp,%r13,2), %ecx
movzwl 0x30(%rsp,%r13,2), %r8d
movq %r15, %rdi
xorl %eax, %eax
callq 0x3160
incq %r13
movzbl 0x8(%r12), %eax
cmpq %rax, %r13
jb 0xeffb
xorl %eax, %eax
movq 0x8(%rsp), %rcx
testb %cl, %cl
setne %al
movb %cl, 0x59(%rbx)
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4a60
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xf054