// File: /workspace/github_c_makefile_star2_O3/thegenemyers[P]DASCRUBBER/QV.c
// Function: QVcoding_Scan
int QVcoding_Scan(FILE *input, int num, FILE *temp)
{ char *slash;
  int   rlen;
  int   i, r;

  //  Zero histograms

  bzero(delHist,sizeof(uint64)*256);
  bzero(mrgHist,sizeof(uint64)*256);
  bzero(insHist,sizeof(uint64)*256);
  bzero(subHist,sizeof(uint64)*256);

  for (i = 0; i < 256; i++)
    delRun[i] = subRun[i] = 1;

  totChar    = 0;
  delChar    = -1;
  subChar    = -1;

  //  Make a sweep through the .quiva entries, histogramming the relevant things
  //    and figuring out the run chars for the deletion and substition streams

  r = 0;
  for (i = 0; i < num; i++)
    { int well, beg, end, qv;

      rlen = Read_Lines(input,1);
      if (rlen == -2)
        EXIT(-1);
      if (rlen < 0)
        break;

      if (rlen == 0 || Read[0] != '@')
        { EPRINTF(EPLACE,"Line %d: Header in quiva file is missing\n",Nline);
          EXIT(-1);
        }
      slash = index(Read+1,'/');
      if (slash == NULL)
  	{ EPRINTF(EPLACE,"%s: Line %d: Header line incorrectly formatted ?\n",
                         Prog_Name,Nline);
          EXIT(-1);
        }
      if (sscanf(slash+1,"%d/%d_%d RQ=0.%d\n",&well,&beg,&end,&qv) != 4)
        { EPRINTF(EPLACE,"%s: Line %d: Header line incorrectly formatted ?\n",
                         Prog_Name,Nline);
          EXIT(-1);
        }

      if (temp != NULL)
        fputs(Read,temp);

      rlen = Read_Lines(input,5);
      if (rlen < 0)
        { if (rlen == -1)
            EPRINTF(EPLACE,"Line %d: incomplete last entry of .quiv file\n",Nline);
          EXIT(-1);
        }

      if (temp != NULL)
        { fputs(Read,temp);
          fputs(Read+Rmax,temp);
          fputs(Read+2*Rmax,temp);
          fputs(Read+3*Rmax,temp);
          fputs(Read+4*Rmax,temp);
        }

      Histogram_Seqs(delHist,(uint8 *) (Read),rlen);
      Histogram_Seqs(insHist,(uint8 *) (Read+2*Rmax),rlen);
      Histogram_Seqs(mrgHist,(uint8 *) (Read+3*Rmax),rlen);
      Histogram_Seqs(subHist,(uint8 *) (Read+4*Rmax),rlen);

      if (delChar < 0)
        { int   k;
          char *del = Read+Rmax;

          for (k = 0; k < rlen; k++)
            if (del[k] == 'n' || del[k] == 'N')
              { delChar = Read[k];
                break;
              }
        }
      if (delChar >= 0)
        Histogram_Runs( delRun,(uint8 *) (Read),rlen,delChar);
      totChar += rlen;
      if (subChar < 0)
        { if (totChar >= 100000)
            { int k;

              subChar = 0;
              for (k = 1; k < 256; k++)
                if (subHist[k] > subHist[subChar])
                  subChar = k;
            }
        }
      if (subChar >= 0)
        Histogram_Runs( subRun,(uint8 *) (Read+4*Rmax),rlen,subChar);

      r += 1;
    }

  return (r);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, %r15
movl %esi, (%rsp)
movq %rdi, %r12
leaq 0xa89b(%rip), %rdi      # 0x12940
xorl %r14d, %r14d
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x1130
leaq 0xb085(%rip), %r13      # 0x13140
movl $0x800, %edx            # imm = 0x800
movq %r13, %rdi
xorl %esi, %esi
callq 0x1130
leaq 0xb86f(%rip), %rbp      # 0x13940
movl $0x800, %edx            # imm = 0x800
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1130
leaq 0xc059(%rip), %rbx      # 0x14140
movl $0x800, %edx            # imm = 0x800
movq %rbx, %rdi
xorl %esi, %esi
callq 0x1130
leaq 0xc843(%rip), %rax      # 0x14940
movaps 0x407c(%rip), %xmm0     # 0xc180
leaq 0xd035(%rip), %rcx      # 0x15140
movaps %xmm0, (%r14,%rax)
movaps %xmm0, (%r14,%rcx)
addq $0x10, %r14
cmpq $0x800, %r14            # imm = 0x800
jne 0x810b
movq $0x0, 0xd813(%rip) # 0x15940
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xd810(%rip)      # 0x15948
movl %eax, 0xd80e(%rip)      # 0x1594c
cmpl $0x0, (%rsp)
jle 0x83f7
xorl %r14d, %r14d
movq %r15, 0x10(%rsp)
movq %r12, 0x8(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x7cbe
cmpl $-0x2, %eax
je 0x841c
testl %eax, %eax
js 0x83fa
je 0x840c
movq 0xa7b0(%rip), %rdi      # 0x12930
cmpb $0x40, (%rdi)
jne 0x840c
incq %rdi
movl $0x2f, %esi
callq 0x1140
testq %rax, %rax
je 0x842b
incq %rax
movq %rax, %rdi
leaq 0x413f(%rip), %rsi      # 0xc2eb
leaq 0x24(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x1c(%rsp), %r8
leaq 0x18(%rsp), %r9
xorl %eax, %eax
callq 0x1200
cmpl $0x4, %eax
jne 0x8426
movl %r14d, 0x4(%rsp)
testq %r15, %r15
je 0x8279
movq 0xa74b(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movq %r12, %rdi
movl $0x5, %esi
callq 0x7cbe
movl %eax, %r14d
testl %eax, %eax
js 0x8411
movq 0xa724(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x7f9d(%rip), %rdi      # 0x101b8
addq 0xa70e(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x7f87(%rip), %rdi      # 0x101b8
addq %rdi, %rdi
addq 0xa6f5(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x7f6e(%rip), %rax      # 0x101b8
leaq (%rax,%rax,2), %rdi
addq 0xa6db(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x7f54(%rip), %rdi      # 0x101b8
shlq $0x2, %rdi
addq 0xa6c1(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
jmp 0x8291
movq %r12, %rdi
movl $0x5, %esi
callq 0x7cbe
movl %eax, %r14d
testl %eax, %eax
js 0x8411
movq 0xa698(%rip), %rsi      # 0x12930
movl %r14d, %r12d
testl %r14d, %r14d
leaq 0xa69b(%rip), %rdx      # 0x12940
je 0x8335
xorl %eax, %eax
movzbl (%rsi,%rax), %ecx
incq (%rdx,%rcx,8)
incq %rax
cmpq %rax, %r12
jne 0x82ad
movslq 0x7ef4(%rip), %rax      # 0x101b8
leaq (%rsi,%rax,2), %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
incq (%rbp,%rdi,8)
incq %rdx
cmpq %rdx, %r12
jne 0x82ca
leaq (%rax,%rax,2), %rcx
addq %rsi, %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
incq (%r13,%rdi,8)
incq %rdx
cmpq %rdx, %r12
jne 0x82e4
leaq (%rsi,%rax,4), %r15
xorl %ecx, %ecx
movzbl (%r15,%rcx), %edx
incq (%rbx,%rdx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x82fb
movl 0xd636(%rip), %ecx      # 0x15948
testl %ecx, %ecx
jns 0x8355
movq %r12, %rdi
movq %rsi, %rdx
movzbl (%rdx,%rax), %r8d
orl $0x20, %r8d
cmpl $0x6e, %r8d
je 0x8348
incq %rdx
decq %rdi
jne 0x831c
jmp 0x8351
movslq 0x7e7c(%rip), %rax      # 0x101b8
leaq (%rsi,%rax,4), %r15
movl 0xd602(%rip), %ecx      # 0x15948
jmp 0x8351
movsbl (%rdx), %ecx
movl %ecx, 0xd5f7(%rip)      # 0x15948
testl %ecx, %ecx
js 0x8364
leaq 0xcde4(%rip), %rdi      # 0x15140
movl %r14d, %edx
callq 0x8021
addq 0xd5d5(%rip), %r12      # 0x15940
movq %r12, 0xd5ce(%rip)      # 0x15940
movl 0xd5d4(%rip), %ecx      # 0x1594c
testl %ecx, %ecx
sets %al
cmpq $0x186a0, %r12          # imm = 0x186A0
setae %dl
andb %al, %dl
cmpb $0x1, %dl
movq 0x8(%rsp), %r12
jne 0x83c4
movl $0x0, 0xd5af(%rip)      # 0x1594c
xorl %ecx, %ecx
movl $0x1, %eax
movq (%rbx,%rax,8), %rdx
movslq %ecx, %rsi
cmpq (%rbx,%rsi,8), %rdx
jbe 0x83b9
movl %eax, 0xd595(%rip)      # 0x1594c
movl %eax, %ecx
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x83a4
testl %ecx, %ecx
js 0x83da
leaq 0xc571(%rip), %rdi      # 0x14940
movq %r15, %rsi
movl %r14d, %edx
callq 0x8021
movl 0x4(%rsp), %r14d
incl %r14d
cmpl (%rsp), %r14d
movq 0x10(%rsp), %r15
jne 0x8155
movl (%rsp), %r14d
jmp 0x83fa
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x204e
cmpl $-0x1, %r14d
jne 0x841c
callq 0x1ff9
movl $0x1, %edi
callq 0x1270
callq 0x1fc8
callq 0x201d