// File: /workspace/github_c_makefile_star2_O1/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 0x8c70
movq %rax, 0x10(%rsp)
movl $0x400, %edi            # imm = 0x400
movl $0x4, %esi
callq 0x8c70
movq %rax, %r14
movl $0x2000, %edi           # imm = 0x2000
movl $0x4, %esi
callq 0x8c70
movl %ebx, 0x1c(%rsp)
cmpl %ebx, %ebp
jge 0x4e45
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 0xb8c9(%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 0x8cf4
movl (%rbx,%r13), %esi
movq %r14, %rdi
movl $0x4, %edx
callq 0x8cf4
movl 0x4(%rbx,%r13), %esi
movq %r15, %rdi
movl $0x4, %edx
callq 0x8cf4
movq %rbx, %rdi
movl 0x4(%rbx,%r13), %r8d
movl $0x0, %r10d
testl %r8d, %r8d
movq %rbx, (%rsp)
je 0x4c11
movq 0x10(%rdi,%r13), %rax
movq 0xb897(%rip), %rcx      # 0x103c0
xorl %edx, %edx
movq 0xb896(%rip), %rsi      # 0x103c8
xorl %r10d, %r10d
movzbl 0x6(%rax,%rdx,8), %r8d
testl %r8d, %r8d
je 0x4c00
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 0x4bfc
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 0x4bfc
movzwl (%rcx,%r8,4), %r9d
movzwl 0x2(%rcx,%r8,4), %r8d
movzwl 0x20(%rdi), %r11d
testw %r11w, %r11w
je 0x4bce
cmpw %r11w, %r9w
jne 0x4bdf
cmpw 0x22(%rdi), %r8w
jae 0x4bc0
movw %r8w, 0x22(%rdi)
cmpw 0x24(%rdi), %r8w
jbe 0x4bfc
movw %r8w, 0x24(%rdi)
jmp 0x4bfc
movw %r9w, 0x20(%rdi)
movw %r8w, 0x24(%rdi)
movw %r8w, 0x22(%rdi)
jmp 0x4bfc
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 0x4b35
movl (%rdi,%r13), %ecx
testq %rcx, %rcx
je 0x4c4e
movq 0x8(%r14), %rax
movslq 0x14(%r14), %rdx
xorl %r11d, %r11d
movq %rcx, %rsi
movslq (%rax), %rdi
testq %rdi, %rdi
je 0x4c44
movq 0x8(%rbp), %r9
movslq 0x14(%rbp), %rbx
imulq %rdi, %rbx
incl 0x8(%r9,%rbx)
incl %r11d
addq %rdx, %rax
decq %rsi
jne 0x4c28
jmp 0x4c51
xorl %r11d, %r11d
movq 0xb738(%rip), %rdi      # 0x10390
movq 0xb7b9(%rip), %rax      # 0x10418
movl (%rax,%r12,4), %r9d
movq (%rsp), %r14
movl 0x8(%r14,%r13), %ebx
subq $0x8, %rsp
leaq 0x5cc1(%rip), %rsi      # 0xa938
movq %r12, 0x28(%rsp)
movl %r12d, %edx
xorl %eax, %eax
pushq %rbx
pushq %r11
pushq %r10
callq 0x1150
movq %r14, %rdx
addq $0x20, %rsp
cmpl $0x0, 0x8(%r14,%r13)
je 0x4e02
movl $0x1, %r12d
movq 0x8(%rbp), %r14
movslq 0x14(%rbp), %rax
movslq %r12d, %rbx
imulq %rax, %rbx
movl 0x4(%r14,%rbx), %r9d
testl %r9d, %r9d
je 0x4def
movq 0xb6c8(%rip), %rdi      # 0x10390
movl 0x8(%r14,%rbx), %r8d
leaq 0x5cc2(%rip), %rsi      # 0xa996
movq 0x20(%rsp), %rdx
movl %r12d, %ecx
xorl %eax, %eax
callq 0x1150
cmpq $0x0, 0xb6d5(%rip)      # 0x103c0
je 0x4dd5
movq 0xb698(%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 0x5ca6(%rip), %rsi      # 0xa9c2
xorl %eax, %eax
pushq %r10
callq 0x1150
addq $0x10, %rsp
movswl 0x20(%r14,%rbx), %edx
testl %edx, %edx
je 0x4d5a
movq 0xb656(%rip), %rdi      # 0x10390
movzwl 0x22(%r14,%rbx), %ecx
movzwl 0x24(%r14,%rbx), %r8d
subl %ecx, %r8d
incl %r8d
leaq 0x5c97(%rip), %rsi      # 0xa9ea
xorl %eax, %eax
callq 0x1150
movl 0x28(%r14,%rbx), %edx
testl %edx, %edx
je 0x4dd5
movq 0xb626(%rip), %rdi      # 0x10390
leaq 0x5c8c(%rip), %rsi      # 0xa9fd
xorl %eax, %eax
callq 0x1150
movl 0x2c(%r14,%rbx), %eax
testl %eax, %eax
je 0x4dd5
movl $0xfffffff7, %ebx       # imm = 0xFFFFFFF7
movq 0xb603(%rip), %r14      # 0x10390
movq (%rsp), %rcx
movq 0x10(%rcx,%r13), %rcx
movslq %eax, %rbp
movl (%rcx,%rbp,8), %edi
callq 0x353c
movq %r14, %rdi
leaq 0x5987(%rip), %rsi      # 0xa732
leaq 0xb62e(%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 0x4dd5
leal 0x1(%rbx), %ecx
testl %ebx, %ebx
movl %ecx, %ebx
jne 0x4d86
movq 0xb5b4(%rip), %rsi      # 0x10390
movl $0xa, %edi
callq 0x1100
movq 0x10(%rsp), %rbp
movq (%rsp), %rdx
leal 0x1(%r12), %eax
cmpl 0x8(%rdx,%r13), %r12d
movl %eax, %r12d
jb 0x4ca4
movq 0xb60f(%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 0x4ab3
jmp 0x4e56
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %eax, %eax
movq 0x10(%rsp), %rbp
testq %rax, %rax
je 0x4e9b
movq 0xb52e(%rip), %rdi      # 0x10390
movq %rax, %xmm0
punpckldq 0x51a1(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x51a9(%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 0x5b74(%rip), %rsi      # 0xaa08
movb $0x1, %al
callq 0x1150
movq %rbp, %rdi
callq 0x8dc9
movq %r14, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8dc9