// File: /workspace/github_c_makefile_star2_O0/yhg926[P]public_kssd/co2mco.c
// Function: combco2mco
void combco2mco(const char *mcodirname, const char *codirname, int cofnum, int comp_num, int p_fit_mem)
{
  char cbdcofname[PATHLEN]; char cbdcoindexf[PATHLEN];
  char mcofname[PATHLEN]; char mcoindexf[PATHLEN];
 size_t comp_sz = (1LLU << 4*COMPONENT_SZ);
 size_t *cbdcoindex = malloc( sizeof(size_t)*(cofnum + 1) );
  gidobj_t ** mco = malloc(comp_sz*sizeof(gidobj_t *));
 size_t *row_offset = malloc(comp_sz*sizeof(size_t) );
  for( int i = 0; i< comp_num; i++){
  memset(row_offset,0,comp_sz*sizeof(size_t));
    sprintf(cbdcoindexf,"%s/%s.%d",codirname,idx_prefix,i);
  FILE *cbdindexfp = fopen(cbdcoindexf,"rb") ;
    if(cbdindexfp == NULL) err(errno,"%s",cbdcoindexf);
    fread(cbdcoindex,sizeof(size_t),cofnum + 1,cbdindexfp);
  fclose(cbdindexfp);
  sprintf(cbdcofname,"%s/%s.%d",codirname,skch_prefix,i);
    mmp_uint_t 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];
    if(row_offset[ind] == 0) mco[ind] = malloc(GID_ARR_SZ*sizeof(gidobj_t));
    else if ((row_offset[ind]*2 >= GID_ARR_SZ) ){
     if ( ((ulong)row_offset[ind] & ((ulong)row_offset[ind] -1)) == 0) {
      mco[ind] = realloc( mco[ind], 2*row_offset[ind] * sizeof(gidobj_t) );
     }
    }
        mco[ind][row_offset[ind]] = j ;
        row_offset[ind]++;
      }
    }
    munmap(mmpcbd_cofile.mmpco, mmpcbd_cofile.fsize);
    for(size_t n=1; n<comp_sz; n++) row_offset[n] += row_offset[n-1];
    sprintf(mcoindexf,"%s/%s.%d",mcodirname,mco_idx_prefix,i);
    FILE *arrmco_index_fp = fopen(mcoindexf,"wb");
    if( arrmco_index_fp == NULL) err(errno,"%s",mcoindexf);
    fwrite(row_offset,sizeof(size_t),comp_sz,arrmco_index_fp);
    fclose(arrmco_index_fp);
    sprintf(mcofname,"%s/%s.%d",mcodirname,mco_gids_prefix,i);
    FILE* arrmco_fp = fopen(mcofname,"wb") ;
    if (arrmco_fp == NULL) err(errno,"combco2mco()::%s",mcofname);
    for(size_t s = 0; s< comp_sz ; s++ ){
   int row_gnum = s>0? row_offset[s] - row_offset[s-1] : row_offset[0];
      if( row_gnum > 0 )
    fwrite(mco[s],sizeof(gidobj_t),row_gnum,arrmco_fp);
   free(mco[s]);
    }
  fclose(arrmco_fp);
  }
 free(mco);
  free(cbdcoindex);
 free(row_offset) ;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x4b0, %rsp            # imm = 0x4B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movq $0x10000000, -0x428(%rbp) # imm = 0x10000000
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x430(%rbp)
movq -0x428(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x438(%rbp)
movq -0x428(%rbp), %rdi
shlq $0x3, %rdi
callq 0x3310
movq %rax, -0x440(%rbp)
movl $0x0, -0x444(%rbp)
movl -0x444(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3b2a
movq -0x440(%rbp), %rdi
movq -0x428(%rbp), %rdx
shlq $0x3, %rdx
xorl %esi, %esi
callq 0x31f0
leaq -0x220(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x444(%rbp), %r8d
leaq 0x189e4(%rip), %rsi     # 0x1c04e
leaq 0x1adef(%rip), %rcx     # 0x1e460
movb $0x0, %al
callq 0x3400
leaq -0x220(%rbp), %rdi
leaq 0x189d1(%rip), %rsi     # 0x1c057
callq 0x3370
movq %rax, -0x450(%rbp)
cmpq $0x0, -0x450(%rbp)
jne 0x36b8
callq 0x3050
movl (%rax), %edi
leaq -0x220(%rbp), %rdx
leaq 0x19c95(%rip), %rsi     # 0x1d346
movb $0x0, %al
callq 0x3300
movq -0x430(%rbp), %rdi
movl -0x14(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rdx
movq -0x450(%rbp), %rcx
movl $0x8, %esi
callq 0x30a0
movq -0x450(%rbp), %rdi
callq 0x30e0
leaq -0x120(%rbp), %rdi
movq -0x10(%rbp), %rdx
movl -0x444(%rbp), %r8d
leaq 0x18950(%rip), %rsi     # 0x1c04e
leaq 0x1ad54(%rip), %rcx     # 0x1e459
movb $0x0, %al
callq 0x3400
leaq -0x120(%rbp), %rdi
callq 0x3b60
movq %rax, -0x460(%rbp)
movq %rdx, -0x458(%rbp)
movl $0x0, -0x464(%rbp)
movl -0x464(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x38ca
movq -0x430(%rbp), %rax
movslq -0x464(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x470(%rbp)
movq -0x470(%rbp), %rax
movq -0x430(%rbp), %rcx
movl -0x464(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jae 0x38b4
movq -0x458(%rbp), %rax
movq -0x470(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x474(%rbp)
movq -0x440(%rbp), %rax
movl -0x474(%rbp), %ecx
cmpq $0x0, (%rax,%rcx,8)
jne 0x37ca
movl $0x40, %edi
callq 0x3310
movq %rax, %rdx
movq -0x438(%rbp), %rax
movl -0x474(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x3859
movq -0x440(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shlq %rax
cmpq $0x10, %rax
jb 0x3857
movq -0x440(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x440(%rbp), %rcx
movl -0x474(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
subq $0x1, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x3855
movq -0x438(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movq -0x440(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
shlq %rsi
shlq $0x2, %rsi
callq 0x3320
movq %rax, %rdx
movq -0x438(%rbp), %rax
movl -0x474(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x3857
jmp 0x3859
movl -0x464(%rbp), %edx
movq -0x438(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq -0x440(%rbp), %rcx
movl -0x474(%rbp), %esi
movq (%rcx,%rsi,8), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x440(%rbp), %rax
movl -0x474(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x470(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x470(%rbp)
jmp 0x3758
jmp 0x38b6
movl -0x464(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x464(%rbp)
jmp 0x3730
movq -0x458(%rbp), %rdi
movq -0x460(%rbp), %rsi
callq 0x3330
movq $0x1, -0x480(%rbp)
movq -0x480(%rbp), %rax
cmpq -0x428(%rbp), %rax
jae 0x3938
movq -0x440(%rbp), %rax
movq -0x480(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x440(%rbp), %rax
movq -0x480(%rbp), %rcx
addq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x480(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x480(%rbp)
jmp 0x38e8
leaq -0x420(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0x444(%rbp), %r8d
leaq 0x186fd(%rip), %rsi     # 0x1c04e
leaq 0x186ec(%rip), %rcx     # 0x1c044
movb $0x0, %al
callq 0x3400
leaq -0x420(%rbp), %rdi
leaq 0x186ed(%rip), %rsi     # 0x1c05a
callq 0x3370
movq %rax, -0x488(%rbp)
cmpq $0x0, -0x488(%rbp)
jne 0x399f
callq 0x3050
movl (%rax), %edi
leaq -0x420(%rbp), %rdx
leaq 0x199ae(%rip), %rsi     # 0x1d346
movb $0x0, %al
callq 0x3300
movq -0x440(%rbp), %rdi
movq -0x428(%rbp), %rdx
movq -0x488(%rbp), %rcx
movl $0x8, %esi
callq 0x3420
movq -0x488(%rbp), %rdi
callq 0x30e0
leaq -0x320(%rbp), %rdi
movq -0x8(%rbp), %rdx
movl -0x444(%rbp), %r8d
leaq 0x1866b(%rip), %rsi     # 0x1c04e
leaq 0x18656(%rip), %rcx     # 0x1c040
movb $0x0, %al
callq 0x3400
leaq -0x320(%rbp), %rdi
leaq 0x1865b(%rip), %rsi     # 0x1c05a
callq 0x3370
movq %rax, -0x490(%rbp)
cmpq $0x0, -0x490(%rbp)
jne 0x3a31
callq 0x3050
movl (%rax), %edi
leaq -0x320(%rbp), %rdx
leaq 0x18633(%rip), %rsi     # 0x1c05d
movb $0x0, %al
callq 0x3300
movq $0x0, -0x498(%rbp)
movq -0x498(%rbp), %rax
cmpq -0x428(%rbp), %rax
jae 0x3b0a
cmpq $0x0, -0x498(%rbp)
jbe 0x3a8b
movq -0x440(%rbp), %rax
movq -0x498(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x440(%rbp), %rcx
movq -0x498(%rbp), %rdx
subq $0x1, %rdx
subq (%rcx,%rdx,8), %rax
movq %rax, -0x4a8(%rbp)
jmp 0x3a9c
movq -0x440(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x4a8(%rbp)
movq -0x4a8(%rbp), %rax
movl %eax, -0x49c(%rbp)
cmpl $0x0, -0x49c(%rbp)
jle 0x3adc
movq -0x438(%rbp), %rax
movq -0x498(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x49c(%rbp), %rdx
movq -0x490(%rbp), %rcx
movl $0x4, %esi
callq 0x3420
movq -0x438(%rbp), %rax
movq -0x498(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x3040
movq -0x498(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x498(%rbp)
jmp 0x3a3c
movq -0x490(%rbp), %rdi
callq 0x30e0
movl -0x444(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x444(%rbp)
jmp 0x3629
movq -0x438(%rbp), %rdi
callq 0x3040
movq -0x430(%rbp), %rdi
callq 0x3040
movq -0x440(%rbp), %rdi
callq 0x3040
addq $0x4b0, %rsp            # imm = 0x4B0
popq %rbp
retq
nopw (%rax,%rax)