// File: /workspace/github_c_makefile_star2_O3/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 0x139f
testl %eax, %eax
jne 0x1949
leaq 0x9f4(%rip), %rsi       # 0x2244
movq %rsp, %r15
xorl %ebp, %ebp
movq %r15, %rdi
movq %rsi, %r13
movl %ebp, %edx
xorl %eax, %eax
callq 0x10f0
movl 0x2a6c(%rip), %r12d     # 0x42d7
cmpl $0x2f595343, %r12d      # imm = 0x2F595343
jne 0x18c1
cmpb $0x20, 0x2a55(%rip)     # 0x42d0
je 0x18c1
leaq 0x2a4c(%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 0x18c1
movb $0x0, (%rax)
movq %r15, %rdi
leaq 0x99b(%rip), %rsi       # 0x224e
leaq 0x2a16(%rip), %rdx      # 0x42d0
xorl %eax, %eax
callq 0x10f0
movq %r15, %rdi
leaq 0x8b8(%rip), %rsi       # 0x2183
callq 0x10d0
testq %rax, %rax
je 0x1984
movq %rax, %r14
cmpl $0x2f595343, %r12d      # imm = 0x2F595343
je 0x18f6
movq %r14, %rdi
callq 0x1475
cmpl $-0x1, %eax
je 0x19a6
movq %rbx, %rdi
callq 0x139f
testl %eax, %eax
jne 0x191d
cmpl $0x2f444e45, 0x29cb(%rip) # imm = 0x2F444E45
je 0x1922
movq %r14, %rdi
callq 0x1475
cmpl $-0x1, %eax
jne 0x18f6
jmp 0x195a
cmpl $-0x2, %eax
jne 0x1941
movq %r14, %rdi
callq 0x1060
incl %ebp
movq %rbx, %rdi
callq 0x139f
testl %eax, %eax
movq %r13, %rsi
je 0x1855
jmp 0x1949
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 0x2697(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x923(%rip), %rsi       # 0x228e
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
movq %r14, %rdi
callq 0x1060
movl $0x3, %eax
jmp 0x194b
movq 0x266d(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x8c1(%rip), %rsi       # 0x2256
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
movl $0x2, %eax
jmp 0x194b
movq 0x264b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x8bb(%rip), %rsi       # 0x2272
jmp 0x196b