// File: kebwi[P]Trifid/src/ImagePairStats.cpp
// Function: calcRGB_ME(Image3ChnlReal const&, Image3ChnlReal const&)
Float_t calcRGB_ME(const Image3ChnlReal &img1, const Image3ChnlReal &img2)
{
	assert(img1.width() > 0 && img1.height() > 0);
	assert(img1.width() == img2.width() && img1.height() == img2.height());
	
	Float_t meanErr = 0;
	
	int width = img1.width(), height = img1.height();
	int numRelevantPixelComponents = 0;
	for (int c = 0; c < 3; c++)
		for (int y = skEdgeSkip; y < height - skEdgeSkip; y++)
			for (int x = skEdgeSkip; x < width - skEdgeSkip; x++)
			{
				meanErr += fabs((*img2[c])(x, y) - (*img1[c])(x, y));
				numRelevantPixelComponents++;
			}
	
	assert(meanErr >= 0);
	
	meanErr /= numRelevantPixelComponents;
	
	return meanErr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x31(%rbp)
jle 0x374f7
movq -0x8(%rbp), %rdi
callq 0xedf0
cmpl $0x0, %eax
setg %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x37500
jmp 0x37502
jmp 0x37521
leaq 0x1607b(%rip), %rdi     # 0x4d584
leaq 0x1609a(%rip), %rsi     # 0x4d5aa
movl $0x65, %edx
leaq 0x16168(%rip), %rcx     # 0x4d684
callq 0x4240
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x38(%rbp)
movq -0x10(%rbp), %rdi
callq 0xedd0
movl -0x38(%rbp), %ecx
movl %eax, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x32(%rbp)
jne 0x37566
movq -0x8(%rbp), %rdi
callq 0xedf0
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rdi
callq 0xedf0
movl %eax, %ecx
movl -0x3c(%rbp), %eax
cmpl %ecx, %eax
sete %al
movb %al, -0x32(%rbp)
movb -0x32(%rbp), %al
testb $0x1, %al
jne 0x3756f
jmp 0x37571
jmp 0x37590
leaq 0x145ae(%rip), %rdi     # 0x4bb26
leaq 0x1602b(%rip), %rsi     # 0x4d5aa
movl $0x66, %edx
leaq 0x160f9(%rip), %rcx     # 0x4d684
callq 0x4240
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedd0
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
callq 0xedf0
movl %eax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl $0x0, -0x28(%rbp)
cmpl $0x3, -0x28(%rbp)
jge 0x37683
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x0, %ecx
cmpl %ecx, %eax
jge 0x37673
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x0, %ecx
cmpl %ecx, %eax
jge 0x37663
movq -0x10(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x25920
movq %rax, %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x1d980
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movq -0x8(%rbp), %rdi
movl -0x28(%rbp), %esi
callq 0x25920
movq %rax, %rdi
movl -0x30(%rbp), %esi
movl -0x2c(%rbp), %edx
callq 0x1d980
movsd -0x48(%rbp), %xmm0
subsd (%rax), %xmm0
movaps 0x119ff(%rip), %xmm1    # 0x49040
pand %xmm1, %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x375e7
jmp 0x37665
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x375cf
jmp 0x37675
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x375be
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x37693
jmp 0x376b2
leaq 0x1602d(%rip), %rdi     # 0x4d6c7
leaq 0x15f09(%rip), %rsi     # 0x4d5aa
movl $0x74, %edx
leaq 0x15fd7(%rip), %rcx     # 0x4d684
callq 0x4240
cvtsi2sdl -0x24(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
addq $0x50, %rsp
popq %rbp
retq