// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/hash10x.c
// Function: clusterSplitCodes
void clusterSplitCodes (void)
{
  int i, j, nSubClusters = 0 ;
  int nCodes = arrayMax (clusterBlocks) ; 
  for (i = 0 ; i < nCodes ; ++i) nSubClusters += arrp(clusterBlocks, i, ClusterBlock)->nSubCluster ;
  Array newBlocks = arrayCreate (nCodes+nSubClusters, ClusterBlock) ;
  arrayMax(newBlocks) = nCodes + nSubClusters ;
  ClusterBlock *old = arrp(clusterBlocks, 0, ClusterBlock) ;
  ClusterBlock *new1 = arrp(newBlocks, 0, ClusterBlock) ;
  ClusterBlock *new2 = arrp(newBlocks, nCodes-1, ClusterBlock) ; //-1 allows for ->subCluster offset
  Array clusterHashCount = arrayCreate (256, int) ; /* how many hashes in each cluster */
  Array readMap = arrayCreate (4096, int) ;
  for (i = 0 ; i < nCodes ; ++i, ++old)
    if (old->nSubCluster)
      { arrayReCreate (clusterHashCount, old->nSubCluster+1, int) ; /* zeroes array */
	ClusterHash *c = old->clusHash ;
	for (j = 0 ; j < old->nHash ; ++j, ++c) ++arr(clusterHashCount,c->subCluster,int) ;
	new1->clusHash = new0(arr(clusterHashCount,0,int), ClusterHash) ;
	for (j = 1 ; j < old->nSubCluster+1 ; ++j)
	  { new2[j].clusHash = new0(arr(clusterHashCount,j,int), ClusterHash) ;
	    new2[j].clusterParent = i+1 ;
	  }
	arrayReCreate (clusterHashCount, old->nSubCluster+1, int) ;
	arrayReCreate (readMap, old->nRead+1, int) ;
	for (j = 0, c = old->clusHash ; j < old->nHash ; ++j, ++c)
	  { int clus = c->subCluster ; c->subCluster = 0 ;
	    if (clus)
	      { if (!array(readMap,c->read,int)) arr(readMap,c->read,int) = ++new2[clus].nRead ;
	    // previous line requires that all hashes from same read are in same cluster
		c->read = arr(readMap,c->read,int) - 1 ;
		new2[clus].clusHash[new2[clus].nHash++] = *c ;
	      }
	    else new1->clusHash[new1->nHash++] = *c ;
	  }
	new1->nRead = old->nRead ; /* not strictly true any more, but safe */
	++new1 ;
	new2 += old->nSubCluster ;
	free (old->clusHash) ;
      }
    else
      *new1++ = *old ; // also carries over existing clusHash
  
  fprintf (outFile, "  made %d additional new barcodes from clusters in %d original barcodes\n",
	   nSubClusters, arrayMax(clusterBlocks)) ;
  if (outFile != stdout)
    printf ("  made %d additional new barcodes from clusters in %d original barcodes\n",
	    nSubClusters, arrayMax(clusterBlocks)) ;
  arrayDestroy (clusterBlocks) ;
  clusterBlocks = newBlocks ;
  arrayDestroy (clusterHashCount) ; arrayDestroy (readMap) ;
  printf ("  cluster timepoint: ") ; timeUpdate (stdout) ;

  // now must rebuild the mapping from hashes to codes
  for (i = 1 ; i < hashNumber ; ++i)
    if (arr(hashDepth,i,U32)) free (arr(hashCodes,i,U32*)) ;
  arrayDestroy (hashCodes) ;
  fillHashTable () ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0xc049(%rip), %rax      # 0x10398
movslq 0x18(%rax), %rcx
xorl %r8d, %r8d
testl %ecx, %ecx
movl $0x0, %ebp
movq %rcx, %r9
cmovgl %ecx, %ebp
xorl %ecx, %ecx
cmpl %ecx, %ebp
je 0x4381
movq 0x8(%rax), %rdx
movslq 0x14(%rax), %rsi
movslq %ecx, %rdi
imulq %rsi, %rdi
addl 0x8(%rdx,%rdi), %r8d
incl %ecx
jmp 0x4365
movq %r8, 0x30(%rsp)
movq %r9, %r14
leal (%r8,%r9), %r15d
pushq $0x20
popq %rsi
movl %r15d, %edi
callq 0x82c8
movl %r15d, 0x18(%rax)
movq 0xbff5(%rip), %rcx      # 0x10398
movq 0x8(%rcx), %rbx
movq 0x8(%rax), %r12
movq %rax, 0x28(%rsp)
movslq 0x14(%rax), %rax
decq %r14
imulq %rax, %r14
addq %r12, %r14
movq %r14, 0x18(%rsp)
pushq $0x4
popq %r14
movl $0x100, %edi            # imm = 0x100
movl %r14d, %esi
callq 0x82c8
movq %rax, %r15
movl $0x1000, %edi           # imm = 0x1000
movl %r14d, %esi
callq 0x82c8
movq %r12, %rcx
movq %rax, %r12
movq $0x0, 0x8(%rsp)
movl %ebp, 0x24(%rsp)
cmpl %ebp, 0x8(%rsp)
je 0x45bb
movl 0x8(%rbx), %esi
testl %esi, %esi
je 0x4594
movq %rcx, 0x10(%rsp)
incl %esi
movq %r15, %rdi
pushq $0x4
popq %rdx
callq 0x8343
movq 0x10(%rbx), %rcx
movq 0x8(%r15), %rax
xorl %edx, %edx
cmpl 0x4(%rbx), %edx
jae 0x4442
movzbl 0x6(%rcx,%rdx,8), %esi
movslq 0x14(%r15), %rdi
imulq %rsi, %rdi
incl (%rax,%rdi)
incq %rdx
jmp 0x4428
movslq (%rax), %rdi
pushq $0x8
popq %rsi
callq 0x8b24
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
leaq 0x30(%rax), %r14
pushq $0x1
popq %r13
movl 0x8(%rbx), %esi
incl %esi
cmpq %rsi, %r13
jae 0x44a9
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
movslq %r13d, %rdx
imulq %rcx, %rdx
movslq (%rax,%rdx), %rdi
pushq $0x8
popq %rsi
callq 0x8b24
movq %rax, (%r14)
movq 0x8(%rsp), %rax
movl %eax, -0x4(%r14)
incq %r13
addq $0x20, %r14
jmp 0x446f
movq %r15, %rdi
pushq $0x4
popq %rbp
movl %ebp, %edx
callq 0x8343
movl (%rbx), %esi
incl %esi
movq %r12, %rdi
movl %ebp, %edx
callq 0x8343
movq 0x10(%rbx), %r14
xorl %ebp, %ebp
movq 0x10(%rsp), %rdi
cmpl 0x4(%rbx), %ebp
jae 0x4570
movzbl 0x6(%r14,%rbp,8), %r13d
movb $0x0, 0x6(%r14,%rbp,8)
movq %rdi, %rax
testq %r13, %r13
je 0x4553
movzwl 0x4(%r14,%rbp,8), %esi
movq %r12, %rdi
callq 0x8560
cmpl $0x0, (%rax)
movq 0x8(%r12), %rax
movzwl 0x4(%r14,%rbp,8), %ecx
movl %ecx, %ecx
jne 0x452e
movl %r13d, %edx
shll $0x5, %edx
movq 0x18(%rsp), %rdi
movl (%rdi,%rdx), %esi
incl %esi
movl %esi, (%rdi,%rdx)
movslq 0x14(%r12), %rdx
movq %rcx, %rdi
imulq %rdx, %rdi
movl %esi, (%rax,%rdi)
movslq 0x14(%r12), %rdx
imulq %rdx, %rcx
movl (%rax,%rcx), %eax
decl %eax
movw %ax, 0x4(%r14,%rbp,8)
shll $0x5, %r13d
addq 0x18(%rsp), %r13
movq %r13, %rax
movq 0x10(%rsp), %rdi
movq 0x10(%rax), %rcx
movl 0x4(%rax), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x4(%rax)
movq (%r14,%rbp,8), %rax
movq %rax, (%rcx,%rdx,8)
incq %rbp
jmp 0x44cf
movl (%rbx), %eax
movl %eax, (%rdi)
movl 0x8(%rbx), %eax
shlq $0x5, %rax
addq %rax, 0x18(%rsp)
movq 0x10(%rbx), %rdi
callq 0x1040
movq 0x10(%rsp), %rcx
movl 0x24(%rsp), %ebp
jmp 0x45ae
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
addq $0x20, %rcx
addq $0x20, %rbx
jmp 0x43f7
movq 0xbdde(%rip), %rdi      # 0x103a0
movq 0xbdcf(%rip), %rax      # 0x10398
movl 0x18(%rax), %ecx
leaq 0x544f(%rip), %rsi      # 0x9a22
movq 0x30(%rsp), %r14
movl %r14d, %edx
xorl %eax, %eax
callq 0x1150
movq 0xbdb7(%rip), %rax      # 0x103a0
movq 0xa9d8(%rip), %rbx      # 0xefc8
cmpq (%rbx), %rax
je 0x4610
movq 0xbd9c(%rip), %rax      # 0x10398
movl 0x18(%rax), %edx
leaq 0x541c(%rip), %rdi      # 0x9a22
movl %r14d, %esi
xorl %eax, %eax
callq 0x10d0
movq 0xbd81(%rip), %rdi      # 0x10398
callq 0x8408
movq 0x28(%rsp), %rax
movq %rax, 0xbd70(%rip)      # 0x10398
movq %r15, %rdi
callq 0x8408
movq %r12, %rdi
callq 0x8408
leaq 0x542c(%rip), %rdi      # 0x9a6b
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rdi
callq 0x8d03
pushq $0x1
popq %rbx
movl 0xbd61(%rip), %eax      # 0x103b8
cmpl %eax, %ebx
jae 0x469d
movq 0xbd2e(%rip), %rcx      # 0x10390
movq 0x8(%rcx), %rdx
movslq 0x14(%rcx), %rsi
movslq %ebx, %rcx
imulq %rcx, %rsi
cmpl $0x0, (%rdx,%rsi)
je 0x4699
movq 0xbd4a(%rip), %rax      # 0x103c8
movq 0x8(%rax), %rdx
movslq 0x14(%rax), %rax
imulq %rcx, %rax
movq (%rdx,%rax), %rdi
callq 0x1040
movl 0xbd1f(%rip), %eax      # 0x103b8
incl %ebx
jmp 0x4657
movq 0xbd24(%rip), %rdi      # 0x103c8
callq 0x8408
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1fdd