// File: /workspace/github_c_makefile_star2_O2/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 $0x468, %rsp            # imm = 0x468
movl %ecx, %ebx
movq %rsi, %r12
movq %rdi, 0x38(%rsp)
movslq %edx, %r14
leaq 0x1(%r14), %rax
movq %rax, 0x30(%rsp)
leaq 0x8(,%r14,8), %rdi
callq 0x3340
movq %rax, 0x20(%rsp)
movl $0x80000000, %edi       # imm = 0x80000000
callq 0x3340
movq %rax, 0x10(%rsp)
movl $0x80000000, %edi       # imm = 0x80000000
callq 0x3340
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %r14d
movq %r14, 0x50(%rsp)
testl %ebx, %ebx
cmovlel %ecx, %ebx
movl %ebx, 0x2c(%rsp)
leaq 0x10a12(%rip), %rbx     # 0x1405e
xorl %ebp, %ebp
movq %r12, 0x48(%rsp)
movq %rax, 0x8(%rsp)
cmpl 0x2c(%rsp), %ebp
je 0x3951
movl $0x80000000, %edx       # imm = 0x80000000
movq %rax, %rdi
xorl %esi, %esi
callq 0x3210
leaq 0x260(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
leaq 0x128fa(%rip), %rcx     # 0x15f83
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
leaq 0x109ca(%rip), %rsi     # 0x14067
callq 0x33a0
testq %rax, %rax
je 0x3982
movq %rbx, %r14
movq %rax, %rbx
movq 0x20(%rsp), %rdi
pushq $0x8
popq %rsi
movq 0x30(%rsp), %rdx
movq %rax, %rcx
callq 0x30c0
movq %rbx, %rdi
callq 0x3100
leaq 0x360(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
leaq 0x12896(%rip), %rcx     # 0x15f7c
movl %ebp, 0x1c(%rsp)
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
callq 0x39cc
movq %rax, 0x40(%rsp)
movq %rdx, %rbx
xorl %r14d, %r14d
movq 0x8(%rsp), %rsi
cmpq 0x50(%rsp), %r14
je 0x380f
movq 0x20(%rsp), %rax
movq (%rax,%r14,8), %r12
movq 0x8(%rax,%r14,8), %r15
leaq 0x1(%r14), %rax
movq %rax, 0x58(%rsp)
cmpq %r15, %r12
jae 0x3800
movl (%rbx,%r12,4), %r13d
movq (%rsi,%r13,8), %rbp
testq %rbp, %rbp
je 0x37d7
movq 0x10(%rsp), %rax
movq (%rax,%r13,8), %rax
movabsq $0x7ffffffffffffff8, %rcx # imm = 0x7FFFFFFFFFFFFFF8
testq %rcx, %rbp
je 0x37ed
movq %rbp, %rcx
shrq %rcx
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
andq %rdx, %rcx
movq %rbp, %rdx
subq %rcx, %rdx
movq %rdx, %rcx
movabsq $0x3333333333333333, %rdi # imm = 0x3333333333333333
andq %rdi, %rcx
shrq $0x2, %rdx
andq %rdi, %rdx
addq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
addq %rdx, %rcx
movabsq $0xf0f0f0f0f0f0f0f, %rdx # imm = 0xF0F0F0F0F0F0F0F
andq %rdx, %rcx
movabsq $0x101010101010101, %rdx # imm = 0x101010101010101
imulq %rdx, %rcx
shrq $0x38, %rcx
cmpl $0x1, %ecx
ja 0x37ed
leaq (,%rbp,8), %rsi
movq %rax, %rdi
callq 0x3350
jmp 0x37df
pushq $0x40
popq %rdi
callq 0x3340
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%r13,8)
movl %r14d, (%rax,%rbp,4)
incq %rbp
movq %rbp, (%rsi,%r13,8)
incq %r12
jmp 0x372e
movq 0x58(%rsp), %r14
movq 0x48(%rsp), %r12
jmp 0x370c
movq %rbx, %rdi
movq 0x40(%rsp), %rsi
callq 0x3360
movq 0x8(%rsp), %rdx
pushq $0x1
popq %rax
movq 0x38(%rsp), %r14
leaq 0x1082e(%rip), %rbx     # 0x1405e
movl 0x1c(%rsp), %ebp
cmpq $0x10000000, %rax       # imm = 0x10000000
je 0x384a
movq -0x8(%rdx,%rax,8), %rcx
addq %rcx, (%rdx,%rax,8)
incq %rax
jmp 0x3834
leaq 0x60(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
leaq 0x107f5(%rip), %rcx     # 0x14054
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r15, %rdi
leaq 0x107f7(%rip), %r13     # 0x1406a
movq %r13, %rsi
callq 0x33a0
testq %rax, %rax
je 0x399a
movq %rbx, %r15
movq %rax, %rbx
movl $0x10000000, %edx       # imm = 0x10000000
movq 0x8(%rsp), %rdi
pushq $0x8
popq %rsi
movq %rax, %rcx
callq 0x3450
movq %rbx, %rdi
callq 0x3100
leaq 0x160(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
movq %r14, %rdx
leaq 0x10791(%rip), %rcx     # 0x14050
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
movq %r13, %rsi
callq 0x33a0
testq %rax, %rax
je 0x39af
movq %rax, %rbx
xorl %r15d, %r15d
movq 0x8(%rsp), %rax
testq %r15, %r15
je 0x3901
cmpq $0x10000000, %r15       # imm = 0x10000000
je 0x3932
movq (%rax,%r15,8), %rdx
subq -0x8(%rax,%r15,8), %rdx
jmp 0x3904
movq (%rax), %rdx
movq 0x10(%rsp), %rax
movq (%rax,%r15,8), %r14
testl %edx, %edx
jle 0x3925
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r14, %rdi
pushq $0x4
popq %rsi
movq %rbx, %rcx
callq 0x3450
movq %r14, %rdi
callq 0x3040
incq %r15
jmp 0x38e3
movq %rbx, %rdi
callq 0x3100
movq 0x8(%rsp), %rax
movl 0x1c(%rsp), %ebp
incl %ebp
leaq 0x10712(%rip), %rbx     # 0x1405e
jmp 0x3658
movq %rax, %rbx
movq 0x10(%rsp), %rdi
callq 0x3040
movq 0x20(%rsp), %rdi
callq 0x3040
movq %rbx, %rdi
callq 0x3040
addq $0x468, %rsp            # imm = 0x468
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3060
movl (%rax), %edi
leaq 0x119e6(%rip), %rsi     # 0x15376
leaq 0x260(%rsp), %rdx
jmp 0x39c5
callq 0x3060
movl (%rax), %edi
leaq 0x119ce(%rip), %rsi     # 0x15376
leaq 0x60(%rsp), %rdx
jmp 0x39c5
callq 0x3060
movl (%rax), %edi
leaq 0x106b0(%rip), %rsi     # 0x1406d
leaq 0x160(%rsp), %rdx
xorl %eax, %eax
callq 0x3330