// File: /workspace/github_c_makefile_star2_O2/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)
andq $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 0xdcab
movq 0x88(%rsp), %rax
movl $0x100, %ecx            # imm = 0x100
cqto
idivq %rcx
movl %eax, 0x48(%rbx)
leaq 0xa61b(%rip), %rax      # 0x17fd8
testb $0x8, 0x2(%rax)
je 0xdcbd
leaq 0xa402(%rip), %r15      # 0x17dd0
leaq 0xa60b(%rip), %r14      # 0x17fe0
movq (%r15), %rsi
testq %rsi, %rsi
je 0xdcdb
movq 0x98(%r14), %rdi
callq 0x31d0
testl %eax, %eax
je 0xd9f7
addq $0x48, %r15
jmp 0xd9d5
movq 0x18(%r15), %rax
movq %rax, 0x40(%rbx)
movq %r15, 0x50(%rbx)
leaq 0x40(%rsp), %r13
xorl %r14d, %r14d
xorl %ecx, %ecx
xorl %edx, %edx
movq %r15, 0x8(%rsp)
movzbl 0x8(%r15), %eax
cmpq %rax, %r14
movq %rcx, 0x10(%rsp)
jae 0xdbf3
movq %rdx, 0x18(%rsp)
andl $0x0, 0x3(%rsp)
andl $0x0, (%rsp)
movzbl %r14b, %ebp
pushq $0x1
popq %rax
movl %eax, %r15d
cmpb $0x0, (%rsp,%r15)
jne 0xdbd5
movq 0x50(%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq *0x30(%rax)
testl %eax, %eax
je 0xdbd5
movq %rbx, %rdi
movl %ebp, %esi
movl %r15d, %edx
xorl %ecx, %ecx
callq 0xc5d7
testl %eax, %eax
je 0xdbd5
movb $0x1, (%rsp,%r15)
movzwl 0x64(%rbx), %r8d
movl %r8d, %ecx
negl %ecx
movl $0xfff, %eax            # imm = 0xFFF
andl %eax, %ecx
cmpq $0x1, %r15
jne 0xda9d
movw %cx, 0x20(%rsp,%r14,2)
movl %ecx, %r12d
cmpw $0x3f, %cx
ja 0xdbd5
cmpw %cx, %r12w
jne 0xdbd5
movzwl 0x62(%rbx), %eax
testw $0xfff, %ax             # imm = 0xFFF
setne %dl
notl %eax
testw $0x300, %ax             # imm = 0x300
setne %al
testb %al, %dl
jne 0xdbd5
movzwl 0x5c(%rbx), %eax
xorl %esi, %esi
subw %ax, %si
movl $0xfff, %eax            # imm = 0xFFF
andl %eax, %esi
testw %si, %si
je 0xdbd5
movzwl %cx, %edi
leal 0x7(%rdi), %r9d
movw $0x100, %ax             # imm = 0x100
xorl %edx, %edx
divw %r9w
addl %eax, %eax
cmpw %si, %ax
jb 0xdbd5
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
pushq $0x5
popq %r9
subw $0x1, %si
jb 0xdbae
movzwl %r9w, %r8d
movzwl 0x5c(%rbx,%r8,2), %r9d
testw $0xfff, %r9w            # imm = 0xFFF
je 0xdb6b
leal (%r8,%rdi), %r9d
movzwl 0x5c(%rbx,%r9,2), %r9d
xorl %r11d, %r11d
subw %r9w, %r11w
andl $0xfff, %r11d           # imm = 0xFFF
movw $0x1, %r10w
movq %r13, %r15
movl %edx, %r9d
jmp 0xdb8e
movl %r8d, %r9d
movzwl 0x5e(%rbx,%r9,2), %r9d
xorl %r10d, %r10d
subw %r9w, %r10w
andl $0xfff, %r10d           # imm = 0xFFF
leaq 0x30(%rsp), %r15
pushq $0x2
popq %r9
movl %r10d, %r11d
addw %r10w, (%r15,%r14,2)
movzwl %r11w, %r10d
addl %eax, %r10d
movl %r10d, %eax
movq 0x50(%rbx), %r10
cmpw 0x20(%r10,%r14,2), %ax
ja 0xdbd5
addl %r8d, %r9d
jmp 0xdb2e
movzwl 0x60(%rbx), %eax
andl $0xfff, %eax            # imm = 0xFFF
cmpw $0x6, %ax
ja 0xdbd5
movl %ecx, %r12d
testw %ax, %ax
jne 0xda3c
pushq $0x1
popq %rax
movl %r14d, %ecx
shll %cl, %eax
movb $0x1, %cl
jmp 0xdbd9
xorl %ecx, %ecx
xorl %eax, %eax
orb 0x10(%rsp), %al
movq 0x18(%rsp), %rdx
addb %cl, %dl
incq %r14
movl %eax, %ecx
movq 0x8(%rsp), %r15
jmp 0xda14
testb %cl, %cl
je 0xdc9c
leaq 0xa3c2(%rip), %rax      # 0x17fc4
cmpl $0x0, (%rax)
jne 0xdc31
leaq 0x8(%rbx), %rsi
movzbl %dl, %edx
cmpb $0x1, %dl
leaq 0x3e68(%rip), %rax      # 0x11a80
leaq 0x345c(%rip), %rcx      # 0x1107b
cmoveq %rax, %rcx
leaq 0x3e29(%rip), %rdi      # 0x11a53
xorl %eax, %eax
callq 0x3160
movzbl 0x10(%rsp), %r12d
leaq 0x8(%rbx), %r14
leaq 0x35cd(%rip), %r15      # 0x1120f
leaq 0x3e38(%rip), %rbp      # 0x11a81
xorl %r13d, %r13d
movq 0x8(%rsp), %rax
movzbl 0x8(%rax), %eax
cmpq %rax, %r13
jae 0xdc9c
btl %r13d, %r12d
jae 0xdc97
movq %r15, %rdi
movq %r14, %rsi
movl %r13d, %edx
xorl %eax, %eax
callq 0x3160
movq 0x8(%rsp), %rax
movzwl 0x20(%rax,%r13,2), %esi
movzwl 0x30(%rsp,%r13,2), %edx
movzwl 0x40(%rsp,%r13,2), %ecx
movzwl 0x20(%rsp,%r13,2), %r8d
movq %rbp, %rdi
xorl %eax, %eax
callq 0x3160
incq %r13
jmp 0xdc4c
xorl %eax, %eax
movq 0x10(%rsp), %rcx
testb %cl, %cl
setne %al
movb %cl, 0x59(%rbx)
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x9334(%rip), %rax      # 0x16ff8
movq (%rax), %rcx
leaq 0x3e2a(%rip), %rdi      # 0x11af8
pushq $0x34
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
jmp 0xdcfa
movq 0x9316(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
movq 0x98(%r14), %rdx
leaq 0x3de4(%rip), %rsi      # 0x11ad7
xorl %eax, %eax
callq 0x31e0
pushq $-0x1
popq %rax
jmp 0xdcab