// File: /workspace/github_c_makefile_star2_O2/yhg926[P]public_kssd/command_composite.c
// Function: index_abv
int index_abv (composite_opt_t *composite_opt){
 char* abv_dpath = malloc(PATHLEN);
 sprintf(abv_dpath,"%s/%s", composite_opt->refdir,binVec_dirname);
 DIR *abv_dir = opendir(abv_dpath);
 if(!abv_dir) err(errno, "index_abv(): %s does not exists! \n",abv_dpath);
 const char *ref_dstat_fpath = test_get_fullpath(composite_opt->refdir,co_dstat);
 if (ref_dstat_fpath == NULL) err(errno,"cannot find %s under %s ",co_dstat, composite_opt->refdir);
 FILE *ref_dstat_fp;
 if( (ref_dstat_fp = fopen(ref_dstat_fpath,"rb")) == NULL ) err(errno, "index_abv():%s",ref_dstat_fpath);
 co_dstat_t ref_dstat;
 fread( &ref_dstat, sizeof(co_dstat_t),1,ref_dstat_fp);
 fclose(ref_dstat_fp);
 int *abunMtx_count = calloc(ref_dstat.infile_num,sizeof(int));
 binVec_t **abunMtx_dynamic = malloc(sizeof(binVec_t *) * ref_dstat.infile_num);
 for(int i =0; i< ref_dstat.infile_num;i++) abunMtx_dynamic[i] = malloc(sizeof(binVec_t));
 int abv_fcnt = 0;
 FILE *abvfh,*namefh,*abunMtx_idxfh,*abunMtx_fh,*y_l2n_fh;
 struct dirent *dirent;
 binVec_t binVec_tmp;
 char* abv_fpath = malloc(PATHLEN);
 sprintf(abv_fpath,"%s/%s.%s",composite_opt->refdir,binVec_dirname,abunMtx_name_suffix);
 if(( namefh = fopen(abv_fpath,"w") ) == NULL) err(errno, "index_abv():%s",abv_fpath);
 sprintf(abv_fpath,"%s/%s.%s",composite_opt->refdir,binVec_dirname,y_l2n_suffix);
 if(( y_l2n_fh = fopen(abv_fpath,"wb") ) == NULL) err(errno, "index_abv():%s",abv_fpath);
 while (( dirent = readdir(abv_dir)) != NULL){
  const char *ext = strrchr(dirent->d_name,'.');
  if(strcmp(ext + 1, binVec_suffix) == 0){
   sprintf(abv_fpath,"%s/%s",abv_dpath,dirent->d_name);
   if(( abvfh = fopen(abv_fpath,"rb") ) == NULL) err(errno, "index_abv():%s",abv_fpath);
   double y_l2n = 0;
   struct stat st;
   stat(abv_fpath, &st);
   int abv_len = st.st_size/sizeof(binVec_t) ;
   for(int i =0; i<abv_len ;i++){
    fread(&binVec_tmp , sizeof(binVec_t), 1,abvfh);
     y_l2n+= binVec_tmp.pct*binVec_tmp.pct;
    abunMtx_dynamic[binVec_tmp.ref_idx] = realloc((binVec_t *)abunMtx_dynamic[binVec_tmp.ref_idx], sizeof(binVec_t) * (abunMtx_count[binVec_tmp.ref_idx] + 1) );
        abunMtx_dynamic[binVec_tmp.ref_idx][abunMtx_count[binVec_tmp.ref_idx]].ref_idx = abv_fcnt ;
    abunMtx_dynamic[binVec_tmp.ref_idx][abunMtx_count[binVec_tmp.ref_idx]].pct = binVec_tmp.pct;
    abunMtx_count[binVec_tmp.ref_idx]++;
   }
   fclose(abvfh);
   sprintf(abv_fpath,"%s\n",dirent->d_name);
   fwrite(abv_fpath,strlen(abv_fpath),1,namefh);
   y_l2n = sqrt(y_l2n);
   fwrite(&y_l2n,sizeof(double),1,y_l2n_fh);
   abv_fcnt++;
  }
 };
 closedir(abv_dir);
 fclose(namefh);
 fclose(y_l2n_fh);
  sprintf(abv_fpath,"%s/%s.%s",composite_opt->refdir,binVec_dirname,abunMtx_suffix);
 if(( abunMtx_fh = fopen(abv_fpath,"wb") ) == NULL) err(errno, "index_abv():%s",abv_fpath);
 for(int i = 0 ;i < ref_dstat.infile_num;i++){
  if(abunMtx_count[i])
   fwrite( abunMtx_dynamic[i], sizeof(binVec_t), abunMtx_count[i],abunMtx_fh);
 }
 fclose(abunMtx_fh);
 for(int i = 1 ;i < ref_dstat.infile_num;i++)
  abunMtx_count[i] += abunMtx_count[i-1];
 sprintf(abv_fpath,"%s/%s.%s",composite_opt->refdir,binVec_dirname,abunMtx_idx_suffix);
 if(( abunMtx_idxfh = fopen(abv_fpath,"wb") ) == NULL) err(errno, "index_abv():%s",abv_fpath);
 fwrite(abunMtx_count,sizeof(int),ref_dstat.infile_num,abunMtx_idxfh);
 fclose(abunMtx_idxfh);
 free(abv_dpath);
 free(abv_fpath);
 free(abunMtx_count);
 free(abunMtx_dynamic);
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x138, %rsp            # imm = 0x138
movq %rdi, %r12
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
addq $0x14, %r12
leaq 0xf0c8(%rip), %rsi      # 0x14393
leaq 0xefa8(%rip), %rcx      # 0x1427a
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, 0x18(%rsp)
movq %rbx, %rdi
callq 0x3110
testq %rax, %rax
je 0x578b
movq %rax, %rbp
leaq 0xf461(%rip), %rsi      # 0x14760
movq %r12, %rdi
callq 0x68a5
testq %rax, %rax
je 0x57a0
movq %rax, %r14
leaq 0xed4d(%rip), %rsi      # 0x14067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x57bf
movq %rax, %r15
leaq 0x88(%rsp), %r14
pushq $0x20
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %rax, %rcx
callq 0x30c0
movq %r15, %rdi
callq 0x3100
movslq 0x14(%r14), %r13
pushq $0x4
popq %rsi
movq %r13, %rdi
callq 0x32a0
movq %rax, 0x10(%rsp)
leaq (,%r13,8), %rdi
callq 0x3340
movq %rax, 0x8(%rsp)
xorl %ebx, %ebx
testl %r13d, %r13d
movl $0x0, %r15d
cmovgl %r13d, %r15d
pushq $0x8
popq %r14
cmpq %rbx, %r15
je 0x53a3
movq %r14, %rdi
callq 0x3340
movq 0x8(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
incq %rbx
jmp 0x5388
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
leaq 0xefc0(%rip), %rsi      # 0x14377
leaq 0xeebc(%rip), %rcx      # 0x1427a
leaq 0xeeb0(%rip), %r8       # 0x14275
movq %rax, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xf01c(%rip), %rsi      # 0x143f5
movq %rbx, %rdi
callq 0x33a0
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x5765
movq %r15, 0x70(%rsp)
leaq 0xef7c(%rip), %rsi      # 0x14377
leaq 0xee78(%rip), %rcx      # 0x1427a
leaq 0xee7f(%rip), %r8       # 0x14288
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xec4d(%rip), %rsi      # 0x1406a
movq %rbx, %rdi
callq 0x33a0
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x5765
pushq $0x1
popq %r14
movl $0x0, 0x4(%rsp)
movq %rbp, %rdi
callq 0x3320
testq %rax, %rax
je 0x561e
movq %rax, %r15
addq $0x13, %r15
movq %r15, %rdi
pushq $0x2e
popq %rsi
callq 0x31d0
leaq 0x1(%rax), %rdi
leaq 0xedfb(%rip), %rsi      # 0x14268
callq 0x32b0
testl %eax, %eax
jne 0x543f
movq %rbp, 0x58(%rsp)
movq %r13, 0x60(%rsp)
movq %r12, 0x68(%rsp)
movq %rbx, %rdi
leaq 0xef04(%rip), %rsi      # 0x14393
movq 0x18(%rsp), %rdx
movq %r15, %rcx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0xebbf(%rip), %rsi      # 0x14067
callq 0x33a0
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x5765
movq %rbx, 0x50(%rsp)
movq %rbx, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x32e0
movq 0xd8(%rsp), %rbx
shrq $0x3, %rbx
testl %ebx, %ebx
movl $0x0, %eax
cmovlel %eax, %ebx
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rsp)
subl $0x1, %ebx
jb 0x558c
leaq 0x48(%rsp), %rdi
pushq $0x8
popq %rsi
movq %r14, %rdx
movq 0x40(%rsp), %rcx
callq 0x30c0
movss 0x4c(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movslq 0x48(%rsp), %r13
movq 0x8(%rsp), %rbp
movq (%rbp,%r13,8), %rdi
movq 0x10(%rsp), %r14
movslq (%r14,%r13,4), %r12
leaq 0x1(%r12), %rax
movq %rax, 0x78(%rsp)
leaq 0x8(,%r12,8), %rsi
callq 0x3350
movq %rax, (%rbp,%r13,8)
movl 0x4(%rsp), %ecx
movl %ecx, (%rax,%r12,8)
movss 0x2c(%rsp), %xmm0
movss %xmm0, 0x4(%rax,%r12,8)
movq 0x78(%rsp), %rax
movl %eax, (%r14,%r13,4)
pushq $0x1
popq %r14
jmp 0x54ef
movq 0x40(%rsp), %rdi
callq 0x3100
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
leaq 0xfef5(%rip), %rsi      # 0x1549a
movq %r15, %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x3130
movq %rbx, %rdi
movq %rax, %rsi
movq %r14, %rdx
movq 0x38(%rsp), %rcx
callq 0x3450
movsd 0x20(%rsp), %xmm0
ucomisd 0xec30(%rip), %xmm0     # 0x14208
movq 0x68(%rsp), %r12
movq 0x60(%rsp), %r13
movq 0x58(%rsp), %rbp
jb 0x55ef
sqrtsd %xmm0, %xmm0
jmp 0x55f4
callq 0x3460
movsd %xmm0, 0x80(%rsp)
leaq 0x80(%rsp), %rdi
pushq $0x8
popq %rsi
movq %r14, %rdx
movq 0x30(%rsp), %rcx
callq 0x3450
incl 0x4(%rsp)
jmp 0x543f
movq %r13, %r14
movq %rbp, %rdi
callq 0x3240
movq 0x38(%rsp), %rdi
callq 0x3100
movq 0x30(%rsp), %rdi
callq 0x3100
leaq 0xed33(%rip), %rsi      # 0x14377
leaq 0xec2f(%rip), %rcx      # 0x1427a
leaq 0xec1a(%rip), %r8       # 0x1426c
movq %rbx, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xea04(%rip), %rsi      # 0x1406a
movq %rbx, %r13
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5778
movq %rax, %rbx
xorl %ebp, %ebp
pushq $0x8
popq %r15
cmpq %rbp, 0x70(%rsp)
je 0x56b1
movq 0x10(%rsp), %rax
movslq (%rax,%rbp,4), %rdx
testq %rdx, %rdx
je 0x56ac
movq 0x8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
movq %r15, %rsi
movq %rbx, %rcx
callq 0x3450
incq %rbp
jmp 0x5683
movq %rbx, %rdi
callq 0x3100
movq %r14, %rbp
pushq $0x1
popq %rdx
movq 0x10(%rsp), %rcx
cmpq %rbp, %rdx
jge 0x56d5
movl -0x4(%rcx,%rdx,4), %eax
addl %eax, (%rcx,%rdx,4)
incq %rdx
jmp 0x56c4
leaq 0xec9b(%rip), %rsi      # 0x14377
leaq 0xeb97(%rip), %rcx      # 0x1427a
leaq 0xeb86(%rip), %r8       # 0x14270
movq %r13, %rdi
movq %r12, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xe96c(%rip), %rsi      # 0x1406a
movq %r13, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5778
movq %rax, %rbx
pushq $0x4
popq %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rbp, %rdx
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq 0x18(%rsp), %rdi
callq 0x3040
movq %r13, %rdi
callq 0x3040
movq %r15, %rdi
callq 0x3040
movq 0x8(%rsp), %rdi
callq 0x3040
pushq $0x1
popq %rax
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xec73(%rip), %rsi      # 0x143e6
movq %rbx, %rdx
jmp 0x57d0
callq 0x3060
movl (%rax), %edi
leaq 0xec60(%rip), %rsi      # 0x143e6
movq %r13, %rdx
jmp 0x57d0
callq 0x3060
movl (%rax), %edi
leaq 0xec11(%rip), %rsi      # 0x143aa
movq 0x18(%rsp), %rdx
jmp 0x57d0
callq 0x3060
movl (%rax), %edi
leaq 0xec1f(%rip), %rsi      # 0x143cd
leaq 0xefab(%rip), %rdx      # 0x14760
movq %r12, %rcx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xec19(%rip), %rsi      # 0x143e6
movq %r14, %rdx
xorl %eax, %eax
callq 0x3330