// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x120, %rsp            # imm = 0x120
movb %dl, %al
movb %sil, %cl
movq %rdi, -0x8(%rbp)
movb %cl, -0x9(%rbp)
movb %al, -0xa(%rbp)
movq -0x8(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6210
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
cmpq $0x0, -0x20(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x31f0
movl %eax, %edi
leaq -0xf8(%rbp), %rsi
callq 0x32d0
movq -0x20(%rbp), %rax
cmpq -0xc8(%rbp), %rax
je 0x112f0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x18(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x64d0
movl %eax, -0xfc(%rbp)
movl %eax, %ecx
movl %ecx, -0x10c(%rbp)
subl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0x111ee
jmp 0x111df
movl -0x10c(%rbp), %eax
incl %eax
subl $0x2, %eax
jb 0x111f3
jmp 0x111ff
jmp 0x113c1
movl $0x1, -0x24(%rbp)
jmp 0x112d3
movl -0xfc(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x112c3
movl -0xfc(%rbp), %eax
cmpq $0xe, %rax
jne 0x112c1
leaq -0x5e(%rbp), %rdi
movl $0x20, %esi
movl $0xe, %edx
callq 0x3170
movb $0x0, -0x51(%rbp)
movq -0x68(%rbp), %rax
movzwl (%rax), %edi
callq 0x10b80
leaq -0x5e(%rbp), %rsi
movzwl %ax, %edi
callq 0x5bf0
movq -0x68(%rbp), %rax
movzwl 0x2(%rax), %edi
callq 0x10b80
leaq -0x5e(%rbp), %rsi
addq $0x3, %rsi
movzwl %ax, %edi
callq 0x5bf0
movq -0x8(%rbp), %rax
movzwl 0x30(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x1129e
movq -0x68(%rbp), %rax
movzwl 0xc(%rax), %edi
callq 0x10b80
leaq -0x5e(%rbp), %rsi
addq $0x6, %rsi
movzwl %ax, %edi
callq 0x5bf0
movb $0x2e, -0x55(%rbp)
movq -0x68(%rbp), %rax
movzwl 0x4(%rax), %edi
callq 0x10b80
leaq -0x5e(%rbp), %rsi
addq $0xa, %rsi
movzwl %ax, %edi
callq 0x5bf0
jmp 0x112d3
jmp 0x112c3
leaq -0x5e(%rbp), %rdi
leaq 0x92da(%rip), %rsi      # 0x1a5a8
callq 0x30b0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x20(%rbp), %rsi
callq 0x6230
cmpl $0x0, %eax
je 0x112ee
jmp 0x113c1
jmp 0x112f7
movl $0x1, -0x24(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x11327
cmpl $0x0, -0x24(%rbp)
jne 0x11327
movq -0x20(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x108(%rbp), %rdx
leaq 0x9290(%rip), %rsi      # 0x1a5b0
movb $0x0, %al
callq 0x3290
movq -0x8(%rbp), %rsi
addq $0x8, %rsi
leaq 0x9286(%rip), %rdi      # 0x1a5bc
movb $0x0, %al
callq 0x3160
cmpl $0x0, -0x28(%rbp)
je 0x11353
leaq 0x9287(%rip), %rax      # 0x1a5d1
movq %rax, -0x118(%rbp)
jmp 0x11382
cmpl $0x0, -0x24(%rbp)
je 0x11369
leaq 0x9283(%rip), %rax      # 0x1a5e3
movq %rax, -0x120(%rbp)
jmp 0x11374
leaq -0x50(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rsi
leaq 0x9231(%rip), %rdi      # 0x1a5c1
movb $0x0, %al
callq 0x3160
cmpl $0x0, -0x24(%rbp)
jne 0x113bf
leaq -0x5e(%rbp), %rsi
movq -0x68(%rbp), %rax
movzbl 0x7(%rax), %edx
movq -0x68(%rbp), %rax
movzbl 0x6(%rax), %ecx
leaq 0x9237(%rip), %rdi      # 0x1a5ef
movb $0x0, %al
callq 0x3160
jmp 0x113e6
movq 0xcc30(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x9237(%rip), %rsi      # 0x1a609
movb $0x0, %al
callq 0x31c0
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x68d0
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
nop