// File: /workspace/github_c_makefile_star2_O3/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, 0xc622(%rip)      # 0x103c0
jne 0x3dae
leaq 0x69e5(%rip), %rdi      # 0xa78c
xorl %eax, %eax
callq 0x95f8
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
xorl %eax, %eax
movl %eax, 0x10(%rsp)
movaps %xmm0, 0x20(%rsp)
movl %eax, 0x30(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x80(%rsp)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movdqa 0x6240(%rip), %xmm0     # 0xa030
movl $0x1, %eax
movdqa 0x6243(%rip), %xmm1     # 0xa040
movdqa 0x624b(%rip), %xmm2     # 0xa050
pshufd $0xf5, %xmm2, %xmm3     # xmm3 = xmm2[1,1,3,3]
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movdqa 0x6244(%rip), %xmm4     # 0xa060
movdqa %xmm0, %xmm5
pxor %xmm1, %xmm5
movdqa %xmm2, %xmm6
pcmpgtd %xmm5, %xmm6
pshufd $0xf5, %xmm5, %xmm5     # xmm5 = xmm5[1,1,3,3]
pcmpeqd %xmm3, %xmm5
pand %xmm6, %xmm5
movd %xmm5, %edx
testb $0x1, %dl
je 0x3e4a
movq %rcx, 0xa8(%rsp,%rax,8)
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x3e5c
movq %rcx, 0xb0(%rsp,%rax,8)
paddq %xmm4, %xmm0
addq $0x2, %rax
cmpq $0x7, %rax
jne 0x3e1c
cmpl %ebp, %ebx
jae 0x409b
movl %ebx, %ebx
movl %ebp, %r14d
movq 0xc54a(%rip), %rax      # 0x103c8
movq 0xc4fb(%rip), %rcx      # 0x10380
leaq 0x6665(%rip), %r12      # 0xa4f1
movzbl (%rax,%rbx), %r15d
movq 0x8(%rcx), %rdx
movl 0x14(%rcx), %esi
imull %ebx, %esi
movl (%rdx,%rsi), %ebp
cmpl $0x4, %ebp
jg 0x3eac
incl (%rsp,%r15,4)
jmp 0x408f
movl %ebx, %edi
callq 0x3837
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), %rdi
testq %rdi, %rdi
je 0x4075
movslq 0x14(%r13), %rdx
leaq -0x1(%rdi), %rsi
imulq %rdx, %rsi
addq %rax, %rsi
negq %rdx
leal -0x4(%rdi), %ecx
cmpl $0x0, (%rsi)
jne 0x3f13
leal -0x1(%rdi), %r8d
movq %rdi, %r9
decq %r9
movl %r8d, 0x18(%r13)
addq %rdx, %rsi
decl %ecx
movq %r9, %rdi
testq %r9, %r9
jne 0x3eee
jmp 0x4075
cmpq $0x5, %rdi
jl 0x4075
movdqu (%rax), %xmm0
pshufd $0xee, %xmm0, %xmm1     # xmm1 = xmm0[2,3,2,3]
paddd %xmm0, %xmm1
pshufd $0x55, %xmm1, %xmm0     # xmm0 = xmm1[1,1,1,1]
paddd %xmm1, %xmm0
movd %xmm0, %edx
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
decl %ecx
jne 0x3f3b
movq %rsi, %xmm0
punpckldq 0x60a8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x60b0(%rip), %xmm0     # 0xa020
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
xorps %xmm1, %xmm1
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 0x3fcb
movsd %xmm2, 0xb0(%rsp,%r15,8)
ucomisd 0x70(%rsp,%r15,8), %xmm2
jbe 0x3fdb
movsd %xmm2, 0x70(%rsp,%r15,8)
testq %r15, %r15
jne 0x3fea
ucomisd 0x60a8(%rip), %xmm2     # 0xa090
ja 0x4001
testq %r15, %r15
je 0x4079
movsd 0x6095(%rip), %xmm0     # 0xa090
ucomisd %xmm2, %xmm0
jbe 0x4079
movl %ebx, %edi
movapd %xmm2, 0xa0(%rsp)
callq 0x3513
movl 0x18(%r13), %ecx
decl %ecx
leaq 0x677f(%rip), %rdi      # 0xa79d
leaq 0xc3bb(%rip), %rsi      # 0x103e0
movl %ebp, %edx
movapd 0xa0(%rsp), %xmm0
movb $0x1, %al
callq 0x10d0
cmpl $0x6, 0x18(%r13)
jl 0x4069
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 0x4044
movl $0xa, %edi
callq 0x1050
jmp 0x4079
incl (%rsp,%r15,4)
movq %r13, %rdi
callq 0x8fd6
movq 0xc340(%rip), %rax      # 0x103c8
movq 0xc2f1(%rip), %rcx      # 0x10380
incq %rbx
cmpq %r14, %rbx
jne 0x3e8c
leaq 0xacfe(%rip), %r14      # 0xeda0
xorl %r15d, %r15d
leaq 0x6712(%rip), %rbx      # 0xa7be
movl 0x20(%rsp,%r15), %ecx
movsd 0x5fdf(%rip), %xmm2     # 0xa098
testl %ecx, %ecx
je 0x40c4
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
movq (%r14), %rsi
movl (%rsp,%r15), %edx
movq 0xb0(%rsp,%r15,2), %xmm0
movsd 0x40(%rsp,%r15,2), %xmm1
divsd %xmm2, %xmm1
movq 0x70(%rsp,%r15,2), %xmm2
movq %rbx, %rdi
movb $0x3, %al
callq 0x10d0
addq $0x4, %r15
addq $0x8, %r14
cmpq $0x14, %r15
jne 0x40ac
movq 0xaec2(%rip), %rax      # 0xefc8
movq (%rax), %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x98d9