// File: /workspace/github_c_makefile_star2_O0/yhg926[P]public_kssd/co2mco.c
// Function: cdb_kmerf2kmerdb
void cdb_kmerf2kmerdb(const char *mcodirname, const char *codirname, int cofnum, int comp_num, int p_fit_mem)
{
 kmerdb_index_t mco_map;
 size_t comp_sz = (1LLU << 4*COMPONENT_SZ);
 int binnum = ceil((double)cofnum/BIN_SZ);
 mco_map.row_bin_gnum = malloc((size_t)comp_sz*binnum*sizeof(unsigned int));
 mco_map.row_gnum = malloc(comp_sz * sizeof(unsigned int));
 mco_map.row_offset = malloc(comp_sz*sizeof(size_t) );
 mco_map.row_offset[0] = 0;
 size_t *cbdcoindex = malloc( sizeof(size_t)*(cofnum + 1) );
 char cbdcofname[PATHLEN]; char cbdcoindexf[PATHLEN];
 char mcofname[PATHLEN]; char mcoindexf[PATHLEN];
 mmp_uint_t mmpcbd_cofile;
 gid_arr_llist_t** mco = malloc(comp_sz* sizeof(gid_arr_llist_t*));
 for(unsigned int i = 0; i< comp_num; i++){
  memset(mco_map.row_bin_gnum,0,(size_t)comp_sz*binnum*sizeof(unsigned int) );
  memset(mco_map.row_gnum,0,comp_sz * sizeof(unsigned int));
  FILE *cbdfp, *cbdindexfp;
  sprintf(cbdcoindexf,"%s/combco.index.%d",codirname,i);
  sprintf(cbdcofname,"%s/combco.%d",codirname,i);
    if( (cbdfp = fopen(cbdcofname,"rb")) == NULL) err(errno,"%s",cbdcofname);
    if( (cbdindexfp = fopen(cbdcoindexf,"rb")) == NULL) err(errno,"%s",cbdcoindexf);
  fread(cbdcoindex,sizeof(size_t),cofnum + 1,cbdindexfp);
  mmpcbd_cofile = mmp_uint_arr(cbdcofname);
  for(int j = 0;j< cofnum; j++ ){
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
   for(size_t k = cbdcoindex[j]; k< cbdcoindex[j+1]; k++){
    unsigned int ind = mmpcbd_cofile.mmpco[k];
    unsigned int mod = mco_map.row_gnum[ind] % GID_ARR_SZ ;
    gid_arr_llist_t* tmp;
    if(mod == 0){
     tmp = mco[ind];
     mco[ind] = malloc(sizeof(gid_arr_llist_t));
     if (mco[ind] == NULL) err(errno,"cdb_kmerf2kmerdb()::mco[ind]") ;
     mco[ind]->next = tmp;
    }
    mco[ind]->gidobj[mod] = j % BIN_SZ ;
    mco_map.row_gnum[ind]++;
    mco_map.row_bin_gnum[(size_t)ind*binnum + j/BIN_SZ]++;
   }
  }
  munmap(mmpcbd_cofile.mmpco, mmpcbd_cofile.fsize);
  for(size_t n=1; n<comp_sz; n++)
   mco_map.row_offset[n] = mco_map.row_offset[n-1] + mco_map.row_gnum[n-1];
  sprintf(mcoindexf,"%s/mco.index.%d",mcodirname,i);
  FILE *arrmco_index_fp = fopen(mcoindexf,"wb");
  if( arrmco_index_fp == NULL) err(errno,"%s",mcoindexf);
  fwrite(mco_map.row_offset,sizeof(size_t),comp_sz,arrmco_index_fp);
  fwrite(mco_map.row_bin_gnum,sizeof(unsigned int),(size_t)comp_sz*binnum, arrmco_index_fp);
  fclose(arrmco_index_fp);
  sprintf(mcofname,"%s/mco.%d",mcodirname,i);
  int arrmco_fp = open(mcofname,O_RDWR|O_CREAT,0600) ;
  if (arrmco_fp == -1) err(errno,"cdb_kmerf2kmerdb()::%s",mcofname);
  size_t mco_comp_fsize = sizeof(gidobj_t)*(mco_map.row_offset[comp_sz-1] + mco_map.row_gnum[comp_sz-1]) ;
  if(ftruncate(arrmco_fp,mco_comp_fsize) == -1) err(errno,"cdb_kmerf2kmerdb()::ftruncate");
  gidobj_t* mco_mmpf = mmap(NULL,mco_comp_fsize,PROT_WRITE,MAP_SHARED,arrmco_fp,0);
  close(arrmco_fp);
#pragma omp parallel for num_threads(p_fit_mem) schedule(guided)
  for(size_t s = 0; s< comp_sz ; s++ ){
   if( mco_map.row_gnum[s] == 0 ) continue;
    gid_arr_llist_t *tmpblk;
    gidobj_t* current_blkpos_mapin_arrmco = mco_mmpf + mco_map.row_offset[s] + mco_map.row_gnum[s] ;
    int blk_num = mco_map.row_gnum[s]/GID_ARR_SZ;
    int remainder = mco_map.row_gnum[s] % GID_ARR_SZ;
    if( remainder > 0 ) blk_num+=1;
    int blk_len;
    for(int blk = 0; blk < blk_num; blk++){
     if((blk==0) && (remainder > 0) ) blk_len = remainder;
     else blk_len = GID_ARR_SZ;
     current_blkpos_mapin_arrmco -= blk_len;
     memcpy(current_blkpos_mapin_arrmco, mco[s]->gidobj, blk_len * sizeof(gidobj_t));
     tmpblk = mco[s];
     mco[s] = mco[s]->next;
     free(tmpblk);
    }
  }
  if ( msync( mco_mmpf, mco_comp_fsize, MS_ASYNC ) < 0 )
          err(errno,"cdb_kmerf2kmerdb()::msync failed");
   munmap(mco_mmpf,mco_comp_fsize);
  fclose(cbdfp);
  fclose(cbdindexfp);
 }
  free(mco_map.row_bin_gnum);
  free(mco_map.row_gnum);
  free(mco_map.row_offset);
  free(cbdcoindex);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x510, %rsp            # imm = 0x510
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq $0x10000000, -0x40(%rbp) # imm = 0x10000000
cvtsi2sdl -0x14(%rbp), %xmm0
movsd 0x18356(%rip), %xmm1    # 0x1c008
divsd %xmm1, %xmm0
callq 0x3460
cvttsd2si %xmm0, %eax
movl %eax, -0x44(%rbp)
movq -0x40(%rbp), %rdi
movslq -0x44(%rbp), %rax
imulq %rax, %rdi
shlq $0x2, %rdi
callq 0x3310
movq %rax, -0x28(%rbp)
movq -0x40(%rbp), %rdi
shlq $0x2, %rdi
callq 0x3310
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq $0x0, (%rax)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x468(%rbp)
movl $0x0, -0x46c(%rbp)
movl -0x46c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0x4468
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rdx
movslq -0x44(%rbp), %rax
imulq %rax, %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x31f0
movq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x31f0
leaq -0x250(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x46c(%rbp), %ecx
leaq 0x182dd(%rip), %rsi     # 0x1c06e
movb $0x0, %al
callq 0x3400
leaq -0x150(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x46c(%rbp), %ecx
leaq 0x182d1(%rip), %rsi     # 0x1c081
movb $0x0, %al
callq 0x3400
leaq -0x150(%rbp), %rdi
leaq 0x18292(%rip), %rsi     # 0x1c057
callq 0x3370
movq %rax, -0x478(%rbp)
cmpq $0x0, %rax
jne 0x3df3
callq 0x3050
movl (%rax), %edi
leaq -0x150(%rbp), %rdx
leaq 0x1955a(%rip), %rsi     # 0x1d346
movb $0x0, %al
callq 0x3300
leaq -0x250(%rbp), %rdi
leaq 0x18256(%rip), %rsi     # 0x1c057
callq 0x3370
movq %rax, -0x480(%rbp)
cmpq $0x0, %rax
jne 0x3e2f
callq 0x3050
movl (%rax), %edi
leaq -0x250(%rbp), %rdx
leaq 0x1951e(%rip), %rsi     # 0x1d346
movb $0x0, %al
callq 0x3300
movq -0x50(%rbp), %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
movq -0x480(%rbp), %rcx
movl $0x8, %esi
callq 0x30a0
leaq -0x150(%rbp), %rdi
callq 0x3b60
movq %rax, -0x490(%rbp)
movq %rdx, -0x488(%rbp)
movq -0x490(%rbp), %rax
movq %rax, -0x460(%rbp)
movq -0x488(%rbp), %rax
movq %rax, -0x458(%rbp)
movl $0x0, -0x494(%rbp)
movl -0x494(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x402d
movq -0x50(%rbp), %rax
movslq -0x494(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4a0(%rbp)
movq -0x4a0(%rbp), %rax
movq -0x50(%rbp), %rcx
movl -0x494(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x4017
movq -0x458(%rbp), %rax
movq -0x4a0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x4a4(%rbp)
movq -0x30(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x4a8(%rbp)
cmpl $0x0, -0x4a8(%rbp)
jne 0x3f84
movq -0x468(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4b0(%rbp)
movl $0x48, %edi
callq 0x3310
movq %rax, %rdx
movq -0x468(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x468(%rbp), %rax
movl -0x4a4(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
jne 0x3f68
callq 0x3050
movl (%rax), %edi
leaq 0x1812d(%rip), %rsi     # 0x1c08e
movb $0x0, %al
callq 0x3300
movq -0x4b0(%rbp), %rcx
movq -0x468(%rbp), %rax
movl -0x4a4(%rbp), %edx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x40(%rax)
movl -0x494(%rbp), %eax
movl $0x10000, %ecx          # imm = 0x10000
cltd
idivl %ecx
movq -0x468(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x4a8(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x30(%rbp), %rax
movl -0x4a4(%rbp), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq %rax, -0x508(%rbp)
movl -0x4a4(%rbp), %eax
movl %eax, %ecx
movslq -0x44(%rbp), %rax
imulq %rax, %rcx
movl -0x494(%rbp), %eax
movl $0x10000, %esi          # imm = 0x10000
cltd
idivl %esi
movl %eax, %edx
movq -0x508(%rbp), %rax
movslq %edx, %rdx
addq %rdx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq -0x4a0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4a0(%rbp)
jmp 0x3eb2
jmp 0x4019
movl -0x494(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x494(%rbp)
jmp 0x3e8d
movq -0x458(%rbp), %rdi
movq -0x460(%rbp), %rsi
callq 0x3330
movq $0x1, -0x4b8(%rbp)
movq -0x4b8(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x40a3
movq -0x38(%rbp), %rax
movq -0x4b8(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rax
movq -0x4b8(%rbp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,4), %eax
addq %rax, %rdx
movq -0x38(%rbp), %rax
movq -0x4b8(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x4b8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4b8(%rbp)
jmp 0x404b
leaq -0x450(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0x46c(%rbp), %ecx
leaq 0x17ff0(%rip), %rsi     # 0x1c0ab
movb $0x0, %al
callq 0x3400
leaq -0x450(%rbp), %rdi
leaq 0x17f8a(%rip), %rsi     # 0x1c05a
callq 0x3370
movq %rax, -0x4c0(%rbp)
cmpq $0x0, -0x4c0(%rbp)
jne 0x4102
callq 0x3050
movl (%rax), %edi
leaq -0x450(%rbp), %rdx
leaq 0x1924b(%rip), %rsi     # 0x1d346
movb $0x0, %al
callq 0x3300
movq -0x38(%rbp), %rdi
movq -0x40(%rbp), %rdx
movq -0x4c0(%rbp), %rcx
movl $0x8, %esi
callq 0x3420
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rdx
movslq -0x44(%rbp), %rax
imulq %rax, %rdx
movq -0x4c0(%rbp), %rcx
movl $0x4, %esi
callq 0x3420
movq -0x4c0(%rbp), %rdi
callq 0x30e0
leaq -0x350(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0x46c(%rbp), %ecx
leaq 0x17f5b(%rip), %rsi     # 0x1c0bb
movb $0x0, %al
callq 0x3400
leaq -0x350(%rbp), %rdi
movl $0x42, %esi
movl $0x180, %edx            # imm = 0x180
movb $0x0, %al
callq 0x3350
movl %eax, -0x4c4(%rbp)
cmpl $-0x1, -0x4c4(%rbp)
jne 0x41aa
callq 0x3050
movl (%rax), %edi
leaq -0x350(%rbp), %rdx
leaq 0x17f22(%rip), %rsi     # 0x1c0c5
movb $0x0, %al
callq 0x3300
movq -0x38(%rbp), %rax
movq -0x40(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rdx
subq $0x1, %rdx
movl (%rcx,%rdx,4), %ecx
addq %rcx, %rax
shlq $0x2, %rax
movq %rax, -0x4d0(%rbp)
movl -0x4c4(%rbp), %edi
movq -0x4d0(%rbp), %rsi
callq 0x31c0
cmpl $-0x1, %eax
jne 0x4203
callq 0x3050
movl (%rax), %edi
leaq 0x17ee0(%rip), %rsi     # 0x1c0dc
movb $0x0, %al
callq 0x3300
movq -0x4d0(%rbp), %rsi
movl -0x4c4(%rbp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x2, %edx
movl $0x1, %ecx
movq %r9, %rdi
callq 0x3130
movq %rax, -0x4d8(%rbp)
movl -0x4c4(%rbp), %edi
callq 0x3200
movq $0x0, -0x4e0(%rbp)
movq -0x4e0(%rbp), %rax
cmpq -0x40(%rbp), %rax
jae 0x43f7
movq -0x30(%rbp), %rax
movq -0x4e0(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x426c
jmp 0x43e0
movq -0x4d8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq -0x4e0(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movq -0x4e0(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x4f0(%rbp)
movq -0x30(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x4, %eax
movl %eax, -0x4f4(%rbp)
movq -0x30(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0xf, %eax
movl %eax, -0x4f8(%rbp)
cmpl $0x0, -0x4f8(%rbp)
jle 0x42eb
movl -0x4f4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4f4(%rbp)
movl $0x0, -0x500(%rbp)
movl -0x500(%rbp), %eax
cmpl -0x4f4(%rbp), %eax
jge 0x43de
cmpl $0x0, -0x500(%rbp)
jne 0x4327
cmpl $0x0, -0x4f8(%rbp)
jle 0x4327
movl -0x4f8(%rbp), %eax
movl %eax, -0x4fc(%rbp)
jmp 0x4331
movl $0x10, -0x4fc(%rbp)
movl -0x4fc(%rbp), %ecx
movq -0x4f0(%rbp), %rax
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x4f0(%rbp)
movq -0x4f0(%rbp), %rdi
movq -0x468(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movslq -0x4fc(%rbp), %rdx
shlq $0x2, %rdx
callq 0x32c0
movq -0x468(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x4e8(%rbp)
movq -0x468(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x40(%rax), %rdx
movq -0x468(%rbp), %rax
movq -0x4e0(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x4e8(%rbp), %rdi
callq 0x3040
movl -0x500(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x500(%rbp)
jmp 0x42f5
jmp 0x43e0
movq -0x4e0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x4e0(%rbp)
jmp 0x4245
movq -0x4d8(%rbp), %rdi
movq -0x4d0(%rbp), %rsi
movl $0x1, %edx
callq 0x3100
cmpl $0x0, %eax
jge 0x4429
callq 0x3050
movl (%rax), %edi
leaq 0x17cd8(%rip), %rsi     # 0x1c0fa
movb $0x0, %al
callq 0x3300
movq -0x4d8(%rbp), %rdi
movq -0x4d0(%rbp), %rsi
callq 0x3330
movq -0x478(%rbp), %rdi
callq 0x30e0
movq -0x480(%rbp), %rdi
callq 0x30e0
movl -0x46c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x46c(%rbp)
jmp 0x3d3c
movq -0x28(%rbp), %rdi
callq 0x3040
movq -0x30(%rbp), %rdi
callq 0x3040
movq -0x38(%rbp), %rdi
callq 0x3040
movq -0x50(%rbp), %rdi
callq 0x3040
addq $0x510, %rsp            # imm = 0x510
popq %rbp
retq
nopw %cs:(%rax,%rax)