// File: /workspace/github_c_makefile_star2_O0/yhg926[P]public_kssd/iseq2comem.c
// Function: reads2mco
int reads2mco(char* seqfname,const char *co_dir, char * pipecmd){
#define unit_incrs 1000000
int comp_code_bits = half_ctx_len - drlevel > COMPONENT_SZ ? 4*(half_ctx_len - drlevel - COMPONENT_SZ ) : 0 ;
 size_t **cof_count = malloc( component_num * sizeof (size_t*) );
 FILE **outindf = malloc(component_num * sizeof(FILE *));
 FILE **outf = malloc(component_num * sizeof(FILE *));
 char indexfname[PATHLEN]; char combined_cof[PATHLEN];
 size_t cof_count_sz = unit_incrs;
 for(int i=0;i<component_num ;i++)
  {
  cof_count[i] = (size_t *)calloc( cof_count_sz , sizeof(size_t) );
  sprintf(combined_cof,"%s/combco.%d",co_dir,i);
  sprintf(indexfname,"%s/combco.index.%d",co_dir,i);
   if( (outf[i] = fopen(combined_cof,"wb")) == NULL) err(errno,"%s",combined_cof);
    if( (outindf[i] = fopen(indexfname,"wb")) == NULL) err(errno,"%s",indexfname);
  };
 FILE *infp;
 char fas_fname[PATHLEN];
 if(pipecmd[0] != '\0'){
  sprintf(fas_fname,"%s %s",pipecmd,seqfname);
  if( (infp=popen(fas_fname,"r")) == NULL ) err(errno,"reads2mco():%s",fas_fname);
 }
 else
  if( (infp=fopen(seqfname,"r")) == NULL ) err(errno,"reads2mco():%s",fas_fname);;
 char seqin_buff[ READSEQ_BUFFSZ + 1 ];
 int newLen = fread(seqin_buff, sizeof(char),READSEQ_BUFFSZ,infp);
 if(! (newLen >0) ) err(errno,"reads2mco():eof or fread error file=%s",seqfname);
 llong base = 1; char ch; int basenum;
 llong tuple = 0LLU, crvstuple = 0LLU,
  unituple, drtuple, pfilter;
 llong readn = 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 == '>' )
    {
   if( readn > cof_count_sz ){
    for(int i=0;i<component_num ;i++){
     size_t *newtmp = (size_t *)realloc(cof_count[i], (cof_count_sz + unit_incrs) * sizeof(size_t));
     if (newtmp != NULL) {
       cof_count[i] = newtmp;
      memset(cof_count[i] + cof_count_sz ,0, unit_incrs * sizeof(size_t) );
     }
     else err(errno,"cof_count[%d] realloc failed",i);
    }
    cof_count_sz += unit_incrs;
   }
   readn++;
     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 ;
   cof_count[drtuple % component_num][readn]++;
   unsigned int newid = (unsigned int)( drtuple >> comp_code_bits ) ;
   fwrite( &newid, sizeof(unsigned int),1,outf[(int)( drtuple % component_num )] );
   };
  };
 for(int i=0;i<component_num ;i++){
  llong cumval = 0 ;
  for(llong n=0; n<=readn;n++ ){
   cumval += cof_count[i][n];
   fwrite(&cumval, sizeof(llong),1,outindf[i]);
  }
  fclose(outf[i]);
  fclose(outindf[i]);
 }
 printf("decomposing %s by reads is complete!\n",seqfname);
 return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10410, %rsp          # imm = 0x10410
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl 0x4c3af(%rip), %eax     # 0x6460c
subl 0x4c3b5(%rip), %eax     # 0x64618
cmpl $0x7, %eax
jle 0x18282
movl 0x4c39e(%rip), %eax     # 0x6460c
subl 0x4c3a4(%rip), %eax     # 0x64618
subl $0x7, %eax
shll $0x2, %eax
movl %eax, -0x103ec(%rbp)
jmp 0x1828c
xorl %eax, %eax
movl %eax, -0x103ec(%rbp)
jmp 0x1828c
movl -0x103ec(%rbp), %eax
movl %eax, -0x1c(%rbp)
movslq 0x4c388(%rip), %rdi     # 0x64624
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x28(%rbp)
movslq 0x4c374(%rip), %rdi     # 0x64624
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x30(%rbp)
movslq 0x4c360(%rip), %rdi     # 0x64624
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x38(%rbp)
movq $0xf4240, -0x248(%rbp) # imm = 0xF4240
movl $0x0, -0x24c(%rbp)
movl -0x24c(%rbp), %eax
cmpl 0x4c332(%rip), %eax     # 0x64624
jge 0x183f7
movq -0x248(%rbp), %rdi
movl $0x8, %esi
callq 0x3270
movq %rax, %rdx
movq -0x28(%rbp), %rax
movslq -0x24c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
leaq -0x240(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x24c(%rbp), %ecx
leaq 0x3d4e(%rip), %rsi      # 0x1c081
movb $0x0, %al
callq 0x3400
leaq -0x140(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x24c(%rbp), %ecx
leaq 0x3d1c(%rip), %rsi      # 0x1c06e
movb $0x0, %al
callq 0x3400
leaq -0x240(%rbp), %rdi
leaq 0x3cf3(%rip), %rsi      # 0x1c05a
callq 0x3370
movq -0x38(%rbp), %rcx
movslq -0x24c(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x1839d
callq 0x3050
movl (%rax), %edi
leaq -0x240(%rbp), %rdx
leaq 0x4fb0(%rip), %rsi      # 0x1d346
movb $0x0, %al
callq 0x3300
leaq -0x140(%rbp), %rdi
leaq 0x3caf(%rip), %rsi      # 0x1c05a
callq 0x3370
movq -0x30(%rbp), %rcx
movslq -0x24c(%rbp), %rdx
movq %rax, (%rcx,%rdx,8)
cmpq $0x0, %rax
jne 0x183e1
callq 0x3050
movl (%rax), %edi
leaq -0x140(%rbp), %rdx
leaq 0x4f6c(%rip), %rsi      # 0x1d346
movb $0x0, %al
callq 0x3300
jmp 0x183e3
movl -0x24c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24c(%rbp)
jmp 0x182e6
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x1845e
leaq -0x360(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x8(%rbp), %rcx
leaq 0x6bcd(%rip), %rsi      # 0x1efe6
movb $0x0, %al
callq 0x3400
leaq -0x360(%rbp), %rdi
leaq 0x58aa(%rip), %rsi      # 0x1dcd8
callq 0x3360
movq %rax, -0x258(%rbp)
cmpq $0x0, %rax
jne 0x1845c
callq 0x3050
movl (%rax), %edi
leaq -0x360(%rbp), %rdx
leaq 0x6b97(%rip), %rsi      # 0x1efec
movb $0x0, %al
callq 0x3300
jmp 0x18499
movq -0x8(%rbp), %rdi
leaq 0x586f(%rip), %rsi      # 0x1dcd8
callq 0x3370
movq %rax, -0x258(%rbp)
cmpq $0x0, %rax
jne 0x18497
callq 0x3050
movl (%rax), %edi
leaq -0x360(%rbp), %rdx
leaq 0x6b5c(%rip), %rsi      # 0x1efec
movb $0x0, %al
callq 0x3300
jmp 0x18499
leaq -0x10370(%rbp), %rdi
movq -0x258(%rbp), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x30a0
movl %eax, -0x10374(%rbp)
cmpl $0x0, -0x10374(%rbp)
jg 0x184de
callq 0x3050
movl (%rax), %edi
movq -0x8(%rbp), %rdx
leaq 0x6b24(%rip), %rsi      # 0x1effb
movb $0x0, %al
callq 0x3300
movq $0x1, -0x10380(%rbp)
movq $0x0, -0x10390(%rbp)
movq $0x0, -0x10398(%rbp)
movq $0x0, -0x103b8(%rbp)
movl $0x0, -0x103bc(%rbp)
movl -0x103bc(%rbp), %eax
cmpl -0x10374(%rbp), %eax
jg 0x18a2b
movl -0x103bc(%rbp), %eax
cmpl -0x10374(%rbp), %eax
jne 0x18573
leaq -0x10370(%rbp), %rdi
movq -0x258(%rbp), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x30a0
movl %eax, -0x10374(%rbp)
cmpl $0x0, -0x10374(%rbp)
jle 0x1856c
movl $0x0, -0x103bc(%rbp)
jmp 0x18571
jmp 0x18a2b
jmp 0x18573
movslq -0x103bc(%rbp), %rax
movb -0x10370(%rbp,%rax), %al
movb %al, -0x10381(%rbp)
movsbl -0x10381(%rbp), %eax
movslq %eax, %rcx
leaq 0x63f8(%rip), %rax      # 0x1e990
movl (%rax,%rcx,4), %eax
movl %eax, -0x10388(%rbp)
cmpl $-0x1, -0x10388(%rbp)
je 0x18610
movq -0x10390(%rbp), %rax
shlq $0x2, %rax
movslq -0x10388(%rbp), %rcx
orq %rcx, %rax
andq 0x4c06a(%rip), %rax     # 0x64630
movq %rax, -0x10390(%rbp)
movq -0x10398(%rbp), %rax
shrq $0x2, %rax
movslq -0x10388(%rbp), %rdx
xorq $0x3, %rdx
movl 0x4c043(%rip), %ecx     # 0x6462c
shlq %cl, %rdx
movq %rdx, %rcx
addq %rcx, %rax
movq %rax, -0x10398(%rbp)
movq -0x10380(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x10380(%rbp)
jmp 0x18847
movsbl -0x10381(%rbp), %eax
cmpl $0xa, %eax
je 0x18628
movsbl -0x10381(%rbp), %eax
cmpl $0xd, %eax
jne 0x1862d
jmp 0x18a17
callq 0x34a0
movq (%rax), %rax
movsbl -0x10381(%rbp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x1865d
movq $0x1, -0x10380(%rbp)
jmp 0x18a17
movsbl -0x10381(%rbp), %eax
cmpl $0x3e, %eax
jne 0x18837
movq -0x103b8(%rbp), %rax
cmpq -0x248(%rbp), %rax
jbe 0x1875a
movl $0x0, -0x103c0(%rbp)
movl -0x103c0(%rbp), %eax
cmpl 0x4bf8d(%rip), %eax     # 0x64624
jge 0x18746
movq -0x28(%rbp), %rax
movslq -0x103c0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x248(%rbp), %rsi
addq $0xf4240, %rsi          # imm = 0xF4240
shlq $0x3, %rsi
callq 0x3320
movq %rax, -0x103c8(%rbp)
cmpq $0x0, -0x103c8(%rbp)
je 0x18715
movq -0x103c8(%rbp), %rdx
movq -0x28(%rbp), %rax
movslq -0x103c0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x103c0(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x248(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
xorl %esi, %esi
movl $0x7a1200, %edx         # imm = 0x7A1200
callq 0x31f0
jmp 0x18730
callq 0x3050
movl (%rax), %edi
movl -0x103c0(%rbp), %edx
leaq 0x68f9(%rip), %rsi      # 0x1f022
movb $0x0, %al
callq 0x3300
jmp 0x18732
movl -0x103c0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x103c0(%rbp)
jmp 0x1868b
movq -0x248(%rbp), %rax
addq $0xf4240, %rax          # imm = 0xF4240
movq %rax, -0x248(%rbp)
movq -0x103b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x103b8(%rbp)
movl -0x103bc(%rbp), %ecx
xorl %eax, %eax
cmpl -0x10374(%rbp), %ecx
movb %al, -0x103ed(%rbp)
jge 0x1879d
movslq -0x103bc(%rbp), %rax
movsbl -0x10370(%rbp,%rax), %eax
cmpl $0xa, %eax
setne %al
movb %al, -0x103ed(%rbp)
movb -0x103ed(%rbp), %al
testb $0x1, %al
jne 0x187a9
jmp 0x18827
movl -0x103bc(%rbp), %eax
movl -0x10374(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x187cd
movl -0x103bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x103bc(%rbp)
jmp 0x18822
leaq -0x10370(%rbp), %rdi
movq -0x258(%rbp), %rcx
movl $0x1, %esi
movl $0x10000, %edx          # imm = 0x10000
callq 0x30a0
movl %eax, -0x10374(%rbp)
cmpl $0x0, -0x10374(%rbp)
jle 0x18805
movl $0xffffffff, -0x103bc(%rbp) # imm = 0xFFFFFFFF
jmp 0x18820
callq 0x3050
movl (%rax), %edi
movl -0x10374(%rbp), %edx
leaq 0x6826(%rip), %rsi      # 0x1f03f
movb $0x0, %al
callq 0x3300
jmp 0x18822
jmp 0x1876c
movq $0x1, -0x10380(%rbp)
jmp 0x18a17
movq $0x1, -0x10380(%rbp)
jmp 0x18a17
movq -0x10380(%rbp), %rax
movslq 0x4bde3(%rip), %rcx     # 0x64638
cmpq %rcx, %rax
jbe 0x18a15
movq -0x10390(%rbp), %rax
cmpq -0x10398(%rbp), %rax
jae 0x1887e
movq -0x10390(%rbp), %rax
movq %rax, -0x103f8(%rbp)
jmp 0x1888c
movq -0x10398(%rbp), %rax
movq %rax, -0x103f8(%rbp)
movq -0x103f8(%rbp), %rax
movq %rax, -0x103a0(%rbp)
movq -0x103a0(%rbp), %rax
andq 0x4bd98(%rip), %rax     # 0x64640
movl 0x4bd66(%rip), %ecx     # 0x64614
shll %ecx
movl %ecx, %ecx
shrq %cl, %rax
movl %eax, -0x103cc(%rbp)
movq 0x4bd8e(%rip), %rax     # 0x64650
movslq -0x103cc(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movq %rax, -0x103b0(%rbp)
movq -0x103b0(%rbp), %rax
movslq 0x4bd7e(%rip), %rcx     # 0x64660
cmpq %rcx, %rax
jae 0x188fa
movq -0x103b0(%rbp), %rax
movslq 0x4bd67(%rip), %rcx     # 0x6465c
cmpq %rcx, %rax
jae 0x188ff
jmp 0x18a17
movq -0x103b0(%rbp), %rax
movslq 0x4bd4f(%rip), %rcx     # 0x6465c
subq %rcx, %rax
movq %rax, -0x103b0(%rbp)
movq -0x103a0(%rbp), %rax
andq 0x4bd23(%rip), %rax     # 0x64648
movq -0x103a0(%rbp), %rdx
movl 0x4bce2(%rip), %ecx     # 0x64614
shll %ecx
movl %ecx, %ecx
movl $0x1, %esi
shlq %cl, %rsi
movq %rsi, %rcx
subq $0x1, %rcx
andq %rcx, %rdx
movl 0x4bcea(%rip), %ecx     # 0x64638
shll %ecx
movl 0x4bcbe(%rip), %esi     # 0x64614
shll $0x2, %esi
subl %esi, %ecx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
addq %rcx, %rax
movl 0x4bcac(%rip), %ecx     # 0x64618
shll $0x2, %ecx
movl %ecx, %ecx
shrq %cl, %rax
addq -0x103b0(%rbp), %rax
movq %rax, -0x103a8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x10408(%rbp)
movq -0x103a8(%rbp), %rax
movslq 0x4bc89(%rip), %rcx     # 0x64624
xorl %edx, %edx
divq %rcx
movq -0x10408(%rbp), %rax
movq (%rax,%rdx,8), %rax
movq -0x103b8(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x103a8(%rbp), %rax
movl -0x1c(%rbp), %ecx
shrq %cl, %rax
movl %eax, -0x103d0(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x10400(%rbp)
movq -0x103a8(%rbp), %rax
movslq 0x4bc3a(%rip), %rcx     # 0x64624
xorl %edx, %edx
divq %rcx
movq -0x10400(%rbp), %rax
movl %edx, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
leaq -0x103d0(%rbp), %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x3420
jmp 0x18a17
movl -0x103bc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x103bc(%rbp)
jmp 0x18514
movl $0x0, -0x103d4(%rbp)
movl -0x103d4(%rbp), %eax
cmpl 0x4bbe3(%rip), %eax     # 0x64624
jge 0x18b0a
movq $0x0, -0x103e0(%rbp)
movq $0x0, -0x103e8(%rbp)
movq -0x103e8(%rbp), %rax
cmpq -0x103b8(%rbp), %rax
ja 0x18ace
movq -0x28(%rbp), %rax
movslq -0x103d4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x103e8(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq -0x103e0(%rbp), %rax
movq %rax, -0x103e0(%rbp)
movq -0x30(%rbp), %rax
movslq -0x103d4(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
leaq -0x103e0(%rbp), %rdi
movl $0x8, %esi
movl $0x1, %edx
callq 0x3420
movq -0x103e8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x103e8(%rbp)
jmp 0x18a5d
movq -0x38(%rbp), %rax
movslq -0x103d4(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x30e0
movq -0x30(%rbp), %rax
movslq -0x103d4(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x30e0
movl -0x103d4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x103d4(%rbp)
jmp 0x18a35
movq -0x8(%rbp), %rsi
leaq 0x6563(%rip), %rdi      # 0x1f078
movb $0x0, %al
callq 0x3150
movl $0x1, %eax
addq $0x10410, %rsp          # imm = 0x10410
popq %rbp
retq
nopw (%rax,%rax)