// File: /workspace/github_c_makefile_star2_O1/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 0xb4ba(%rip), %rcx      # 0x10388
movslq 0x18(%rcx), %rbx
testq %rbx, %rbx
jle 0x4ef4
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 0x4ee8
jmp 0x4ef6
xorl %esi, %esi
movq %rsi, 0x28(%rsp)
leal (%rsi,%rbx), %ebp
movl %ebp, %edi
movl $0x20, %esi
callq 0x8c70
movl %ebp, 0x18(%rax)
movq 0xb474(%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 0x8c70
movq %rax, %r15
movl $0x1000, %edi           # imm = 0x1000
movl $0x4, %esi
callq 0x8c70
movq %rax, %r12
testl %ebx, %ebx
jle 0x514b
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 0x512a
movq %rax, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
incl %esi
movq %r15, %rdi
movl $0x4, %edx
callq 0x8cf4
cmpl $0x0, 0x4(%rbp)
je 0x4fb7
movq 0x10(%rbp), %rax
movq 0x8(%r15), %rcx
xorl %edx, %edx
movzbl 0x6(%rax,%rdx,8), %esi
movslq 0x14(%r15), %rdi
imulq %rsi, %rdi
incl (%rcx,%rdi)
incq %rdx
cmpl 0x4(%rbp), %edx
jb 0x4f9f
movq 0x8(%r15), %rax
movslq (%rax), %rdi
movl $0x8, %esi
callq 0x94f8
movq 0x8(%rsp), %rcx
movq %rax, 0x10(%rcx)
movl 0x8(%rbp), %esi
incl %esi
cmpl $0x2, %esi
jb 0x5027
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 0x94f8
movq %rax, (%r14)
movl %ebx, -0x4(%r14)
incq %r13
movl 0x8(%rbp), %esi
incl %esi
addq $0x20, %r14
cmpq %rsi, %r13
jb 0x4ff2
movq %r15, %rdi
movl $0x4, %edx
callq 0x8cf4
movl (%rbp), %esi
incl %esi
movq %r12, %rdi
movl $0x4, %edx
callq 0x8cf4
cmpl $0x0, 0x4(%rbp)
movq 0x8(%rsp), %rdi
je 0x50ff
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 0x50dd
movzwl 0x4(%rbx,%r13,8), %esi
movq %r12, %rdi
callq 0x8f2b
cmpl $0x0, (%rax)
jne 0x50ad
movl %r14d, %eax
shll $0x5, %eax
movq 0x10(%rsp), %rdx
movl (%rdx,%rax), %ecx
incl %ecx
movl %ecx, (%rdx,%rax)
movq 0x8(%r12), %rax
movzwl 0x4(%rbx,%r13,8), %edx
movslq 0x14(%r12), %rsi
imulq %rdx, %rsi
movl %ecx, (%rax,%rsi)
movq 0x8(%r12), %rax
movzwl 0x4(%rbx,%r13,8), %ecx
movslq 0x14(%r12), %rdx
imulq %rcx, %rdx
movl (%rax,%rdx), %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 0x505c
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 0x5139
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 0x4f6b
movq 0xb23e(%rip), %rdi      # 0x10390
movq 0xb22f(%rip), %rax      # 0x10388
movl 0x18(%rax), %ecx
leaq 0x58bf(%rip), %rsi      # 0xaa22
movq 0x28(%rsp), %r14
movl %r14d, %edx
xorl %eax, %eax
callq 0x1150
movq 0xb217(%rip), %rax      # 0x10390
movq 0x9e48(%rip), %rbx      # 0xefc8
cmpq (%rbx), %rax
je 0x51a0
movq 0xb1fc(%rip), %rax      # 0x10388
movl 0x18(%rax), %edx
leaq 0x588c(%rip), %rdi      # 0xaa22
movl %r14d, %esi
xorl %eax, %eax
callq 0x10d0
movq 0xb1e1(%rip), %rdi      # 0x10388
callq 0x8dc9
movq 0x20(%rsp), %rax
movq %rax, 0xb1d0(%rip)      # 0x10388
movq %r15, %rdi
callq 0x8dc9
movq %r12, %rdi
callq 0x8dc9
leaq 0x589c(%rip), %rdi      # 0xaa6b
xorl %eax, %eax
callq 0x10d0
movq (%rbx), %rdi
callq 0x96ed
cmpl $0x2, 0xb1c3(%rip)      # 0x103a8
jb 0x522e
movl $0x1, %ebx
movq 0xb18d(%rip), %rax      # 0x10380
movq 0x8(%rax), %rcx
movslq 0x14(%rax), %rdx
movslq %ebx, %rax
imulq %rax, %rdx
cmpl $0x0, (%rcx,%rdx)
je 0x5224
movq 0xb1a9(%rip), %rcx      # 0x103b8
movq 0x8(%rcx), %rdx
movslq 0x14(%rcx), %rcx
imulq %rax, %rcx
movq (%rdx,%rcx), %rdi
callq 0x1040
incl %ebx
cmpl 0xb17c(%rip), %ebx      # 0x103a8
jb 0x51ec
movq 0xb183(%rip), %rdi      # 0x103b8
callq 0x8dc9
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x296d