// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
leaq 0x1392a(%rip), %rdi     # 0x16240
movl $0x10000, %esi          # imm = 0x10000
callq 0x1f70
movl %eax, -0x10(%rbp)
movl %eax, %ecx
movl %ecx, -0x58(%rbp)
subl $-0x1, %eax
je 0x2938
jmp 0x292f
movl -0x58(%rbp), %eax
testl %eax, %eax
je 0x293d
jmp 0x2949
jmp 0x2c49
movl $0xffffffff, -0x10(%rbp) # imm = 0xFFFFFFFF
jmp 0x2c49
movl -0x10(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
jne 0x2c09
movl -0x10(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
cmpq $0xc, %rax
je 0x297b
movl -0x10(%rbp), %eax
cmpq $0xe, %rax
jne 0x2bef
leaq 0x138be(%rip), %rax     # 0x16240
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x4c(%rbp)
movq -0x38(%rbp), %rax
movw (%rax), %ax
movslq -0x3c(%rbp), %rcx
leaq -0x30(%rbp), %rsi
addq %rcx, %rsi
movzwl %ax, %edi
callq 0x2c60
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x38(%rbp), %rax
movw 0x2(%rax), %ax
movslq -0x3c(%rbp), %rcx
leaq -0x30(%rbp), %rsi
addq %rcx, %rsi
movzwl %ax, %edi
callq 0x2c60
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x10(%rbp), %eax
cmpq $0xe, %rax
jne 0x29ff
movq -0x38(%rbp), %rax
movw 0xc(%rax), %ax
movslq -0x3c(%rbp), %rcx
leaq -0x30(%rbp), %rsi
addq %rcx, %rsi
movzwl %ax, %edi
callq 0x2c60
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x2a3a
movslq -0x3c(%rbp), %rax
leaq -0x30(%rbp), %rdi
addq %rax, %rdi
movq -0x38(%rbp), %rax
movzbl 0x7(%rax), %edx
movq -0x38(%rbp), %rax
movzbl 0x6(%rax), %ecx
leaq 0x1b72(%rip), %rsi      # 0x4599
movb $0x0, %al
callq 0x11b0
leaq -0x30(%rbp), %rdi
callq 0x10b0
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
cltq
movb $0x2e, -0x30(%rbp,%rax)
movq -0x38(%rbp), %rax
movw 0x4(%rax), %ax
movslq -0x3c(%rbp), %rcx
leaq -0x30(%rbp), %rsi
addq %rcx, %rsi
movzwl %ax, %edi
callq 0x2c60
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, -0x3c(%rbp)
cltq
movb $0x0, -0x30(%rbp,%rax)
movq -0x8(%rbp), %rdi
movslq -0x40(%rbp), %rax
leaq -0x30(%rbp), %rsi
addq %rax, %rsi
callq 0x11f0
movq %rax, -0x48(%rbp)
leaq -0x30(%rbp), %rsi
leaq 0x1af8(%rip), %rdi      # 0x45a0
movb $0x0, %al
callq 0x10d0
callq 0x2d50
leaq -0x30(%rbp), %rdi
leaq 0x1af4(%rip), %rsi      # 0x45b3
callq 0x1180
movq %rax, 0x13765(%rip)     # 0x16230
cmpq $0x0, %rax
je 0x2bdf
jmp 0x2ad7
leaq 0x13762(%rip), %rdi     # 0x16240
movl $0x10000, %esi          # imm = 0x10000
callq 0x1f70
movl %eax, -0x10(%rbp)
incl %eax
subl $0x1, %eax
ja 0x2af9
jmp 0x2af4
jmp 0x2b84
movl -0x10(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x2b0f
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x10(%rbp), %eax
andl $0xffffff, %eax         # imm = 0xFFFFFF
movl %eax, -0x50(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x2b52
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x50(%rbp), %eax
jae 0x2b50
movl -0x54(%rbp), %eax
movl %eax, %ecx
leaq 0x13704(%rip), %rax     # 0x16240
movsbl (%rax,%rcx), %edi
callq 0x2d60
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x2b28
jmp 0x2b82
movl -0x50(%rbp), %eax
movl %eax, %edx
movq 0x136d2(%rip), %rcx     # 0x16230
leaq 0x136db(%rip), %rdi     # 0x16240
movl $0x1, %esi
callq 0x11d0
movl -0x50(%rbp), %ecx
cmpq %rcx, %rax
je 0x2b80
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x2b82
jmp 0x2b84
jmp 0x2b86
xorl %eax, %eax
cmpl $-0x1, -0x10(%rbp)
movb %al, -0x59(%rbp)
je 0x2b9b
cmpl $0x0, -0x10(%rbp)
setne %al
movb %al, -0x59(%rbp)
movb -0x59(%rbp), %al
testb $0x1, %al
jne 0x2ad7
callq 0x2e50
movl -0x4c(%rbp), %ecx
leaq 0x1a15(%rip), %rsi      # 0x45ca
leaq 0x19fe(%rip), %rax      # 0x45ba
cmpl $0x0, %ecx
cmovneq %rax, %rsi
leaq 0x19eb(%rip), %rdi      # 0x45b5
movb $0x0, %al
callq 0x10d0
movq 0x13658(%rip), %rdi     # 0x16230
callq 0x10a0
jmp 0x2c49
leaq 0x19e9(%rip), %rdi      # 0x45cf
movb $0x0, %al
callq 0x10d0
jmp 0x2c07
movq 0x3402(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x19e6(%rip), %rsi      # 0x45e6
movb $0x0, %al
callq 0x1110
jmp 0x2c21
movq 0x33e8(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x19eb(%rip), %rsi      # 0x4605
movb $0x0, %al
callq 0x1110
jmp 0x2c23
callq 0x2080
movl %eax, -0x10(%rbp)
xorl %eax, %eax
cmpl $-0x1, -0x10(%rbp)
movb %al, -0x5a(%rbp)
je 0x2c40
cmpl $0x0, -0x10(%rbp)
setne %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
testb $0x1, %al
jne 0x2c23
jmp 0x2c49
jmp 0x2c4b
cmpl $-0x1, -0x10(%rbp)
jne 0x290f
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)