// File: /workspace/github_c_makefile_star2_O2/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 $0x4318, %rsp           # imm = 0x4318
movq %rdi, %r12
callq 0x103a0
movl 0x8(%rax), %ecx
movq %rcx, %r14
leal (,%rcx,4), %ecx
pushq $0x1
popq %rdx
movl %ecx, 0x48(%rsp)
shlq %cl, %rdx
movl %edx, %ecx
xorl %edx, %edx
xorl %ebx, %ebx
cmpq %rdx, %rcx
je 0xcbfd
movq 0x10(%rax), %rsi
movslq (%rsi,%rdx,4), %rsi
cmpq $0xfff, %rsi            # imm = 0xFFF
jg 0xcbf8
movl %edx, 0x310(%rsp,%rsi,4)
incl %ebx
incq %rdx
jmp 0xcbd9
cmpl $0x1000, %ebx           # imm = 0x1000
jne 0xcf9e
movl 0x4(%rax), %r15d
movl 0xc(%rax), %ebp
movl %r15d, %eax
subl %ebp, %eax
xorl %ecx, %ecx
cmpl $0x8, %eax
leal -0x1c(,%rax,4), %eax
cmovll %ecx, %eax
movl %eax, 0x44(%rsp)
cmpl $0x1, 0x208(%r12)
jne 0xcfba
movq 0x210(%r12), %rax
movq (%rax), %rdi
leaq 0x7b17(%rip), %rsi      # 0x14760
callq 0x68a5
testq %rax, %rax
je 0xcfcf
movq %rax, %rbx
leaq 0x7406(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0xcfea
movl %r15d, %ecx
subl %r14d, %ecx
addl %ecx, %ecx
movl %ecx, 0x40(%rsp)
subl %ebp, %r14d
shll $0x2, %r14d
movq %r14, 0x58(%rsp)
addl %r15d, %r15d
movl %r15d, 0x28(%rsp)
movq 0x210(%r12), %rcx
movq (%rcx), %r12
leaq 0x60(%rsp), %rbx
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %rax, %rcx
callq 0x30c0
leaq 0x9106(%rip), %rsi      # 0x15dc0
leaq 0x80(%rsp), %r15
movq %r15, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0x280(%rsp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x32e0
movq 0x30(%r14), %r14
movq %r14, %rax
shrq $0x3, %rax
movq %rax, 0x30(%rsp)
decq %rax
movq %rax, 0x50(%rsp)
movslq 0x10(%rbx), %r15
movq %r15, %rbx
shlq $0x3, %rbx
movq %rbx, %rdi
callq 0x3340
movq %rax, 0x10(%rsp)
movq %rbx, %rdi
movq %r12, %rbx
callq 0x3340
movq %rax, 0x18(%rsp)
andq $-0x8, %r14
movq %r14, 0x38(%rsp)
testl %r15d, %r15d
movl $0x0, %eax
cmovgl %r15d, %eax
movq %rax, 0x20(%rsp)
leaq 0x7324(%rip), %rbp      # 0x14067
leaq 0x180(%rsp), %r13
xorl %r15d, %r15d
cmpq %r15, 0x20(%rsp)
je 0xce20
movq 0x38(%rsp), %rdi
callq 0x3340
movq %rax, %r12
movq 0x10(%rsp), %rax
movq %r12, (%rax,%r15,8)
leaq 0x80(%rsp), %r14
movq %r14, %rdi
leaq 0x72fd(%rip), %rsi      # 0x1407e
movq %rbx, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %rbp, %rsi
callq 0x33a0
testq %rax, %rax
je 0xcf81
movq %rbx, %r14
movq %rax, %rbx
movq %r12, %rdi
pushq $0x8
popq %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %rbx, %rdi
callq 0x3100
movq %r13, %rdi
leaq 0x72c4(%rip), %rsi      # 0x14091
movq %r14, %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3430
movq %r13, %rdi
movq %rbp, %rsi
callq 0x33a0
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
testq %rax, %rax
movq %r14, %rbx
jne 0xcd4e
callq 0x3060
movl (%rax), %edi
decl %r15d
leaq 0x8fde(%rip), %rsi      # 0x15dec
leaq 0x180(%rsp), %rdx
movl %r15d, %ecx
xorl %eax, %eax
callq 0x3330
movl 0x28(%rsp), %ebx
movl %ebx, %eax
orl $0x1, %eax
movslq %eax, %rdi
callq 0x3340
movq %rax, %r12
movslq %ebx, %rax
movb $0x0, (%r12,%rax)
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
movq %rcx, 0x28(%rsp)
decl %eax
movq %rax, 0x30(%rsp)
leaq 0x9e57(%rip), %r14      # 0x16cb0
xorl %r15d, %r15d
cmpq 0x50(%rsp), %r15
je 0xcf2e
movq %r15, 0x38(%rsp)
leaq 0x1(%r15), %rsi
leaq 0x8f93(%rip), %rdi      # 0x15e0a
movq %rsi, %r15
xorl %eax, %eax
callq 0x3170
xorl %r13d, %r13d
cmpq 0x20(%rsp), %r13
je 0xce5c
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rbp
xorl %ebx, %ebx
movq (%rbp,%r15,8), %rax
movq 0x38(%rsp), %rcx
subq (%rbp,%rcx,8), %rax
cmpq %rax, %rbx
jae 0xcf26
movq 0x18(%rsp), %rax
movq (%rax,%r13,8), %rcx
leaq 0x4c(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x30c0
movl 0x4c(%rsp), %edi
leaq 0x310(%rsp), %rax
movq %rax, (%rsp)
movl %r13d, %esi
movl 0x44(%rsp), %edx
movq 0x58(%rsp), %rcx
movl 0x48(%rsp), %r8d
movl 0x40(%rsp), %r9d
callq 0xd595
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rdx
subq $0x1, %rcx
jb 0xcf16
movl %eax, %esi
andl $0x3, %esi
movb (%r14,%rsi), %sil
movslq %edx, %rdx
movb %sil, (%r12,%rdx)
shrq $0x2, %rax
decl %edx
jmp 0xcef8
movq %r12, %rdi
callq 0x30a0
incq %rbx
jmp 0xce96
incq %r13
jmp 0xce84
xorl %ebx, %ebx
cmpq %rbx, 0x20(%rsp)
je 0xcf58
movq 0x18(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x3100
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x3040
incq %rbx
jmp 0xcf30
movq 0x10(%rsp), %rdi
callq 0x3040
movq 0x18(%rsp), %rdi
callq 0x3040
pushq $0x1
popq %rax
addq $0x4318, %rsp           # imm = 0x4318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x8e43(%rip), %rsi      # 0x15dd2
leaq 0x80(%rsp), %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x8dad(%rip), %rsi      # 0x15d59
movl %ebx, %edx
movl $0x1000, %ecx           # imm = 0x1000
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0x8dbd(%rip), %rsi      # 0x15d85
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
movq 0x210(%r12), %rax
movq (%rax), %rdx
leaq 0x8db9(%rip), %rsi      # 0x15da1
jmp 0xcf97
callq 0x3060
movl (%rax), %edi
leaq 0x7a1b(%rip), %rsi      # 0x14a13
movq %rbx, %rdx
jmp 0xcf97