// File: /workspace/github_c_makefile_star2_O1/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 0x69cf
movq %rax, %r14
movq 0x38(%rbx), %rdi
callq 0x3200
leaq 0x38(%rsp), %r15
movl %eax, %edi
movq %r15, %rsi
callq 0x32e0
movl $0x1, %ebp
cmpq 0x30(%r15), %r14
je 0xc8e4
leaq 0x48(%rbx), %rsi
leaq 0x38(%rbx), %r15
movq (%r15), %rdi
movl $0x200, %edx            # imm = 0x200
callq 0x6b76
movl $0x1, %ebp
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0xc8b8
cmpl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0xc89f
cmpl $0xe, %eax
jne 0xc8a8
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rsp, %rsi
movq %rax, 0x6(%rsi)
movq %rax, (%rsi)
movb $0x0, 0xd(%rsi)
movzwl 0x48(%rbx), %edi
callq 0x65fc
movzwl 0x4a(%rbx), %edi
leaq 0x3(%rsp), %rsi
callq 0x65fc
testb $0x1, 0x31(%rbx)
je 0xc88b
movzwl 0x54(%rbx), %edi
leaq 0x6(%rsp), %rsi
callq 0x65fc
leaq 0xa(%rsp), %rsi
movb $0x2e, -0x1(%rsi)
movzwl 0x4c(%rbx), %edi
callq 0x65fc
jmp 0xc8b6
xorl %ebp, %ebp
movl $0x3, %eax
jmp 0xc8cd
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, (%rsp)
xorl %ebp, %ebp
movq (%r15), %rdi
movq %r14, %rsi
callq 0x69d4
xorl %ecx, %ecx
testl %eax, %eax
setne %cl
leal (%rcx,%rcx,2), %eax
testl %eax, %eax
je 0xc8e4
cmpl $0x3, %eax
jne 0xc963
movq %r15, %rdi
callq 0x4339
jmp 0xc963
testq %r14, %r14
sete %al
movl %ebp, %ecx
orb %al, %cl
jne 0xc906
leaq 0x5c61(%rip), %rsi      # 0x12558
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32a0
leaq 0x8(%rbx), %rsi
leaq 0x5c53(%rip), %rdi      # 0x12564
xorl %eax, %eax
callq 0x3160
testl %ebp, %ebp
leaq 0x5c6a(%rip), %rax      # 0x1258b
leaq 0x10(%rsp), %rcx
cmovneq %rax, %rcx
testq %r14, %r14
leaq 0x5c45(%rip), %rsi      # 0x12579
cmovneq %rcx, %rsi
leaq 0x5c2a(%rip), %rdi      # 0x12569
xorl %eax, %eax
callq 0x3160
testl %ebp, %ebp
jne 0xc963
movzbl 0x4f(%rbx), %edx
movzbl 0x4e(%rbx), %ecx
leaq 0x5c3e(%rip), %rdi      # 0x12597
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3160
addq $0xc8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq