// File: /workspace/github_c_makefile_star2_O1/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 $0x128, %rsp            # imm = 0x128
movq %rdi, %r14
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %rbx
addq $0x14, %r14
leaq 0xfece(%rip), %rsi      # 0x15393
leaq 0xfdae(%rip), %rcx      # 0x1527a
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, 0x28(%rsp)
movq %rbx, %rdi
callq 0x3110
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x59b5
leaq 0x10265(%rip), %rsi     # 0x15760
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x6bcc
testq %rax, %rax
je 0x59ca
movq %rax, %rbx
leaq 0xfb4c(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5989
movq %rax, %r14
leaq 0x78(%rsp), %rbx
movl $0x20, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
movslq 0x14(%rbx), %r15
movl $0x4, %esi
movq %r15, %rdi
callq 0x32a0
movq %rax, %rbp
leaq (,%r15,8), %rdi
callq 0x3340
movq %rax, %r13
testq %r15, %r15
jle 0x5593
xorl %ebx, %ebx
movl $0x8, %edi
callq 0x3340
movq %rax, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x557c
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %r12
leaq 0xfdd0(%rip), %rsi      # 0x15377
leaq 0xfccc(%rip), %rcx      # 0x1527a
leaq 0xfcc0(%rip), %r8       # 0x15275
movq %rax, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xfe27(%rip), %rsi      # 0x153f5
movq %r12, %rdi
callq 0x33a0
movq %rax, 0x50(%rsp)
testq %rax, %rax
movq 0x30(%rsp), %r14
je 0x59eb
leaq 0xfd87(%rip), %rsi      # 0x15377
leaq 0xfc83(%rip), %rcx      # 0x1527a
leaq 0xfc8a(%rip), %r8       # 0x15288
movq %r12, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xfa58(%rip), %rsi      # 0x1506a
movq %r12, (%rsp)
movq %r12, %rdi
callq 0x33a0
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x59a1
movq %r14, %rdi
callq 0x3320
testq %rax, %rax
je 0x5841
leaq 0xfc24(%rip), %rbx      # 0x15268
movl $0x0, 0xc(%rsp)
movq %r13, 0x38(%rsp)
movq %r15, 0x60(%rsp)
movq %r13, %r12
addq $0x13, %rax
movq %rax, %rdi
movl $0x2e, %esi
movq %rax, %r13
callq 0x31d0
leaq 0x1(%rax), %rdi
movq %rbx, %rsi
callq 0x32b0
testl %eax, %eax
je 0x5685
movq %r12, %r13
jmp 0x5830
movq (%rsp), %rbx
movq %rbx, %rdi
leaq 0xfd00(%rip), %rsi      # 0x15393
movq 0x28(%rsp), %rdx
movq %r13, 0x68(%rsp)
movq %r13, %rcx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0xf9b6(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x5989
movq %rax, %r14
movq $0x0, 0x20(%rsp)
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0x32e0
movq 0xc8(%rsp), %rbx
shrq $0x3, %rbx
xorpd %xmm0, %xmm0
testl %ebx, %ebx
jle 0x578b
movsd %xmm0, 0x18(%rsp)
movq %r14, 0x70(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x58(%rsp), %rdi
movq %r14, %rcx
callq 0x30c0
movss 0x5c(%rsp), %xmm0
movss %xmm0, 0x44(%rsp)
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movslq 0x58(%rsp), %r13
movq 0x38(%rsp), %r15
movq (%r15,%r13,8), %rdi
movslq (%rbp,%r13,4), %r12
leaq 0x1(%r12), %r14
leaq 0x8(,%r12,8), %rsi
callq 0x3350
movq %rax, (%r15,%r13,8)
movl 0xc(%rsp), %ecx
movl %ecx, (%rax,%r12,8)
movss 0x44(%rsp), %xmm0
movss %xmm0, 0x4(%rax,%r12,8)
movl %r14d, (%rbp,%r13,4)
movq 0x70(%rsp), %r14
decl %ebx
jne 0x56fe
jmp 0x5791
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x3100
movq (%rsp), %rbx
movq %rbx, %rdi
leaq 0x10ce7(%rip), %rsi     # 0x1649a
movq 0x68(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x3130
movl $0x1, %edx
movq %rbx, %rdi
movq %rax, %rsi
movq 0x50(%rsp), %rcx
callq 0x3450
movsd 0x20(%rsp), %xmm0
ucomisd 0xfa1e(%rip), %xmm0     # 0x15208
movq 0x60(%rsp), %r15
jb 0x57f7
sqrtsd %xmm0, %xmm0
jmp 0x57fc
callq 0x3460
movq 0x38(%rsp), %r13
movq 0x30(%rsp), %r14
leaq 0xfa5b(%rip), %rbx      # 0x15268
movsd %xmm0, 0x20(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x20(%rsp), %rdi
movq 0x48(%rsp), %rcx
callq 0x3450
incl 0xc(%rsp)
movq %r14, %rdi
callq 0x3320
testq %rax, %rax
jne 0x5656
movq %r14, %rdi
callq 0x3240
movq 0x50(%rsp), %rdi
callq 0x3100
movq 0x48(%rsp), %rdi
callq 0x3100
leaq 0xfb13(%rip), %rsi      # 0x15377
leaq 0xfa0f(%rip), %rcx      # 0x1527a
leaq 0xf9fa(%rip), %r8       # 0x1526c
movq (%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xf7de(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x59a1
movq %rax, %rbx
testl %r15d, %r15d
jle 0x58cc
xorl %r14d, %r14d
movslq (%rbp,%r14,4), %rdx
testq %rdx, %rdx
je 0x58c4
movq (%r13,%r14,8), %rdi
movl $0x8, %esi
movq %rbx, %rcx
callq 0x3450
incq %r14
cmpq %r14, %r15
jne 0x58a8
movq %rbx, %rdi
callq 0x3100
cmpl $0x2, %r15d
jl 0x58f2
movl (%rbp), %eax
movl $0x1, %ecx
addl (%rbp,%rcx,4), %eax
movl %eax, (%rbp,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0x58e2
leaq 0xfa7e(%rip), %rsi      # 0x15377
leaq 0xf97a(%rip), %rcx      # 0x1527a
leaq 0xf969(%rip), %r8       # 0x15270
movq (%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xf749(%rip), %rsi      # 0x1506a
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x59fe
movq %rax, %rbx
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq 0x28(%rsp), %rdi
callq 0x3040
movq %r14, %rdi
callq 0x3040
movq %rbp, %rdi
callq 0x3040
movq %r13, %rdi
callq 0x3040
movl $0x1, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0xfa4f(%rip), %rsi      # 0x153e6
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xfa37(%rip), %rsi      # 0x153e6
movq (%rsp), %rdx
jmp 0x599a
callq 0x3060
movl (%rax), %edi
leaq 0xf9e7(%rip), %rsi      # 0x153aa
movq 0x28(%rsp), %rdx
jmp 0x599a
callq 0x3060
movl (%rax), %edi
leaq 0xf9f5(%rip), %rsi      # 0x153cd
leaq 0xfd81(%rip), %rdx      # 0x15760
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xf9ed(%rip), %rsi      # 0x153e6
movq %r12, %rdx
jmp 0x599a
callq 0x3060
movl (%rax), %edi
leaq 0xf9da(%rip), %rsi      # 0x153e6
movq %r14, %rdx
jmp 0x599a