// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/extracters/dbtap/dos11.c
// Function: extractFiles
void extractFiles(
  char *ascii,
  int ppn
)
{
  unsigned int status;

  do {
    switch (status = ReadTapeRecord(record, sizeof(record))) {
      case ST_EOM:
        break;

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

      default:
        if ((status & ST_ERROR) == 0) {
          status &= ST_LENGTH;

          if ((status == sizeof(struct dos11hdr1)) ||
              (status == sizeof(struct dos11hdr2))) {
            char filename[32];
            struct dos11hdr2 *hdr = (struct dos11hdr2 *)record;
            int offset = 0, extension;
            char *useAscii;
            uint32 errorCount = 0, length, i;

            /*
             * Construct the output filename
             */
            offset += r50AscNoSpace(hdr->fname[0], &filename[offset]);
            offset += r50AscNoSpace(hdr->fname[1], &filename[offset]);
            if (status == sizeof(struct dos11hdr2))
              offset += r50AscNoSpace(hdr->fname3, &filename[offset]);
            if (ppn) {
              sprintf(&filename[offset], "_%o_%o", hdr->prog, hdr->proj);
              offset = strlen(filename);
            }
            extension = offset;
            filename[offset++] = '.';
            offset += r50AscNoSpace(hdr->ext, &filename[offset]);
            filename[offset++] = '\0';

            useAscii = strstr(ascii, &filename[extension]);

            printf("   Extracting: %s ", filename);

            initAscii();

            if ((file = fopen(filename, "w")) != NULL) {
              do {
                switch (status = ReadTapeRecord(record, sizeof(record))) {
                  case ST_EOM:
                  case ST_TM:
                    break;

                  default:
                    if ((status & ST_ERROR) != 0)
                      errorCount++;
                    length = status & ST_LENGTH;

                    if (useAscii != NULL) {
                      /*
                       * Process each character separately in order to map
                       * CRLF -> LF.
                       */
                      for (i = 0; i < length; i++)
                        xferAscii(record[i]);
                    } else {
                      if (fwrite(record, sizeof(char), length, file) != length)
                        errorCount++;
                    }
                }
              } while ((status != ST_EOM) && (status != ST_TM));
              flushAscii();
              printf("%s \n", errorCount ? "Errors detected" : "Done");
              fclose(file);
              break;
            } else printf("*** File open failure\n");
          } else fprintf(stderr, "   *** Unexpected record size\n");
        } else fprintf(stderr, "   *** Directory entry contains error\n");

        /*
         * Scan forward to the end of this file
         */
        do {
          status = ReadTapeRecordLength();
        } while ((status != ST_EOM) && (status != ST_TM));
    }
  } while (status != ST_EOM);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %esi, 0xc(%rsp)
movq %rdi, 0x30(%rsp)
leaq 0x12d0a(%rip), %r15     # 0x15240
leaq 0x10(%rsp), %r12
movq %r15, %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x1e89
movl %eax, %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
leal 0x1(%r13), %ecx
cmpl $0x2, %ecx
jb 0x27e0
testl %r13d, %r13d
js 0x27eb
andl $0xffffff, %r13d        # imm = 0xFFFFFF
movl %r13d, %eax
orl $0x2, %eax
cmpl $0xe, %eax
jne 0x27f2
movzwl 0x12cbd(%rip), %edi     # 0x15240
movq %r12, %rsi
callq 0x2808
movzwl 0x12cb0(%rip), %edi     # 0x15242
movslq %eax, %rbx
leaq (%rsp,%rbx), %rsi
addq $0x10, %rsi
callq 0x2808
addl %eax, %ebx
cmpl $0xe, %r13d
jne 0x25c3
movzwl 0x12c9b(%rip), %edi     # 0x1524c
movslq %ebx, %rbx
leaq (%rsp,%rbx), %rsi
addq $0x10, %rsi
callq 0x2808
addl %eax, %ebx
cmpl $0x0, 0xc(%rsp)
je 0x25fc
movslq %ebx, %rax
leaq (%rsp,%rax), %rdi
addq $0x10, %rdi
movzbl 0x12c6b(%rip), %edx     # 0x15247
movzbl 0x12c63(%rip), %ecx     # 0x15246
leaq 0xef6(%rip), %rsi       # 0x34e0
xorl %eax, %eax
callq 0x11c0
movq %r12, %rdi
callq 0x10c0
movq %rax, %rbx
movslq %ebx, %r14
leaq (%rsp,%r14), %rbx
addq $0x10, %rbx
movb $0x2e, (%rbx)
movzwl 0x12c33(%rip), %edi     # 0x15244
leaq (%rsp,%r14), %rsi
addq $0x11, %rsi
callq 0x2808
addl %r14d, %eax
incl %eax
cltq
movb $0x0, 0x10(%rsp,%rax)
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x1200
movq %rax, %rbx
leaq 0xea6(%rip), %rdi       # 0x34e7
movq %r12, %rsi
xorl %eax, %eax
callq 0x10e0
movl $0x0, 0x12be3(%rip)     # 0x15238
movq %r12, %rdi
leaq 0xe9b(%rip), %rsi       # 0x34fa
callq 0x1190
movq %rax, 0x12bc5(%rip)     # 0x15230
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x27bc
xorl %r12d, %r12d
movq %rbx, 0x40(%rsp)
movq %r15, %rdi
movl $0x10000, %esi          # imm = 0x10000
callq 0x1e89
movl %eax, %r13d
leal 0x1(%r13), %eax
cmpl $0x2, %eax
jae 0x26a8
leal -0x1(%r13), %eax
cmpl $-0x2, %eax
jb 0x2681
jmp 0x276c
movl %r13d, %eax
shrl $0x1f, %eax
addl %eax, %r12d
movl %r13d, %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
testq %rbx, %rbx
je 0x2742
testl %eax, %eax
je 0x269a
movl %eax, %ebp
xorl %ebx, %ebx
movsbl (%rbx,%r15), %r14d
movl 0x12b63(%rip), %eax     # 0x15238
cmpl $0xd, %r14d
jne 0x26fc
testl %eax, %eax
je 0x26f0
movq 0x12b4a(%rip), %rsi     # 0x15230
movl $0xd, %edi
callq 0x1110
movl $0x1, 0x12b3e(%rip)     # 0x15238
jmp 0x2730
testl %eax, %eax
je 0x2721
movl $0x0, 0x12b2e(%rip)     # 0x15238
cmpb $0xa, %r14b
je 0x2721
movq 0x12b19(%rip), %rsi     # 0x15230
movl $0xd, %edi
callq 0x1110
movq 0x12b08(%rip), %rsi     # 0x15230
movl %r14d, %edi
callq 0x1110
incq %rbx
cmpq %rbx, %rbp
jne 0x26ca
movq 0x40(%rsp), %rbx
jmp 0x269a
movl %eax, %r14d
movq 0x12ae4(%rip), %rcx     # 0x15230
movl $0x1, %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x11e0
xorl %ecx, %ecx
cmpq %r14, %rax
setne %cl
addl %ecx, %r12d
jmp 0x269a
cmpl $0x0, 0x12ac5(%rip)     # 0x15238
je 0x2786
movq 0x12ab4(%rip), %rsi     # 0x15230
movl $0xd, %edi
callq 0x1110
testl %r12d, %r12d
leaq 0xd71(%rip), %rsi       # 0x3501
leaq 0xd7a(%rip), %rax       # 0x3511
cmoveq %rax, %rsi
leaq 0xd5a(%rip), %rdi       # 0x34fc
xorl %eax, %eax
callq 0x10e0
movq 0x12a80(%rip), %rdi     # 0x15230
callq 0x10b0
leaq 0x10(%rsp), %r12
jmp 0x27c8
leaq 0xdd8(%rip), %rdi       # 0x359b
callq 0x1080
movl %r13d, %eax
cmpq $0x0, 0x38(%rsp)
jne 0x27e0
callq 0x1f6a
leal -0x1(%rax), %ecx
cmpl $-0x2, %ecx
jb 0x27d3
cmpl $-0x1, %eax
jne 0x253b
jmp 0x27f9
callq 0x1418
jmp 0x27d3
callq 0x143a
jmp 0x27d3
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq