// File: /workspace/github_c_makefile_star2_O3/richarddurbin[P]hash10x/hash10x.c
// Function: codeClusterReport
void codeClusterReport (int codeMin, int codeMax)
{
  int code ;
  typedef struct {
    int i ;
    int n ;
    int nRead ;
    int nt[5] ;
    I16 chr ;
    U16 pMin, pMax ;
    int nBad ;
    int bad ;			/* point to bad hash */
  } ReportInfo ;
  Array info = arrayCreate (256, ReportInfo) ;
  Array readClus = arrayCreate (1024, int) ;
  Array badLink = arrayCreate (8192, int) ;
  ReportInfo *r ;
  int i, c ;
  U64 totalGoodHash = 0 ;
  double totalPointToMin = 0.0 ;

  for (code = codeMin ; code < codeMax ; ++code)
    { ClusterBlock *b = arrp(clusterBlocks, code, ClusterBlock) ;
      arrayReCreate (info, b->nSubCluster+1, ReportInfo) ;
      arrayReCreate (readClus, b->nRead, int) ;
      arrayReCreate (badLink, b->nHash, int) ;
      int nClusHash = 0 ;
      for (i = 0 ; i < b->nHash ; ++i)
	{ if (!(c = b->clusHash[i].subCluster)) continue ;
	  ++nClusHash ;
	  arr(readClus, b->clusHash[i].read, int) = c ;
	  r = arrp(info, c, ReportInfo) ;
	  ++r->n ;
	  U32 bh = b->clusHash[i].hash ;
	  if (crib)
	    { ++r->nt[cribType[bh]] ;
	      if (cribType[bh] > CRIB_ERR && cribType[bh] < CRIB_MUL)
		{ CribInfo ch = crib[bh] ;
		  if (!r->chr) { r->chr = ch.chr ; r->pMin = r->pMax = ch.pos ; }
		  else if (ch.chr == r->chr)
		    { if (ch.pos < r->pMin) r->pMin = ch.pos ;
		      if (ch.pos > r->pMax) r->pMax = ch.pos ;
		    }
		  else { ++r->nBad ; arr(badLink,i,int) = r->bad ; r->bad = i ; }
		}
	    }
	}

      int nClusRead = 0 ;
      for (i = 0 ; i < b->nRead ; ++i)
	if ((c = arr(readClus,i,int))) { ++arrp(info,c,ReportInfo)->nRead ; ++nClusRead ; }
      
      fprintf (outFile, "  CLUSTER_SUMMARY %d nRead %d nHash %d nGoodHash %d nClusHash %d nClusRead %d nSubCluster %d\n",
	      code, b->nRead, b->nHash, nGoodHashes[code], nClusHash, nClusRead, b->nSubCluster) ;
      for (i = 1 ; i <= b->nSubCluster ; ++i)
	{ r = arrp(info, i, ReportInfo) ; if (!r->n) continue ;
	  fprintf (outFile, "    CODE_CLUSTER %d %d : %d reads %d hashes",
		   code, i, r->nRead, r->n) ;
	  if (crib)
	    { fprintf (outFile, " %d hom, %d htA, %d htB, %d mul, %d err", r->nt[CRIB_HOM],
		      r->nt[CRIB_HTA], r->nt[CRIB_HTB], r->nt[CRIB_MUL], r->nt[CRIB_ERR]) ;
	      if (r->chr)
		fprintf (outFile, "  chr %d pos %d %d", r->chr, r->pMin, r->pMax-r->pMin+1) ;
	      if (r->nBad)
		{ fprintf (outFile, "  OTHER %d", r->nBad) ;
		  int x = r->bad, j = 10 ;
		  while (x && j--)
		    { fprintf (outFile, " %s", cribText(b->clusHash[x].hash)) ;
		      x = arr(badLink, x, int) ;
		    }
		}
	    }
	  fputc ('\n', outFile) ;
	}
      totalGoodHash += nGoodHashes[code] ;
      totalPointToMin += b->pointToMin ;
    }

  if (totalGoodHash)
    fprintf (outFile, "  MIN_POINT_DENSITY %.3f\n", totalPointToMin / totalGoodHash) ;
  
  arrayDestroy (info) ; arrayDestroy (readClus) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %esi, %ebx
movl %edi, %ebp
movl $0x100, %edi            # imm = 0x100
movl $0x30, %esi
callq 0x8e88
movq %rax, 0x10(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x4, %esi
callq 0x8e88
movq %rax, %r14
movl $0x2000, %edi           # imm = 0x2000
movl $0x4, %esi
callq 0x8e88
movl %ebx, 0x1c(%rsp)
cmpl %ebx, %ebp
jge 0x4f55
movq %rax, %r15
movslq %ebp, %r12
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
movq 0x10(%rsp), %rbp
movq %r14, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movq 0xb804(%rip), %rax      # 0x10388
movq 0x8(%rax), %rbx
movslq 0x14(%rax), %r13
imulq %r12, %r13
movl 0x8(%rbx,%r13), %esi
incl %esi
movq %rbp, %rdi
movl $0x30, %edx
callq 0x8f0c
movl (%rbx,%r13), %esi
movq %r14, %rdi
movl $0x4, %edx
callq 0x8f0c
movl 0x4(%rbx,%r13), %esi
movq %r15, %rdi
movl $0x4, %edx
callq 0x8f0c
movq %rbx, %rdi
cmpl $0x0, 0x4(%rbx,%r13)
movl $0x0, %r10d
movl $0x0, %r8d
movq %rbx, (%rsp)
je 0x4cda
movq 0x10(%rdi,%r13), %rax
movq 0xb7ce(%rip), %rcx      # 0x103c0
xorl %edx, %edx
movq 0xb7cd(%rip), %rsi      # 0x103c8
xorl %r10d, %r10d
movzbl 0x6(%rax,%rdx,8), %r8d
testl %r8d, %r8d
je 0x4cc9
incl %r10d
movq 0x8(%r14), %rdi
movzwl 0x4(%rax,%rdx,8), %r9d
movslq 0x14(%r14), %r11
imulq %r9, %r11
movl %r8d, (%rdi,%r11)
movq 0x8(%rbp), %rdi
movslq 0x14(%rbp), %r9
movl %r8d, %r8d
imulq %r9, %r8
incl 0x4(%rdi,%r8)
testq %rcx, %rcx
je 0x4cc5
addq %r8, %rdi
movl (%rax,%rdx,8), %r8d
movzbl (%rsi,%r8), %r9d
incl 0xc(%rdi,%r9,4)
movb (%rsi,%r8), %r9b
decb %r9b
cmpb $0x2, %r9b
ja 0x4cc5
movzwl (%rcx,%r8,4), %r9d
movzwl 0x2(%rcx,%r8,4), %r8d
movzwl 0x20(%rdi), %r11d
testw %r11w, %r11w
je 0x4c97
cmpw %r11w, %r9w
jne 0x4ca8
cmpw 0x22(%rdi), %r8w
jae 0x4c89
movw %r8w, 0x22(%rdi)
cmpw 0x24(%rdi), %r8w
jbe 0x4cc5
movw %r8w, 0x24(%rdi)
jmp 0x4cc5
movw %r9w, 0x20(%rdi)
movw %r8w, 0x24(%rdi)
movw %r8w, 0x22(%rdi)
jmp 0x4cc5
incl 0x28(%rdi)
movl 0x2c(%rdi), %r8d
movq 0x8(%r15), %r9
movslq 0x14(%r15), %r11
movslq %edx, %rbx
imulq %rbx, %r11
movl %r8d, (%r9,%r11)
movl %ebx, 0x2c(%rdi)
movq (%rsp), %rdi
incq %rdx
movl 0x4(%rdi,%r13), %r8d
cmpq %r8, %rdx
jb 0x4bfe
movl (%rdi,%r13), %ecx
testq %rcx, %rcx
je 0x4d17
movq 0x8(%r14), %rax
movslq 0x14(%r14), %rdx
xorl %r11d, %r11d
movq %rcx, %rsi
movslq (%rax), %rdi
testq %rdi, %rdi
je 0x4d0d
movq 0x8(%rbp), %r9
movslq 0x14(%rbp), %rbx
imulq %rdi, %rbx
incl 0x8(%r9,%rbx)
incl %r11d
addq %rdx, %rax
decq %rsi
jne 0x4cf1
jmp 0x4d1a
xorl %r11d, %r11d
movq 0xb66f(%rip), %rdi      # 0x10390
movq 0xb6f0(%rip), %rax      # 0x10418
movl (%rax,%r12,4), %r9d
movq (%rsp), %r14
movl 0x8(%r14,%r13), %ebx
subq $0x8, %rsp
leaq 0x5c38(%rip), %rsi      # 0xa978
movq %r12, 0x28(%rsp)
movl %r12d, %edx
xorl %eax, %eax
pushq %rbx
pushq %r11
pushq %r10
callq 0x1150
movq %r14, %rdx
addq $0x20, %rsp
movl 0x8(%r14,%r13), %eax
testl %eax, %eax
je 0x4ecf
movl $0x1, %r12d
movq 0x8(%rbp), %r14
movslq 0x14(%rbp), %rcx
movslq %r12d, %rbx
imulq %rcx, %rbx
movl 0x4(%r14,%rbx), %r9d
testl %r9d, %r9d
je 0x4ebe
movq 0xb5fe(%rip), %rdi      # 0x10390
movl 0x8(%r14,%rbx), %r8d
leaq 0x5c38(%rip), %rsi      # 0xa9d6
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x1150
cmpq $0x0, 0xb60b(%rip)      # 0x103c0
je 0x4e9f
movq 0xb5ce(%rip), %rdi      # 0x10390
movl 0x18(%r14,%rbx), %edx
movl 0xc(%r14,%rbx), %r10d
movl 0x10(%r14,%rbx), %ecx
movl 0x14(%r14,%rbx), %r8d
movl 0x1c(%r14,%rbx), %r9d
subq $0x8, %rsp
leaq 0x5c1c(%rip), %rsi      # 0xaa02
xorl %eax, %eax
pushq %r10
callq 0x1150
addq $0x10, %rsp
movswl 0x20(%r14,%rbx), %edx
testl %edx, %edx
je 0x4e24
movq 0xb58c(%rip), %rdi      # 0x10390
movzwl 0x22(%r14,%rbx), %ecx
movzwl 0x24(%r14,%rbx), %r8d
subl %ecx, %r8d
incl %r8d
leaq 0x5c0d(%rip), %rsi      # 0xaa2a
xorl %eax, %eax
callq 0x1150
movl 0x28(%r14,%rbx), %edx
testl %edx, %edx
je 0x4e9f
movq 0xb55c(%rip), %rdi      # 0x10390
leaq 0x5c02(%rip), %rsi      # 0xaa3d
xorl %eax, %eax
callq 0x1150
movl 0x2c(%r14,%rbx), %eax
testl %eax, %eax
je 0x4e9f
movl $0xfffffff7, %ebx       # imm = 0xFFFFFFF7
movq 0xb539(%rip), %r14      # 0x10390
movq (%rsp), %rcx
movq 0x10(%rcx,%r13), %rcx
movslq %eax, %rbp
movl (%rcx,%rbp,8), %edi
callq 0x3513
movq %r14, %rdi
leaq 0x58fd(%rip), %rsi      # 0xa772
leaq 0xb564(%rip), %rdx      # 0x103e0
xorl %eax, %eax
callq 0x1150
movq 0x8(%r15), %rax
movslq 0x14(%r15), %rcx
imulq %rbp, %rcx
movl (%rax,%rcx), %eax
testl %eax, %eax
je 0x4e9f
leal 0x1(%rbx), %ecx
testl %ebx, %ebx
movl %ecx, %ebx
jne 0x4e50
movq 0xb4ea(%rip), %rsi      # 0x10390
movl $0xa, %edi
callq 0x1100
movq (%rsp), %rdx
movl 0x8(%rdx,%r13), %eax
movq 0x10(%rsp), %rbp
leal 0x1(%r12), %ecx
cmpl %eax, %r12d
movl %ecx, %r12d
jb 0x4d6e
movq 0xb542(%rip), %rax      # 0x10418
movq 0x20(%rsp), %r12
movslq (%rax,%r12,4), %rax
movq 0x30(%rsp), %rcx
addq %rax, %rcx
movq %rcx, %rax
movsd 0x8(%rsp), %xmm0
addsd 0x18(%rdx,%r13), %xmm0
movsd %xmm0, 0x8(%rsp)
incq %r12
cmpl 0x1c(%rsp), %r12d
movq 0x28(%rsp), %r14
jne 0x4b78
testq %rax, %rax
je 0x4f55
movq 0xb474(%rip), %rdi      # 0x10390
movq %rax, %xmm0
punpckldq 0x50e7(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x50ef(%rip), %xmm0     # 0xa020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x5afa(%rip), %rsi      # 0xaa48
movb $0x1, %al
callq 0x1150
movq 0x10(%rsp), %rdi
callq 0x8fd6
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8fd6