// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4f8, %rsp            # imm = 0x4F8
movl %ecx, %ebp
movq %rsi, %r15
movq %rdi, %r12
movl %edx, 0x28(%rsp)
movslq %edx, %rbx
leaq 0x8(,%rbx,8), %rdi
callq 0x3340
movq %rax, 0x18(%rsp)
movl $0x80000000, %edi       # imm = 0x80000000
callq 0x3340
movq %rax, 0x10(%rsp)
movl $0x80000000, %edi       # imm = 0x80000000
callq 0x3340
movq %rax, 0x8(%rsp)
movl %ebp, 0x24(%rsp)
testl %ebp, %ebp
jle 0x3a0d
leaq 0x1(%rbx), %rax
movq %rax, 0x40(%rsp)
movl %ebx, %eax
movq %rax, 0x58(%rsp)
leaq 0x119ef(%rip), %r13     # 0x1505e
xorl %ebp, %ebp
movq %r15, 0x38(%rsp)
movq %r12, 0x48(%rsp)
movl $0x80000000, %edx       # imm = 0x80000000
movq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x3210
leaq 0x2f0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
leaq 0x138df(%rip), %rcx     # 0x16f83
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x119af(%rip), %rsi     # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x3a3d
movq %rax, %r14
movl $0x8, %esi
movq 0x18(%rsp), %rdi
movq 0x40(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %r14, %rdi
callq 0x3100
leaq 0x3f0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
leaq 0x1387c(%rip), %rcx     # 0x16f7c
movl %ebp, 0x2c(%rsp)
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x3380
movl %eax, %r12d
movl %eax, %ebp
shrl $0x1f, %ebp
callq 0x3060
movq %rax, %r15
movl (%rax), %edi
callq 0x3470
movl %ebp, %edi
leaq 0x11a75(%rip), %rsi     # 0x151af
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x46d6
movl %r12d, %edi
leaq 0x60(%rsp), %rsi
callq 0x34a0
movq 0x90(%rsp), %rsi
xorl %edi, %edi
movq %rsi, 0x50(%rsp)
movl $0x1, %edx
movl $0x2, %ecx
movl %r12d, %r8d
xorl %r9d, %r9d
callq 0x3150
movq %rax, %rbp
xorl %r14d, %r14d
cmpq $-0x1, %rax
sete %r14b
movq %r15, 0x30(%rsp)
movl (%r15), %edi
callq 0x3470
movl %r14d, %edi
leaq 0x11a25(%rip), %rsi     # 0x151c2
movq %rbx, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x46d6
movl %r12d, %edi
callq 0x3220
cmpl $0x0, 0x28(%rsp)
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rsi
jle 0x38c0
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %r12
movq 0x8(%rax,%r14,8), %r15
cmpq %r15, %r12
jae 0x38b2
movl (%rbp,%r12,4), %ebx
movq (%rdx,%rbx,8), %r13
testq %r13, %r13
je 0x387f
movabsq $0x7ffffffffffffff8, %rax # imm = 0x7FFFFFFFFFFFFFF8
testq %rax, %r13
je 0x3897
movq %r13, %rax
shrq %rax
movabsq $0x5555555555555555, %rcx # imm = 0x5555555555555555
andq %rcx, %rax
movq %r13, %rcx
subq %rax, %rcx
movq %rcx, %rax
movabsq $0x3333333333333333, %rdi # imm = 0x3333333333333333
andq %rdi, %rax
shrq $0x2, %rcx
andq %rdi, %rcx
addq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
addq %rcx, %rax
movabsq $0xf0f0f0f0f0f0f0f, %rcx # imm = 0xF0F0F0F0F0F0F0F
andq %rcx, %rax
movabsq $0x101010101010101, %rcx # imm = 0x101010101010101
imulq %rcx, %rax
shrq $0x38, %rax
cmpl $0x1, %eax
ja 0x3897
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
leaq (,%r13,8), %rsi
callq 0x3350
jmp 0x3889
movl $0x40, %edi
callq 0x3340
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
movq %rax, (%rsi,%rbx,8)
movq (%rsi,%rbx,8), %rax
movl %r14d, (%rax,%r13,4)
incq %r13
movq %r13, (%rdx,%rbx,8)
incq %r12
cmpq %r12, %r15
jne 0x37e1
incq %r14
cmpq 0x58(%rsp), %r14
jne 0x37ca
movq %rbp, %rdi
movq 0x50(%rsp), %rsi
callq 0x3360
movq 0x8(%rsp), %rdx
movq (%rdx), %rax
movl $0x1, %ecx
addq (%rdx,%rcx,8), %rax
movq %rax, (%rdx,%rcx,8)
incq %rcx
cmpq $0x10000000, %rcx       # imm = 0x10000000
jne 0x38da
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1175e(%rip), %r13     # 0x1505e
movq %r13, %rsi
movq 0x48(%rsp), %r12
movq %r12, %rdx
leaq 0x11742(%rip), %rcx     # 0x15054
movl 0x2c(%rsp), %ebp
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x11740(%rip), %rbx     # 0x1506a
movq %rbx, %rsi
callq 0x33a0
testq %rax, %rax
je 0x3a55
movq %rax, %r14
movl $0x8, %esi
movl $0x10000000, %edx       # imm = 0x10000000
movq 0x8(%rsp), %rdi
movq %rax, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3100
leaq 0x1f0(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0x116db(%rip), %rcx     # 0x15050
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %rbx, %rsi
callq 0x33a0
testq %rax, %rax
je 0x3a6d
movq %rax, %r14
xorl %ebx, %ebx
movq 0x38(%rsp), %r15
testq %rbx, %rbx
je 0x39b2
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdx
subq -0x8(%rax,%rbx,8), %rdx
jmp 0x39ba
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rsp), %rax
testl %edx, %edx
jle 0x39e4
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x4, %esi
movq %r14, %rcx
callq 0x3450
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rdi
callq 0x3040
incq %rbx
cmpq $0x10000000, %rbx       # imm = 0x10000000
jne 0x399d
movq %r14, %rdi
callq 0x3100
incl %ebp
cmpl 0x24(%rsp), %ebp
jne 0x367b
movq 0x10(%rsp), %rdi
callq 0x3040
movq 0x18(%rsp), %rdi
callq 0x3040
movq 0x8(%rsp), %rdi
callq 0x3040
addq $0x4f8, %rsp            # imm = 0x4F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x1292b(%rip), %rsi     # 0x16376
leaq 0x2f0(%rsp), %rdx
jmp 0x3a83
movq 0x30(%rsp), %rax
movl (%rax), %edi
leaq 0x12913(%rip), %rsi     # 0x16376
leaq 0xf0(%rsp), %rdx
jmp 0x3a83
movq 0x30(%rsp), %rax
movl (%rax), %edi
leaq 0x115f2(%rip), %rsi     # 0x1506d
leaq 0x1f0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330