// File: zhangk145[P]video_envalue/Envaluer.cpp
// Function: Envaluer::end()
void Envaluer::end() {
    double diff = 0;
    int psnr_stdv = 0;
    int ssim_stdv = 0;
    int i = 0;

    if (mCount) {
        if (mMode == EVL_PSNR || mMode == EVL_BOTH) {
            mPMean /= mCount;
        }
        if (mMode == EVL_SSIM || mMode == EVL_BOTH) {
            mSMean /= mCount;
        }
        for (psnr_stdv = 0, ssim_stdv = 0, i = 0; i < mCount; i++) {
            if (mMode == EVL_PSNR || mMode == EVL_BOTH) {
                diff = mYPsnr[i] - mPMean;
                psnr_stdv += diff * diff;
            }
            if (mMode == EVL_SSIM || mMode == EVL_BOTH) {
                diff = mYSsim[i] - mSMean;
                ssim_stdv += diff * diff;
            }
        }
        if (mMode == EVL_PSNR || mMode == EVL_BOTH) {
            psnr_stdv = sqrt(psnr_stdv / (mCount - 1));
        }
        if (mMode == EVL_SSIM || mMode == EVL_BOTH) {
            ssim_stdv = sqrt(ssim_stdv / (mCount - 1));
        }
    }

    fprintf(stderr, "%d frames (CPU: %lu s) psnr mean: %.2f ssim mean:%.2f psnr stdv: %.2f ssim stdv: %.2f\n",
            mCount, (unsigned long) ((clock() - mStartClock) / CLOCKS_PER_SEC), mPMean, mSMean, psnr_stdv, ssim_stdv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x0, 0x50(%rax)
je 0x2f0a
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2d9d
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2db4
movq -0x28(%rbp), %rax
cvtsi2sdl 0x50(%rax), %xmm1
movsd 0x38(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x38(%rax)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x2dc6
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2ddd
movq -0x28(%rbp), %rax
cvtsi2sdl 0x50(%rax), %xmm1
movsd 0x40(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rax)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x28(%rbp), %rcx
movl -0x1c(%rbp), %eax
cmpl 0x50(%rcx), %eax
jge 0x2ea8
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2e14
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2e4d
movq -0x28(%rbp), %rax
movq 0x28(%rax), %rcx
movslq -0x1c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd 0x38(%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x10(%rbp), %xmm2
cvtsi2sdl -0x14(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x2e5f
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2e98
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rcx
movslq -0x1c(%rbp), %rdx
movsd (%rcx,%rdx,8), %xmm0
subsd 0x40(%rax), %xmm0
movsd %xmm0, -0x10(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x10(%rbp), %xmm2
cvtsi2sdl -0x18(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x18(%rbp)
jmp 0x2e9a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x2df2
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
je 0x2eba
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2ed8
movq -0x28(%rbp), %rcx
movl -0x14(%rbp), %eax
movl 0x50(%rcx), %ecx
subl $0x1, %ecx
cltd
idivl %ecx
movl %eax, %edi
callq 0x3840
cvttsd2si %xmm0, %eax
movl %eax, -0x14(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x2eea
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2f08
movq -0x28(%rbp), %rcx
movl -0x18(%rbp), %eax
movl 0x50(%rcx), %ecx
subl $0x1, %ecx
cltd
idivl %ecx
movl %eax, %edi
callq 0x3840
cvttsd2si %xmm0, %eax
movl %eax, -0x18(%rbp)
jmp 0x2f0a
movq -0x28(%rbp), %rax
movq 0x40cb(%rip), %rcx      # 0x6fe0
movq (%rcx), %rcx
movq %rcx, -0x38(%rbp)
movl 0x50(%rax), %eax
movl %eax, -0x2c(%rbp)
callq 0x2030
movq -0x28(%rbp), %rcx
movq -0x38(%rbp), %rdi
subq 0x48(%rcx), %rax
movl $0xf4240, %ecx          # imm = 0xF4240
cqto
idivq %rcx
movl -0x2c(%rbp), %edx
movq %rax, %rcx
movq -0x28(%rbp), %rax
movsd 0x38(%rax), %xmm0
movsd 0x40(%rax), %xmm1
movl -0x14(%rbp), %r8d
movl -0x18(%rbp), %r9d
leaq 0x22e0(%rip), %rsi      # 0x5240
movb $0x2, %al
callq 0x2090
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)