// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/dosmt.c
// Function: dosmtInfo
static void dosmtInfo(
  struct mountedFS *mount,
  uint8_t UNUSED(unit),
  uint8_t UNUSED(present)
)
{
  struct DOSMTdata *data = &mount->dosmtdata;
  off_t pos = tapeGetPosition(mount->container);
  int eot = 0, bot = pos == 0;
  char temp[32], filename[14];
  struct dosmthdr *hdr = (struct dosmthdr *)data->buf;
  struct stat stat;

  fstat(fileno(mount->container), &stat);

  /*
   * If we are positioned at the end-of-file, there is a tape mark or
   * end-of-media marker missing. Treat it as though the missing marker
   * is present.
   */
  if (pos != stat.st_size) {
    uint32_t bc;

    switch (bc = tapeReadRecord(mount->container, data->buf, DOSMTRCLNT)) {
      case ST_FAIL:
        goto error;

      case ST_TM:
      case ST_EOM:
        eot = 1;
        break;

      default:
        if ((bc & ST_ERROR) == 0) {
          if (bc == sizeof(struct dosmthdr)) {

            memset(filename, ' ', sizeof(filename));
            filename[13]='\0';

            r50Asc(le16toh(hdr->fname[0]), &filename[0]);
            r50Asc(le16toh(hdr->fname[1]), &filename[3]);
            if ((mount->flags & FS_DOSMTEXT) != 0)
              r50Asc(le16toh(hdr->fname3), &filename[6]);
            filename[9] = '.';
            r50Asc(le16toh(hdr->ext), &filename[10]);
            break;
          }
        }
        strcpy(filename, "Unknown");
        break;
    }

    /*
     * Restore the tape position
     */
    if (tapeSetPosition(mount->container, pos) != 0)
      goto error;

  } else eot = 1;

  if ((bot == 0) && (eot == 0)) {
    unsigned long long position = pos;

    sprintf(temp, "Offset %llu", position);
  }

  printf("%s:\n", mount->name);
  printf("  Position: %s\n",
         bot ? "Beginning of tape" :
           (eot ? "End of tape" : temp));
  if (!eot)
    printf("  Next file: %s[%3o,%3o]\n",
           filename, hdr->proj, hdr->prog);
  return;

 error:
  fprintf(stderr, "info: container file I/O error\n");
  tapeRewind(mount->container);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq 0x38(%rdi), %rdi
callq 0x53df
movq %rax, %r14
movq 0x38(%rbx), %rdi
callq 0x3210
leaq 0x38(%rsp), %r15
movl %eax, %edi
movq %r15, %rsi
callq 0x32f0
cmpq 0x30(%r15), %r14
jne 0xb2b3
addq $0x8, %rbx
leaq 0x62eb(%rip), %rdi      # 0x11564
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3160
testq %r14, %r14
leaq 0x62fe(%rip), %rax      # 0x1158b
leaq 0x62e5(%rip), %rsi      # 0x11579
cmovneq %rax, %rsi
leaq 0x62ca(%rip), %rdi      # 0x11569
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x3160
leaq 0x48(%rbx), %rsi
movq 0x38(%rbx), %rdi
movl $0x200, %edx            # imm = 0x200
callq 0x5568
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0xb2ed
cmpl $0xe, %eax
je 0xb2f1
cmpl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0xb3ef
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, (%rsp)
jmp 0xb346
xorl %ebp, %ebp
jmp 0xb349
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rsp, %rsi
movq %rax, 0x5(%rsi)
movq %rax, (%rsi)
movb $0x0, 0xd(%rsi)
movzwl 0x48(%rbx), %edi
callq 0x5068
movzwl 0x4a(%rbx), %edi
leaq 0x3(%rsp), %rsi
callq 0x5068
testb $0x1, 0x31(%rbx)
je 0xb334
movzwl 0x54(%rbx), %edi
leaq 0x6(%rsp), %rsi
callq 0x5068
leaq 0xa(%rsp), %rsi
movb $0x2e, -0x1(%rsi)
movzwl 0x4c(%rbx), %edi
callq 0x5068
movb $0x1, %bpl
movq 0x38(%rbx), %rdi
movq %r14, %rsi
callq 0x53e4
testl %eax, %eax
jne 0xb3ef
testq %r14, %r14
sete %al
movl %ebp, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0xb382
leaq 0x61e5(%rip), %rsi      # 0x11558
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32b0
leaq 0x8(%rbx), %rsi
leaq 0x61d7(%rip), %rdi      # 0x11564
xorl %eax, %eax
callq 0x3160
leaq 0x61f0(%rip), %rax      # 0x1158b
testb %bpl, %bpl
leaq 0x10(%rsp), %rcx
cmoveq %rax, %rcx
testq %r14, %r14
leaq 0x61c8(%rip), %rsi      # 0x11579
cmovneq %rcx, %rsi
leaq 0x61ad(%rip), %rdi      # 0x11569
xorl %eax, %eax
callq 0x3160
testb %bpl, %bpl
je 0xb3e1
movzbl 0x4f(%rbx), %edx
movzbl 0x4e(%rbx), %ecx
leaq 0x61c0(%rip), %rdi      # 0x11597
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3160
addq $0xc8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xbc02(%rip), %rax      # 0x16ff8
movq (%rax), %rcx
leaq 0x61b1(%rip), %rdi      # 0x115b1
pushq $0x1f
popq %rsi
pushq $0x1
popq %rdx
callq 0x32d0
movq 0x38(%rbx), %rdi
callq 0x57e5
jmp 0xb3e1