// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x18(%rbp)
movb $0x0, -0xa9(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3170
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3170
leaq -0xe0(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x3170
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movb $-0x1, 0x11(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x31f0
movl %eax, %edi
leaq -0xa8(%rbp), %rsi
callq 0x32d0
cmpl $0x0, %eax
jne 0x15e2a
movq -0x78(%rbp), %rax
movl $0x100, %ecx            # imm = 0x100
cqto
idivq %rcx
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
leaq 0x96a8(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0x15e09
leaq 0x9309(%rip), %rax      # 0x1ee70
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x15dda
leaq 0x967a(%rip), %rax      # 0x1f200
movq 0x98(%rax), %rdi
movq -0xe8(%rbp), %rax
movq (%rax), %rsi
callq 0x31b0
cmpl $0x0, %eax
jne 0x15dc3
movb $0x0, -0xea(%rbp)
movq -0xe8(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x40(%rax)
movq -0xe8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x8(%rax)
movb $0x0, -0xe9(%rbp)
movzbl -0xe9(%rbp), %eax
movq -0xe8(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jge 0x15c86
movq -0x10(%rbp), %rdi
movb -0xe9(%rbp), %al
movzbl -0xe9(%rbp), %ecx
leaq -0xc0(%rbp), %rdx
shlq %rcx
addq %rcx, %rdx
movzbl -0xe9(%rbp), %ecx
movl %ecx, %esi
leaq -0xd0(%rbp), %rcx
shlq %rsi
addq %rsi, %rcx
movzbl -0xe9(%rbp), %esi
leaq -0xe0(%rbp), %r8
shlq %rsi
addq %rsi, %r8
movzbl %al, %esi
callq 0x16b30
cmpl $0x0, %eax
je 0x15c71
movb -0xea(%rbp), %al
addb $0x1, %al
movb %al, -0xea(%rbp)
movzbl -0xe9(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, %ecx
movzbl -0xa9(%rbp), %eax
orl %ecx, %eax
movb %al, -0xa9(%rbp)
jmp 0x15c73
movb -0xe9(%rbp), %al
addb $0x1, %al
movb %al, -0xe9(%rbp)
jmp 0x15bd5
movzbl -0xa9(%rbp), %eax
cmpl $0x0, %eax
je 0x15d9d
leaq 0x9547(%rip), %rax      # 0x1f1e4
cmpl $0x0, (%rax)
jne 0x15cdb
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movzbl -0xea(%rbp), %edx
movzbl -0xea(%rbp), %edi
leaq 0x440a(%rip), %rcx      # 0x1a0c9
leaq 0x4cda(%rip), %rax      # 0x1a9a0
cmpl $0x1, %edi
cmoveq %rax, %rcx
leaq 0x4c9f(%rip), %rdi      # 0x1a973
movb $0x0, %al
callq 0x3160
movb $0x0, -0xe9(%rbp)
movzbl -0xe9(%rbp), %eax
movq -0xe8(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
jge 0x15d9b
movzbl -0xa9(%rbp), %eax
movzbl -0xe9(%rbp), %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x15d86
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movzbl -0xe9(%rbp), %edx
leaq 0x452d(%rip), %rdi      # 0x1a25d
movb $0x0, %al
callq 0x3160
movq -0xe8(%rbp), %rax
movzbl -0xe9(%rbp), %ecx
movzwl 0x20(%rax,%rcx,2), %esi
movzbl -0xe9(%rbp), %eax
movzwl -0xd0(%rbp,%rax,2), %edx
movzbl -0xe9(%rbp), %eax
movzwl -0xc0(%rbp,%rax,2), %ecx
movzbl -0xe9(%rbp), %eax
movzwl -0xe0(%rbp,%rax,2), %r8d
leaq 0x4c22(%rip), %rdi      # 0x1a9a1
movb $0x0, %al
callq 0x3160
jmp 0x15d88
movb -0xe9(%rbp), %al
addb $0x1, %al
movb %al, -0xe9(%rbp)
jmp 0x15ce2
jmp 0x15d9d
movb -0xa9(%rbp), %cl
movq -0x18(%rbp), %rax
movb %cl, 0x11(%rax)
movzbl -0xa9(%rbp), %edx
xorl %eax, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x15e31
movq -0xe8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0xe8(%rbp)
jmp 0x15b6e
movq 0x8217(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x9415(%rip), %rax      # 0x1f200
movq 0x98(%rax), %rdx
leaq 0x4bfe(%rip), %rsi      # 0x1a9f7
movb $0x0, %al
callq 0x31c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15e31
movq 0x81e8(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x4bfe(%rip), %rsi      # 0x1aa18
movb $0x0, %al
callq 0x31c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x15e31
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)