// File: /workspace/github_c_makefile_star2_O2/yhg926[P]public_kssd/iseq2comem.c
// Function: fasta2co
llong * fasta2co(char* seqfname, llong *co, char * pipecmd)
{
 llong tuple = 0LLU, crvstuple = 0LLU,
    unituple, drtuple, pfilter;
 memset(co,0LLU,hashsize*sizeof(llong));
 char seqin_buff[ READSEQ_BUFFSZ + 1 ];
 FILE *infp;
 char fas_fname[PATHLEN];
 if(pipecmd[0] != '\0')
  sprintf(fas_fname,"%s %s",pipecmd,seqfname);
 else
  sprintf(fas_fname,"%s %s",gzpipe_cmd,seqfname);
 if( (infp=popen(fas_fname,"r")) == NULL ) err(errno,"fasta2co():%s",fas_fname);
 int newLen = fread(seqin_buff, sizeof(char),READSEQ_BUFFSZ,infp);
 if(! (newLen >0) ) err(errno,"fastco():eof or fread error file=%s",seqfname);
 llong base = 1; char ch; int basenum;
 unsigned int keycount = 0;
 for(int pos = 0; pos <= newLen; pos++)
 {
  if(pos == newLen){
    newLen = fread(seqin_buff, sizeof(char),READSEQ_BUFFSZ,infp);
   if(newLen > 0)
    pos = 0;
   else break;
  };
  ch = seqin_buff[pos];
  basenum = Basemap[(int)ch];
  if(basenum != DEFAULT)
  {
   tuple = ( ( tuple<< 2 ) | (llong)basenum ) & tupmask ;
   crvstuple = ( crvstuple >> 2 ) + (((llong)basenum^3LLU) << crvsaddmove);
   base++;
  }
  else if ( (ch == '\n') || (ch == '\r') ) { continue;}
  else if (isalpha(ch)){ base=1; continue; }
  else if ( ch == '>' )
  {
   while( (pos < newLen ) && ( seqin_buff[pos] != '\n' ) )
   {
    if (pos < newLen - 1)
     pos++;
    else
    {
     newLen = fread(seqin_buff, sizeof(char),READSEQ_BUFFSZ,infp);
     if(newLen > 0) pos = -1;
     else err(errno,"fasta2co(): can not find seqences head start from '>' %d",newLen);
    };
   };
      base = 1;
      continue;
  }
  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] == 0)
       {
         co[n] = drtuple;
         keycount++;
         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] == drtuple )
          break;
   };
  };
 };
  pclose(infp);
  return co;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x10128, %rsp          # imm = 0x10128
movq %rdx, %r14
movq %rdi, %r12
movl 0x4b88f(%rip), %edx     # 0x5d628
shlq $0x3, %rdx
movq %rsi, 0x8(%rsp)
movq %rsi, %rdi
xorl %esi, %esi
callq 0x3210
cmpb $0x0, (%r14)
leaq 0x554d(%rip), %rdx      # 0x17304
cmovneq %r14, %rdx
leaq 0x5342(%rip), %rsi      # 0x17104
leaq 0x20(%rsp), %r14
movq %r14, %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x3430
leaq 0x3fe3(%rip), %rsi      # 0x15dbe
movq %r14, %rdi
callq 0x3390
testq %rax, %rax
je 0x1207f
leaq 0x120(%rsp), %rdi
pushq $0x1
popq %r14
movl $0x10000, %edx          # imm = 0x10000
movq %r14, %rsi
movq %rax, 0x10(%rsp)
movq %rax, %rcx
callq 0x30c0
movq %rax, %r13
testl %r13d, %r13d
jle 0x12094
movq $0x0, 0x18(%rsp)
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq 0x8(%rsp), %r11
cmpl %r13d, %r12d
jg 0x12045
jne 0x11e68
movl $0x10000, %edx          # imm = 0x10000
leaq 0x120(%rsp), %rdi
pushq $0x1
popq %rsi
movq 0x10(%rsp), %rcx
callq 0x30c0
movq 0x8(%rsp), %r11
movq %rax, %r13
xorl %r12d, %r12d
testl %r13d, %r13d
jle 0x12045
movslq %r12d, %rax
movsbq 0x120(%rsp,%rax), %rbx
leaq 0x4c35(%rip), %rax      # 0x16ab0
movslq (%rax,%rbx,4), %rax
cmpq $-0x1, %rax
je 0x11f89
shlq $0x2, %r15
orq %rax, %r15
andq 0x4b7a1(%rip), %r15     # 0x5d638
movq %rbp, %rdx
shrq $0x2, %rdx
xorq $0x3, %rax
movb 0x4b78c(%rip), %cl      # 0x5d634
shlq %cl, %rax
movq %rax, %rbp
addq %rdx, %rbp
incq %r14
movslq 0x4b785(%rip), %rax     # 0x5d640
cmpq %rax, %r14
jbe 0x1203d
cmpq %rbp, %r15
movq %rbp, %r8
cmovbq %r15, %r8
movq 0x4b773(%rip), %rdx     # 0x5d648
andq %r8, %rdx
movl 0x4b742(%rip), %edi     # 0x5d620
leal (%rdi,%rdi), %ecx
shrq %cl, %rdx
movq 0x4b76d(%rip), %rsi     # 0x5d658
movslq %edx, %rdx
movslq (%rsi,%rdx,4), %rdx
cmpl 0x4b768(%rip), %edx     # 0x5d660
jae 0x1203d
movq 0x4b74b(%rip), %r9      # 0x5d650
andq %r8, %r9
pushq $-0x1
popq %rsi
shlq %cl, %rsi
notq %rsi
andq %r8, %rsi
addl %eax, %eax
shll $0x2, %edi
subl %edi, %eax
movl %eax, %ecx
shlq %cl, %rsi
addq %r9, %rsi
movb 0x4b6fb(%rip), %cl      # 0x5d624
shlb $0x2, %cl
shrq %cl, %rsi
addq %rdx, %rsi
movl 0x4b6f0(%rip), %edi     # 0x5d628
leal -0x1(%rdi), %r8d
leaq 0x1(%rdi), %r9
xorl %r10d, %r10d
decq %r9
je 0x1203d
movq %rsi, %rax
xorl %edx, %edx
divq %rdi
movq %rdx, %rcx
movq %rsi, %rax
xorl %edx, %edx
divq %r8
leaq 0x1(%rdx), %rax
imulq %r10, %rax
addq %rcx, %rax
xorl %edx, %edx
divq %rdi
movq (%r11,%rdx,8), %rax
testq %rax, %rax
je 0x1201a
incq %r10
cmpq %rsi, %rax
jne 0x11f43
jmp 0x1203d
cmpb $0xa, %bl
je 0x1203d
movzbl %bl, %eax
cmpl $0xd, %eax
je 0x1203d
callq 0x34d0
cmpb $0x3e, %bl
jne 0x12034
movq (%rax), %rax
movzwl (%rax,%rbx,2), %eax
andl $0x400, %eax            # imm = 0x400
movq 0x8(%rsp), %r11
pushq $0x1
popq %rbx
jne 0x12015
leal -0x1(%r13), %eax
movslq %r12d, %r12
cmpl %r13d, %r12d
jge 0x12015
cmpb $0xa, 0x120(%rsp,%r12)
je 0x12015
cmpl %eax, %r12d
jge 0x11fe3
incq %r12
jmp 0x11fc9
movl $0x10000, %edx          # imm = 0x10000
leaq 0x120(%rsp), %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %rcx
callq 0x30c0
movq 0x8(%rsp), %r11
movq %rax, %r13
pushq $-0x1
popq %rax
movl %eax, %r12d
testl %r13d, %r13d
jg 0x11fc2
jmp 0x120ac
movq %rbx, %r14
jmp 0x1203d
movq %rsi, (%r11,%rdx,8)
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
cmpl 0x4b5fc(%rip), %eax     # 0x5d62c
jbe 0x1203d
jmp 0x12067
pushq $0x1
popq %r14
movq 0x8(%rsp), %r11
incl %r12d
jmp 0x11e2f
movq 0x10(%rsp), %rdi
movq %r11, %rbx
callq 0x31a0
movq %rbx, %rax
addq $0x10128, %rsp          # imm = 0x10128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
movl 0x4b5a4(%rip), %edx     # 0x5d618
incl %edx
leaq 0x5171(%rip), %rsi      # 0x171ee
jmp 0x120bd
callq 0x3060
movl (%rax), %edi
leaq 0x512f(%rip), %rsi      # 0x171bc
leaq 0x20(%rsp), %rdx
jmp 0x120a5
callq 0x3060
movl (%rax), %edi
leaq 0x5128(%rip), %rsi      # 0x171ca
movq %r12, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x50a3(%rip), %rsi      # 0x1715d
movl %r13d, %edx
xorl %eax, %eax
callq 0x3330