// File: /workspace/github_c_makefile_star2_O2/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, %ebp
movl %edi, %r15d
pushq $0x30
popq %rsi
movl $0x100, %edi            # imm = 0x100
callq 0x82c8
movq %rax, %r13
pushq $0x4
popq %r14
movl $0x400, %edi            # imm = 0x400
movl %r14d, %esi
callq 0x82c8
movq %rax, %rbx
movl $0x2000, %edi           # imm = 0x2000
movl %r14d, %esi
callq 0x82c8
movq %rax, %r12
movslq %r15d, %rcx
movslq %ebp, %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %eax, %eax
movq %r13, 0x30(%rsp)
movq %rbx, 0x18(%rsp)
cmpq 0x20(%rsp), %rcx
jge 0x42d8
movq %rax, 0x28(%rsp)
movq 0xc3ea(%rip), %rax      # 0x10398
movq 0x8(%rax), %rbp
movslq 0x14(%rax), %r15
movq %rcx, 0x8(%rsp)
imulq %rcx, %r15
movl 0x8(%rbp,%r15), %esi
incl %esi
movq %r13, %rdi
pushq $0x30
popq %rdx
callq 0x8343
movl (%rbp,%r15), %esi
movq %rbx, %rdi
pushq $0x4
popq %r14
movl %r14d, %edx
callq 0x8343
movl 0x4(%rbp,%r15), %esi
movq %r12, %rdi
movl %r14d, %edx
callq 0x8343
movq 0xc3d4(%rip), %rax      # 0x103d0
xorl %ecx, %ecx
movq 0xc3d3(%rip), %rdx      # 0x103d8
xorl %r10d, %r10d
movl 0x4(%rbp,%r15), %r8d
cmpq %r8, %rcx
jae 0x40e0
movq 0x10(%rbp,%r15), %rdi
movzbl 0x6(%rdi,%rcx,8), %r8d
testl %r8d, %r8d
je 0x40d8
incl %r10d
movq 0x8(%rbx), %rsi
movzwl 0x4(%rdi,%rcx,8), %r9d
movslq 0x14(%rbx), %r11
imulq %r9, %r11
movl %r8d, (%rsi,%r11)
movq 0x8(%r13), %rsi
movslq 0x14(%r13), %r9
movl %r8d, %r8d
imulq %r9, %r8
incl 0x4(%rsi,%r8)
testq %rax, %rax
je 0x40d8
addq %r8, %rsi
movl (%rdi,%rcx,8), %edi
movzbl (%rdx,%rdi), %r8d
incl 0xc(%rsi,%r8,4)
movb (%rdx,%rdi), %r8b
decb %r8b
cmpb $0x2, %r8b
ja 0x40d8
movzwl (%rax,%rdi,4), %r8d
movzwl 0x2(%rax,%rdi,4), %edi
movzwl 0x20(%rsi), %r9d
testw %r9w, %r9w
je 0x40aa
cmpw %r9w, %r8w
jne 0x40b9
cmpw 0x22(%rsi), %di
jae 0x409e
movw %di, 0x22(%rsi)
cmpw 0x24(%rsi), %di
jbe 0x40d8
movw %di, 0x24(%rsi)
jmp 0x40d8
movw %r8w, 0x20(%rsi)
movw %di, 0x24(%rsi)
movw %di, 0x22(%rsi)
jmp 0x40d8
incl 0x28(%rsi)
movl 0x2c(%rsi), %edi
movq 0x8(%r12), %r8
movslq 0x14(%r12), %r9
movslq %ecx, %r11
imulq %r11, %r9
movl %edi, (%r8,%r9)
movl %r11d, 0x2c(%rsi)
incq %rcx
jmp 0x4008
movl (%rbp,%r15), %ecx
xorl %eax, %eax
xorl %r11d, %r11d
cmpl %eax, %ecx
je 0x411d
movq 0x8(%rbx), %rdx
movslq 0x14(%rbx), %rsi
movslq %eax, %rdi
imulq %rsi, %rdi
movslq (%rdx,%rdi), %rdx
testq %rdx, %rdx
je 0x4119
movq 0x8(%r13), %rsi
movslq 0x14(%r13), %rdi
imulq %rdx, %rdi
incl 0x8(%rsi,%rdi)
incl %r11d
incl %eax
jmp 0x40ea
movq 0xc27c(%rip), %rdi      # 0x103a0
movq 0xc2fd(%rip), %rax      # 0x10428
movq 0x8(%rsp), %rdx
movl (%rax,%rdx,4), %r9d
movl 0x8(%rbp,%r15), %ebx
subq $0x8, %rsp
leaq 0x57f4(%rip), %rsi      # 0x9938
xorl %eax, %eax
pushq %rbx
pushq %r11
pushq %r10
callq 0x1150
addq $0x20, %rsp
pushq $0x1
popq %rcx
cmpl 0x8(%rbp,%r15), %ecx
ja 0x429f
movq 0x8(%r13), %r14
movslq 0x14(%r13), %rdx
movslq %ecx, %rax
imulq %rdx, %rax
movl 0x4(%r14,%rax), %r9d
testl %r9d, %r9d
je 0x4298
addq %rax, %r14
movq 0xc217(%rip), %rdi      # 0x103a0
movl 0x8(%r14), %r8d
leaq 0x5802(%rip), %rsi      # 0x9996
movq 0x8(%rsp), %rdx
movl %ecx, 0x14(%rsp)
xorl %eax, %eax
callq 0x1150
cmpq $0x0, 0xc224(%rip)      # 0x103d0
je 0x4280
movq 0xc1e7(%rip), %rdi      # 0x103a0
movl 0x18(%r14), %edx
movl 0xc(%r14), %r10d
movl 0x10(%r14), %ecx
movl 0x14(%r14), %r8d
movl 0x1c(%r14), %r9d
subq $0x8, %rsp
leaq 0x57ea(%rip), %rsi      # 0x99c2
xorl %eax, %eax
pushq %r10
callq 0x1150
popq %rcx
popq %rdx
movswl 0x20(%r14), %edx
testl %edx, %edx
je 0x4211
movq 0xc1ad(%rip), %rdi      # 0x103a0
movzwl 0x22(%r14), %ecx
movzwl 0x24(%r14), %r8d
subl %ecx, %r8d
incl %r8d
leaq 0x57e0(%rip), %rsi      # 0x99ea
xorl %eax, %eax
callq 0x1150
movl 0x28(%r14), %edx
testl %edx, %edx
je 0x4280
movq 0xc180(%rip), %rdi      # 0x103a0
leaq 0x57d6(%rip), %rsi      # 0x99fd
xorl %eax, %eax
callq 0x1150
addq $0x2c, %r14
pushq $-0xa
popq %rbx
movslq (%r14), %r13
testq %r13, %r13
je 0x4280
testl %ebx, %ebx
je 0x4280
movq 0xc158(%rip), %r14      # 0x103a0
movq 0x10(%rbp,%r15), %rax
movl (%rax,%r13,8), %edi
callq 0x2a97
movq %r14, %rdi
leaq 0x54d2(%rip), %rsi      # 0x9732
leaq 0xc189(%rip), %rdx      # 0x103f0
xorl %eax, %eax
callq 0x1150
movslq 0x14(%r12), %r14
imulq %r13, %r14
addq 0x8(%r12), %r14
incl %ebx
jmp 0x4235
movq 0xc119(%rip), %rsi      # 0x103a0
pushq $0xa
popq %rdi
callq 0x1100
movq 0x30(%rsp), %r13
movl 0x14(%rsp), %ecx
incl %ecx
jmp 0x4157
movq 0xc182(%rip), %rax      # 0x10428
movq 0x8(%rsp), %rcx
movslq (%rax,%rcx,4), %rax
movq 0x28(%rsp), %rdx
addq %rax, %rdx
movq %rdx, %rax
movsd (%rsp), %xmm0
addsd 0x18(%rbp,%r15), %xmm0
movsd %xmm0, (%rsp)
incq %rcx
movq 0x18(%rsp), %rbx
jmp 0x3f97
testq %rax, %rax
je 0x431c
movq 0xc0bc(%rip), %rdi      # 0x103a0
movq %rax, %xmm0
punpckldq 0x4d1f(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x4d27(%rip), %xmm0     # 0x9020
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd (%rsp), %xmm0
divsd %xmm1, %xmm0
leaq 0x56f3(%rip), %rsi      # 0x9a08
movb $0x1, %al
callq 0x1150
movq %r13, %rdi
callq 0x8408
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8408