// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/fsio/dosmt.c
// Function: dosmtMount
static int dosmtMount(
  struct mountedFS *mount
)
{
  struct DOSMTdata *data = &mount->dosmtdata;

  if (tapeVerify(mount->container, &data->eot)) {
    unsigned char buf[DOSMTRCLNT];
    uint32_t status;

    /*
     * Scan each file making sure it is preceeded by a dos11 header (either
     * version is valid).
     */
    do {
      /*
       * If we are at end-of-tape, everything is OK
       */
      if (tapeGetPosition(mount->container) == data->eot)
        break;

      switch (status = tapeReadRecord(mount->container, buf, sizeof(buf))) {
        case ST_FAIL:
          return 0;

        case ST_EOM:
          break;

        case ST_TM:
          /* Second tape mark in a row - treat as end of media */
          status = ST_EOM;
          break;

        default:
          /*
           * If the header has an error, unable to use this tape.
           */
          if ((status & ST_ERROR) != 0)
            return 0;

          status &= ST_LENGTH;

          if (status != sizeof(struct dosmthdr))
            return 0;

          /*
           * Scan forward to the end of this file.
           */
          do {
            switch (status = tapeReadRecordLength(mount->container)) {
              case ST_FAIL:
                return 0;

              case ST_EOM:
              case ST_TM:
                break;

              default:
                if ((status & ST_ERROR) == 0)
                  if ((status & ST_LENGTH) != DOSMTRCLNT)
                    return 0;
            }
          } while ((status != ST_EOM) && (status != ST_TM));
      }
    } while (status != ST_EOM);

    data->proj = 01;
    data->prog = 01;
    data->prot = 0233;

    if (SWISSET('x'))
      mount->flags |= FS_DOSMTEXT;

    /*
     * Position the tape at the beginning
     */
    tapeRewind(mount->container);

    return 1;
  } else fprintf(stderr, "mount: Invalid tape format\n");
  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq -0x18(%rbp), %rsi
addq $0x200, %rsi            # imm = 0x200
callq 0x5fc0
cmpl $0x0, %eax
je 0x10f0e
jmp 0x10d2e
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6210
movq -0x18(%rbp), %rcx
cmpq 0x200(%rcx), %rax
jne 0x10d4d
jmp 0x10eb2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
leaq -0x220(%rbp), %rsi
movl $0x200, %edx            # imm = 0x200
callq 0x64d0
movl %eax, -0x224(%rbp)
movl %eax, %ecx
movl %ecx, -0x228(%rbp)
subl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0x10d96
jmp 0x10d7d
movl -0x228(%rbp), %eax
subl $-0x1, %eax
je 0x10da2
jmp 0x10d8a
movl -0x228(%rbp), %eax
testl %eax, %eax
je 0x10da7
jmp 0x10db6
movl $0x0, -0x4(%rbp)
jmp 0x10f2d
jmp 0x10ea3
movl $0xffffffff, -0x224(%rbp) # imm = 0xFFFFFFFF
jmp 0x10ea3
movl -0x224(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x10dd2
movl $0x0, -0x4(%rbp)
jmp 0x10f2d
movl -0x224(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x224(%rbp)
movl -0x224(%rbp), %eax
cmpq $0xe, %rax
je 0x10dfb
movl $0x0, -0x4(%rbp)
jmp 0x10f2d
jmp 0x10dfd
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x6290
movl %eax, -0x224(%rbp)
movl %eax, %ecx
movl %ecx, -0x22c(%rbp)
subl $0xfefefefe, %eax       # imm = 0xFEFEFEFE
je 0x10e30
jmp 0x10e21
movl -0x22c(%rbp), %eax
incl %eax
subl $0x2, %eax
jb 0x10e3c
jmp 0x10e3e
movl $0x0, -0x4(%rbp)
jmp 0x10f2d
jmp 0x10e70
movl -0x224(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x10e6e
movl -0x224(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
cmpl $0x200, %eax            # imm = 0x200
je 0x10e6c
movl $0x0, -0x4(%rbp)
jmp 0x10f2d
jmp 0x10e6e
jmp 0x10e70
jmp 0x10e72
xorl %eax, %eax
cmpl $-0x1, -0x224(%rbp)
movb %al, -0x22d(%rbp)
je 0x10e93
cmpl $0x0, -0x224(%rbp)
setne %al
movb %al, -0x22d(%rbp)
movb -0x22d(%rbp), %al
testb $0x1, %al
jne 0x10dfd
jmp 0x10ea3
jmp 0x10ea5
cmpl $-0x1, -0x224(%rbp)
jne 0x10d2e
movq -0x18(%rbp), %rax
movb $0x1, 0x208(%rax)
movq -0x18(%rbp), %rax
movb $0x1, 0x209(%rax)
movq -0x18(%rbp), %rax
movb $-0x65, 0x20a(%rax)
leaq 0xe31e(%rip), %rax      # 0x1f1f8
movl (%rax), %eax
andl $0x800000, %eax         # imm = 0x800000
cmpl $0x0, %eax
je 0x10ef8
movq -0x10(%rbp), %rax
movzwl 0x30(%rax), %ecx
orl $0x100, %ecx            # imm = 0x100
movw %cx, 0x30(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
callq 0x68d0
movl $0x1, -0x4(%rbp)
jmp 0x10f2d
movq 0xd0e3(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0x95b2(%rip), %rsi      # 0x1a4d1
movb $0x0, %al
callq 0x31c0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
nopl (%rax)