// File: /workspace/github_c_makefile_star2_O3/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 0x6968
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 0xc526
addq $0x8, %rbx
leaq 0x6070(%rip), %rdi      # 0x12564
movq %rbx, %rsi
xorl %eax, %eax
callq 0x3160
testq %r14, %r14
leaq 0x6083(%rip), %rax      # 0x1258b
leaq 0x606a(%rip), %rsi      # 0x12579
cmovneq %rax, %rsi
leaq 0x604f(%rip), %rdi      # 0x12569
xorl %eax, %eax
callq 0x3160
jmp 0xc660
leaq 0x48(%rbx), %rsi
leaq 0x38(%rbx), %r15
movq (%r15), %rdi
movl $0x200, %edx            # imm = 0x200
callq 0x6b0f
leal 0x1(%rax), %ecx
cmpl $0x2, %ecx
jb 0xc563
cmpl $0xe, %eax
je 0xc567
cmpl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0xc66e
movabsq $0x6e776f6e6b6e55, %rax # imm = 0x6E776F6E6B6E55
movq %rax, (%rsp)
jmp 0xc5bc
xorl %ebp, %ebp
jmp 0xc5bf
movabsq $0x2020202020202020, %rax # imm = 0x2020202020202020
movq %rsp, %rsi
movq %rax, 0x5(%rsi)
movq %rax, (%rsi)
movb $0x0, 0xd(%rsi)
movzwl 0x48(%rbx), %edi
callq 0x658c
movzwl 0x4a(%rbx), %edi
leaq 0x3(%rsp), %rsi
callq 0x658c
testb $0x1, 0x31(%rbx)
je 0xc5aa
movzwl 0x54(%rbx), %edi
leaq 0x6(%rsp), %rsi
callq 0x658c
leaq 0xa(%rsp), %rsi
movb $0x2e, -0x1(%rsi)
movzwl 0x4c(%rbx), %edi
callq 0x658c
movb $0x1, %bpl
movq (%r15), %rdi
movq %r14, %rsi
callq 0x696d
testl %eax, %eax
jne 0xc66e
testq %r14, %r14
sete %al
movl %ebp, %ecx
xorb $0x1, %cl
orb %al, %cl
jne 0xc60b
leaq 0x5f70(%rip), %rsi      # 0x12558
leaq 0x10(%rsp), %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x32b0
leaq 0x8(%rbx), %rsi
leaq 0x5f62(%rip), %rdi      # 0x12564
xorl %eax, %eax
callq 0x3160
jmp 0xc626
leaq 0x8(%rbx), %rsi
leaq 0x5f4e(%rip), %rdi      # 0x12564
xorl %eax, %eax
callq 0x3160
testb %bpl, %bpl
je 0xc4fe
testq %r14, %r14
leaq 0x5f49(%rip), %rax      # 0x12579
leaq 0x10(%rsp), %rsi
cmoveq %rax, %rsi
leaq 0x5f29(%rip), %rdi      # 0x12569
xorl %eax, %eax
callq 0x3160
movzbl 0x4f(%rbx), %edx
movzbl 0x4e(%rbx), %ecx
leaq 0x5f41(%rip), %rdi      # 0x12597
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3160
addq $0xc8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x43b8
jmp 0xc660