// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/converters/cosy/cosy.c
// Function: doCompress
int doCompress(
  FILE *dest,
  int argc,
  char *argv[]
)
{
  int status = 0;
  unsigned int i;
  char *filename;
  FILE *src;

  while (argc != 0) {
    filename = argv[0];

    if ((src = fopen(filename, "r")) == NULL) {
      status = 2;
      break;
    }

    /*
     * Build a leading CSY/ card.
     */
    strcpy(card, csy);
    if (strncmp(filename, "deck_", 5) == 0) {
      /*
       * Possible deck name derived from filename.
       */
      if (strlen(filename) <= 11) {
        for (i = 5; i < strlen(filename); i++)
          if (!VALID(filename[i]))
            goto noname;

        strncpy(card, &filename[5], strlen(filename) - 5);
        goto named;
      }
    noname:
      fprintf(stderr, "Unable to use filename (%s) for deck name\n", filename);
    }
  named:

    if ((status = compressCard(dest)) != 0)
      break;

    /*
     * Copy the source file to the destination while compressing.
     */
    while (fgets(card, sizeof(card), src) != NULL) {
      int len = strlen(card);

      if (card[len - 1] == '\n')
        card[len - 1] = '\0';

      if ((status = compressCard(dest)) != 0)
        goto error;
    }

    /*
     * Build a trailing END/ card.
     */
    strcpy(card, end);
    if ((status = compressCard(dest)) != 0)
      break;

    fclose(src);

    argc--, argv++;
  }
 error:

  /*
   * Report possible error.
   */
  switch (status) {
    case 0:
      if ((outcount % RECLEN) != 0)
        fwrite(pad, sizeof(char), outcount % RECLEN, dest);
      break;

    case 2:
      fprintf(stderr, "Failed to open file - %s\n", filename);
      break;

    case 3:
      fprintf(stderr, "Error writing COSY file\n");
      break;

    case 4:
      fprintf(stderr, "Invalid character in file - %s\n", filename);
      break;

    default:
      fprintf(stderr, "Unknown exit status - %u\n", status);
      break;
  }
  fclose(dest);
  return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x0, -0xc(%rbp)
je 0x1a36
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
leaq 0xa3b(%rip), %rsi       # 0x2295
callq 0x10d0
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x1875
movl $0x2, -0x1c(%rbp)
jmp 0x1a36
movq 0x2824(%rip), %rsi      # 0x40a0
leaq 0x2a4d(%rip), %rdi      # 0x42d0
callq 0x1050
movq -0x28(%rbp), %rdi
leaq 0xa23(%rip), %rsi       # 0x22b6
movl $0x5, %edx
callq 0x1040
cmpl $0x0, %eax
jne 0x1967
movq -0x28(%rbp), %rdi
callq 0x1070
cmpq $0xb, %rax
ja 0x1949
movl $0x5, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1070
movq %rax, %rcx
movq -0x40(%rbp), %rax
cmpq %rcx, %rax
jae 0x191b
movq -0x28(%rbp), %rax
movl -0x20(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x20, %eax
jl 0x190c
movq -0x28(%rbp), %rax
movl -0x20(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x5e, %eax
jg 0x190c
movq -0x28(%rbp), %rax
movl -0x20(%rbp), %ecx
movsbl (%rax,%rcx), %eax
cmpl $0x26, %eax
jne 0x190e
jmp 0x194b
jmp 0x1910
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x18c0
movq -0x28(%rbp), %rax
addq $0x5, %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1070
movq -0x48(%rbp), %rsi
movq %rax, %rdx
subq $0x5, %rdx
leaq 0x298e(%rip), %rdi      # 0x42d0
callq 0x1030
jmp 0x1969
jmp 0x194b
movq 0x26a6(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x95c(%rip), %rsi       # 0x22bc
movb $0x0, %al
callq 0x10c0
jmp 0x1969
movq -0x8(%rbp), %rdi
callq 0x1220
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x197f
jmp 0x1a36
jmp 0x1981
movq -0x30(%rbp), %rdx
leaq 0x2944(%rip), %rdi      # 0x42d0
movl $0x51, %esi
callq 0x10b0
cmpq $0x0, %rax
je 0x19ed
leaq 0x292d(%rip), %rdi      # 0x42d0
callq 0x1070
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x2915(%rip), %rax      # 0x42d0
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0x19d8
movl -0x34(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rcx
leaq 0x28fc(%rip), %rax      # 0x42d0
movb $0x0, (%rax,%rcx)
movq -0x8(%rbp), %rdi
callq 0x1220
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x19eb
jmp 0x1a38
jmp 0x1981
movq 0x26b4(%rip), %rsi      # 0x40a8
leaq 0x28d5(%rip), %rdi      # 0x42d0
callq 0x1050
movq -0x8(%rbp), %rdi
callq 0x1220
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x1a13
jmp 0x1a36
movq -0x30(%rbp), %rdi
callq 0x1060
movl -0xc(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x18(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x18(%rbp)
jmp 0x183a
jmp 0x1a38
movl -0x1c(%rbp), %eax
movq %rax, -0x50(%rbp)
subq $0x4, %rax
ja 0x1aee
movq -0x50(%rbp), %rax
leaq 0x6ac(%rip), %rcx       # 0x2100
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x2861(%rip), %eax      # 0x42c4
movl $0x180, %ecx            # imm = 0x180
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x1a96
movl 0x284e(%rip), %eax      # 0x42c4
movl $0x180, %ecx            # imm = 0x180
cltd
idivl %ecx
movslq %edx, %rdx
movq -0x8(%rbp), %rcx
leaq 0x28a4(%rip), %rdi      # 0x4330
movl $0x1, %esi
callq 0x1110
jmp 0x1b09
movq 0x2559(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x83a(%rip), %rsi       # 0x22e7
movb $0x0, %al
callq 0x10c0
jmp 0x1b09
movq 0x253b(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
leaq 0x83a(%rip), %rsi       # 0x2301
movb $0x0, %al
callq 0x10c0
jmp 0x1b09
movq 0x2521(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movq -0x28(%rbp), %rdx
leaq 0x835(%rip), %rsi       # 0x231a
movb $0x0, %al
callq 0x10c0
jmp 0x1b09
movq 0x2503(%rip), %rax      # 0x3ff8
movq (%rax), %rdi
movl -0x1c(%rbp), %edx
leaq 0x838(%rip), %rsi       # 0x233a
movb $0x0, %al
callq 0x10c0
movq -0x8(%rbp), %rdi
callq 0x1060
movl -0x1c(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)