// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1420
cmpl $0x0, %eax
jne 0x1d65
leaq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
leaq 0x7f9(%rip), %rsi       # 0x2354
movb $0x0, %al
callq 0x10f0
movl $0x1, -0x18(%rbp)
leaq 0x5ab(%rip), %rdi       # 0x211b
leaq 0x2759(%rip), %rsi      # 0x42d0
addq $0x7, %rsi
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1bf3
movsbl 0x273f(%rip), %eax      # 0x42d0
cmpl $0x20, %eax
je 0x1bec
leaq 0x2733(%rip), %rdi      # 0x42d0
movl $0x20, %esi
callq 0x1080
movq %rax, -0x48(%rbp)
cmpq $0x0, %rax
je 0x1bea
movq -0x48(%rbp), %rax
leaq 0x2714(%rip), %rcx      # 0x42d0
subq %rcx, %rax
movl %eax, -0x54(%rbp)
cmpl $0x6, -0x54(%rbp)
jg 0x1be8
movq -0x48(%rbp), %rax
movb $0x0, (%rax)
leaq -0x40(%rbp), %rdi
leaq 0x784(%rip), %rsi       # 0x235e
leaq 0x26ef(%rip), %rdx      # 0x42d0
movb $0x0, %al
callq 0x10f0
jmp 0x1bea
jmp 0x1bec
movl $0x0, -0x18(%rbp)
leaq -0x40(%rbp), %rdi
leaq 0x695(%rip), %rsi       # 0x2293
callq 0x10d0
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x1c35
movq 0x23e4(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq -0x40(%rbp), %rdx
leaq 0x744(%rip), %rsi       # 0x2366
movb $0x0, %al
callq 0x10c0
movl $0x2, -0x4(%rbp)
jmp 0x1d6c
cmpl $0x0, -0x18(%rbp)
je 0x1c7c
movq -0x50(%rbp), %rdi
callq 0x1590
cmpl $-0x1, %eax
jne 0x1c7a
movq 0x23a8(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq -0x40(%rbp), %rdx
leaq 0x724(%rip), %rsi       # 0x2382
movb $0x0, %al
callq 0x10c0
movq -0x50(%rbp), %rdi
callq 0x1060
movl $0x3, -0x4(%rbp)
jmp 0x1d6c
jmp 0x1c7c
jmp 0x1c7e
cmpq $0x0, -0x50(%rbp)
je 0x1d57
movq -0x10(%rbp), %rdi
callq 0x1420
movl %eax, %ecx
movl %ecx, -0x58(%rbp)
subl $-0x2, %eax
je 0x1d41
jmp 0x1ca2
movl -0x58(%rbp), %eax
subl $-0x1, %eax
je 0x1d2f
jmp 0x1cb0
movl -0x58(%rbp), %eax
testl %eax, %eax
jne 0x1d52
jmp 0x1cbd
leaq 0x463(%rip), %rdi       # 0x2127
leaq 0x2605(%rip), %rsi      # 0x42d0
addq $0x7, %rsi
movl $0x4, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1cf1
movq -0x50(%rbp), %rdi
callq 0x1060
movq $0x0, -0x50(%rbp)
jmp 0x1d52
movq -0x50(%rbp), %rdi
callq 0x1590
cmpl $-0x1, %eax
jne 0x1d2d
movq 0x22f2(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq -0x40(%rbp), %rdx
leaq 0x68a(%rip), %rsi       # 0x239e
movb $0x0, %al
callq 0x10c0
movq -0x50(%rbp), %rdi
callq 0x1060
movl $0x3, -0x4(%rbp)
jmp 0x1d6c
jmp 0x1d52
movq -0x50(%rbp), %rdi
callq 0x1060
movl $0x0, -0x4(%rbp)
jmp 0x1d6c
movq -0x50(%rbp), %rdi
callq 0x1060
movq $0x0, -0x50(%rbp)
jmp 0x1c7e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x1b3b
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq