// File: /workspace/github_c_makefile_star2_O3/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 0xb3fe(%rip), %rcx      # 0x10388
movslq 0x18(%rcx), %rbx
testq %rbx, %rbx
jle 0x4fb0
movq 0x8(%rcx), %rax
movslq 0x14(%rcx), %rcx
addq $0x8, %rax
xorl %esi, %esi
movq %rbx, %rdx
addl (%rax), %esi
addq %rcx, %rax
decq %rdx
jne 0x4fa4
jmp 0x4fb2
xorl %esi, %esi
movq %rsi, 0x28(%rsp)
leal (%rsi,%rbx), %ebp
movl %ebp, %edi
movl $0x20, %esi
callq 0x8e88
movl %ebp, 0x18(%rax)
movq 0xb3b8(%rip), %rcx      # 0x10388
movq 0x8(%rcx), %rbp
movq 0x8(%rax), %r14
movq %rax, 0x20(%rsp)
movslq 0x14(%rax), %r13
movl $0x100, %edi            # imm = 0x100
movl $0x4, %esi
callq 0x8e88
movq %rax, %r15
movl $0x1000, %edi           # imm = 0x1000
movl $0x4, %esi
callq 0x8e88
movq %rax, %r12
testl %ebx, %ebx
jle 0x51fd
movq %r14, %rcx
leaq -0x1(%rbx), %rax
imulq %rax, %r13
addq %r14, %r13
movq %r13, 0x10(%rsp)
xorl %eax, %eax
movq %rbx, 0x30(%rsp)
movl 0x8(%rbp), %esi
testl %esi, %esi
je 0x51dc
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
incl %esi
movq %r15, %rdi
movl $0x4, %edx
callq 0x8f0c
cmpl $0x0, 0x4(%rbp)
movq 0x8(%r15), %rax
je 0x5073
movq 0x10(%rbp), %rcx
xorl %edx, %edx
movzbl 0x6(%rcx,%rdx,8), %esi
movslq 0x14(%r15), %rdi
imulq %rsi, %rdi
incl (%rax,%rdi)
incq %rdx
cmpl 0x4(%rbp), %edx
jb 0x505b
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x96e8
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movl 0x8(%rbp), %esi
incl %esi
cmpl $0x2, %esi
jb 0x50df
movq 0x18(%rsp), %rax
leal 0x1(%rax), %ebx
movq 0x10(%rsp), %rax
leaq 0x30(%rax), %r14
movl $0x1, %r13d
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
movslq %r13d, %rdx
imulq %rcx, %rdx
movslq (%rax,%rdx), %rdi
movl $0x8, %esi
callq 0x96e8
movq %rax, (%r14)
movl %ebx, -0x4(%r14)
incq %r13
movl 0x8(%rbp), %esi
incl %esi
addq $0x20, %r14
cmpq %rsi, %r13
jb 0x50aa
movq %r15, %rdi
movl $0x4, %edx
callq 0x8f0c
movl (%rbp), %esi
incl %esi
movq %r12, %rdi
movl $0x4, %edx
callq 0x8f0c
cmpl $0x0, 0x4(%rbp)
movq 0x8(%rsp), %rdi
je 0x51b1
movq 0x10(%rbp), %rbx
xorl %r13d, %r13d
movzbl 0x6(%rbx,%r13,8), %r14d
movb $0x0, 0x6(%rbx,%r13,8)
movq %rdi, %rax
testq %r14, %r14
je 0x518f
movzwl 0x4(%rbx,%r13,8), %esi
movq %r12, %rdi
callq 0x9131
cmpl $0x0, (%rax)
movq 0x8(%r12), %rax
movzwl 0x4(%rbx,%r13,8), %ecx
movl %ecx, %ecx
jne 0x516a
movl %r14d, %edx
shll $0x5, %edx
movq 0x10(%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(%rbx,%r13,8)
shll $0x5, %r14d
addq 0x10(%rsp), %r14
movq %r14, %rax
movq 0x8(%rsp), %rdi
movq 0x10(%rax), %rcx
movl 0x4(%rax), %edx
leal 0x1(%rdx), %esi
movl %esi, 0x4(%rax)
movq (%rbx,%r13,8), %rax
movq %rax, (%rcx,%rdx,8)
incq %r13
cmpl 0x4(%rbp), %r13d
jb 0x5114
movl (%rbp), %eax
movl %eax, (%rdi)
movl 0x8(%rbp), %eax
shlq $0x5, %rax
addq %rax, 0x10(%rsp)
movq 0x10(%rbp), %rdi
callq 0x1040
movq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rbx
movq 0x18(%rsp), %rax
jmp 0x51eb
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
addq $0x20, %rcx
incl %eax
addq $0x20, %rbp
cmpl %ebx, %eax
jne 0x5027
movq 0xb18c(%rip), %rdi      # 0x10390
movq 0xb17d(%rip), %rax      # 0x10388
movl 0x18(%rax), %ecx
leaq 0x584d(%rip), %rsi      # 0xaa62
movq 0x28(%rsp), %r14
movl %r14d, %edx
xorl %eax, %eax
callq 0x1150
movq 0xb165(%rip), %rax      # 0x10390
movq 0x9d96(%rip), %rbx      # 0xefc8
cmpq (%rbx), %rax
je 0x5252
movq 0xb14a(%rip), %rax      # 0x10388
movl 0x18(%rax), %edx
leaq 0x581a(%rip), %rdi      # 0xaa62
movl %r14d, %esi
xorl %eax, %eax
callq 0x10d0
movq 0xb12f(%rip), %rdi      # 0x10388
callq 0x8fd6
movq 0x20(%rsp), %rax
movq %rax, 0xb11e(%rip)      # 0x10388
movq %r15, %rdi
callq 0x8fd6
movq %r12, %rdi
callq 0x8fd6
leaq 0x582a(%rip), %rdi      # 0xaaab
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rdi
callq 0x98d9
movl 0xb112(%rip), %eax      # 0x103a8
cmpl $0x2, %eax
jb 0x52eb
movl $0x1, %ebx
movq 0xb0d9(%rip), %rcx      # 0x10380
movq 0x8(%rcx), %rsi
movslq 0x14(%rcx), %rdi
movslq %ebx, %rdx
imulq %rdx, %rdi
cmpl $0x0, (%rsi,%rdi)
je 0x52e5
movq 0xb0f5(%rip), %rax      # 0x103b8
movq 0x8(%rax), %rcx
movslq 0x14(%rax), %rax
imulq %rdx, %rax
movq (%rcx,%rax), %rdi
callq 0x1040
movq 0xb0a1(%rip), %rcx      # 0x10380
movl 0xb0c3(%rip), %eax      # 0x103a8
incl %ebx
cmpl %eax, %ebx
jb 0x52a7
movq 0xb0c6(%rip), %rdi      # 0x103b8
callq 0x8fd6
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2957