// File: /workspace/github_c_makefile_star2_O2/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 0xc9a3(%rip), %rax      # 0x10398
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movslq 0x14(%rax), %r15
movslq %edi, %r14
movslq 0x18(%rax), %rdi
pushq $0x4
popq %rsi
callq 0x8b24
movq %rax, 0x40(%rsp)
pushq $0x40
popq %rdi
pushq $0x4
popq %rsi
callq 0x82c8
movq %r14, %rcx
movq %rax, %r14
movq 0xc9fa(%rip), %rax      # 0x10428
movslq (%rax,%rcx,4), %r13
testq %r13, %r13
je 0x3cfa
imulq %rcx, %r15
leaq (,%r13,4), %rdi
movq %rdi, 0x58(%rsp)
movq %rcx, 0x18(%rsp)
callq 0x8afc
movq 0x18(%rsp), %r9
movq %rax, %r12
movq 0xc9bb(%rip), %rax      # 0x10420
xorl %ecx, %ecx
testl %r13d, %r13d
movl $0x0, %edx
cmovgl %r13d, %edx
movq 0x20(%rsp), %r8
movq %r15, %r10
cmpq %rcx, %rdx
je 0x3a97
movq 0x10(%r8,%r10), %rsi
movq (%rax,%r9,8), %rdi
movzwl (%rdi,%rcx,2), %edi
movb $0x0, 0x6(%rsi,%rdi,8)
incq %rcx
jmp 0x3a7b
movq %r13, 0x60(%rsp)
movq %r14, 0x10(%rsp)
andl $0x0, 0x8(%r8,%r10)
andq $0x0, 0x18(%r8,%r10)
movq $0x0, 0x8(%rsp)
pushq $0x1
popq %r11
movq %r10, 0x28(%rsp)
cmpq 0x60(%rsp), %r11
jge 0x3c80
movq %r11, %rbp
movq 0x10(%r8,%r10), %rax
movq 0xc947(%rip), %rcx      # 0x10420
movq (%rcx,%r9,8), %rcx
movzwl (%rcx,%r11,2), %ecx
movl (%rax,%rcx,8), %r14d
movq 0xc8a3(%rip), %rax      # 0x10390
movq 0x8(%rax), %rcx
movl 0x14(%rax), %eax
imull %r14d, %eax
movl (%rcx,%rax), %r13d
movq %r12, %rdi
xorl %esi, %esi
movq 0x58(%rsp), %rdx
callq 0x10f0
movq 0xc8b6(%rip), %rax      # 0x103c8
leaq 0x1(%rbp), %r11
xorl %ecx, %ecx
movq 0x40(%rsp), %rdi
cmpq %rcx, %r13
je 0x3b54
movq 0x8(%rax), %rdx
movl 0x14(%rax), %esi
imull %r14d, %esi
movq (%rdx,%rsi), %rdx
movslq (%rdx,%rcx,4), %rdx
cmpl %ebx, %edx
je 0x3b4f
movl (%rdi,%rdx,4), %esi
testl %esi, %esi
jne 0x3b47
movl %r11d, (%rdi,%rdx,4)
movl %r11d, %esi
movslq %esi, %rdx
incl -0x4(%r12,%rdx,4)
incq %rcx
jmp 0x3b1d
movq 0xc8c5(%rip), %rax      # 0x10420
movq 0x18(%rsp), %r9
movq (%rax,%r9,8), %rax
movq %rax, 0x30(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r14d, %r14d
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %r10
cmpq %rax, %rbp
je 0x3b94
movl (%r12,%rax,4), %edx
cmpl %ecx, %edx
cmovgl %edx, %ecx
cmovgl %eax, %r15d
addl %edx, %r14d
incq %rax
jmp 0x3b7a
cmpl 0x3c(%rsp), %ecx
jl 0x3abf
movq 0x10(%r8,%r10), %rsi
movslq %r15d, %rax
movq 0x30(%rsp), %rcx
movzwl (%rcx,%rax,2), %edi
movb 0x6(%rsi,%rdi,8), %al
testb %al, %al
je 0x3bc1
movq %rsi, %rcx
movq 0x8(%rsp), %r13
jmp 0x3c2f
movq %rsi, %rcx
movl 0x8(%r8,%r10), %esi
incl %esi
movl %esi, 0x8(%r8,%r10)
cmpl $0x100, %esi            # imm = 0x100
jae 0x3d27
movq %rcx, 0x48(%rsp)
movb %sil, 0x6(%rcx,%rdi,8)
movq %rdi, 0x50(%rsp)
movq 0x8(%rsp), %r13
incl %r13d
movq 0x10(%rsp), %rdi
movq %r11, 0x8(%rsp)
callq 0x8560
movq 0x48(%rsp), %rsi
movq 0x8(%rsp), %r11
movq 0x28(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x20(%rsp), %r8
movl %r15d, (%rax)
movq 0x50(%rsp), %rax
movq %rax, %rdi
movb 0x6(%rsi,%rax,8), %al
movq 0x10(%r8,%r10), %rcx
movq 0x30(%rsp), %rdx
movzwl (%rdx,%rbp,2), %edx
movb %al, 0x6(%rcx,%rdx,8)
incl %r13d
movq %r13, 0x8(%rsp)
movq 0x10(%rsp), %rdx
movq 0x8(%rdx), %rax
movzbl 0x6(%rsi,%rdi,8), %ecx
movslq 0x14(%rdx), %rdx
imulq %rcx, %rdx
movslq (%rax,%rdx), %rax
cvtsi2sdl (%r12,%rax,4), %xmm0
cvtsi2sd %r14d, %xmm1
divsd %xmm1, %xmm0
addsd 0x18(%r8,%r10), %xmm0
movsd %xmm0, 0x18(%r8,%r10)
jmp 0x3abf
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x40(%rsp), %rdi
callq 0x1040
movq %r12, %rdi
callq 0x1040
movq %r14, %rdi
callq 0x8408
cmpb $0x0, 0xc6d6(%rip)      # 0x10381
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rsi
je 0x3cfa
movq 0x20(%rsp), %rax
movl 0x8(%rax,%rsi), %r10d
movq 0xc6d8(%rip), %rdi      # 0x103a0
movl (%rax,%rsi), %ecx
movl 0x4(%rax,%rsi), %r8d
movq 0xc751(%rip), %rax      # 0x10428
movl (%rax,%rdx,4), %r9d
testl %r10d, %r10d
je 0x3d09
leaq 0x5ba5(%rip), %rsi      # 0x988c
movl %ebx, %edx
xorl %eax, %eax
pushq %r10
pushq %r15
callq 0x1150
addq $0x78, %rsp
jmp 0x3cfe
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5bcf(%rip), %rsi      # 0x98df
movl %ebx, %edx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1150
andl $0x0, 0x8(%r8,%r10)
xorl %eax, %eax
movq 0x10(%rsp), %r14
movq %rcx, %rdx
cmpq %rax, %rbp
je 0x3d4f
movq 0x30(%rsp), %rcx
movzwl (%rcx,%rax,2), %ecx
movb $0x0, 0x6(%rdx,%rcx,8)
incq %rax
jmp 0x3d37
movq 0xb29a(%rip), %rax      # 0xeff0
movq (%rax), %rdi
movq 0xc6c8(%rip), %rax      # 0x10428
movl (%rax,%r9,4), %ecx
leaq 0x5aea(%rip), %rsi      # 0x9855
xorl %r15d, %r15d
movl %ebx, %edx
xorl %eax, %eax
callq 0x1150
jmp 0x3c8a