// File: /workspace/github_c_makefile_star2_O2/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 $0x148, %rsp            # imm = 0x148
movl %ecx, 0x2c(%rsp)
cmpl $0xf, %r8d
jae 0x12436
movl %r8d, %ebp
movq %rdx, %r12
movq %rdi, %r15
movl 0x4b536(%rip), %edx     # 0x5d628
shlq $0x3, %rdx
xorl %r14d, %r14d
movq %rsi, 0x18(%rsp)
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3210
cmpb $0x0, (%r12)
leaq 0x51f0(%rip), %rdx      # 0x17304
cmovneq %r12, %rdx
leaq 0x4fe5(%rip), %rsi      # 0x17104
leaq 0x40(%rsp), %r12
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3430
leaq 0x3c86(%rip), %rsi      # 0x15dbe
movq %r12, %rdi
callq 0x3390
testq %rax, %rax
je 0x1244e
movq %rax, %r15
movslq %ebp, %rax
movq %rax, 0x30(%rsp)
movl $0x4e2a, %edi           # imm = 0x4E2A
callq 0x3340
movq %rax, %r12
movl $0x4e2a, %edi           # imm = 0x4E2A
callq 0x3340
movq %rax, %rbx
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 %rbx, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, %rdx
callq 0x3290
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
movl $0x4e20, %esi           # imm = 0x4E20
movq %r15, %rdx
callq 0x3290
movq %r12, %rdi
callq 0x3130
cmpl $0x1, %ebp
pushq $0xf
popq %rcx
pushq $0x1
popq %rdi
cmovneq %rdi, %rcx
movq %rcx, 0x38(%rsp)
movq %rax, %rbp
xorl %r8d, %r8d
xorl %r13d, %r13d
xorl %r11d, %r11d
cmpl %ebp, %r8d
jge 0x123f4
movslq %r8d, %rcx
movsbq (%r12,%rcx), %rax
cmpq $0xa, %rax
jne 0x12263
movq %r11, %rbx
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 0x20(%rsp), %rbp
movq %rbp, %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 %r12, %rdi
callq 0x3130
movq %rax, %rbp
addl $0x4, %r14d
movq %r15, %rdi
callq 0x32d0
testl %eax, %eax
jne 0x123f4
pushq $0x1
popq %rdi
pushq $-0x1
popq %r8
movq %rbx, %r11
jmp 0x12286
leaq 0x4846(%rip), %rdx      # 0x16ab0
movslq (%rdx,%rax,4), %rax
cmpq $-0x1, %rax
je 0x12283
movq 0x20(%rsp), %rdx
movsbl (%rdx,%rcx), %ecx
cmpl 0x2c(%rsp), %ecx
jge 0x1228e
pushq $0x1
popq %rdi
incl %r8d
jmp 0x121d9
shlq $0x2, %r11
orq %rax, %r11
andq 0x4b39c(%rip), %r11     # 0x5d638
movq %r13, %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movb 0x4b387(%rip), %cl      # 0x5d634
shlq %cl, %rax
movq %rax, %r13
addq %rdx, %r13
incq %rdi
movslq 0x4b380(%rip), %rax     # 0x5d640
cmpq %rax, %rdi
jbe 0x12286
cmpq %r13, %r11
movq %r13, %r10
cmovbq %r11, %r10
movq 0x4b372(%rip), %rdx     # 0x5d648
andq %r10, %rdx
movl 0x4b340(%rip), %r9d     # 0x5d620
leal (%r9,%r9), %ecx
shrq %cl, %rdx
movq 0x4b36a(%rip), %rsi     # 0x5d658
movslq %edx, %rdx
movslq (%rsi,%rdx,4), %rdx
cmpl 0x4b365(%rip), %edx     # 0x5d660
jae 0x12286
movq %r13, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movq 0x4b342(%rip), %r11     # 0x5d650
andq %r10, %r11
pushq $-0x1
popq %rsi
shlq %cl, %rsi
notq %rsi
andq %r10, %rsi
addl %eax, %eax
shll $0x2, %r9d
subl %r9d, %eax
movl %eax, %ecx
shlq %cl, %rsi
addq %r11, %rsi
movb 0x4b2f0(%rip), %cl      # 0x5d624
shlb $0x2, %cl
shrq %cl, %rsi
addq %rdx, %rsi
movl 0x4b2e4(%rip), %r9d     # 0x5d628
leal -0x1(%r9), %r10d
leaq 0x1(%r9), %r11
xorl %ebx, %ebx
decq %r11
je 0x123e5
movq %rsi, %rax
xorl %edx, %edx
divq %r9
movq %rdx, %rcx
movq %rsi, %rax
xorl %edx, %edx
divq %r10
leaq 0x1(%rdx), %rax
imulq %rbx, %rax
addq %rcx, %rax
xorl %edx, %edx
divq %r9
movq 0x18(%rsp), %rax
movq (%rax,%rdx,8), %rax
testq %rax, %rax
je 0x123d3
incq %rbx
movq %rax, %rcx
shrq $0x4, %rcx
cmpq %rsi, %rcx
jne 0x1234e
movl %eax, %ecx
notl %ecx
testb $0xf, %cl
je 0x123e5
incq %rax
movq 0x18(%rsp), %rsi
movq %rax, (%rsi,%rdx,8)
movl %eax, %ecx
andl $0xf, %ecx
cmpq 0x30(%rsp), %rcx
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %r13
jb 0x12286
orq $0xf, %rax
movq %rax, (%rsi,%rdx,8)
jmp 0x12286
shlq $0x4, %rsi
addq 0x38(%rsp), %rsi
movq 0x18(%rsp), %rax
movq %rsi, (%rax,%rdx,8)
movq 0x10(%rsp), %r11
movq 0x8(%rsp), %r13
jmp 0x12286
leaq 0x4e73(%rip), %rdi      # 0x1726e
movl %r14d, %esi
xorl %eax, %eax
callq 0x3170
movq %r15, %rdi
callq 0x31a0
movq %r12, %rdi
callq 0x3040
movq 0x20(%rsp), %rdi
callq 0x3040
movq 0x18(%rsp), %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x4deb(%rip), %rsi      # 0x1722f
pushq $0xf
popq %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x4e04(%rip), %rsi      # 0x17260
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x3330