// File: /workspace/github_c_makefile_star2_O0/yhg926[P]public_kssd/command_reverse.c
// Function: co_reverse2kmer
int co_reverse2kmer(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 >0 ))
  err(errno,"need speficy the 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);
 ctx_obj_ct_t * qry_ctx_ct_list = malloc(co_qry_dstat.infile_num * sizeof(ctx_obj_ct_t));
 fread(qry_ctx_ct_list,sizeof(ctx_obj_ct_t),co_qry_dstat.infile_num,qry_co_stat_fp);
 char (*cofname)[PATHLEN] = malloc(co_qry_dstat.infile_num * PATHLEN);
 fread(cofname,PATHLEN,co_qry_dstat.infile_num,qry_co_stat_fp);
 fclose(qry_co_stat_fp);
 FILE *cbd_fcode_comp_fp,*cbd_fcode_comp_index_fp;
  struct stat cbd_fcode_stat;
 size_t *fco_pos = malloc(sizeof(size_t) * (co_qry_dstat.infile_num + 1) );
 char co_cbd_fcode[PATHLEN];char co_cbd_index_fcode[PATHLEN];
 llong **kmer = malloc( co_qry_dstat.infile_num * sizeof(llong*) );
 int *filled_len = calloc( co_qry_dstat.infile_num, sizeof(int));
 for(int k = 0; k < co_qry_dstat.infile_num; k++){
  kmer[k] = malloc( sizeof(llong) * qry_ctx_ct_list[k] );
 }
 int p_fit_mem = opt_val->p ;
 for ( int j = 0; j < co_qry_dstat.comp_num; j++ ) {
  sprintf(co_cbd_fcode,"%s/combco.%d",qryco_dname,j);
  if( (cbd_fcode_comp_fp = fopen(co_cbd_fcode,"rb"))==NULL) err(errno,"co_reverse2kmer()::%s",co_cbd_fcode);
    stat(co_cbd_fcode, &cbd_fcode_stat);
  unsigned int *cbd_fcode_mem = malloc(cbd_fcode_stat.st_size);
  fread(cbd_fcode_mem,sizeof(unsigned int),cbd_fcode_stat.st_size/sizeof(unsigned int),cbd_fcode_comp_fp);
  fclose(cbd_fcode_comp_fp);
  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_reverse2kmer()::%s",co_cbd_index_fcode);
  fread(fco_pos,sizeof(size_t),co_qry_dstat.infile_num + 1 ,cbd_fcode_comp_index_fp);
  fclose(cbd_fcode_comp_index_fp);
  #pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
  for(int k = 0; k < co_qry_dstat.infile_num; k++){
   if(qry_ctx_ct_list[k]==0) continue;
   char *kstring = malloc(TL + 1);
   kstring[TL] = '\0';
   for(int n = 0; n < fco_pos[k+1] - fco_pos[k]; n++){
    unsigned int ind = cbd_fcode_mem[ fco_pos[k] + n ];
    kmer[k][filled_len[k] + n] = core_reverse2unituple(ind,j,comp_code_bits,pf_bits,inner_ctx_bits,half_outer_ctx_bits,rev_shuf_arr);
   }
   filled_len[k] += (fco_pos[k+1] - fco_pos[k]) ;
  }
 }
 #pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
 for(int k = 0; k < co_qry_dstat.infile_num; k++) {
  if(qry_ctx_ct_list[k]==0) continue;
    char *kstring = malloc(TL + 1);
    kstring[TL] = '\0';
  char *filename;
  (filename = strrchr(cofname[k],'/') ) ? ++filename : (filename = cofname[k]);
  char fullname[PATHLEN];
  sprintf(fullname,"%s/%s",opt_val->outdir,filename);
  FILE *kmerf;
  if ( ( kmerf = fopen(fullname,"w")) == NULL ) err(errno,"%s",filename);
  for (int n =0 ; n< qry_ctx_ct_list[k]; n++){
   llong unituple = kmer[k][n];
   for(int i=0; i<TL;i++){
    kstring[TL-i-1] = Mapbase[unituple % 4] ;
    unituple >>= 2 ;
   }
   fprintf(kmerf,"%s\n",kstring);
  }
  fclose(kmerf);
 }
 return co_qry_dstat.infile_num;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x44c0, %rsp           # imm = 0x44C0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x16300
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shll $0x2, %eax
movl %eax, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movl %eax, -0x14(%rbp)
movl $0x0, -0x4024(%rbp)
movl $0x0, -0x4028(%rbp)
movl -0x4028(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x113ac
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4028(%rbp), %ecx
cmpl $0x1000, (%rax,%rcx,4)  # imm = 0x1000
jge 0x11399
movl -0x4028(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4028(%rbp), %edx
movslq (%rax,%rdx,4), %rax
movl %ecx, -0x4020(%rbp,%rax,4)
movl -0x4024(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4024(%rbp)
jmp 0x1139b
movl -0x4028(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4028(%rbp)
jmp 0x11349
cmpl $0x1000, -0x4024(%rbp)  # imm = 0x1000
je 0x113d8
callq 0x3050
movl (%rax), %edi
movl -0x4024(%rbp), %edx
leaq 0xc8a7(%rip), %rsi      # 0x1dc73
movl $0x1000, %ecx           # imm = 0x1000
movb $0x0, %al
callq 0x3300
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
cmpl $0x7, %eax
jle 0x11407
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
subl $0x7, %eax
shll $0x2, %eax
movl %eax, -0x44b0(%rbp)
jmp 0x11411
xorl %eax, %eax
movl %eax, -0x44b0(%rbp)
jmp 0x11411
movl -0x44b0(%rbp), %eax
movl %eax, -0x402c(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shll $0x2, %eax
movl %eax, -0x4030(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0x8(%rcx), %eax
shll %eax
movl %eax, -0x4034(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
subl 0xc(%rcx), %eax
shll $0x2, %eax
movl %eax, -0x4038(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
shll %eax
movl %eax, -0x403c(%rbp)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x208(%rax)
jg 0x1148b
callq 0x3050
movl (%rax), %edi
leaq 0xc8ac(%rip), %rsi      # 0x1dd30
movb $0x0, %al
callq 0x3300
movq $0x0, -0x4048(%rbp)
movq -0x8(%rbp), %rax
movq 0x210(%rax), %rax
movq (%rax), %rdi
leaq 0xb245(%rip), %rsi      # 0x1c6f0
callq 0x8250
movq %rax, -0x4048(%rbp)
cmpq $0x0, -0x4048(%rbp)
jne 0x114e4
callq 0x3050
movl (%rax), %edi
movq -0x8(%rbp), %rax
movq 0x210(%rax), %rax
movq (%rax), %rdx
leaq 0xc7de(%rip), %rsi      # 0x1dcbb
movb $0x0, %al
callq 0x3300
movq -0x4048(%rbp), %rdi
leaq 0xab65(%rip), %rsi      # 0x1c057
callq 0x3370
movq %rax, -0x4050(%rbp)
cmpq $0x0, %rax
jne 0x11520
callq 0x3050
movl (%rax), %edi
movq -0x4048(%rbp), %rdx
leaq 0xb48a(%rip), %rsi      # 0x1c9a3
movb $0x0, %al
callq 0x3300
movq -0x8(%rbp), %rax
movq 0x210(%rax), %rax
movq (%rax), %rax
movq %rax, -0x4058(%rbp)
movq -0x4050(%rbp), %rcx
leaq -0x4078(%rbp), %rdi
movl $0x20, %esi
movl $0x1, %edx
callq 0x30a0
movslq -0x4064(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3310
movq %rax, -0x4080(%rbp)
movq -0x4080(%rbp), %rdi
movslq -0x4064(%rbp), %rdx
movq -0x4050(%rbp), %rcx
movl $0x4, %esi
callq 0x30a0
movl -0x4064(%rbp), %eax
shll $0x8, %eax
movslq %eax, %rdi
callq 0x3310
movq %rax, -0x4088(%rbp)
movq -0x4088(%rbp), %rdi
movslq -0x4064(%rbp), %rdx
movq -0x4050(%rbp), %rcx
movl $0x100, %esi            # imm = 0x100
callq 0x30a0
movq -0x4050(%rbp), %rdi
callq 0x30e0
movl -0x4064(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x4130(%rbp)
movslq -0x4064(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x4338(%rbp)
movslq -0x4064(%rbp), %rdi
movl $0x4, %esi
callq 0x3270
movq %rax, -0x4340(%rbp)
movl $0x0, -0x4344(%rbp)
movl -0x4344(%rbp), %eax
cmpl -0x4064(%rbp), %eax
jge 0x11670
movq -0x4080(%rbp), %rax
movslq -0x4344(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, %edi
shlq $0x3, %rdi
callq 0x3310
movq %rax, %rdx
movq -0x4338(%rbp), %rax
movslq -0x4344(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x4344(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4344(%rbp)
jmp 0x11620
movq -0x8(%rbp), %rax
movl 0x200(%rax), %eax
movl %eax, -0x4348(%rbp)
movl $0x0, -0x434c(%rbp)
movl -0x434c(%rbp), %eax
cmpl -0x4068(%rbp), %eax
jge 0x11993
leaq -0x4230(%rbp), %rdi
movq -0x4058(%rbp), %rdx
movl -0x434c(%rbp), %ecx
leaq 0xa9ca(%rip), %rsi      # 0x1c081
movb $0x0, %al
callq 0x3400
leaq -0x4230(%rbp), %rdi
leaq 0xa98b(%rip), %rsi      # 0x1c057
callq 0x3370
movq %rax, -0x4090(%rbp)
cmpq $0x0, %rax
jne 0x116fa
callq 0x3050
movl (%rax), %edi
leaq -0x4230(%rbp), %rdx
leaq 0xc659(%rip), %rsi      # 0x1dd4c
movb $0x0, %al
callq 0x3300
leaq -0x4230(%rbp), %rdi
leaq -0x4128(%rbp), %rsi
callq 0x32b0
movq -0x40f8(%rbp), %rdi
callq 0x3310
movq %rax, -0x4358(%rbp)
movq -0x4358(%rbp), %rdi
movq -0x40f8(%rbp), %rdx
shrq $0x2, %rdx
movq -0x4090(%rbp), %rcx
movl $0x4, %esi
callq 0x30a0
movq -0x4090(%rbp), %rdi
callq 0x30e0
leaq -0x4330(%rbp), %rdi
movq -0x4058(%rbp), %rdx
movl -0x434c(%rbp), %ecx
leaq 0xa904(%rip), %rsi      # 0x1c06e
movb $0x0, %al
callq 0x3400
leaq -0x4330(%rbp), %rdi
leaq 0xa8d8(%rip), %rsi      # 0x1c057
callq 0x3370
movq %rax, -0x4098(%rbp)
cmpq $0x0, %rax
jne 0x117ad
callq 0x3050
movl (%rax), %edi
leaq -0x4330(%rbp), %rdx
leaq 0xc5a6(%rip), %rsi      # 0x1dd4c
movb $0x0, %al
callq 0x3300
movq -0x4130(%rbp), %rdi
movl -0x4064(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
movq -0x4098(%rbp), %rcx
movl $0x8, %esi
callq 0x30a0
movq -0x4098(%rbp), %rdi
callq 0x30e0
movl $0x0, -0x435c(%rbp)
movl -0x435c(%rbp), %eax
cmpl -0x4064(%rbp), %eax
jge 0x1197d
movq -0x4080(%rbp), %rax
movslq -0x435c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x11812
jmp 0x11969
movl -0x403c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3310
movq %rax, -0x4368(%rbp)
movq -0x4368(%rbp), %rax
movslq -0x403c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x436c(%rbp)
movslq -0x436c(%rbp), %rax
movq -0x4130(%rbp), %rcx
movl -0x435c(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movq -0x4130(%rbp), %rdx
movslq -0x435c(%rbp), %rsi
subq (%rdx,%rsi,8), %rcx
cmpq %rcx, %rax
jae 0x11928
movq -0x4358(%rbp), %rax
movq -0x4130(%rbp), %rcx
movslq -0x435c(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x436c(%rbp), %rdx
addq %rdx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4370(%rbp)
movl -0x4370(%rbp), %edi
movl -0x434c(%rbp), %esi
movl -0x402c(%rbp), %edx
movl -0x4038(%rbp), %ecx
movl -0x4030(%rbp), %r8d
movl -0x4034(%rbp), %r9d
leaq -0x4020(%rbp), %rax
movq %rax, (%rsp)
callq 0x11bd0
movq %rax, %rdx
movq -0x4338(%rbp), %rax
movslq -0x435c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x4340(%rbp), %rcx
movslq -0x435c(%rbp), %rsi
movl (%rcx,%rsi,4), %ecx
addl -0x436c(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x436c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x436c(%rbp)
jmp 0x11846
movq -0x4130(%rbp), %rax
movl -0x435c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
movq -0x4130(%rbp), %rax
movslq -0x435c(%rbp), %rcx
subq (%rax,%rcx,8), %rsi
movq -0x4340(%rbp), %rax
movslq -0x435c(%rbp), %rcx
movslq (%rax,%rcx,4), %rdx
addq %rsi, %rdx
movl %edx, (%rax,%rcx,4)
movl -0x435c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x435c(%rbp)
jmp 0x117e7
jmp 0x1197f
movl -0x434c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x434c(%rbp)
jmp 0x1168a
movl $0x0, -0x4374(%rbp)
movl -0x4374(%rbp), %eax
cmpl -0x4064(%rbp), %eax
jge 0x11bb8
movq -0x4080(%rbp), %rax
movslq -0x4374(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x119c8
jmp 0x11ba4
movl -0x403c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
callq 0x3310
movq %rax, -0x4380(%rbp)
movq -0x4380(%rbp), %rax
movslq -0x403c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x4088(%rbp), %rdi
movslq -0x4374(%rbp), %rax
shlq $0x8, %rax
addq %rax, %rdi
movl $0x2f, %esi
callq 0x31b0
movq %rax, -0x4388(%rbp)
cmpq $0x0, %rax
je 0x11a32
movq -0x4388(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4388(%rbp)
jmp 0x11a4e
movq -0x4088(%rbp), %rax
movslq -0x4374(%rbp), %rcx
shlq $0x8, %rcx
addq %rcx, %rax
movq %rax, -0x4388(%rbp)
leaq -0x4490(%rbp), %rdi
movq -0x8(%rbp), %rdx
addq $0x100, %rdx            # imm = 0x100
movq -0x4388(%rbp), %rcx
leaq 0xa8bd(%rip), %rsi      # 0x1c32b
movb $0x0, %al
callq 0x3400
leaq -0x4490(%rbp), %rdi
leaq 0xa924(%rip), %rsi      # 0x1c3a7
callq 0x3370
movq %rax, -0x4498(%rbp)
cmpq $0x0, %rax
jne 0x11ab1
callq 0x3050
movl (%rax), %edi
movq -0x4388(%rbp), %rdx
leaq 0xb89c(%rip), %rsi      # 0x1d346
movb $0x0, %al
callq 0x3300
movl $0x0, -0x449c(%rbp)
movl -0x449c(%rbp), %eax
movq -0x4080(%rbp), %rcx
movslq -0x4374(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x11b98
movq -0x4338(%rbp), %rax
movslq -0x4374(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x449c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x44a8(%rbp)
movl $0x0, -0x44ac(%rbp)
movl -0x44ac(%rbp), %eax
cmpl -0x403c(%rbp), %eax
jge 0x11b68
movq -0x44a8(%rbp), %rcx
andq $0x3, %rcx
leaq 0xd06a(%rip), %rax      # 0x1eb90
movb (%rax,%rcx), %dl
movq -0x4380(%rbp), %rax
movl -0x403c(%rbp), %ecx
subl -0x44ac(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movq -0x44a8(%rbp), %rax
shrq $0x2, %rax
movq %rax, -0x44a8(%rbp)
movl -0x44ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44ac(%rbp)
jmp 0x11b06
movq -0x4498(%rbp), %rdi
movq -0x4380(%rbp), %rdx
leaq 0xb8ed(%rip), %rsi      # 0x1d46a
movb $0x0, %al
callq 0x3290
movl -0x449c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x449c(%rbp)
jmp 0x11abb
movq -0x4498(%rbp), %rdi
callq 0x30e0
movl -0x4374(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4374(%rbp)
jmp 0x1199d
movl -0x4064(%rbp), %eax
addq $0x44c0, %rsp           # imm = 0x44C0
popq %rbp
retq
nopw (%rax,%rax)