// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movl %esi, 0x3c(%rsp)
movq 0xbe99(%rip), %rax      # 0x10388
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%rsp)
movslq 0x14(%rax), %r14
movl %edi, 0x4(%rsp)
movslq %edi, %rbx
movslq 0x18(%rax), %rdi
movl $0x4, %esi
callq 0x94f8
movq %rax, %r15
movl $0x40, %edi
movl $0x4, %esi
callq 0x8c70
movq %rbx, %rcx
movq 0xbeeb(%rip), %rdx      # 0x10418
movslq (%rdx,%rbx,4), %rbx
testq %rbx, %rbx
je 0x4845
movq %rax, 0x20(%rsp)
imulq %rcx, %r14
leaq (,%rbx,4), %rdi
movq %rdi, 0x50(%rsp)
movq %rcx, 0x8(%rsp)
callq 0x94d0
movq 0x8(%rsp), %r8
movq %rax, %r12
testl %ebx, %ebx
movq 0x10(%rsp), %rdi
movq %r14, %r9
jle 0x4591
movq 0x10(%rdi,%r9), %rax
movq 0xbe96(%rip), %rcx      # 0x10410
movq (%rcx,%r8,8), %rcx
xorl %edx, %edx
movzwl (%rcx,%rdx,2), %esi
movb $0x0, 0x6(%rax,%rsi,8)
incq %rdx
cmpq %rdx, %rbx
jne 0x4580
movl $0x0, 0x8(%rdi,%r9)
movq $0x0, 0x18(%rdi,%r9)
xorl %r14d, %r14d
cmpl $0x2, %ebx
jl 0x47d5
xorl %r14d, %r14d
movl $0x1, %r13d
movq %r9, 0x30(%rsp)
movq %rbx, 0x28(%rsp)
movq %r14, 0x18(%rsp)
movq 0x10(%rdi,%r9), %rax
movq 0xbe3d(%rip), %rcx      # 0x10410
movq (%rcx,%r8,8), %rcx
movzwl (%rcx,%r13,2), %ecx
movl (%rax,%rcx,8), %ebx
movq 0xbd9a(%rip), %rax      # 0x10380
movq 0x8(%rax), %rcx
movl 0x14(%rax), %eax
imull %ebx, %eax
movl (%rcx,%rax), %r14d
movq %r12, %rdi
xorl %esi, %esi
movq 0x50(%rsp), %rdx
callq 0x10f0
testq %r14, %r14
movl 0x4(%rsp), %edx
je 0x464b
movq 0xbda5(%rip), %rax      # 0x103b8
movq 0x8(%rax), %rcx
leal 0x1(%r13), %r8d
xorl %esi, %esi
movl 0x14(%rax), %edi
imull %ebx, %edi
movq (%rcx,%rdi), %rdi
movslq (%rdi,%rsi,4), %rdi
cmpl %edx, %edi
je 0x4643
cmpl $0x0, (%r15,%rdi,4)
jne 0x463a
movl %r8d, (%r15,%rdi,4)
movslq (%r15,%rdi,4), %rdi
incl -0x4(%r12,%rdi,4)
incq %rsi
cmpq %rsi, %r14
jne 0x461d
movq 0xbdbe(%rip), %rax      # 0x10410
movq 0x8(%rsp), %r8
movq (%rax,%r8,8), %r10
xorl %eax, %eax
xorl %ebx, %ebx
xorl %ecx, %ecx
movl (%r12,%rax,4), %esi
cmpl %ecx, %esi
cmovgl %esi, %ecx
cmovgl %eax, %ebp
addl %esi, %ebx
incq %rax
cmpq %rax, %r13
jne 0x4661
cmpl 0x3c(%rsp), %ecx
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %r9
jge 0x4698
xorl %eax, %eax
movq 0x28(%rsp), %rbx
movq 0x18(%rsp), %r14
jmp 0x4767
movq 0x10(%rdi,%r9), %r14
movslq %ebp, %rax
movzwl (%r10,%rax,2), %r11d
cmpb $0x0, 0x6(%r14,%r11,8)
je 0x46b4
movq 0x18(%rsp), %rsi
jmp 0x4711
movl 0x8(%rdi,%r9), %esi
incl %esi
movl %esi, 0x8(%rdi,%r9)
cmpl $0x100, %esi            # imm = 0x100
jae 0x4779
movb %sil, 0x6(%r14,%r11,8)
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
movq %r10, 0x48(%rsp)
movq %r11, 0x40(%rsp)
callq 0x8f2b
movq 0x40(%rsp), %r11
movq 0x18(%rsp), %rsi
movq 0x48(%rsp), %r10
movq 0x30(%rsp), %r9
movq 0x8(%rsp), %r8
movq 0x10(%rsp), %rdi
movl %ebp, (%rax)
movb 0x6(%r14,%r11,8), %al
movq 0x10(%rdi,%r9), %rcx
movzwl (%r10,%r13,2), %edx
movb %al, 0x6(%rcx,%rdx,8)
movq 0x20(%rsp), %rdx
movq 0x8(%rdx), %rax
movzbl 0x6(%r14,%r11,8), %ecx
movslq 0x14(%rdx), %rdx
imulq %rcx, %rdx
movslq (%rax,%rdx), %rax
cvtsi2sdl (%r12,%rax,4), %xmm0
incl %esi
cvtsi2sd %ebx, %xmm1
divsd %xmm1, %xmm0
addsd 0x18(%rdi,%r9), %xmm0
movsd %xmm0, 0x18(%rdi,%r9)
xorl %eax, %eax
movq 0x28(%rsp), %rbx
movq %rsi, %r14
testb %al, %al
jne 0x47d5
incq %r13
cmpq %rbx, %r13
jne 0x45c2
jmp 0x47d5
movl $0x0, 0x8(%rdi,%r9)
xorl %eax, %eax
movzwl (%r10,%rax,2), %ecx
movb $0x0, 0x6(%r14,%rcx,8)
incq %rax
cmpq %rax, %r13
jne 0x4784
movq 0xa852(%rip), %rax      # 0xeff0
movq (%rax), %rdi
movq 0xbc70(%rip), %rax      # 0x10418
movl (%rax,%r8,4), %ecx
xorl %r14d, %r14d
leaq 0x609f(%rip), %rsi      # 0xa855
xorl %eax, %eax
callq 0x1150
movq 0x8(%rsp), %r8
movb $0x1, %al
movq 0x10(%rsp), %rdi
movq 0x30(%rsp), %r9
movq 0x28(%rsp), %rbx
jmp 0x4767
movq %r15, %rdi
movq %r9, %rbx
callq 0x1040
movq %r12, %rdi
callq 0x1040
movq 0x20(%rsp), %rdi
callq 0x8dc9
movq 0x8(%rsp), %rdx
cmpb $0x0, 0xbb73(%rip)      # 0x10371
je 0x4845
movq 0x10(%rsp), %rax
movl 0x8(%rax,%rbx), %r10d
movq 0xbb7f(%rip), %rdi      # 0x10390
movl (%rax,%rbx), %ecx
movl 0x4(%rax,%rbx), %r8d
movq 0xbbf8(%rip), %rax      # 0x10418
movl (%rax,%rdx,4), %r9d
testl %r10d, %r10d
je 0x4854
leaq 0x605c(%rip), %rsi      # 0xa88c
movl 0x4(%rsp), %edx
xorl %eax, %eax
pushq %r10
pushq %r14
callq 0x1150
addq $0x68, %rsp
jmp 0x4849
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6084(%rip), %rsi      # 0xa8df
movl 0x4(%rsp), %edx
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1150