// File: /workspace/github_c_makefile_star2_O1/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, 0xc61b(%rip)      # 0x103c0
jne 0x3db5
leaq 0x699e(%rip), %rdi      # 0xa74c
xorl %eax, %eax
callq 0x9408
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movapd %xmm0, 0x20(%rsp)
movl %eax, 0x30(%rsp)
movapd %xmm0, 0x70(%rsp)
movapd %xmm0, 0x80(%rsp)
movq %rax, 0x90(%rsp)
movapd %xmm0, 0x40(%rsp)
movapd %xmm0, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, 0xb0(%rsp,%rax,8)
incq %rax
cmpq $0x5, %rax
jne 0x3e00
cmpl %ebp, %ebx
jae 0x401b
movl %ebx, %ebx
movl %ebp, %r14d
leaq 0x668c(%rip), %r12      # 0xa4b1
movq 0xc59c(%rip), %rax      # 0x103c8
movzbl (%rax,%rbx), %r15d
movq 0xc548(%rip), %rax      # 0x10380
movq 0x8(%rax), %rcx
movl 0x14(%rax), %eax
imull %ebx, %eax
movl (%rcx,%rax), %ebp
cmpl $0x4, %ebp
jg 0x3e53
incl (%rsp,%r15,4)
jmp 0x400f
movl %ebx, %edi
callq 0x384d
movq %rax, %r13
movq 0x8(%rax), %rax
movslq 0x18(%r13), %rcx
decq %rcx
movslq 0x14(%r13), %rdx
imulq %rcx, %rdx
decl (%rax,%rdx)
movslq 0x18(%r13), %rcx
testq %rcx, %rcx
je 0x3ead
movslq 0x14(%r13), %rdx
leaq -0x1(%rcx), %rsi
imulq %rdx, %rsi
addq %rax, %rsi
negq %rdx
cmpl $0x0, (%rsi)
jne 0x3ead
leal -0x1(%rcx), %edi
movq %rcx, %r8
decq %r8
movl %edi, 0x18(%r13)
addq %rdx, %rsi
movq %r8, %rcx
testq %r8, %r8
jne 0x3e8e
xorl %ecx, %ecx
cmpl $0x5, %ecx
jl 0x4003
xorl %esi, %esi
xorl %edx, %edx
addl (%rax,%rsi,4), %edx
incq %rsi
cmpl $0x4, %esi
jne 0x3eba
addl $-0x4, %ecx
xorl %edi, %edi
xorl %esi, %esi
movl 0x10(%rax,%rdi,4), %r8d
incq %rdi
movl %edi, %r9d
imull %edi, %r9d
imull %r8d, %r9d
movslq %r9d, %r9
addq %r9, %rsi
addl %r8d, %edx
cmpl %edi, %ecx
jne 0x3ecc
movq %rsi, %xmm0
punpckldq 0x6117(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x611f(%rip), %xmm0     # 0xa020
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
cvtsi2sd %edx, %xmm1
addsd %xmm0, %xmm2
leal -0x3(%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
incl 0x20(%rsp,%r15,4)
divsd %xmm0, %xmm2
leal (,%r15,8), %eax
movsd 0x40(%rsp,%rax), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, 0x40(%rsp,%rax)
movsd 0xb0(%rsp,%rax), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x3f59
movsd %xmm2, 0xb0(%rsp,%r15,8)
ucomisd 0x70(%rsp,%r15,8), %xmm2
jbe 0x3f69
movsd %xmm2, 0x70(%rsp,%r15,8)
testq %r15, %r15
jne 0x3f78
ucomisd 0x60da(%rip), %xmm2     # 0xa050
ja 0x3f8f
testq %r15, %r15
je 0x4007
movsd 0x60c7(%rip), %xmm0     # 0xa050
ucomisd %xmm2, %xmm0
jbe 0x4007
movl %ebx, %edi
movapd %xmm2, 0xa0(%rsp)
callq 0x353c
movl 0x18(%r13), %ecx
decl %ecx
leaq 0x67b1(%rip), %rdi      # 0xa75d
leaq 0xc42d(%rip), %rsi      # 0x103e0
movl %ebp, %edx
movapd 0xa0(%rsp), %xmm0
movb $0x1, %al
callq 0x10d0
cmpl $0x6, 0x18(%r13)
jl 0x3ff7
movl $0x5, %r15d
movq 0x8(%r13), %rax
movslq 0x14(%r13), %rcx
movslq %r15d, %r15
imulq %r15, %rcx
movl (%rax,%rcx), %esi
movq %r12, %rdi
xorl %eax, %eax
callq 0x10d0
incl %r15d
cmpl 0x18(%r13), %r15d
jl 0x3fd2
movl $0xa, %edi
callq 0x1050
jmp 0x4007
incl (%rsp,%r15,4)
movq %r13, %rdi
callq 0x8dc9
incq %rbx
cmpq %r14, %rbx
jne 0x3e25
leaq 0xad7e(%rip), %r14      # 0xeda0
xorl %r15d, %r15d
leaq 0x6752(%rip), %rbx      # 0xa77e
movl 0x20(%rsp,%r15), %ecx
movsd 0x601f(%rip), %xmm2     # 0xa058
testl %ecx, %ecx
je 0x4044
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
movq (%r14), %rsi
movl (%rsp,%r15), %edx
movsd 0xb0(%rsp,%r15,2), %xmm0
movsd 0x40(%rsp,%r15,2), %xmm1
divsd %xmm2, %xmm1
movsd 0x70(%rsp,%r15,2), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x10d0
addq $0x4, %r15
addq $0x8, %r14
cmpq $0x14, %r15
jne 0x402c
movq 0xaf42(%rip), %rax      # 0xefc8
movq (%rax), %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x96ed