// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl $0x0, 0x4(%rax)
leaq 0x1106b(%rip), %rax     # 0x1f1f8
movl (%rax), %eax
andl $0x80000, %eax          # imm = 0x80000
cmpl $0x0, %eax
je 0xe23b
leaq 0x1105c(%rip), %rax     # 0x1f200
movq 0x98(%rax), %rsi
leaq 0xc034(%rip), %rdi      # 0x1a1e6
callq 0x31b0
cmpl $0x0, %eax
jne 0xe1d3
movq -0x10(%rbp), %rax
movq $0xd00, 0x40(%rax)      # imm = 0xD00
movq -0x18(%rbp), %rax
movl $0x80, 0x4(%rax)
leaq 0x11026(%rip), %rax     # 0x1f200
movq 0x98(%rax), %rsi
leaq 0xc003(%rip), %rdi      # 0x1a1eb
callq 0x31b0
cmpl $0x0, %eax
jne 0xe209
movq -0x10(%rbp), %rax
movq $0x1a00, 0x40(%rax)     # imm = 0x1A00
movq -0x18(%rbp), %rax
movl $0x100, 0x4(%rax)       # imm = 0x100
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0xe239
movq 0xfdde(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x10fdc(%rip), %rax     # 0x1f200
movq 0x98(%rax), %rdx
leaq 0xbfbe(%rip), %rsi      # 0x1a1f0
movb $0x0, %al
callq 0x31c0
jmp 0xe23b
movq -0x18(%rbp), %rdi
addq $0xa, %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x3170
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x31f0
movl %eax, %edi
leaq -0xa8(%rbp), %rsi
callq 0x32d0
cmpl $0x0, %eax
jne 0xe8e0
movw $0x0, -0xb0(%rbp)
movq -0x78(%rbp), %rax
movl $0x200, %ecx            # imm = 0x200
cqto
idivq %rcx
movl %eax, %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x10, %eax
movw %ax, -0xac(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
movw %ax, -0xae(%rbp)
movzwl -0xae(%rbp), %eax
cmpl $0x8, %eax
jl 0xe2d2
movw -0xac(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xac(%rbp)
movw $0x0, -0xaa(%rbp)
movzwl -0xaa(%rbp), %eax
movzwl -0xac(%rbp), %ecx
cmpl %ecx, %eax
jge 0xe421
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, %ecx
movl $0x1, %esi
shll %cl, %esi
movq -0x18(%rbp), %rax
movq %rax, -0xe0(%rbp)
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xe0(%rbp), %rax
movslq %ecx, %rcx
movzwl 0xa(%rax,%rcx,2), %edx
orl %esi, %edx
movw %dx, 0xa(%rax,%rcx,2)
movq -0x18(%rbp), %rax
movzwl -0xaa(%rbp), %ecx
movw $0xffff, 0x2a(%rax,%rcx,2) # imm = 0xFFFF
movq -0x10(%rbp), %rdi
movw -0xaa(%rbp), %ax
movq -0x18(%rbp), %rdx
addq $0x2a, %rdx
movzwl -0xaa(%rbp), %ecx
shlq %rcx
addq %rcx, %rdx
movq -0x18(%rbp), %rcx
addq $0x22a, %rcx            # imm = 0x22A
movzwl -0xaa(%rbp), %esi
shlq %rsi
addq %rsi, %rcx
movzbl %al, %esi
callq 0xf670
movl %eax, -0xb4(%rbp)
cmpl $0x0, -0xb4(%rbp)
je 0xe3b0
movw -0xb0(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xb0(%rbp)
jmp 0xe3fd
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %edx, %ecx
movl $0x1, %esi
shll %cl, %esi
xorl $-0x1, %esi
movq -0x18(%rbp), %rax
movq %rax, -0xe8(%rbp)
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xe8(%rbp), %rax
movslq %ecx, %rcx
movzwl 0xa(%rax,%rcx,2), %edx
andl %esi, %edx
movw %dx, 0xa(%rax,%rcx,2)
cmpl $0x1, -0xb4(%rbp)
jne 0xe408
jmp 0xe421
jmp 0xe40a
movw -0xaa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xaa(%rbp)
jmp 0xe2db
movw -0xb0(%rbp), %cx
movq -0x18(%rbp), %rax
movw %cx, 0x8(%rax)
movzwl -0xb0(%rbp), %eax
cmpl $0x0, %eax
je 0xe8de
leaq 0x10d9d(%rip), %rax     # 0x1f1e4
cmpl $0x0, (%rax)
jne 0xe485
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movzwl -0xb0(%rbp), %edx
movzwl -0xb0(%rbp), %edi
leaq 0xbc60(%rip), %rcx      # 0x1a0c9
leaq 0xc530(%rip), %rax      # 0x1a9a0
cmpl $0x1, %edi
cmoveq %rax, %rcx
leaq 0xbd9a(%rip), %rdi      # 0x1a218
movb $0x0, %al
callq 0x3160
movw $0x0, -0xaa(%rbp)
movzwl -0xaa(%rbp), %ecx
xorl %eax, %eax
cmpl $0x100, %ecx            # imm = 0x100
movb %al, -0xe9(%rbp)
jge 0xe4b8
movzwl -0xb0(%rbp), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0xe9(%rbp)
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0xe4c7
jmp 0xe8d5
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movq -0xf8(%rbp), %rax
movslq %ecx, %rcx
movzwl 0xa(%rax,%rcx,2), %eax
movl %eax, -0xf0(%rbp)
movzwl -0xaa(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl -0xf0(%rbp), %eax
movl %edx, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0xe8bc
movw $0x0, -0xb8(%rbp)
movw $0x1, -0xba(%rbp)
movw $0x0, -0xbc(%rbp)
movw $0x5, -0xbe(%rbp)
movq -0x10(%rbp), %rdi
movw -0xaa(%rbp), %ax
movzbl %al, %esi
movzwl -0xba(%rbp), %edx
callq 0xc3e0
cmpl $0x0, %eax
jne 0xe572
movl $0x0, -0x4(%rbp)
jmp 0xe8e7
movzwl -0xbc(%rbp), %eax
cmpl $0x0, %eax
jne 0xe595
movq -0x18(%rbp), %rax
movzwl 0x42e(%rax), %edi
callq 0xc6b0
movw %ax, -0xbc(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x430(%rax), %edi
callq 0xc6b0
movzwl %ax, %eax
sarl %eax
addl $0x7, %eax
movw %ax, -0xb6(%rbp)
movq -0x18(%rbp), %rax
movzwl -0xbe(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movzwl %ax, %ecx
andl $0x800, %ecx            # imm = 0x800
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0xf9(%rbp)
jne 0xe608
movzwl -0xbe(%rbp), %ecx
movl $0x200, %eax            # imm = 0x200
subl %ecx, %eax
movzwl -0xb6(%rbp), %ecx
cmpl %ecx, %eax
setge %al
movb %al, -0xf9(%rbp)
movb -0xf9(%rbp), %al
testb $0x1, %al
jne 0xe617
jmp 0xe69a
movq -0x18(%rbp), %rax
movzwl -0xbe(%rbp), %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movw %ax, -0xc0(%rbp)
movzwl -0xc0(%rbp), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0xe67e
movq -0x18(%rbp), %rax
movzwl -0xbe(%rbp), %ecx
addl $0x4, %ecx
movslq %ecx, %rcx
movzwl 0x42a(%rax,%rcx,2), %edi
callq 0xc6b0
movzwl %ax, %ecx
movzwl -0xb8(%rbp), %eax
addl %ecx, %eax
movw %ax, -0xb8(%rbp)
movzwl -0xb6(%rbp), %ecx
movzwl -0xbe(%rbp), %eax
addl %ecx, %eax
movw %ax, -0xbe(%rbp)
jmp 0xe5b4
movq -0x18(%rbp), %rax
movzwl 0x42c(%rax), %edi
callq 0xc6b0
movw %ax, -0xba(%rbp)
movzwl -0xba(%rbp), %eax
cmpl $0x0, %eax
jne 0xe53e
leaq 0x10b1c(%rip), %rax     # 0x1f1e4
cmpl $0x0, (%rax)
jne 0xe8aa
movq $0x0, -0xd0(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x42a(%rax), %edi
callq 0xc6b0
movw %ax, -0xd2(%rbp)
movq -0x18(%rbp), %rax
movzwl 0x430(%rax), %edi
callq 0xc6b0
movw %ax, -0xd4(%rbp)
movq -0x10(%rbp), %rdi
movw -0xaa(%rbp), %ax
movl $0x1, %edx
xorl %ecx, %ecx
movzbl %al, %esi
callq 0xbdc0
cmpl $0x0, %eax
jne 0xe735
movl $0x0, -0x4(%rbp)
jmp 0xe8e7
movq -0x18(%rbp), %rdi
addq $0x42a, %rdi            # imm = 0x42A
addq $0x1f0, %rdi            # imm = 0x1F0
leaq 0xbaf6(%rip), %rsi      # 0x1a244
movl $0xc, %edx
callq 0x3090
cmpl $0x0, %eax
jne 0xe78c
movq -0x18(%rbp), %rax
movzwl 0x600(%rax), %edi
callq 0xc6b0
leaq -0xc4(%rbp), %rsi
movzwl %ax, %edi
callq 0x5bf0
leaq -0xc4(%rbp), %rax
movq %rax, -0xd0(%rbp)
jmp 0xe7fc
movq -0x18(%rbp), %rax
movzwl 0x600(%rax), %edi
callq 0xc6b0
movzwl %ax, %eax
movl %eax, -0x100(%rbp)
subl $0x8e52, %eax           # imm = 0x8E52
je 0xe7dc
jmp 0xe7ae
movl -0x100(%rbp), %eax
subl $0x8e53, %eax           # imm = 0x8E53
je 0xe7ec
jmp 0xe7bd
movl -0x100(%rbp), %eax
subl $0x8ea9, %eax           # imm = 0x8EA9
jne 0xe7fa
jmp 0xe7cc
leaq 0xba7e(%rip), %rax      # 0x1a251
movq %rax, -0xd0(%rbp)
jmp 0xe7fa
leaq 0xba72(%rip), %rax      # 0x1a255
movq %rax, -0xd0(%rbp)
jmp 0xe7fa
leaq 0xba66(%rip), %rax      # 0x1a259
movq %rax, -0xd0(%rbp)
jmp 0xe7fc
movq -0x10(%rbp), %rsi
addq $0x8, %rsi
movzwl -0xaa(%rbp), %edx
leaq 0xba4b(%rip), %rdi      # 0x1a25d
movb $0x0, %al
callq 0x3160
cmpq $0x0, -0xd0(%rbp)
je 0xe84a
movq -0xd0(%rbp), %rsi
movq -0x18(%rbp), %rdx
addq $0x42a, %rdx            # imm = 0x42A
addq $0x1f0, %rdx            # imm = 0x1F0
leaq 0xba21(%rip), %rdi      # 0x1a264
movb $0x0, %al
callq 0x3160
movq -0x18(%rbp), %rax
movzwl -0xaa(%rbp), %ecx
movzwl 0x2a(%rax,%rcx,2), %esi
addl $0x1, %esi
movzwl -0xb8(%rbp), %edx
movzwl -0xd2(%rbp), %ecx
movzwl -0xbc(%rbp), %r8d
movzwl -0xd4(%rbp), %r9d
leaq 0xba09(%rip), %rdi      # 0x1a28b
movb $0x0, %al
callq 0x3160
movq -0x18(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0xe8a8
movq -0x18(%rbp), %rax
movl 0x4(%rax), %esi
leaq 0xba62(%rip), %rdi      # 0x1a303
movb $0x0, %al
callq 0x3160
jmp 0xe8aa
movw -0xb0(%rbp), %ax
addw $-0x1, %ax
movw %ax, -0xb0(%rbp)
jmp 0xe8be
movw -0xaa(%rbp), %ax
addw $0x1, %ax
movw %ax, -0xaa(%rbp)
jmp 0xe48e
movl $0x1, -0x4(%rbp)
jmp 0xe8e7
jmp 0xe8e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw %cs:(%rax,%rax)