// File: /workspace/github_c_makefile_star2_O2/richarddurbin[P]hash10x/hash10x.c
// Function: errorFix
void errorFix (int hashMin, int hashMax)
{
  if (!crib) die ("need to set crib") ;
  U32 x ; int i ;
  int low[CRIBTYPE_MAX], nt[CRIBTYPE_MAX] ;
  double min[CRIBTYPE_MAX], max[CRIBTYPE_MAX], sum[CRIBTYPE_MAX] ;
  for (i = 0 ; i < CRIBTYPE_MAX ; ++i)
    { low[i] = 0 ; nt[i] = 0 ; min[i] = 1.0 ; max[i] = 0.0 ; sum[i] = 0.0 ; }
  for (x = hashMin ; x < hashMax ; ++x)
    { int type = cribType[x] ;
      int xCount = arr(hashDepth, x, U32) ; if (xCount < 5) { ++low[type] ; continue ; }
      Array a = countHashNeighbours (x) ;
      --*arrp(a,arrayMax(a)-1,int) ; /* remove top match - often wrong */
      while (arrayMax(a) && !arr(a,arrayMax(a)-1,int)) --arrayMax(a) ;
      if (arrayMax(a) > 4)
	{ int n = 0 ; U64 sumSq = 0 ; int *ai = arrp(a,0,int) ;
	  for (i = 0 ; i < 4 ; ++i) n += *ai++ ;
	  for ( ; i < arrayMax(a) ; ++i) { sumSq += *ai * (i-3)*(i-3) ; n += *ai++ ; }
	  double score = sumSq/((double)n*(xCount-3)) ;
	  ++nt[type] ; sum[type] += score ;
	  if (score < min[type]) min[type] = score ;
	  if (score > max[type]) max[type] = score ;
	  if ((type == CRIB_ERR && score > 0.00005) || (type != CRIB_ERR && score < 0.00005))
	    { printf ("  %s count %d max %d score %.6f ",
		      cribText(x), xCount, arrayMax(a)-1, score) ;
	      for (i = 5 ; i < arrayMax(a) ; ++i) printf (" %d", arr(a,i,int)) ;
	      putchar ('\n') ;
	    }
	}
      else
	++low[type] ;
      arrayDestroy (a) ;
    }
  for (i = 0 ; i < CRIBTYPE_MAX ; ++i)
    printf ("  %s low %d n %d min %.6f av %.6f max %.6f\n",
	    cribTypeName[i], low[i], nt[i], min[i], sum[i] / (nt[i]?nt[i]:1), max[i]) ;
  timeUpdate (stdout) ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movl %esi, %ebp
movl %edi, %ebx
cmpq $0x0, 0xd0c9(%rip)      # 0x103d0
jne 0x3317
leaq 0x643c(%rip), %rdi      # 0x974c
xorl %eax, %eax
callq 0x8a3c
xorl %eax, %eax
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
cmpq $0x14, %rax
je 0x334f
andl $0x0, (%rsp,%rax)
andl $0x0, 0x20(%rsp,%rax)
movq %rcx, 0xb0(%rsp,%rax,2)
andq $0x0, 0x80(%rsp,%rax,2)
andq $0x0, 0x50(%rsp,%rax,2)
addq $0x4, %rax
jmp 0x3323
movl %ebx, %ebx
movl %ebp, %r15d
leaq 0x6156(%rip), %r12      # 0x94b1
cmpq %r15, %rbx
jae 0x3535
movq 0xd06d(%rip), %rax      # 0x103d8
movzbl (%rax,%rbx), %ebp
movq 0xd01a(%rip), %rax      # 0x10390
movq 0x8(%rax), %rcx
movl 0x14(%rax), %eax
imull %ebx, %eax
movl (%rcx,%rax), %r14d
cmpl $0x4, %r14d
jg 0x338f
incl (%rsp,%rbp,4)
jmp 0x33f4
movl %ebx, %edi
callq 0x2d8e
movq %rax, %r13
movq 0x8(%rax), %rax
movslq 0x18(%r13), %rcx
decq %rcx
movslq 0x14(%r13), %rdx
imulq %rcx, %rdx
decl (%rax,%rdx)
movl 0x18(%r13), %ecx
testl %ecx, %ecx
je 0x33e9
leal -0x1(%rcx), %edx
movslq 0x14(%r13), %rsi
movslq %edx, %rdi
imulq %rsi, %rdi
cmpl $0x0, (%rax,%rdi)
jne 0x33d3
movl %edx, 0x18(%r13)
movl %edx, %ecx
jmp 0x33b3
cmpl $0x5, %ecx
jl 0x33e9
xorl %esi, %esi
xorl %edx, %edx
cmpl $0x4, %esi
je 0x33fc
addl (%rax,%rsi,4), %edx
incq %rsi
jmp 0x33dc
incl (%rsp,%rbp,4)
movq %r13, %rdi
callq 0x8408
incq %rbx
jmp 0x335b
pushq $0x4
popq %rsi
pushq $0x1
popq %rdi
xorl %r8d, %r8d
cmpl %ecx, %esi
jge 0x3428
movl (%rax,%rsi,4), %r9d
movl %edi, %r10d
imull %edi, %r10d
imull %r9d, %r10d
movslq %r10d, %r10
addq %r10, %r8
addl %r9d, %edx
incl %edi
incq %rsi
jmp 0x3405
movq %r8, %xmm0
punpckldq 0x5bdb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x5be3(%rip), %xmm0     # 0x9020
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
cvtsi2sd %edx, %xmm1
addsd %xmm0, %xmm2
leal -0x3(%r14), %eax
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
incl 0x20(%rsp,%rbp,4)
divsd %xmm0, %xmm2
leal (,%rbp,8), %eax
movsd 0x50(%rsp,%rax), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x50(%rsp,%rax)
movsd 0xb0(%rsp,%rax), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x3490
movsd %xmm2, 0xb0(%rsp,%rbp,8)
ucomisd 0x80(%rsp,%rbp,8), %xmm2
jbe 0x34a4
movsd %xmm2, 0x80(%rsp,%rbp,8)
testq %rbp, %rbp
jne 0x34b3
ucomisd 0x5ba7(%rip), %xmm2     # 0x9058
ja 0x34ce
testq %rbp, %rbp
je 0x33ec
movsd 0x5b94(%rip), %xmm0     # 0x9058
ucomisd %xmm2, %xmm0
jbe 0x33ec
movl %ebx, %edi
movapd %xmm2, 0x40(%rsp)
callq 0x2a97
movl 0x18(%r13), %ecx
decl %ecx
leaq 0x6275(%rip), %rdi      # 0x975d
leaq 0xcf01(%rip), %rsi      # 0x103f0
movl %r14d, %edx
movapd 0x40(%rsp), %xmm0
movb $0x1, %al
callq 0x10d0
pushq $0x5
popq %rbp
cmpl 0x18(%r13), %ebp
jge 0x3528
movq 0x8(%r13), %rax
movslq 0x14(%r13), %rcx
movslq %ebp, %rdx
imulq %rcx, %rdx
movl (%rax,%rdx), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x10d0
incl %ebp
jmp 0x3502
pushq $0xa
popq %rdi
callq 0x1050
jmp 0x33ec
leaq 0xb864(%rip), %r14      # 0xeda0
xorl %r15d, %r15d
leaq 0x6238(%rip), %rbx      # 0x977e
cmpq $0x14, %r15
je 0x359b
movl 0x20(%rsp,%r15), %ecx
movsd 0x5af7(%rip), %xmm2     # 0x9050
testl %ecx, %ecx
je 0x3561
cvtsi2sd %ecx, %xmm2
movq (%r14), %rsi
movl (%rsp,%r15), %edx
movsd 0xb0(%rsp,%r15,2), %xmm0
movsd 0x50(%rsp,%r15,2), %xmm1
divsd %xmm2, %xmm1
movsd 0x80(%rsp,%r15,2), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x10d0
addq $0x4, %r15
addq $0x8, %r14
jmp 0x3546
movq 0xba26(%rip), %rax      # 0xefc8
movq (%rax), %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x8d03