// File: /workspace/github_c_makefile_star2_O1/simh[P]simtools/converters/cosy/cosy.c
// Function: doDecompress
int doDecompress(
  FILE *src
)
{
  int seqno = 0, valid;
  char filename[32], *eofn;
  FILE *dest = NULL;

  while (decompressCard(src) == 0) {
    /*
     * First card of next deck has been read - is is a CSY/ card?
     */
    sprintf(filename, "%05u.deck", seqno);
    valid = 1;
    if (strncmp("CSY/", &card[7], 4) == 0) {
      if (card[0] != ' ') {
        if ((eofn = strchr(card, ' ')) != NULL) {
          int len = eofn - card;

          if (len <= 6) {
            *eofn = '\0';
            sprintf(filename, "deck_%s", card);
          }
        }
      }
      valid = 0;
    }

    if ((dest = fopen(filename, "w")) == 0) {
      fprintf(stderr, "Failed to create file - %s\n", filename);
      return 2;
    }

    /*
     * If the first line was not a CSY/ card, write to the destination file
     */
    if (valid) {
      if (writeCard(dest) == -1) {
        fprintf(stderr, "Error writing to file - %s\n", filename);
        fclose(dest);
        return 3;
      }
    }

    /*
     * Now process the rest of this file.
     */
    while (dest != NULL) {
      switch (decompressCard(src)) {
        case 0:
          if (strncmp("END/", &card[7], 4) == 0) {
            fclose(dest);
            dest = NULL;
            break;
          }
          if (writeCard(dest) == -1) {
            fprintf(stderr, "Error writing to file%s\n", filename);
            fclose(dest);
            return 3;
          }
          break;

        case -1:
          fclose(dest);
          return 0;

        case -2:
          fclose(dest);
          dest = NULL;
          break;
      }
    }
    seqno++;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x13bb
testl %eax, %eax
jne 0x198d
leaq 0x9b8(%rip), %rsi       # 0x2244
movq %rsp, %r15
xorl %ebp, %ebp
movq %r15, %rdi
movq %rsi, %r13
movl %ebp, %edx
xorl %eax, %eax
callq 0x10f0
movl 0x2a30(%rip), %r12d     # 0x42d7
cmpl $0x2f595343, %r12d      # imm = 0x2F595343
jne 0x18fd
cmpb $0x20, 0x2a19(%rip)     # 0x42d0
je 0x18fd
leaq 0x2a10(%rip), %r14      # 0x42d0
movq %r14, %rdi
movl $0x20, %esi
callq 0x1080
testq %rax, %rax
sete %cl
movl %eax, %edx
subl %r14d, %edx
cmpl $0x7, %edx
setge %dl
orb %cl, %dl
jne 0x18fd
movb $0x0, (%rax)
movq %r15, %rdi
leaq 0x95f(%rip), %rsi       # 0x224e
leaq 0x29da(%rip), %rdx      # 0x42d0
xorl %eax, %eax
callq 0x10f0
movq %r15, %rdi
leaq 0x87c(%rip), %rsi       # 0x2183
callq 0x10d0
testq %rax, %rax
je 0x19c8
movq %rax, %r14
cmpl $0x2f595343, %r12d      # imm = 0x2F595343
je 0x1932
movq %r14, %rdi
callq 0x148b
cmpl $-0x1, %eax
je 0x19ea
movq %rbx, %rdi
callq 0x13bb
cmpl $-0x2, %eax
je 0x195e
testl %eax, %eax
jne 0x1985
cmpl $0x2f444e45, 0x298a(%rip) # imm = 0x2F444E45
je 0x195e
movq %r14, %rdi
callq 0x148b
cmpl $-0x1, %eax
jne 0x1969
jmp 0x199e
movq %r14, %rdi
callq 0x1060
xorl %r14d, %r14d
testq %r14, %r14
jne 0x1932
incl %ebp
movq %rbx, %rdi
callq 0x13bb
testl %eax, %eax
movq %r13, %rsi
je 0x1891
jmp 0x198d
movq %r14, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2653(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x8df(%rip), %rsi       # 0x228e
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
movq %r14, %rdi
callq 0x1060
movl $0x3, %eax
jmp 0x198f
movq 0x2629(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x87d(%rip), %rsi       # 0x2256
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
movl $0x2, %eax
jmp 0x198f
movq 0x2607(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x877(%rip), %rsi       # 0x2272
jmp 0x19af