// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/extracters/dbtap/dbtap.c
// Function: main
int main(
  int argc,
  char *argv[]
)
{
  int ch;
  uint8 myprog, myproj;

  while ((ch = getopt(argc, argv, "lcaer:A:EP:S")) != -1) {
    switch (ch) {
      case 'l':
        list = 1;
        break;

      case 'c':
        create = 1;
        break;

      case 'a':
        append = 1;
        break;

      case 'e':
        extract = 1;
        break;

      case 'r':
        reclen = strtoul(optarg, NULL, 0);
        if (reclen < 512)
          reclen = 512;
        if (reclen > MAXRCLNT)
          reclen = MAXRCLNT;
        break;

      case 'A':
        ascii = optarg;
        break;

      case 'E':
        extra = 1;
        break;

      case 'P':
        if (sscanf(optarg, "%hho,%hho", &myprog, &myproj) != 2)
          usage();

        prog = myprog;
        proj = myproj;
        break;

      case 'S':
        strict = 1;
        break;

      case '?':
      default:
        usage();
    }
  }
  argc -= optind;
  argv += optind;

  /*
   * Only one of -l, -c, -a, -e can be specified.
   */
  if ((list + create + append + extract) != 1)
    usage();

  if (list != 0) {
    /*
     * List directories on one or more container files.
     */
    if (argc == 0)
      usage();

    while (argc >= 1) {
      switch (OpenTapeForRead(argv[0])) {
        case TIO_SUCCESS:
        case TIO_ERROR:
          printf("%s:\n\n", argv[0]);
          listDirectory();
          printf("\n");
          CloseTape();
          break;

        case TIO_CORRUPT:
          fprintf(stderr, "%s is not a SIMH .tap container file\n", argv[0]);
          exit(2);

        case TIO_OPENFAIL:
          fprintf(stderr, "%s open failed\n", argv[0]);
          exit(3);
      }
      argc--, argv++;
    }
  } else if (create != 0) {
    /*
     * Create a new container file and append 0 or more files to the tape.
     */
    if (argc <= 1)
      usage();

    switch (OpenTapeForWrite(argv[0])) {
      case TIO_SUCCESS:
        argc--, argv++;

        while (argc >= 1) {
          switch (appendFile(argv[0], ascii, prog, proj, reclen, strict)) {
            case -1:
              fprintf(stderr, "Failed to append %s to tape\n", argv[0]);
              fprintf(stderr, "Container file is probably corrupt\n");
              exit(6);

            case 1:
              fprintf(stderr, "Failed to open file %s - skipping\n", argv[0]);
              /* FALLTHROUGH */

            case 0:
              break;
          }
          argc--, argv++;
        }
        CloseTape();
        break;

      case TIO_IOERROR:
        fprintf(stderr, "Error writing to container file - %s\n", argv[0]);
        exit(5);

      case TIO_CREATEFAIL:
        fprintf(stderr, "Failed to create container file - %s\n", argv[0]);
        exit(3);
    }
  } else if (append != 0) {
    /*
     * Open an existing container file and append 0 or more files to the tape.
     */
    if (argc <= 1)
      usage();

    switch (OpenTapeForAppend(argv[0])) {
      case TIO_SUCCESS:
      case TIO_ERROR:
        argc--, argv++;

        while (argc >= 1) {
          switch (appendFile(argv[0], ascii, prog, proj, reclen, strict)) {
            case -1:
              fprintf(stderr, "Failed to append %s to tape\n", argv[0]);
              fprintf(stderr, "Container file is probably corrupt\n");
              exit(6);

            case 1:
              fprintf(stderr, "Failed to open file %s - skipping\n", argv[0]);
              /* FALLTHROUGH */

            case 0:
              break;
          }
          argc--, argv++;
        }
        CloseTape();
        break;

      case TIO_CORRUPT:
        fprintf(stderr, "%s is not a SIMH .tap container file\n", argv[0]);
        exit(2);

      case TIO_OPENFAIL:
        fprintf(stderr, "%s open failed\n", argv[0]);
        exit(3);
    }
  } else if (extract != 0) {
    /*
     * Extract files from one or more container files.
     */
    if (argc == 0)
      usage();

    while (argc >= 1) {
      switch (OpenTapeForRead(argv[0])) {
        case TIO_SUCCESS:
        case TIO_ERROR:
          printf("%s:\n\n", argv[0]);
          extractFiles(ascii, extra);
          printf("\n");
          CloseTape();
          break;

        case TIO_CORRUPT:
          fprintf(stderr, "%s is not a SIMH .tap container file\n", argv[0]);
          exit(2);

        case TIO_OPENFAIL:
          fprintf(stderr, "%s open failed\n", argv[0]);
          exit(3);
      }
      argc--, argv++;
    }
  }

  return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x2f7c(%rip), %rdx      # 0x4460
callq 0x1190
movl %eax, -0x14(%rbp)
cmpl $-0x1, %eax
je 0x1618
movl -0x14(%rbp), %eax
addl $-0x3f, %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x33, %eax
ja 0x160e
movq -0x20(%rbp), %rax
leaq 0x2aef(%rip), %rcx      # 0x4004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x1, 0x4ce4(%rip)      # 0x620c
jmp 0x1613
movl $0x1, 0x4cd9(%rip)      # 0x6210
jmp 0x1613
movl $0x1, 0x4cce(%rip)      # 0x6214
jmp 0x1613
movl $0x1, 0x4cc3(%rip)      # 0x6218
jmp 0x1613
movq 0x4a77(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
xorl %edx, %edx
callq 0x11a0
movl %eax, 0x4ba3(%rip)      # 0x6118
cmpl $0x200, 0x4b99(%rip)    # imm = 0x200
jge 0x158b
movl $0x200, 0x4b8d(%rip)    # imm = 0x200
cmpl $0x10000, 0x4b83(%rip)  # imm = 0x10000
jle 0x15a1
movl $0x10000, 0x4b77(%rip)  # imm = 0x10000
jmp 0x1613
movq 0x4a2e(%rip), %rax      # 0x5fd8
movq (%rax), %rax
movq %rax, 0x4b5c(%rip)      # 0x6110
jmp 0x1613
movl $0x1, 0x4c44(%rip)      # 0x6204
jmp 0x1613
movq 0x4a0f(%rip), %rax      # 0x5fd8
movq (%rax), %rdi
leaq 0x2e9a(%rip), %rsi      # 0x446d
leaq -0x15(%rbp), %rdx
leaq -0x16(%rbp), %rcx
movb $0x0, %al
callq 0x1150
cmpl $0x2, %eax
je 0x15ec
callq 0x1300
movb -0x15(%rbp), %al
movb %al, 0x4b27(%rip)       # 0x611c
movb -0x16(%rbp), %al
movb %al, 0x4b1f(%rip)       # 0x611d
jmp 0x1613
movl $0x1, 0x4bfe(%rip)      # 0x6208
jmp 0x1613
jmp 0x160e
callq 0x1300
jmp 0x14d6
movq 0x49b1(%rip), %rax      # 0x5fd0
movl (%rax), %ecx
movl -0x8(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x8(%rbp)
movq 0x49a0(%rip), %rax      # 0x5fd0
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq %ecx, %rcx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x10(%rbp)
movl 0x4bc2(%rip), %eax      # 0x620c
addl 0x4bc0(%rip), %eax      # 0x6210
addl 0x4bbe(%rip), %eax      # 0x6214
addl 0x4bbc(%rip), %eax      # 0x6218
cmpl $0x1, %eax
je 0x1666
callq 0x1300
cmpl $0x0, 0x4b9f(%rip)      # 0x620c
je 0x175c
cmpl $0x0, -0x8(%rbp)
jne 0x167e
callq 0x1300
jmp 0x1680
cmpl $0x1, -0x8(%rbp)
jl 0x1757
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1ba0
movl %eax, %ecx
movl %ecx, -0x24(%rbp)
subl $-0x3, %eax
je 0x1714
jmp 0x16a2
movl -0x24(%rbp), %eax
subl $-0x2, %eax
je 0x16eb
jmp 0x16ac
movl -0x24(%rbp), %eax
incl %eax
subl $0x1, %eax
ja 0x173d
jmp 0x16bc
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x2dad(%rip), %rdi      # 0x4477
movb $0x0, %al
callq 0x10d0
callq 0x2ea0
leaq 0x2b60(%rip), %rdi      # 0x423d
movb $0x0, %al
callq 0x10d0
callq 0x1e20
jmp 0x173d
movq 0x4906(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2d7a(%rip), %rsi      # 0x447d
movb $0x0, %al
callq 0x1110
movl $0x2, %edi
callq 0x11c0
movq 0x48dd(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2d77(%rip), %rsi      # 0x44a3
movb $0x0, %al
callq 0x1110
movl $0x3, %edi
callq 0x11c0
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x1680
jmp 0x1b95
cmpl $0x0, 0x4aad(%rip)      # 0x6210
je 0x18f2
cmpl $0x1, -0x8(%rbp)
jg 0x1774
callq 0x1300
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1e50
movl %eax, %ecx
movl %ecx, -0x28(%rbp)
subl $-0x5, %eax
je 0x189b
jmp 0x1790
movl -0x28(%rbp), %eax
subl $-0x4, %eax
je 0x18c4
jmp 0x179e
movl -0x28(%rbp), %eax
testl %eax, %eax
jne 0x18ed
jmp 0x17ab
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jl 0x1894
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq 0x4938(%rip), %rsi      # 0x6110
movzbl 0x493d(%rip), %edx      # 0x611c
movzbl 0x4937(%rip), %ecx      # 0x611d
movl 0x492b(%rip), %r8d      # 0x6118
movl 0x4a14(%rip), %r9d      # 0x6208
callq 0x2380
movl %eax, %ecx
movl %ecx, -0x2c(%rbp)
subl $-0x1, %eax
je 0x1818
jmp 0x1805
movl -0x2c(%rbp), %eax
testl %eax, %eax
je 0x1878
jmp 0x180e
movl -0x2c(%rbp), %eax
subl $0x1, %eax
je 0x1859
jmp 0x187a
movq 0x47d9(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2c83(%rip), %rsi      # 0x44b3
movb $0x0, %al
callq 0x1110
movq 0x47ba(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x2c88(%rip), %rsi      # 0x44d0
movb $0x0, %al
callq 0x1110
movl $0x6, %edi
callq 0x11c0
movq 0x4798(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2c83(%rip), %rsi      # 0x44f4
movb $0x0, %al
callq 0x1110
jmp 0x187a
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x17c0
callq 0x1e20
jmp 0x18ed
movq 0x4756(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2c64(%rip), %rsi      # 0x4517
movb $0x0, %al
callq 0x1110
movl $0x5, %edi
callq 0x11c0
movq 0x472d(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2c61(%rip), %rsi      # 0x453d
movb $0x0, %al
callq 0x1110
movl $0x3, %edi
callq 0x11c0
jmp 0x1b93
cmpl $0x0, 0x491b(%rip)      # 0x6214
je 0x1a8b
cmpl $0x1, -0x8(%rbp)
jg 0x190a
callq 0x1300
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1f10
movl %eax, %ecx
movl %ecx, -0x30(%rbp)
subl $-0x3, %eax
je 0x1a5d
jmp 0x1926
movl -0x30(%rbp), %eax
subl $-0x2, %eax
je 0x1a34
jmp 0x1934
movl -0x30(%rbp), %eax
incl %eax
subl $0x1, %eax
ja 0x1a86
jmp 0x1944
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
cmpl $0x1, -0x8(%rbp)
jl 0x1a2d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq 0x479f(%rip), %rsi      # 0x6110
movzbl 0x47a4(%rip), %edx      # 0x611c
movzbl 0x479e(%rip), %ecx      # 0x611d
movl 0x4792(%rip), %r8d      # 0x6118
movl 0x487b(%rip), %r9d      # 0x6208
callq 0x2380
movl %eax, %ecx
movl %ecx, -0x34(%rbp)
subl $-0x1, %eax
je 0x19b1
jmp 0x199e
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x1a11
jmp 0x19a7
movl -0x34(%rbp), %eax
subl $0x1, %eax
je 0x19f2
jmp 0x1a13
movq 0x4640(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2aea(%rip), %rsi      # 0x44b3
movb $0x0, %al
callq 0x1110
movq 0x4621(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
leaq 0x2aef(%rip), %rsi      # 0x44d0
movb $0x0, %al
callq 0x1110
movl $0x6, %edi
callq 0x11c0
movq 0x45ff(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2aea(%rip), %rsi      # 0x44f4
movb $0x0, %al
callq 0x1110
jmp 0x1a13
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x1959
callq 0x1e20
jmp 0x1a86
movq 0x45bd(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2a31(%rip), %rsi      # 0x447d
movb $0x0, %al
callq 0x1110
movl $0x2, %edi
callq 0x11c0
movq 0x4594(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2a2e(%rip), %rsi      # 0x44a3
movb $0x0, %al
callq 0x1110
movl $0x3, %edi
callq 0x11c0
jmp 0x1b91
cmpl $0x0, 0x4786(%rip)      # 0x6218
je 0x1b8f
cmpl $0x0, -0x8(%rbp)
jne 0x1aa3
callq 0x1300
jmp 0x1aa5
cmpl $0x1, -0x8(%rbp)
jl 0x1b8d
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x1ba0
movl %eax, %ecx
movl %ecx, -0x38(%rbp)
subl $-0x3, %eax
je 0x1b4a
jmp 0x1acb
movl -0x38(%rbp), %eax
subl $-0x2, %eax
je 0x1b21
jmp 0x1ad5
movl -0x38(%rbp), %eax
incl %eax
subl $0x1, %eax
ja 0x1b73
jmp 0x1ae5
movq -0x10(%rbp), %rax
movq (%rax), %rsi
leaq 0x2984(%rip), %rdi      # 0x4477
movb $0x0, %al
callq 0x10d0
movq 0x460f(%rip), %rdi      # 0x6110
movl 0x46fd(%rip), %esi      # 0x6204
callq 0x2900
leaq 0x272a(%rip), %rdi      # 0x423d
movb $0x0, %al
callq 0x10d0
callq 0x1e20
jmp 0x1b73
movq 0x44d0(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2944(%rip), %rsi      # 0x447d
movb $0x0, %al
callq 0x1110
movl $0x2, %edi
callq 0x11c0
movq 0x44a7(%rip), %rax      # 0x5ff8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rdx
leaq 0x2941(%rip), %rsi      # 0x44a3
movb $0x0, %al
callq 0x1110
movl $0x3, %edi
callq 0x11c0
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x1aa5
jmp 0x1b8f
jmp 0x1b91
jmp 0x1b93
jmp 0x1b95
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)