// File: /workspace/github_c_makefile_star2_O3/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 $0xe8, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x50(%rdi)
movb $-0x1, 0x59(%rdi)
movq 0x38(%rdi), %rdi
callq 0x3210
leaq 0x58(%rsp), %rsi
movl %eax, %edi
callq 0x32f0
movl %eax, %ecx
xorl %eax, %eax
testl %ecx, %ecx
jne 0xed3b
movq 0x88(%rsp), %rax
leaq 0xff(%rax), %rcx
testq %rax, %rax
cmovnsq %rax, %rcx
shrq $0x8, %rcx
movl %ecx, 0x48(%rbx)
leaq 0xa5e9(%rip), %rax      # 0x18fd8
testb $0x8, 0x2(%rax)
je 0xed54
movq 0xa3d0(%rip), %rsi      # 0x18dd0
leaq 0xa5d9(%rip), %rax      # 0x18fe0
movq 0x98(%rax), %r14
testq %rsi, %rsi
je 0xea34
leaq 0xa3b6(%rip), %r12      # 0x18dd0
movq %r14, %rdi
callq 0x31d0
testl %eax, %eax
je 0xea54
movq 0x48(%r12), %rsi
addq $0x48, %r12
testq %rsi, %rsi
jne 0xea1a
movq 0x95b5(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x40b2(%rip), %rsi      # 0x12af7
movq %r14, %rdx
xorl %eax, %eax
callq 0x31e0
jmp 0xed59
movq 0x18(%r12), %rax
movq %rax, 0x40(%rbx)
movq %r12, 0x50(%rbx)
cmpb $0x0, 0x8(%r12)
je 0xed32
leaq 0x40(%rsp), %rbp
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %edx, %edx
xorl %r15d, %r15d
movl %ecx, 0x14(%rsp)
movq %rdx, 0x18(%rsp)
movl %r15d, 0x4(%rsp)
xorl %eax, %eax
movl %eax, 0xf(%rsp)
movl %eax, 0xc(%rsp)
movzbl %r14b, %eax
movl %eax, 0x8(%rsp)
movl $0x1, %eax
movl %eax, %r15d
cmpb $0x0, 0xc(%rsp,%r15)
jne 0xec4c
movq 0x50(%rbx), %rax
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movl %r15d, %edx
callq *0x30(%rax)
testl %eax, %eax
je 0xec4c
movq %rbx, %rdi
movl 0x8(%rsp), %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0xd707
testl %eax, %eax
je 0xec4c
movb $0x1, 0xc(%rsp,%r15)
movzwl 0x64(%rbx), %r8d
movl %r8d, %ecx
negl %ecx
movl $0xfff, %eax            # imm = 0xFFF
andl %eax, %ecx
cmpq $0x1, %r15
jne 0xeb08
movw %cx, 0x20(%rsp,%r14,2)
movl %ecx, %r13d
cmpw $0x3f, %cx
ja 0xec4c
cmpw %cx, %r13w
jne 0xec4c
movzwl 0x62(%rbx), %eax
testl $0xfff, %eax            # imm = 0xFFF
setne %dl
notl %eax
testl $0x300, %eax            # imm = 0x300
setne %al
testb %al, %dl
jne 0xec4c
movzwl 0x5c(%rbx), %eax
xorl %esi, %esi
subw %ax, %si
movl $0xfff, %eax            # imm = 0xFFF
andl %eax, %esi
testw %si, %si
je 0xec4c
movzwl %cx, %edi
leal 0x7(%rdi), %r9d
movw $0x100, %ax             # imm = 0x100
xorl %edx, %edx
divw %r9w
addl %eax, %eax
cmpw %si, %ax
jb 0xec4c
movl %r8d, %eax
movl $0xfff, %edx            # imm = 0xFFF
andl %edx, %eax
andl $0x800, %r8d            # imm = 0x800
addl %r8d, %r8d
subl %eax, %r8d
addl $0x5, %r8d
movzwl 0x5e(%rbx), %eax
andl %edx, %eax
addl $0x4, %edi
movzwl %r8w, %edx
movq 0x50(%rbx), %r8
movzwl 0x20(%r8,%r14,2), %r8d
movl $0x5, %r10d
movzwl %r10w, %r9d
movzwl 0x5c(%rbx,%r9,2), %r10d
testl $0xfff, %r10d           # imm = 0xFFF
je 0xebdf
leal (%r9,%rdi), %r10d
movzwl 0x5c(%rbx,%r10,2), %r10d
xorl %r15d, %r15d
subw %r10w, %r15w
andl $0xfff, %r15d           # imm = 0xFFF
movw $0x1, %r11w
movq %rbp, %r13
movl %edx, %r10d
jmp 0xec04
movl %r9d, %r10d
movzwl 0x5e(%rbx,%r10,2), %r10d
xorl %r11d, %r11d
subw %r10w, %r11w
andl $0xfff, %r11d           # imm = 0xFFF
movl $0x2, %r10d
leaq 0x30(%rsp), %r13
movl %r11d, %r15d
addw %r11w, (%r13,%r14,2)
movzwl %r15w, %r11d
addl %eax, %r11d
cmpw %r8w, %r11w
ja 0xec4c
movl %r11d, %eax
addl %r9d, %r10d
decw %si
jne 0xeba7
movzwl 0x60(%rbx), %eax
andl $0xfff, %eax            # imm = 0xFFF
cmpw $0x6, %ax
ja 0xec4c
movl %ecx, %r13d
testw %ax, %ax
jne 0xeaa1
movl $0x1, %eax
movl 0x14(%rsp), %ecx
shll %cl, %eax
movb $0x1, %cl
jmp 0xec50
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x18(%rsp), %rdx
addb %cl, %dl
movl 0x4(%rsp), %r15d
orb %al, %r15b
incq %r14
movzbl 0x8(%r12), %eax
movl %r14d, %ecx
cmpq %rax, %r14
jb 0xea7c
testb %r15b, %r15b
je 0xed32
leaq 0xa340(%rip), %rcx      # 0x18fc4
cmpl $0x0, (%rcx)
jne 0xecb8
leaq 0x8(%rbx), %rsi
movzbl %dl, %edx
cmpb $0x1, %dl
leaq 0x3e06(%rip), %rax      # 0x12aa0
leaq 0x33da(%rip), %rcx      # 0x1207b
cmoveq %rax, %rcx
leaq 0x3dc7(%rip), %rdi      # 0x12a73
xorl %eax, %eax
callq 0x3160
movb 0x8(%r12), %al
testb %al, %al
je 0xed4d
movl %r15d, 0x4(%rsp)
movzbl %r15b, %ebp
leaq 0x8(%rbx), %r14
leaq 0x3dcd(%rip), %r15      # 0x12aa1
xorl %r13d, %r13d
btl %r13d, %ebp
jae 0xed18
leaq 0x352b(%rip), %rdi      # 0x1220f
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3160
movzwl 0x20(%r12,%r13,2), %esi
movzwl 0x30(%rsp,%r13,2), %edx
movzwl 0x40(%rsp,%r13,2), %ecx
movzwl 0x20(%rsp,%r13,2), %r8d
movq %r15, %rdi
xorl %eax, %eax
callq 0x3160
movb 0x8(%r12), %al
incq %r13
movzbl %al, %ecx
cmpq %rcx, %r13
jb 0xecd7
xorl %eax, %eax
movl 0x4(%rsp), %r15d
testb %r15b, %r15b
setne %al
jmp 0xed37
xorl %eax, %eax
xorl %r15d, %r15d
movb %r15b, 0x59(%rbx)
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %eax
jmp 0xed37
callq 0x4a58
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0xed3b