// File: /workspace/github_c_makefile_star2_O1/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 0x131f5
movl %r8d, %ebx
movq %rdx, %r12
movq %rdi, %r15
movl 0x4b7ad(%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 0x5482(%rip), %rdx      # 0x18324
cmovneq %r12, %rdx
leaq 0x5277(%rip), %rsi      # 0x18124
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x3430
leaq 0x3ef8(%rip), %rsi      # 0x16dbe
movq %r12, %rdi
callq 0x3390
testq %rax, %rax
je 0x1320f
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 0x131b0
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 0x13019
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 0x131b0
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl $0x1, %r8d
movq %r13, %rbx
movq %r12, %r13
jmp 0x1303f
leaq 0x4ab0(%rip), %rdx      # 0x17ad0
movslq (%rdx,%rax,4), %rax
cmpq $-0x1, %rax
je 0x13039
movq 0x20(%rsp), %rdx
movsbl (%rdx,%rcx), %ecx
cmpl 0x2c(%rsp), %ecx
jge 0x13050
movl $0x1, %r8d
incl %r9d
cmpl %ebp, %r9d
jl 0x12f83
jmp 0x131b0
shlq $0x2, %rbx
orq %rax, %rbx
andq 0x4b5da(%rip), %rbx     # 0x5e638
movq %r13, %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movb 0x4b5c5(%rip), %cl      # 0x5e634
shlq %cl, %rax
movq %rax, %r13
addq %rdx, %r13
incq %r8
movslq 0x4b5be(%rip), %rax     # 0x5e640
cmpq %rax, %r8
jbe 0x1303f
cmpq %r13, %rbx
movq %r13, %rdx
cmovbq %rbx, %rdx
movq 0x4b5b0(%rip), %rsi     # 0x5e648
andq %rdx, %rsi
movl 0x4b57e(%rip), %r10d    # 0x5e620
leal (%r10,%r10), %ecx
shrq %cl, %rsi
movq 0x4b5a8(%rip), %rdi     # 0x5e658
movslq %esi, %rsi
movslq (%rdi,%rsi,4), %rdi
cmpl 0x4b5a3(%rip), %edi     # 0x5e660
jae 0x1303f
movq 0x4b58a(%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 0x4b534(%rip), %cl      # 0x5e624
shlb $0x2, %cl
shrq %cl, %rsi
movl 0x4b52b(%rip), %r10d    # 0x5e628
testq %r10, %r10
je 0x1303f
movq %r13, 0x10(%rsp)
movq %rbx, 0x18(%rsp)
addq %rdi, %rsi
xorl %r11d, %r11d
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
movl %r10d, %ebx
movq 0x30(%rsp), %rcx
movl %r11d, %eax
imulq %rdi, %rax
addq %r14, %rax
xorl %edx, %edx
divq %r10
movq (%rcx,%rdx,8), %r13
testq %r13, %r13
je 0x13168
movq %r13, %rax
shrq $0x4, %rax
cmpq %rsi, %rax
je 0x13184
incl %r11d
decl %ebx
jne 0x1313b
jmp 0x13175
shlq $0x4, %rsi
addq 0x48(%rsp), %rsi
movq %rsi, (%rcx,%rdx,8)
movq 0x18(%rsp), %rbx
movq 0x10(%rsp), %r13
jmp 0x1303f
movl %r13d, %eax
notl %eax
testb $0xf, %al
movq 0x18(%rsp), %rbx
je 0x1317a
incq %r13
movq %r13, (%rcx,%rdx,8)
movl %r13d, %eax
andl $0xf, %eax
cmpq 0x40(%rsp), %rax
jb 0x1317a
orq $0xf, %r13
movq %r13, (%rcx,%rdx,8)
jmp 0x1317a
leaq 0x50d7(%rip), %rdi      # 0x1828e
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 0x504c(%rip), %rsi      # 0x1824f
movl $0xf, %edx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x5063(%rip), %rsi      # 0x18280
leaq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x3330