// File: /workspace/github_c_makefile_star2_O3/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 0xfe9b(%rip), %rsi      # 0x153e3
leaq 0xfd7b(%rip), %rcx      # 0x152ca
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0x3110
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x5a33
leaq 0x10232(%rip), %rsi     # 0x157b0
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0x6d79
testq %rax, %rax
je 0x5a48
movq %rax, %rbx
leaq 0xfac9(%rip), %rsi      # 0x15067
movq %rax, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5a07
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 0x5616
xorl %ebx, %ebx
movl $0x8, %edi
callq 0x3340
movq %rax, (%r13,%rbx,8)
incq %rbx
cmpq %rbx, %r15
jne 0x55ff
movl $0x100, %edi            # imm = 0x100
callq 0x3340
movq %rax, %r12
leaq 0xfd9d(%rip), %rsi      # 0x153c7
leaq 0xfc99(%rip), %rcx      # 0x152ca
leaq 0xfc8d(%rip), %r8       # 0x152c5
movq %rax, %rdi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xfdf4(%rip), %rsi      # 0x15445
movq %r12, %rdi
callq 0x33a0
movq %rax, 0x48(%rsp)
testq %rax, %rax
movq 0x28(%rsp), %r14
je 0x5a69
leaq 0xfd54(%rip), %rsi      # 0x153c7
leaq 0xfc50(%rip), %rcx      # 0x152ca
leaq 0xfc57(%rip), %r8       # 0x152d8
movq %r12, %rdi
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xf9d5(%rip), %rsi      # 0x1506a
movq %r12, (%rsp)
movq %r12, %rdi
callq 0x33a0
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x5a1f
movq %r14, %rdi
callq 0x3320
testq %rax, %rax
je 0x58af
leaq 0xfbf1(%rip), %rbx      # 0x152b8
movl $0x0, 0xc(%rsp)
movq %r13, 0x30(%rsp)
movq %r15, 0x58(%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 0x5708
movq %r12, %r13
jmp 0x589e
movq (%rsp), %rbx
movq %rbx, %rdi
leaq 0xfccd(%rip), %rsi      # 0x153e3
movq 0x20(%rsp), %rdx
movq %r13, 0x60(%rsp)
movq %r13, %rcx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0xf933(%rip), %rsi      # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x5a07
movq %rax, %r14
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0x32e0
movq 0xc8(%rsp), %rbx
shrq $0x3, %rbx
xorpd %xmm0, %xmm0
testl %ebx, %ebx
jle 0x5805
movsd %xmm0, 0x18(%rsp)
movq %r14, 0x68(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x50(%rsp), %rdi
movq %r14, %rcx
callq 0x30c0
movss 0x54(%rsp), %xmm0
movss %xmm0, 0x3c(%rsp)
mulss %xmm0, %xmm0
cvtss2sd %xmm0, %xmm0
movsd 0x18(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
movslq 0x50(%rsp), %r13
movq 0x30(%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 0x3c(%rsp), %xmm0
movss %xmm0, 0x4(%rax,%r12,8)
movl %r14d, (%rbp,%r13,4)
movq 0x68(%rsp), %r14
decl %ebx
jne 0x5778
jmp 0x580b
movsd %xmm0, 0x18(%rsp)
movq %r14, %rdi
callq 0x3100
movq (%rsp), %rbx
movq %rbx, %rdi
leaq 0x10cc9(%rip), %rsi     # 0x164ea
movq 0x60(%rsp), %rdx
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x3130
movl $0x1, %edx
movq %rbx, %rdi
movq %rax, %rsi
movq 0x48(%rsp), %rcx
callq 0x3450
movsd 0x18(%rsp), %xmm0
ucomisd 0xfa00(%rip), %xmm0     # 0x15258
movq 0x58(%rsp), %r15
jb 0x5865
sqrtsd %xmm0, %xmm0
jmp 0x586a
callq 0x3460
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %r14
leaq 0xfa3d(%rip), %rbx      # 0x152b8
movsd %xmm0, 0x70(%rsp)
movl $0x8, %esi
movl $0x1, %edx
leaq 0x70(%rsp), %rdi
movq 0x40(%rsp), %rcx
callq 0x3450
incl 0xc(%rsp)
movq %r14, %rdi
callq 0x3320
testq %rax, %rax
jne 0x56d9
movq %r14, %rdi
callq 0x3240
movq 0x48(%rsp), %rdi
callq 0x3100
movq 0x40(%rsp), %rdi
callq 0x3100
leaq 0xfaf5(%rip), %rsi      # 0x153c7
leaq 0xf9f1(%rip), %rcx      # 0x152ca
leaq 0xf9dc(%rip), %r8       # 0x152bc
movq (%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rdx
xorl %eax, %eax
callq 0x3430
leaq 0xf76d(%rip), %rsi      # 0x1506a
movq %rbx, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5a1f
movq %rax, %rbx
testl %r15d, %r15d
jle 0x596a
xorl %r14d, %r14d
movslq (%rbp,%r14,4), %rdx
testq %rdx, %rdx
je 0x5935
movq (%r13,%r14,8), %rdi
movl $0x8, %esi
movq %rbx, %rcx
callq 0x3450
incq %r14
cmpq %r14, %r15
jne 0x5919
movq %rbx, %rdi
callq 0x3100
cmpl $0x1, %r15d
movq 0x10(%rsp), %r14
je 0x5972
movl (%rbp), %eax
movl $0x1, %ecx
addl (%rbp,%rcx,4), %eax
movl %eax, (%rbp,%rcx,4)
incq %rcx
cmpq %rcx, %r15
jne 0x5958
jmp 0x5972
movq %rbx, %rdi
callq 0x3100
leaq 0xfa4e(%rip), %rsi      # 0x153c7
leaq 0xf94a(%rip), %rcx      # 0x152ca
leaq 0xf939(%rip), %r8       # 0x152c0
movq (%rsp), %rdi
movq %r14, %rdx
movq %rdi, %r14
xorl %eax, %eax
callq 0x3430
leaq 0xf6cb(%rip), %rsi      # 0x1506a
movq %r14, %rdi
callq 0x33a0
testq %rax, %rax
je 0x5a7c
movq %rax, %rbx
movl $0x4, %esi
movq %rbp, %rdi
movq %r15, %rdx
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
movq 0x20(%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 0xfa21(%rip), %rsi      # 0x15436
movq %rbx, %rdx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xfa09(%rip), %rsi      # 0x15436
movq (%rsp), %rdx
jmp 0x5a18
callq 0x3060
movl (%rax), %edi
leaq 0xf9b9(%rip), %rsi      # 0x153fa
movq 0x20(%rsp), %rdx
jmp 0x5a18
callq 0x3060
movl (%rax), %edi
leaq 0xf9c7(%rip), %rsi      # 0x1541d
leaq 0xfd53(%rip), %rdx      # 0x157b0
movq 0x10(%rsp), %rcx
xorl %eax, %eax
callq 0x3330
callq 0x3060
movl (%rax), %edi
leaq 0xf9bf(%rip), %rsi      # 0x15436
movq %r12, %rdx
jmp 0x5a18
callq 0x3060
movl (%rax), %edi
leaq 0xf9ac(%rip), %rsi      # 0x15436
movq %r14, %rdx
jmp 0x5a18