// File: /workspace/github_c_makefile_star2_O3/richarddurbin[P]hash10x/hash10x.c
// Function: codeClusterFind
void codeClusterFind (int code, int clusterThreshold) /* clusters this barcode's good hashes */
{
  ClusterBlock *b = arrp(clusterBlocks, code, ClusterBlock), *c ;
  ClusterHash *cb = b->clusHash, *cc ;
  int i, j ;
  U32 x, nc ;
  int *minShare = new0 (arrayMax(clusterBlocks), int) ; /* lowest hash shared with code */
  U16 *g, *gi, *gc, *gcn ;
  Array clusterMin = arrayCreate (64, int) ;

  int n = nGoodHashes[code] ; if (!n) return ;
  int *minShareCount = new (n, int) ;

  for (i = 0 ; i < n ; ++i) b->clusHash[goodHashes[code][i]].subCluster = 0 ; /* wipe existing */

  b->nSubCluster = 0 ;
  //  if (!b->cluster) b->cluster = arrayCreate (32, ClusterInfo) ;
  b->pointToMin = 0.0 ;
  int nSubClustered = 0 ;
  for (i = 1 ; i < n ; ++i)	// shouldn't this be from i = 0 ?
    { x = b->clusHash[goodHashes[code][i]].hash ;
      nc = arr(hashDepth, x, U32) ;
      memset (minShareCount, 0, n*sizeof(int)) ;
					       
      for (j = 0 ; j < nc ; ++j)
	{ int cj = arr(hashCodes, x, U32*)[j] ;
	  if (cj == code) continue ;
	  if (!minShare[cj]) minShare[cj] = i+1 ;
	  ++minShareCount[minShare[cj]-1] ;
	}

      int msMax = 0, msTot = 0, msBest ;
      g = goodHashes[code] ;
      for (j = 0 ; j < i ; ++j)
	{ if (minShareCount[j] > msMax)  { msBest = j ; msMax = minShareCount[j] ; }
	  msTot += minShareCount[j] ;
	}
      if (msMax >= clusterThreshold)
	{ ClusterHash *ch = &b->clusHash[g[msBest]] ;
	  if (!ch->subCluster)	/* create a new cluster */
	    { if (++b->nSubCluster > U8MAX) /* abandon this clustering */
		{ b->nSubCluster = 0 ; nSubClustered = 0 ;
		  for (j = 0 ; j < i ; ++j) b->clusHash[g[j]].subCluster = 0 ;
		  fprintf (stderr, "    code %d with %d good hashes has too many clusters\n",
			   code, nGoodHashes[code]) ;
		  break ;
		}
	      ch->subCluster = b->nSubCluster ; ++nSubClustered ;
	      array(clusterMin,b->nSubCluster,int) = msBest ;
	    }
	  b->clusHash[g[i]].subCluster = ch->subCluster ; ++nSubClustered ;
	  b->pointToMin += minShareCount[arr(clusterMin,ch->subCluster,int)] / (double)msTot ;
	}
    }
  free (minShare) ;
  free (minShareCount) ;
  arrayDestroy (clusterMin) ;
  if (isVerbose)
    { if (b->nSubCluster)
	fprintf (outFile, "  code %d with %d reads %d hashes, %d good hashes, of which %d cluster into %d raw",
		 code, b->nRead, b->nHash, nGoodHashes[code], nSubClustered, b->nSubCluster) ;
      else
	fprintf (outFile, "  code %d with %d reads %d hashes, %d good hashes, 0 clusters\n",
		 code, b->nRead, b->nHash, nGoodHashes[code]) ;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, 0x3c(%rsp)
movl %edi, %ebx
movq 0xbdfe(%rip), %rax      # 0x10388
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movslq 0x14(%rax), %r15
movslq %edi, %r14
movslq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x96e8
movq %rax, 0x40(%rsp)
movl $0x40, %edi
movl $0x4, %esi
callq 0x8e88
movq 0xbe55(%rip), %rdx      # 0x10418
movslq (%rdx,%r14,4), %r13
testq %r13, %r13
je 0x48b6
movq %rax, 0x10(%rsp)
imulq %r14, %r15
leaq (,%r13,4), %rdi
movq %rdi, 0x60(%rsp)
callq 0x96c0
movq %rax, %r12
testl %r13d, %r13d
movq %r14, 0x20(%rsp)
jle 0x4825
movq 0x8(%rsp), %rdi
movq 0x10(%rdi,%r15), %rax
movq 0xbe03(%rip), %rcx      # 0x10410
movq (%rcx,%r14,8), %rcx
xorl %edx, %edx
movq %r14, %r8
movq %r15, %r9
movzwl (%rcx,%rdx,2), %esi
movb $0x0, 0x6(%rax,%rsi,8)
incq %rdx
cmpq %rdx, %r13
jne 0x4619
movl $0x0, 0x8(%rdi,%r9)
movq $0x0, 0x18(%rdi,%r9)
xorl %r10d, %r10d
movq %r13, 0x58(%rsp)
cmpl $0x1, %r13d
je 0x4842
xorl %r10d, %r10d
movl $0x1, %ebp
movq 0xbdb3(%rip), %rax      # 0x10410
movq %r9, 0x18(%rsp)
movq %r10, 0x30(%rsp)
movq 0x10(%rdi,%r9), %rcx
movq (%rax,%r8,8), %rax
movzwl (%rax,%rbp,2), %eax
movl (%rcx,%rax,8), %r14d
movq 0xbd01(%rip), %rax      # 0x10380
movq 0x8(%rax), %rcx
movl 0x14(%rax), %eax
imull %r14d, %eax
movl (%rcx,%rax), %r15d
movq %r12, %rdi
xorl %esi, %esi
movq 0x60(%rsp), %rdx
callq 0x10f0
testq %r15, %r15
movq 0x40(%rsp), %r9
je 0x46ea
movq 0xbd0a(%rip), %rax      # 0x103b8
movq 0x8(%rax), %rcx
leal 0x1(%rbp), %edx
xorl %esi, %esi
movl 0x14(%rax), %edi
imull %r14d, %edi
movq (%rcx,%rdi), %rdi
movslq (%rdi,%rsi,4), %rdi
cmpl %ebx, %edi
je 0x46e2
movl (%r9,%rdi,4), %r8d
testl %r8d, %r8d
jne 0x46da
movl %edx, (%r9,%rdi,4)
movl %edx, %r8d
movslq %r8d, %rdi
incl -0x4(%r12,%rdi,4)
incq %rsi
cmpq %rsi, %r15
jne 0x46b7
movq 0xbd1f(%rip), %rax      # 0x10410
movq 0x20(%rsp), %r8
movq (%rax,%r8,8), %rcx
movq %rcx, 0x28(%rsp)
xorl %ecx, %ecx
xorl %r14d, %r14d
xorl %edx, %edx
movl (%r12,%rcx,4), %esi
cmpl %edx, %esi
cmovgl %esi, %edx
cmovgl %ecx, %r13d
addl %esi, %r14d
incq %rcx
cmpq %rcx, %rbp
jne 0x4706
cmpl 0x3c(%rsp), %edx
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %r9
movq 0x30(%rsp), %r10
jl 0x4815
movq 0x10(%rdi,%r9), %rdx
movslq %r13d, %rcx
movq 0x28(%rsp), %rsi
movzwl (%rsi,%rcx,2), %r15d
movb 0x6(%rdx,%r15,8), %cl
testb %cl, %cl
je 0x475f
movq %rdx, %r11
movq %r15, %r8
movq 0x10(%rsp), %r15
jmp 0x47cd
movl 0x8(%rdi,%r9), %esi
incl %esi
movl %esi, 0x8(%rdi,%r9)
cmpl $0x100, %esi            # imm = 0x100
jae 0x48e3
movb %sil, 0x6(%rdx,%r15,8)
incl %r10d
movq %r10, 0x30(%rsp)
movq %r15, 0x50(%rsp)
movq 0x10(%rsp), %r15
movq %r15, %rdi
movq %rdx, 0x48(%rsp)
callq 0x9131
movq 0x30(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rdi
movl %r13d, (%rax)
movq 0xbc5c(%rip), %rax      # 0x10410
movq 0x50(%rsp), %rcx
movq %rcx, %r8
movq 0x48(%rsp), %rdx
movq %rdx, %r11
movb 0x6(%rdx,%rcx,8), %cl
movq 0x10(%rdi,%r9), %rdx
movq 0x28(%rsp), %rsi
movzwl (%rsi,%rbp,2), %esi
movb %cl, 0x6(%rdx,%rsi,8)
incl %r10d
movq 0x8(%r15), %rcx
movzbl 0x6(%r11,%r8,8), %edx
movslq 0x14(%r15), %rsi
imulq %rdx, %rsi
movslq (%rcx,%rsi), %rcx
cvtsi2sdl (%r12,%rcx,4), %xmm0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
addsd 0x18(%rdi,%r9), %xmm0
movsd %xmm0, 0x18(%rdi,%r9)
movq 0x20(%rsp), %r8
incq %rbp
cmpq 0x58(%rsp), %rbp
jne 0x4662
jmp 0x4842
movq 0x8(%rsp), %rax
movl $0x0, 0x8(%rax,%r15)
movq $0x0, 0x18(%rax,%r15)
xorl %r10d, %r10d
movq %r15, %r9
movq %r10, %r15
movq 0x40(%rsp), %rdi
movq %r9, %r14
callq 0x1040
movq %r12, %rdi
callq 0x1040
movq 0x10(%rsp), %rdi
callq 0x8fd6
movq 0x20(%rsp), %rdx
cmpb $0x0, 0xbb01(%rip)      # 0x10371
je 0x48b6
movq 0x8(%rsp), %rax
movl 0x8(%rax,%r14), %r10d
movq 0xbb0d(%rip), %rdi      # 0x10390
movl (%rax,%r14), %ecx
movl 0x4(%rax,%r14), %r8d
movq 0xbb85(%rip), %rax      # 0x10418
movl (%rax,%rdx,4), %r9d
testl %r10d, %r10d
je 0x48c5
leaq 0x6029(%rip), %rsi      # 0xa8cc
movl %ebx, %edx
xorl %eax, %eax
pushq %r10
pushq %r15
callq 0x1150
addq $0x78, %rsp
jmp 0x48ba
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6053(%rip), %rsi      # 0xa91f
movl %ebx, %edx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1150
movl $0x0, 0x8(%rdi,%r9)
xorl %eax, %eax
movq 0x28(%rsp), %rcx
movzwl (%rcx,%rax,2), %ecx
movb $0x0, 0x6(%rdx,%rcx,8)
incq %rax
cmpq %rax, %rbp
jne 0x48ee
movq 0xa6e5(%rip), %rax      # 0xeff0
movq (%rax), %rdi
movq 0xbb03(%rip), %rax      # 0x10418
movl (%rax,%r8,4), %ecx
leaq 0x5f75(%rip), %rsi      # 0xa895
movl %ebx, %edx
xorl %eax, %eax
callq 0x1150
xorl %r10d, %r10d
movq 0x18(%rsp), %r9
jmp 0x4842