// File: /workspace/github_c_makefile_star2_O3/yhg926[P]public_kssd/command_reverse.c
// Function: co_rvs2kmer_byreads
int co_rvs2kmer_byreads( reverse_opt_val_t *opt_val ){
  dim_shuffle_t* shuf_arr = read_dim_shuffle_file(opt_val->shufile);
 int shuf_arr_len = 1LLU << (4 * shuf_arr->dim_shuffle_stat.subk) ;
 unsigned int rev_shuf_arr[MIN_SUBCTX_DIM_SMP_SZ];
 int count = 0;
  for(unsigned int i=0; i< shuf_arr_len; i++) {
    if( shuf_arr->shuffled_dim[i] < MIN_SUBCTX_DIM_SMP_SZ ){
      rev_shuf_arr[shuf_arr->shuffled_dim[i]] = i ;
      count++;
    }
  }
 if(count != MIN_SUBCTX_DIM_SMP_SZ) err(errno,"count %d not match MIN_SUBCTX_DIM_SMP_SZ %d",count,MIN_SUBCTX_DIM_SMP_SZ);
 int comp_code_bits = shuf_arr->dim_shuffle_stat.k - shuf_arr->dim_shuffle_stat.drlevel > COMPONENT_SZ
                      ? 4*(shuf_arr->dim_shuffle_stat.k - shuf_arr->dim_shuffle_stat.drlevel - COMPONENT_SZ ) : 0 ;
 int inner_ctx_bits = shuf_arr->dim_shuffle_stat.subk * 4;
 int half_outer_ctx_bits = (shuf_arr->dim_shuffle_stat.k - shuf_arr->dim_shuffle_stat.subk) *2 ;
 int pf_bits = ( shuf_arr->dim_shuffle_stat.subk - shuf_arr->dim_shuffle_stat.drlevel ) * 4;
 int TL = shuf_arr->dim_shuffle_stat.k * 2;
 if (!(opt_val->num_remaining_args == 1 ))
  err(errno,"need speficy one query path");
 const char *qryco_dstat_fpath = NULL;
 qryco_dstat_fpath = test_get_fullpath(opt_val->remaining_args[0],co_dstat);
 if( qryco_dstat_fpath == NULL )
 err(errno,"%s is not a valid query folder",opt_val->remaining_args[0]);
 FILE *qry_co_stat_fp;
 if (( qry_co_stat_fp = fopen(qryco_dstat_fpath,"rb")) == NULL) err(errno,"qry co stat file:%s",qryco_dstat_fpath);
 char *qryco_dname = opt_val->remaining_args[0];
 co_dstat_t co_qry_dstat;
 fread( &co_qry_dstat, sizeof(co_dstat_t), 1, qry_co_stat_fp);
 FILE *cbd_fcode_comp_index_fp;
 char co_cbd_fcode[PATHLEN];char co_cbd_index_fcode[PATHLEN];
 struct stat fstat;
 sprintf(co_cbd_index_fcode,"%s/combco.index.0",qryco_dname);
 stat(co_cbd_index_fcode, &fstat);
 llong readn = fstat.st_size/sizeof(size_t) - 1 ;
 size_t **cbd_fcode_index_mem = (size_t **) malloc( co_qry_dstat.comp_num * sizeof(size_t *));
 FILE **cbd_fcode_comp_fp = (FILE **) malloc(co_qry_dstat.comp_num * sizeof(FILE *)) ;
 for ( int j = 0; j < co_qry_dstat.comp_num; j++ ){
  cbd_fcode_index_mem[j] = (size_t *) malloc( (readn+1)* sizeof(size_t));
  sprintf(co_cbd_index_fcode,"%s/combco.index.%d",qryco_dname,j);
  if( (cbd_fcode_comp_index_fp = fopen(co_cbd_index_fcode,"rb"))==NULL) err(errno,"co_rvs2kmer_btreads()::%s",co_cbd_index_fcode);
  fread(cbd_fcode_index_mem[j],sizeof(size_t),readn+1,cbd_fcode_comp_index_fp);
  fclose(cbd_fcode_comp_index_fp);
  sprintf(co_cbd_fcode,"%s/combco.%d",qryco_dname,j);
  if( (cbd_fcode_comp_fp[j] = fopen(co_cbd_fcode,"rb"))==NULL) err(errno,"co_rvs2kmer_btreads()::%s[%d]",co_cbd_fcode,j);
 }
 char *kstring = malloc(TL + 1);
 kstring[TL] = '\0';
 unsigned int ind;
 for(llong n=0; n< readn;n++){
  printf(">read %llu\n", n+1);
  for ( int j = 0; j < co_qry_dstat.comp_num; j++ ){
   for ( llong k=0; k< cbd_fcode_index_mem[j][n+1]-cbd_fcode_index_mem[j][n]; k++){
    fread(&ind,sizeof(unsigned int),1,cbd_fcode_comp_fp[j]);
    llong unituple = core_reverse2unituple(ind,j,comp_code_bits,pf_bits,inner_ctx_bits,half_outer_ctx_bits,rev_shuf_arr);
    for(int i=0; i<TL;i++){
     kstring[TL-i-1] = Mapbase[unituple % 4] ;
     unituple >>= 2 ;
    }
    printf("%s\n",kstring);
   }
  }
 }
 for ( int j = 0; j < co_qry_dstat.comp_num; j++ ){
  fclose(cbd_fcode_comp_fp[j]);
   free(cbd_fcode_index_mem[j]);
 }
 free(cbd_fcode_index_mem);
 free(cbd_fcode_comp_fp);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4348, %rsp           # imm = 0x4348
movq %rdi, %rbx
callq 0x112a1
movl 0x8(%rax), %r12d
leal (,%r12,4), %r15d
cmpl $0x1f, %r15d
ja 0xdb02
movl $0x1, %esi
movl %r15d, %ecx
shlq %cl, %rsi
movq 0x10(%rax), %rcx
cmpl $0x2, %esi
movl $0x1, %edx
cmovael %esi, %edx
xorl %esi, %esi
xorl %ebp, %ebp
movslq (%rcx,%rsi,4), %rdi
cmpq $0xfff, %rdi            # imm = 0xFFF
jg 0xd67e
movl %esi, 0x340(%rsp,%rdi,4)
incl %ebp
incq %rsi
cmpq %rsi, %rdx
jne 0xd668
cmpl $0x1000, %ebp           # imm = 0x1000
jne 0xdb04
movl 0x4(%rax), %ecx
movl 0xc(%rax), %ebp
movq %rcx, %rax
movq %rcx, 0x38(%rsp)
subl %ebp, %eax
xorl %ecx, %ecx
cmpl $0x8, %eax
leal -0x1c(,%rax,4), %r13d
cmovll %ecx, %r13d
cmpl $0x1, 0x208(%rbx)
jne 0xdb20
movq 0x210(%rbx), %rax
movq (%rax), %rdi
leaq 0x80df(%rip), %rsi      # 0x157b0
callq 0x6d79
testq %rax, %rax
je 0xdb35
movq %rax, %r14
movl %r13d, 0x30(%rsp)
movl %ebp, 0x8(%rsp)
movq %r12, 0x40(%rsp)
leaq 0x7970(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xdb4f
movq %r15, 0x58(%rsp)
movq 0x210(%rbx), %rcx
movq (%rcx), %rbx
leaq 0x90(%rsp), %r14
movl $0x20, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %rax, %rcx
callq 0x30c0
leaq 0x96d5(%rip), %rsi      # 0x16e10
leaq 0xb0(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x2b0(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x32e0
movq 0x30(%r12), %rax
movq %rax, 0x10(%rsp)
shrq $0x3, %rax
movq %rax, 0x18(%rsp)
movslq 0x10(%r14), %r13
leaq (,%r13,8), %r14
movq %r14, %rdi
callq 0x3340
movq %rax, 0x28(%rsp)
movq %r14, %rdi
callq 0x3340
movq %rax, 0x20(%rsp)
testq %r13, %r13
movq %r13, 0x50(%rsp)
jle 0xd870
andq $-0x8, 0x10(%rsp)
leaq 0x78b0(%rip), %rbp      # 0x15067
leaq 0x1b0(%rsp), %r12
xorl %r15d, %r15d
movq 0x10(%rsp), %rdi
callq 0x3340
movq %rax, %r14
movq 0x28(%rsp), %rax
movq %r14, (%rax,%r15,8)
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
leaq 0x7894(%rip), %rsi      # 0x1507e
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
movq %rbp, %rsi
callq 0x33a0
testq %rax, %rax
je 0xdac5
movq %rax, %r13
movl $0x8, %esi
movq %r14, %rdi
movq 0x18(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %r13, %rdi
callq 0x3100
movq %r12, %rdi
leaq 0x785c(%rip), %rsi      # 0x15091
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r12, %rdi
movq %rbp, %rsi
callq 0x33a0
movq 0x20(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
testq %rax, %rax
je 0xdae2
incq %r15
movq 0x50(%rsp), %r13
cmpq %r15, %r13
jne 0xd7c2
movq 0x38(%rsp), %rax
leal (%rax,%rax), %ebx
movq 0x18(%rsp), %r14
decq %r14
movl %ebx, %eax
orl $0x1, %eax
movslq %eax, %rdi
callq 0x3340
movslq %ebx, %rdx
movq %rax, 0x60(%rsp)
movb $0x0, (%rax,%rdx)
movq %r14, 0x18(%rsp)
testq %r14, %r14
je 0xda73
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rsi
subl %esi, %eax
addl %eax, %eax
subl 0x8(%rsp), %esi
shll $0x2, %esi
movl 0x30(%rsp), %ecx
movq %rcx, 0x30(%rsp)
movq $-0x1, %rdi
movl %eax, %ecx
shlq %cl, %rdi
movl %esi, %ecx
movq %rcx, 0x80(%rsp)
movq $-0x1, %r8
notq %rdi
movq 0x58(%rsp), %rsi
movl %esi, %ecx
shlq %cl, %rdi
movq %rdi, 0x88(%rsp)
movl %eax, %ecx
shlq %cl, %rdi
movq %rdi, 0x70(%rsp)
movl %esi, %ecx
shlq %cl, %r8
movl %eax, %eax
movq %rax, 0x68(%rsp)
notq %r8
movq %r8, 0x78(%rsp)
cmpl $0x2, %edx
movl $0x1, %r12d
cmovgel %edx, %r12d
movq 0x60(%rsp), %rax
leaq (%rdx,%rax), %r14
decq %r14
negq %r12
leaq 0xa3c8(%rip), %r15      # 0x17d00
xorl %ebp, %ebp
movq %rbp, 0x10(%rsp)
incq %rbp
leaq 0x9511(%rip), %rdi      # 0x16e5a
movq %rbp, %rsi
xorl %eax, %eax
callq 0x3170
testl %r13d, %r13d
jle 0xda68
xorl %ecx, %ecx
movq 0x28(%rsp), %rax
movq %rcx, 0x8(%rsp)
movq (%rax,%rcx,8), %rbx
movq (%rbx,%rbp,8), %rax
movq 0x10(%rsp), %rcx
cmpq (%rbx,%rcx,8), %rax
je 0xda52
movq 0x20(%rsp), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, 0x40(%rsp)
xorl %r13d, %r13d
movl $0x4, %esi
movl $0x1, %edx
leaq 0x4c(%rsp), %rdi
movq 0x40(%rsp), %rcx
callq 0x30c0
cmpl $0x0, 0x38(%rsp)
jle 0xda2f
movl 0x4c(%rsp), %eax
movq 0x30(%rsp), %rcx
shlq %cl, %rax
addq 0x8(%rsp), %rax
movq %rax, %rdx
movq 0x80(%rsp), %rcx
shrq %cl, %rdx
movq 0x58(%rsp), %rcx
shlq %cl, %rdx
andl $0xfff, %eax            # imm = 0xFFF
movl 0x340(%rsp,%rax,4), %eax
addq %rdx, %rax
movq %rax, %rdx
andq 0x88(%rsp), %rdx
shrq %cl, %rdx
movq %rax, %rsi
andq 0x78(%rsp), %rax
movq 0x68(%rsp), %rcx
shlq %cl, %rax
andq 0x70(%rsp), %rsi
addq %rdx, %rsi
addq %rsi, %rax
xorl %ecx, %ecx
movl %eax, %edx
andl $0x3, %edx
movb (%r15,%rdx), %dl
movb %dl, (%r14,%rcx)
shrq $0x2, %rax
decq %rcx
cmpq %rcx, %r12
jne 0xda16
movq 0x60(%rsp), %rdi
callq 0x30a0
incq %r13
movq (%rbx,%rbp,8), %rax
movq 0x10(%rsp), %rcx
subq (%rbx,%rcx,8), %rax
cmpq %rax, %r13
jb 0xd995
movq 0x8(%rsp), %rcx
incq %rcx
movq 0x50(%rsp), %r13
cmpq %r13, %rcx
jne 0xd95e
cmpq 0x18(%rsp), %rbp
jne 0xd93a
testl %r13d, %r13d
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %r15
jle 0xda9e
xorl %ebx, %ebx
movq (%r15,%rbx,8), %rdi
callq 0x3100
movq (%r14,%rbx,8), %rdi
callq 0x3040
incq %rbx
cmpq %rbx, %r13
jne 0xda84
movq %r14, %rdi
callq 0x3040
movq %r15, %rdi
callq 0x3040
movl $0x1, %eax
addq $0x4348, %rsp           # imm = 0x4348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x934f(%rip), %rsi      # 0x16e22
leaq 0xb0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x934c(%rip), %rsi      # 0x16e3c
leaq 0x1b0(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3330
xorl %ebp, %ebp
callq 0x3060
movl (%rax), %edi
leaq 0x9297(%rip), %rsi      # 0x16da9
movl %ebp, %edx
movl $0x1000, %ecx           # imm = 0x1000
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x92a7(%rip), %rsi      # 0x16dd5
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
movq 0x210(%rbx), %rax
movq (%rax), %rdx
leaq 0x92a4(%rip), %rsi      # 0x16df1
jmp 0xdadb
callq 0x3060
movl (%rax), %edi
leaq 0x7f06(%rip), %rsi      # 0x15a63
movq %r14, %rdx
jmp 0xdadb