// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/fsio/rt11.c
// Function: rt11Mount
static int rt11Mount(
  struct mountedFS *mount
)
{
  struct RT11data *data = &mount->rt11data;
  struct stat stat;

  data->sectorsz = 0;

  /*
   * Check for device type override.
   */
  if (SWISSET('t')) {
    if (strcmp("rx01", SWGETVAL('t')) == 0) {
      mount->skip = RT11_RX0xNSECT * RT11_RX01SS;
      data->sectorsz = RT11_RX01SS;
    }
    if (strcmp("rx02", SWGETVAL('t')) == 0) {
      mount->skip = RT11_RX0xNSECT * RT11_RX02SS;
      data->sectorsz = RT11_RX02SS;
    }

    if (data->sectorsz == 0)
      fprintf(stderr,
              "mount: Ignoring unknown disk type \"%s\"\n", SWGETVAL('t'));
  }

  memset(&data->valid, 0, sizeof(data->valid));

  if (fstat(fileno(mount->container), &stat) == 0) {
    uint16_t i, count, lastsz, validcount = 0;;

    data->blocks = stat.st_size / RT11_BLOCKSIZE;

    count = data->blocks / RT11_MAXPARTSZ;
    lastsz = data->blocks % RT11_MAXPARTSZ;

    if (lastsz >= RT11_MINPARTSZ)
      count++;

    /*
     * Check each file system for validity.
     */
    for (i = 0; i < count; i++) {
      int type;

      /*
       * Assume valid and maximal size
       */
      data->valid[i / 16] |= 1 << (i % 16);
      data->maxblk[i] = RT11_MAXPARTSZ - 1;

      type = validate(mount, i, &data->maxblk[i], &data->first[i]);

      if (type != RT11_NOPART)
        validcount++;
      else data->valid[i / 16] &= ~(1 << (i % 16));

      if (type == RT11_SINGLE)
        break;
    }

    data->filesystems = validcount;

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

      for (i = 0; (i < 256) && (validcount != 0); i++)
        if (RT11_PARTITIONVALID(data, i)) {
          uint16_t entrysz, freeblks = 0, dsseg = 1;
          uint16_t highest = 0;

          do {
            uint16_t off = RT11_DH_SIZE;

            if (rt11ReadDirSegment(mount, i, dsseg) == 0)
              return 0;

            if (highest == 0)
              highest = le16toh(data->buf[RT11_DH_HIGHEST]);

            entrysz = RT11_DI_SIZE + (le16toh(data->buf[RT11_DH_EXTRA]) >> 1);

            while (!RT11EOS(le16toh(data->buf[off + RT11_DI_STATUS])) &&
                   ((RT11_DS_SIZE - off) >= entrysz)) {
              uint16_t status = le16toh(data->buf[off + RT11_DI_STATUS]);

              if ((status & RT11_E_MPTY) != 0)
                freeblks += le16toh(data->buf[off + RT11_DI_LENGTH]);

              off += entrysz;
            }
            dsseg = le16toh(data->buf[RT11_DH_NEXT]);
          } while (dsseg != 0);

          if (!quiet) {
            char vers[4], *version = NULL;
            uint16_t cnt, extra;

            cnt = le16toh(data->buf[RT11_DH_COUNT]);
            extra = le16toh(data->buf[RT11_DH_EXTRA]);

            if (rt11ReadBlock(mount, i, RT11_HOME, NULL) == 0)
              return 0;

            /*
             * Special handling of volumes created by non-RT-11 systenms
             * (e.g. VMS Exchange).
             */
            if (strncmp((char *)&data->buf[RT11_HB_SYSID], RT11_VMSSYSID, strlen(RT11_VMSSYSID)) == 0) {
              r50Asc(le16toh(data->buf[RT11_HB_SYSVER]), vers);
              version = vers;
            } else {
              switch (le16toh(data->buf[RT11_HB_SYSVER])) {
                case RT11_SYSVER_V3A:
                  version = "V3A";
                  break;

                case RT11_SYSVER_V04:
                  version = "V04";
                  break;

                case RT11_SYSVER_V05:
                  version = "V05";
                  break;
              }
            }

            printf("%s%o:\n", mount->name, i);
            if (version != NULL)
              printf("  Version: %s,        System ID: %12s\n",
                     version, (char *)&data->buf[RT11_HB_SYSID]);
            printf("  Total blocks: %5d, Free blocks: %5d\n"
                   "  Directory segments: %2d (Highest in use: %d)\n"
                   "  Extra bytes/directory entry: %d\n",
                   data->maxblk[i] + 1, freeblks, cnt, highest, extra);
            if (data->sectorsz != 0)
              printf("  Sector size: %d\n", data->sectorsz);
          }
          validcount--;
        }
      return 1;
    }
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rdi, %rbx
movl $0x0, 0x4c(%rdi)
leaq 0xe124(%rip), %rax      # 0x18fc8
testb $0x8, 0x2(%rax)
je 0xaf06
leaq 0xe11f(%rip), %rax      # 0x18fd0
movq 0x98(%rax), %r14
leaq 0x72d9(%rip), %rdi      # 0x12198
movq %r14, %rsi
callq 0x31c0
testl %eax, %eax
jne 0xaeda
movq $0xd00, 0x40(%rbx)      # imm = 0xD00
movl $0x80, 0x4c(%rbx)
leaq 0x72bc(%rip), %rdi      # 0x1219d
movq %r14, %rsi
callq 0x31c0
testl %eax, %eax
jne 0xaefc
movq $0x1a00, 0x40(%rbx)     # imm = 0x1A00
movl $0x100, 0x4c(%rbx)      # imm = 0x100
cmpl $0x0, 0x4c(%rbx)
je 0xb4c1
xorps %xmm0, %xmm0
movups %xmm0, 0x62(%rbx)
movups %xmm0, 0x52(%rbx)
movq 0x38(%rbx), %rdi
callq 0x3200
leaq 0x68(%rsp), %rsi
movl %eax, %edi
callq 0x32e0
testl %eax, %eax
je 0xaf31
xorl %ebp, %ebp
jmp 0xb4ad
leaq 0x52(%rbx), %rax
movq %rax, 0x38(%rsp)
movq 0x98(%rsp), %rcx
leaq 0x1ff(%rcx), %rax
testq %rcx, %rcx
cmovsq %rax, %rcx
sarq $0x9, %rcx
movl %ecx, 0x48(%rbx)
movl %ecx, %edx
shrl $0x10, %edx
xorl %eax, %eax
testl $0xfff8, %ecx           # imm = 0xFFF8
setne %al
addw %dx, %ax
je 0xb213
leaq 0x662(%rbx), %rcx
movq %rcx, 0x30(%rsp)
movzwl %ax, %eax
movq %rax, 0x28(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
movl %r12d, %ecx
andb $0xf, %cl
movl $0x1, %r14d
shll %cl, %r14d
movl %r12d, %r15d
shrl $0x4, %r15d
andl $0xfff, %r15d           # imm = 0xFFF
orw %r14w, 0x52(%rbx,%r15,2)
movw $0xffff, 0x72(%rbx,%r12,2) # imm = 0xFFFF
movzbl %r12b, %esi
movq %rbx, %rdi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x9cd9
movl $0x0, %ecx
testl %eax, %eax
je 0xb1e9
leaq 0xdfed(%rip), %rax      # 0x18fc8
testb $0x20, (%rax)
jne 0xb010
movl $0xc, %edx
movq 0x30(%rsp), %rdi
leaq 0x72d7(%rip), %rsi      # 0x122c8
callq 0x30a0
testl %eax, %eax
jne 0xb055
movzwl 0x648(%rbx), %ecx
testb %r12b, %r12b
je 0xb027
cmpl $0x8e53, %ecx           # imm = 0x8E53
jne 0xb046
jmp 0xb04a
movl %r14d, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movl $0x1, 0x20(%rsp)
movw $0x6, %ax
jmp 0xb096
movl $0x1, %edx
xorl %eax, %eax
cmpl $0x8e52, %ecx           # imm = 0x8E52
je 0xb051
cmpl $0x8e53, %ecx           # imm = 0x8E53
je 0xb04a
cmpl $0x8ea9, %ecx           # imm = 0x8EA9
je 0xb051
movb $0x1, %al
jmp 0xb051
movl $0x2, %edx
xorl %eax, %eax
testb %al, %al
je 0xb075
movl $0xc, %edx
movq 0x30(%rsp), %rdi
leaq 0x7190(%rip), %rsi      # 0x121f6
callq 0x30a0
testl %eax, %eax
movl $0x0, %edx
sete %dl
movl $0x0, %ecx
testl %edx, %edx
je 0xb1e9
movl %edx, 0x20(%rsp)
movl %r14d, 0x10(%rsp)
movl %ebp, 0xc(%rsp)
movzwl 0x646(%rbx), %eax
movw %ax, 0x272(%rbx,%r12,2)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movw $0x1, %bp
movl $0x0, 0x8(%rsp)
movzbl %r12b, %esi
movzwl %bp, %r13d
movq %rbx, %rdi
movl %r13d, %edx
callq 0xa037
movl $0x1, %ecx
testl %eax, %eax
je 0xb0e5
movb 0x40(%rsp,%r13), %al
leal 0x1(%rax), %edx
movb %dl, 0x40(%rsp,%r13)
testb %al, %al
je 0xb0f7
testl %ecx, %ecx
jne 0xb1cc
testw %bp, %bp
jne 0xb0b8
jmp 0xb1d0
movzwl 0x478(%rbx), %edx
movzwl 0x47a(%rbx), %eax
cmpw $0x1, %bp
jne 0xb135
movzwl 0x472(%rbx), %edi
movzwl 0x476(%rbx), %r14d
cmpw $0x20, %r14w
setae %sil
movw %di, 0x18(%rsp)
cmpw %di, %r14w
seta %dil
orb %sil, %dil
jne 0xb0e5
movzwl 0x18(%rsp), %esi
cmpw 0x472(%rbx), %si
jne 0xb0e5
shrl %edx
addl $0x7, %edx
movl $0x200, %esi            # imm = 0x200
subl %edx, %esi
movw $0x5, %di
movzwl %di, %ecx
movzwl 0x472(%rbx,%rcx,2), %r8d
btl $0xb, %r8d
jb 0xb1a9
cmpl %ecx, %esi
jl 0xb1a9
movl %ecx, %ecx
movzwl 0x47a(%rbx,%rcx,2), %r9d
addl %r9d, %eax
movl $0x5, %ecx
btl $0x9, %r8d
jb 0xb19c
xorl %r8d, %r8d
xorl %ecx, %ecx
addw %ax, %r9w
setb %r9b
jb 0xb196
movl %edx, %r8d
movb %r9b, %cl
addl %r8d, %edi
testl %ecx, %ecx
je 0xb153
cmpl $0x5, %ecx
jne 0xb0e5
movl 0x8(%rsp), %ecx
cmpw %cx, %ax
cmoval %eax, %ecx
movl %ecx, 0x8(%rsp)
movzwl 0x474(%rbx), %ebp
xorl %ecx, %ecx
cmpw %r14w, %bp
seta %cl
jmp 0xb0e5
xorl %ecx, %ecx
jmp 0xb1e0
movl 0x8(%rsp), %eax
decl %eax
movw %ax, 0x72(%rbx,%r12,2)
movl 0x20(%rsp), %ecx
movl 0xc(%rsp), %ebp
movl 0x10(%rsp), %r14d
testl %ecx, %ecx
je 0xb1f1
incl %ebp
jmp 0xb1fe
notl %r14d
movq 0x38(%rsp), %rax
andw %r14w, (%rax,%r15,2)
cmpl $0x1, %ecx
je 0xb215
incq %r12
cmpq 0x28(%rsp), %r12
jne 0xaf89
jmp 0xb215
xorl %ebp, %ebp
movw %bp, 0x50(%rbx)
testw %bp, %bp
movl %ebp, 0xc(%rsp)
je 0xb4a1
leaq 0xdd87(%rip), %rax      # 0x18fb4
cmpl $0x0, (%rax)
jne 0xb25d
movzwl %bp, %edx
leaq 0x8(%rbx), %rsi
cmpw $0x1, %bp
leaq 0x783c(%rip), %rax      # 0x12a80
leaq 0x6e30(%rip), %rcx      # 0x1207b
cmoveq %rax, %rcx
leaq 0x6f74(%rip), %rdi      # 0x121ca
xorl %eax, %eax
callq 0x3160
leaq 0x662(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x8(%rbx), %rax
movq %rax, 0x20(%rsp)
xorl %edx, %edx
movl %ebp, %esi
movl %edx, %eax
shrl $0x4, %eax
movq 0x38(%rsp), %rcx
movzwl (%rcx,%rax,2), %eax
movl %edx, %ecx
andl $0xf, %ecx
btl %ecx, %eax
jae 0xb3d9
movl %esi, 0x8(%rsp)
movw $0x1, %r12w
movq %rdx, 0x18(%rsp)
movzbl %dl, %r13d
xorl %r14d, %r14d
xorl %r15d, %r15d
movzwl %r12w, %edx
movq %rbx, %rdi
movl %r13d, %esi
callq 0xa037
testl %eax, %eax
je 0xb334
testw %r15w, %r15w
jne 0xb2cb
movzwl 0x476(%rbx), %r15d
movzwl 0x478(%rbx), %ecx
movzwl 0x47c(%rbx), %edi
btl $0xb, %edi
setae %dl
cmpl $0x3ea, %ecx            # imm = 0x3EA
setb %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0xb32c
shrl %ecx
movl $0x1f9, %edx            # imm = 0x1F9
subl %ecx, %edx
addl $0x7, %ecx
movl $0x5, %esi
btl $0x9, %edi
jae 0xb315
movl %esi, %edi
addw 0x47a(%rbx,%rdi,2), %r14w
addl %ecx, %esi
movzwl %si, %esi
movzwl 0x472(%rbx,%rsi,2), %edi
btl $0xb, %edi
jb 0xb32c
cmpl %edx, %esi
jle 0xb304
movzwl 0x474(%rbx), %r12d
xorl %ebp, %ebp
testl %eax, %eax
je 0xb3c6
testw %r12w, %r12w
jne 0xb2aa
leaq 0xdc65(%rip), %rax      # 0x18fb4
cmpl $0x0, (%rax)
je 0xb35e
movl 0x8(%rsp), %esi
decl %esi
movb $0x1, %al
jmp 0xb3cc
movzwl 0x472(%rbx), %eax
movl %eax, 0x28(%rsp)
movzwl 0x478(%rbx), %r12d
movq %rbx, %rdi
movl %r13d, %esi
movl $0x1, %edx
xorl %ecx, %ecx
callq 0x9cd9
testl %eax, %eax
je 0xb3c6
movl $0xc, %edx
movq 0x10(%rsp), %rdi
leaq 0x6e5e(%rip), %rsi      # 0x121f6
callq 0x30a0
testl %eax, %eax
je 0xb3fc
movzwl 0x648(%rbx), %eax
cmpl $0x8e52, %eax           # imm = 0x8E52
je 0xb41b
cmpl $0x8e53, %eax           # imm = 0x8E53
je 0xb412
cmpl $0x8ea9, %eax           # imm = 0x8EA9
jne 0xb424
leaq 0x6e3f(%rip), %r13      # 0x12203
jmp 0xb427
xorl %eax, %eax
movl 0x8(%rsp), %esi
testb %al, %al
movq 0x18(%rsp), %rdx
je 0xb4a1
movl $0x1, %ebp
cmpq $0xfe, %rdx
ja 0xb4a1
incq %rdx
testw %si, %si
jne 0xb276
jmp 0xb4a1
movzwl 0x648(%rbx), %edi
leaq 0x40(%rsp), %r13
movq %r13, %rsi
callq 0x65fc
jmp 0xb427
leaq 0x6df2(%rip), %r13      # 0x1220b
jmp 0xb427
leaq 0x6de5(%rip), %r13      # 0x12207
jmp 0xb427
xorl %r13d, %r13d
leaq 0x6de1(%rip), %rdi      # 0x1220f
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x3160
testq %r13, %r13
je 0xb45a
leaq 0x6dcb(%rip), %rdi      # 0x12216
movq %r13, %rsi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3160
movq 0x18(%rsp), %rax
movzwl 0x72(%rbx,%rax,2), %esi
incl %esi
movzwl %r14w, %edx
movzwl %r15w, %r8d
leaq 0x6dc8(%rip), %rdi      # 0x1223d
movl 0x28(%rsp), %ecx
movl %r12d, %r9d
xorl %eax, %eax
callq 0x3160
movl 0x4c(%rbx), %esi
testl %esi, %esi
je 0xb354
leaq 0x6e20(%rip), %rdi      # 0x122b5
xorl %eax, %eax
callq 0x3160
jmp 0xb354
cmpw $0x0, 0xc(%rsp)
je 0xaf2a
movl %ebp, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xcb28(%rip), %rax      # 0x17ff0
movq (%rax), %rdi
leaq 0x6cd0(%rip), %rsi      # 0x121a2
movq %r14, %rdx
xorl %eax, %eax
callq 0x31d0
jmp 0xaf06