// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/iseq2comem.c
// Function: fastq2co
llong * fastq2co(char* seqfname, llong *co, char *pipecmd, int Q, int M )
{
 if(M >= CT_MAX) err(errno,"fastq2co(): Occurence num should smaller than %d", (int)CT_MAX);
 llong tuple = 0LLU, crvstuple = 0LLU, unituple, drtuple, pfilter;
 memset(co,0LLU,hashsize*sizeof(llong));
 FILE *infp;
 char fq_fname[PATHLEN];
 if(pipecmd[0] != '\0')
    sprintf(fq_fname,"%s %s",pipecmd,seqfname);
  else
    sprintf(fq_fname,"%s %s",gzpipe_cmd,seqfname);
 if( (infp=popen(fq_fname,"r")) == NULL ) err(errno,"fastq2co():%s",fq_fname);
 char *seq = malloc(LEN+10);
 char *qual = malloc(LEN+10);
 fgets(seq,LEN,infp); fgets(seq,LEN,infp);
 fgets(qual,LEN,infp); fgets(qual,LEN,infp);
 llong base = 1; char ch ; int basenum,line_num = 0 ;
 unsigned int keycount =0 ;
 int sl = strlen(seq);
 for(int pos = 0; pos < sl; pos++){
  if(seq[pos] == '\n' ){
   fgets(seq,LEN,infp); fgets(seq,LEN,infp);
   fgets(qual,LEN,infp); fgets(qual,LEN,infp);
   sl = strlen(seq);
   line_num+=4;
   if( !feof(infp) ) {
    base = 1;
    pos = -1;
    continue ;
   }
   else break;
  }
  else{
   ch = seq[pos];
   basenum = Basemap[(int)ch];
   if( (basenum != DEFAULT) && ( qual[pos] >= Q ) ){
    tuple = ( ( tuple<< 2 ) | (llong)basenum ) & tupmask ;
    crvstuple = ( crvstuple >> 2 ) + (((llong)basenum^3LLU) << crvsaddmove);
    base++;
   }
   else {
    base = 1;
    continue;
   };
  };
  if( base > TL ){
   unituple = tuple < crvstuple ? tuple:crvstuple;
   int dim_tup = ((unituple & domask) >> ( (half_outctx_len)*2 ) ) ;
      pfilter = dim_shuf_arr[dim_tup];
      if( ( pfilter >= dim_end) || (pfilter < dim_start ) ) continue;
   pfilter = pfilter - dim_start;
      drtuple = ( ( (unituple & undomask)
              + ( ( unituple & ( ( 1LLU<< ( half_outctx_len*2) ) - 1)) << (TL*2 - half_outctx_len*4) ) )
              >> ( drlevel*4 ) )
              + pfilter ;
   unsigned int i,n ;
   for(i=0;i<hashsize;i++) {
    n = HASH(drtuple, i, hashsize);
    if (co[n] == 0LLU){
     if( M == 1) co[n] = (drtuple << CT_BIT) | CT_MAX;
     else co[n] = (drtuple << CT_BIT) + 1LLU;
          if( keycount > hashlimit)
            err(errno,"the context space is too crowd, try rerun the program using -k%d", half_ctx_len + 1);
     break;
    }
    else if ( ( co[n] >> CT_BIT ) == drtuple ) {
           if( (co[n] & CT_MAX) == CT_MAX ) break;
      co[n] += 1LLU;
      if( !((co[n] & CT_MAX) < M) ) co[n]|= CT_MAX ;
      break ;
        };
   };
  };
 }
 printf("%d reads detected\n",line_num);
 pclose(infp);
 free(seq);
  free(qual);
 return co;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %ecx, 0x2c(%rsp)
cmpl $0xf, %r8d
jae 0x13b27
movl %r8d, %ebx
movq %rdx, %r12
movq %rdi, %r15
movl 0x4ae7b(%rip), %edx     # 0x5e628
shlq $0x3, %rdx
movl $0x0, 0xc(%rsp)
movq %rsi, 0x30(%rsp)
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3210
cmpb $0x0, (%r12)
leaq 0x4b80(%rip), %rdx      # 0x18354
cmovneq %r12, %rdx
leaq 0x4975(%rip), %rsi      # 0x18154
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3430
leaq 0x3616(%rip), %rsi      # 0x16e0e
movq %r12, %rdi
callq 0x3390
testq %rax, %rax
je 0x13b41
movq %rax, %r15
movl $0x4e2a, %edi           # imm = 0x4E2A
callq 0x3340
movq %rax, %r12
movl $0x4e2a, %edi           # imm = 0x4E2A
callq 0x3340
movq %rax, %rbp
movq %r12, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, %rdx
callq 0x3290
movq %r12, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, %rdx
callq 0x3290
movq %rbp, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, %rdx
callq 0x3290
movq %rbp, 0x20(%rsp)
movq %rbp, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, 0x38(%rsp)
movq %r15, %rdx
callq 0x3290
movq %r12, %rdi
callq 0x3130
movq %r12, %r15
movq %rax, %rbp
testl %ebp, %ebp
jle 0x13ae2
movslq %ebx, %rax
movq %rax, 0x40(%rsp)
cmpl $0x1, %ebx
movl $0xf, %eax
movl $0x1, %r8d
cmovneq %r8, %rax
movq %rax, 0x48(%rsp)
xorl %ebx, %ebx
xorl %r13d, %r13d
xorl %r9d, %r9d
movl $0x0, 0xc(%rsp)
movslq %r9d, %rcx
movsbq (%r15,%rcx), %rax
cmpq $0xa, %rax
jne 0x1394b
movq %r13, %r12
movq %rbx, %r13
movq %r15, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq 0x38(%rsp), %r14
movq %r14, %rdx
callq 0x3290
movq %r15, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r14, %rdx
callq 0x3290
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r14, %rdx
callq 0x3290
movq %rbx, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r14, %rdx
callq 0x3290
movq %r15, %rdi
callq 0x3130
movq %rax, %rbp
addl $0x4, 0xc(%rsp)
movq %r14, %rdi
callq 0x32d0
testl %eax, %eax
jne 0x13ae2
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0x1, %r8d
movq %r13, %rbx
movq %r12, %r13
jmp 0x13971
leaq 0x41ae(%rip), %rdx      # 0x17b00
movslq (%rdx,%rax,4), %rax
cmpq $-0x1, %rax
je 0x1396b
movq 0x20(%rsp), %rdx
movsbl (%rdx,%rcx), %ecx
cmpl 0x2c(%rsp), %ecx
jge 0x13982
movl $0x1, %r8d
incl %r9d
cmpl %ebp, %r9d
jl 0x138b5
jmp 0x13ae2
shlq $0x2, %rbx
orq %rax, %rbx
andq 0x4aca8(%rip), %rbx     # 0x5e638
movq %r13, %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movb 0x4ac93(%rip), %cl      # 0x5e634
shlq %cl, %rax
movq %rax, %r13
addq %rdx, %r13
incq %r8
movslq 0x4ac8c(%rip), %rax     # 0x5e640
cmpq %rax, %r8
jbe 0x13971
cmpq %r13, %rbx
movq %r13, %rdx
cmovbq %rbx, %rdx
movq 0x4ac7e(%rip), %rsi     # 0x5e648
andq %rdx, %rsi
movl 0x4ac4c(%rip), %r10d    # 0x5e620
leal (%r10,%r10), %ecx
shrq %cl, %rsi
movq 0x4ac76(%rip), %rdi     # 0x5e658
movslq %esi, %rsi
movslq (%rdi,%rsi,4), %rdi
cmpl 0x4ac71(%rip), %edi     # 0x5e660
jae 0x13971
movq 0x4ac58(%rip), %r11     # 0x5e650
movq $-0x1, %rsi
shlq %cl, %rsi
notq %rsi
andq %rdx, %rsi
addl %eax, %eax
shll $0x2, %r10d
subl %r10d, %eax
movl %eax, %ecx
shlq %cl, %rsi
andq %rdx, %r11
addq %r11, %rsi
movb 0x4ac02(%rip), %cl      # 0x5e624
shlb $0x2, %cl
shrq %cl, %rsi
movl 0x4abf9(%rip), %r10d    # 0x5e628
testq %r10, %r10
je 0x13971
movq %r13, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
addq %rdi, %rsi
movq %rsi, %rax
xorl %edx, %edx
divq %r10
movq %rdx, %r14
leal -0x1(%r10), %edi
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
movq %rdx, %rdi
incq %rdi
movq %r10, %r11
xorl %ebx, %ebx
movq 0x30(%rsp), %rcx
movq %rdi, %rax
imulq %rbx, %rax
addq %r14, %rax
xorl %edx, %edx
divq %r10
movq (%rcx,%rdx,8), %r13
testq %r13, %r13
je 0x13a9a
movq %r13, %rax
shrq $0x4, %rax
cmpq %rsi, %rax
je 0x13ab6
incq %rbx
decq %r11
jne 0x13a6c
jmp 0x13aa7
shlq $0x4, %rsi
addq 0x48(%rsp), %rsi
movq %rsi, (%rcx,%rdx,8)
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r13
jmp 0x13971
movl %r13d, %eax
notl %eax
testb $0xf, %al
movq 0x18(%rsp), %rbx
je 0x13aac
incq %r13
movq %r13, (%rcx,%rdx,8)
movl %r13d, %eax
andl $0xf, %eax
cmpq 0x40(%rsp), %rax
jb 0x13aac
orq $0xf, %r13
movq %r13, (%rcx,%rdx,8)
jmp 0x13aac
leaq 0x47d5(%rip), %rdi      # 0x182be
movl 0xc(%rsp), %esi
xorl %eax, %eax
callq 0x3170
movq 0x38(%rsp), %rdi
callq 0x31a0
movq %r15, %rdi
callq 0x3040
movq 0x20(%rsp), %rdi
callq 0x3040
movq 0x30(%rsp), %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x474a(%rip), %rsi      # 0x1827f
movl $0xf, %edx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x4761(%rip), %rsi      # 0x182b0
leaq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x3330