// File: /workspace/github_c_makefile_star2_O1/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, %r13
leaq 0xac6c(%rip), %rdi      # 0x12940
xorl %ebx, %ebx
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x1130
leaq 0xb457(%rip), %rdi      # 0x13140
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x1130
leaq 0xbc44(%rip), %rdi      # 0x13940
movl $0x800, %edx            # imm = 0x800
xorl %esi, %esi
callq 0x1130
leaq 0xc431(%rip), %rbp      # 0x14140
movl $0x800, %edx            # imm = 0x800
movq %rbp, %rdi
xorl %esi, %esi
callq 0x1130
leaq 0xcc1b(%rip), %rax      # 0x14940
movl $0x1, %ecx
leaq 0xd40f(%rip), %rdx      # 0x15140
movq %rcx, (%rbx,%rax)
movq %rcx, (%rbx,%rdx)
addq $0x8, %rbx
cmpq $0x800, %rbx            # imm = 0x800
jne 0x7d31
movq $0x0, 0xdbef(%rip) # 0x15940
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0xdbec(%rip)      # 0x15948
movl %eax, 0xdbea(%rip)      # 0x1594c
cmpl $0x0, (%rsp)
jle 0x802b
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %r15, 0x10(%rsp)
movq %r13, 0x8(%rsp)
movq %r13, %rdi
movl $0x1, %esi
callq 0x78ce
cmpl $-0x2, %eax
je 0x8052
movl %eax, %r14d
testl %eax, %eax
js 0x8017
je 0x803e
movq 0xab87(%rip), %rdi      # 0x12930
cmpb $0x40, (%rdi)
jne 0x803e
incq %rdi
movl $0x2f, %esi
callq 0x1140
testq %rax, %rax
je 0x8043
incq %rax
movq %rax, %rdi
leaq 0x44a6(%rip), %rsi      # 0xc27b
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 0x805c
movl %ebx, 0x4(%rsp)
testq %r15, %r15
je 0x7e11
movq 0xab27(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movq %r13, %rdi
movl $0x5, %esi
callq 0x78ce
movl %eax, %ebx
testl %eax, %eax
js 0x8048
testq %r15, %r15
je 0x7e9f
movq 0xaafc(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x8375(%rip), %rdi      # 0x101b8
addq 0xaae6(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x835f(%rip), %rdi      # 0x101b8
addq %rdi, %rdi
addq 0xaacd(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x8346(%rip), %rax      # 0x101b8
leaq (%rax,%rax,2), %rdi
addq 0xaab3(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movslq 0x832c(%rip), %rdi      # 0x101b8
shlq $0x2, %rdi
addq 0xaa99(%rip), %rdi      # 0x12930
movq %r15, %rsi
callq 0x1120
movq 0xaa8a(%rip), %rsi      # 0x12930
movl %ebx, %r13d
testl %ebx, %ebx
leaq 0xaa8e(%rip), %rdx      # 0x12940
je 0x7ec6
xorl %eax, %eax
movzbl (%rsi,%rax), %ecx
incq (%rdx,%rcx,8)
incq %rax
cmpq %rax, %r13
jne 0x7eb6
movslq 0x82eb(%rip), %rax      # 0x101b8
testl %ebx, %ebx
leaq 0xba6a(%rip), %r8       # 0x13940
je 0x7ef3
leal (%rax,%rax), %ecx
movslq %ecx, %rcx
addq %rsi, %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
incq (%r8,%rdi,8)
incq %rdx
cmpq %rdx, %r13
jne 0x7ee3
testl %ebx, %ebx
leaq 0xb244(%rip), %r8       # 0x13140
je 0x7f19
leal (%rax,%rax,2), %ecx
movslq %ecx, %rcx
addq %rsi, %rcx
xorl %edx, %edx
movzbl (%rcx,%rdx), %edi
incq (%r8,%rdi,8)
incq %rdx
cmpq %rdx, %r13
jne 0x7f09
leal (,%rax,4), %ecx
movslq %ecx, %r15
addq %rsi, %r15
testl %ebx, %ebx
je 0x7f3e
xorl %ecx, %ecx
movzbl (%r15,%rcx), %edx
incq (%rbp,%rdx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x7f2c
cmpl $0x0, 0xda03(%rip)      # 0x15948
jns 0x7f78
testl %ebx, %ebx
je 0x7f78
cmpl $0x2, %ebx
movl $0x1, %ecx
cmovgel %ebx, %ecx
movq %rsi, %rdx
movzbl (%rdx,%rax), %edi
orl $0x20, %edi
cmpl $0x6e, %edi
je 0x7f6f
incq %rdx
decq %rcx
jne 0x7f59
jmp 0x7f78
movsbl (%rdx), %eax
movl %eax, 0xd9d0(%rip)      # 0x15948
movl 0xd9ca(%rip), %ecx      # 0x15948
testl %ecx, %ecx
js 0x7f90
leaq 0xd1b7(%rip), %rdi      # 0x15140
movl %ebx, %edx
callq 0x7c35
addq 0xd9a9(%rip), %r13      # 0x15940
movq %r13, 0xd9a2(%rip)      # 0x15940
cmpl $0x0, 0xd9a7(%rip)      # 0x1594c
sets %al
cmpq $0x186a0, %r13          # imm = 0x186A0
setae %cl
andb %al, %cl
cmpb $0x1, %cl
movq 0x8(%rsp), %r13
jne 0x7ff1
movl $0x0, 0xd984(%rip)      # 0x1594c
xorl %ecx, %ecx
movl $0x1, %eax
movq (%rbp,%rax,8), %rdx
movslq %ecx, %rsi
cmpq (%rbp,%rsi,8), %rdx
jbe 0x7fe6
movl %eax, 0xd968(%rip)      # 0x1594c
movl %eax, %ecx
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x7fcf
movl 0xd955(%rip), %ecx      # 0x1594c
testl %ecx, %ecx
js 0x800c
leaq 0xc93e(%rip), %rdi      # 0x14940
movq %r15, %rsi
movl %ebx, %edx
callq 0x7c35
movl 0x4(%rsp), %ebx
incl %ebx
movq 0x10(%rsp), %r15
testl %r14d, %r14d
js 0x802d
incl %r12d
cmpl (%rsp), %r12d
jne 0x7d7b
jmp 0x802d
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x20c6
callq 0x2095
cmpl $-0x1, %ebx
jne 0x8052
callq 0x2071
movl $0x1, %edi
callq 0x1270
callq 0x2040