// File: /workspace/github_c_makefile_star2_O3/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, 0x2c(%rsp)
movslq %edx, %rbx
leaq 0x8(,%rbx,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
movq %rax, 0x8(%rsp)
movl %ebp, 0x28(%rsp)
testl %ebp, %ebp
jle 0x3a0a
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 0x1392f(%rip), %rcx     # 0x16fd3
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x119af(%rip), %rsi     # 0x15067
callq 0x33a0
testq %rax, %rax
je 0x3a3a
movq %rax, %r14
movl $0x8, %esi
movq 0x20(%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 0x138cc(%rip), %rcx     # 0x16fcc
movl %ebp, 0x1c(%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 0x46f2
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 0x46f2
movl %r12d, %edi
callq 0x3220
cmpl $0x0, 0x2c(%rsp)
movq 0x8(%rsp), %rsi
jle 0x38c1
movq 0x20(%rsp), %rax
movq (%rax), %r15
xorl %r12d, %r12d
movq %r15, %r14
movq 0x20(%rsp), %rax
movq 0x8(%rax,%r12,8), %r15
cmpq %r15, %r14
jae 0x38b3
movl (%rbp,%r14,4), %ebx
movq (%rsi,%rbx,8), %r13
testq %r13, %r13
je 0x3884
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rax
movabsq $0x7ffffffffffffff8, %rcx # imm = 0x7FFFFFFFFFFFFFF8
testq %rcx, %r13
je 0x389c
movq %r13, %rcx
shrq %rcx
movabsq $0x5555555555555555, %rdx # imm = 0x5555555555555555
andq %rdx, %rcx
movq %r13, %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 0x389c
leaq (,%r13,8), %rsi
movq %rax, %rdi
callq 0x3350
jmp 0x388e
movl $0x40, %edi
callq 0x3340
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movl %r12d, (%rax,%r13,4)
incq %r13
movq %r13, (%rsi,%rbx,8)
incq %r14
cmpq %r14, %r15
jne 0x37e3
incq %r12
cmpq 0x58(%rsp), %r12
jne 0x37cd
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 0x38db
leaq 0xf0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x1175d(%rip), %r13     # 0x1505e
movq %r13, %rsi
movq 0x48(%rsp), %r12
movq %r12, %rdx
leaq 0x11741(%rip), %rcx     # 0x15054
movl 0x1c(%rsp), %ebp
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %rbx, %rdi
leaq 0x1173f(%rip), %rbx     # 0x1506a
movq %rbx, %rsi
callq 0x33a0
testq %rax, %rax
je 0x3a52
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 0x116da(%rip), %rcx     # 0x15050
movl %ebp, %r8d
xorl %eax, %eax
callq 0x3430
movq %r14, %rdi
movq %rbx, %rsi
callq 0x33a0
testq %rax, %rax
je 0x3a6a
movq %rax, %r14
xorl %ebx, %ebx
movq 0x38(%rsp), %r15
testq %rbx, %rbx
je 0x39b3
movq 0x8(%rsp), %rax
movq (%rax,%rbx,8), %rdx
subq -0x8(%rax,%rbx,8), %rdx
jmp 0x39bb
movq 0x8(%rsp), %rax
movq (%rax), %rdx
movq 0x10(%rsp), %rax
movq (%rax,%rbx,8), %rbp
testl %edx, %edx
jle 0x39de
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movl $0x4, %esi
movq %rbp, %rdi
movq %r14, %rcx
callq 0x3450
movq %rbp, %rdi
callq 0x3040
incq %rbx
cmpq $0x10000000, %rbx       # imm = 0x10000000
jne 0x399e
movq %r14, %rdi
callq 0x3100
movl 0x1c(%rsp), %ebp
incl %ebp
cmpl 0x28(%rsp), %ebp
jne 0x367b
movq 0x10(%rsp), %rdi
callq 0x3040
movq 0x20(%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 0x1297e(%rip), %rsi     # 0x163c6
leaq 0x2f0(%rsp), %rdx
jmp 0x3a80
movq 0x30(%rsp), %rax
movl (%rax), %edi
leaq 0x12966(%rip), %rsi     # 0x163c6
leaq 0xf0(%rsp), %rdx
jmp 0x3a80
movq 0x30(%rsp), %rax
movl (%rax), %edi
leaq 0x115f5(%rip), %rsi     # 0x1506d
leaq 0x1f0(%rsp), %rdx
xorl %eax, %eax
callq 0x3330