// File: /workspace/github_c_makefile_star2_O2/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, %r14
leaq 0xbe0(%rip), %rbx       # 0x23c8
movq %rsp, %r13
xorl %r15d, %r15d
movq %r14, %rdi
callq 0x134d
testl %eax, %eax
jne 0x18f8
movq %r13, %rdi
movq %rbx, %rsi
movl %r15d, %edx
xorl %eax, %eax
callq 0x10f0
xorl %ebp, %ebp
cmpl $0x2f595343, 0x2abd(%rip) # imm = 0x2F595343
setne %bl
jne 0x186a
cmpb $0x20, 0x2aaa(%rip)     # 0x42d0
je 0x186a
leaq 0x2aa1(%rip), %r12      # 0x42d0
movq %r12, %rdi
pushq $0x20
popq %rsi
callq 0x1080
testq %rax, %rax
sete %cl
movl %eax, %edx
subl %r12d, %edx
cmpl $0x7, %edx
setge %dl
orb %cl, %dl
jne 0x186a
movb $0x0, (%rax)
movq %r13, %rdi
leaq 0xb76(%rip), %rsi       # 0x23d2
leaq 0x2a6d(%rip), %rdx      # 0x42d0
xorl %eax, %eax
callq 0x10f0
movq %r13, %r12
movq %r13, %rdi
leaq 0xa90(%rip), %rsi       # 0x2307
callq 0x10d0
testq %rax, %rax
je 0x1931
movq %rax, %r13
movb %bl, %bpl
testl %ebp, %ebp
je 0x18a0
movq %r13, %rdi
callq 0x1417
cmpl $-0x1, %eax
je 0x1950
testq %r13, %r13
je 0x18de
movq %r14, %rdi
callq 0x134d
testl %eax, %eax
jne 0x18cc
cmpl $0x2f444e45, 0x2a1c(%rip) # imm = 0x2F444E45
je 0x18d1
movq %r13, %rdi
callq 0x1417
cmpl $-0x1, %eax
jne 0x18a0
jmp 0x1909
cmpl $-0x2, %eax
jne 0x18f0
movq %r13, %rdi
callq 0x1060
xorl %r13d, %r13d
jmp 0x18a0
incl %r15d
leaq 0xae0(%rip), %rbx       # 0x23c8
movq %r12, %r13
jmp 0x17ee
movq %r13, %rdi
callq 0x1060
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x26e8(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xaf8(%rip), %rsi       # 0x2412
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
movq %r13, %rdi
callq 0x1060
pushq $0x3
popq %rax
jmp 0x18fa
movq 0x26c0(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xa98(%rip), %rsi       # 0x23da
movq %rsp, %rdx
xorl %eax, %eax
callq 0x10c0
pushq $0x2
jmp 0x192e
movq 0x26a1(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0xa95(%rip), %rsi       # 0x23f6
jmp 0x191a