// File: kebwi[P]Trifid/src/ImagePairStats.cpp
// Function: calcRGB_MSE(Image3ChnlReal const&, Image3ChnlReal const&)
Float_t calcRGB_MSE(const Image3ChnlReal &img1, const Image3ChnlReal &img2)
{
	assert(img1.width() > 0 && img1.height() > 0);
	assert(img1.width() == img2.width() && img1.height() == img2.height());
	
	Float_t mse = 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++)
			{
				mse += SQR((*img2[c])(x, y) - (*img1[c])(x, y));
				numRelevantPixelComponents++;
			}
	
	assert(mse >= 0);
	
	mse /= numRelevantPixelComponents;
	
	return mse;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %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 0x37707
movq -0x8(%rbp), %rdi
callq 0xedf0
cmpl $0x0, %eax
setg %al
movb %al, -0x31(%rbp)
movb -0x31(%rbp), %al
testb $0x1, %al
jne 0x37710
jmp 0x37712
jmp 0x37731
leaq 0x15e6b(%rip), %rdi     # 0x4d584
leaq 0x15e8a(%rip), %rsi     # 0x4d5aa
movl $0x7d, %edx
leaq 0x15fa8(%rip), %rcx     # 0x4d6d4
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 0x37776
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 0x3777f
jmp 0x37781
jmp 0x377a0
leaq 0x1439e(%rip), %rdi     # 0x4bb26
leaq 0x15e1b(%rip), %rsi     # 0x4d5aa
movl $0x7e, %edx
leaq 0x15f39(%rip), %rcx     # 0x4d6d4
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 0x378e7
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movl -0x20(%rbp), %ecx
subl $0x0, %ecx
cmpl %ecx, %eax
jge 0x378d7
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x1c(%rbp), %ecx
subl $0x0, %ecx
cmpl %ecx, %eax
jge 0x378c7
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, -0x58(%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 -0x58(%rbp), %xmm0
subsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
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, -0x50(%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 -0x50(%rbp), %xmm2
movsd -0x48(%rbp), %xmm0
subsd (%rax), %xmm2
movsd -0x18(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %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 0x377f7
jmp 0x378c9
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x377df
jmp 0x378d9
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x377ce
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x378f7
jmp 0x37916
leaq 0x15d42(%rip), %rdi     # 0x4d640
leaq 0x15ca5(%rip), %rsi     # 0x4d5aa
movl $0x8c, %edx
leaq 0x15dc3(%rip), %rcx     # 0x4d6d4
callq 0x4240
cvtsi2sdl -0x24(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movsd -0x18(%rbp), %xmm0
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)