// File: zhangk145[P]video_envalue/Envaluer.cpp
// Function: Envaluer::compute(unsigned char*, unsigned char*)
float Envaluer::compute(uint8_t *org_buf, uint8_t *new_buf) {
    double yrmse = 0;
    double diff = 0;
    int inc = 1;
    int i = 0;
    // printf("[%s:%d]==\n", __FUNCTION__, __LINE__);
    if (++mCount > mBufSize) {
      mBufSize += 0xffff;
      if (mMode == EVL_PSNR || mMode == EVL_BOTH) {
        mYPsnr = (double *)realloc(mYPsnr, mBufSize * sizeof(*mYPsnr));
        if (!mYPsnr) {
            return -1;
        }
      }
      if (mMode == EVL_SSIM || mMode == EVL_BOTH) {
      mYSsim = (double *)realloc(mYSsim, mBufSize * sizeof(*mYSsim));
        if (!mYSsim) {
            return -1;
        }
      }
    }
    if (mMode == EVL_SSIM || mMode == EVL_BOTH) {
        mSMean += mYSsim[mCount - 1] = compute_ssim(org_buf, mWidth, new_buf, mWidth, mWidth, mHeight);
        // printf("ssim %.3f\n", mYSsim[mCount - 1]);
        mSsimCallback(mYSsim[mCount - 1], mUsr);
    }
    if (mMode == EVL_PSNR || mMode == EVL_BOTH) {
        for (yrmse = 0, i = inc - 1; i < (inc == 1 ? mYuvSize : mWidth*mHeight); i += inc) {
            diff = org_buf[i] - new_buf[i];
            yrmse += diff * diff;
        }
        mPMean += mYPsnr[mCount - 1] = yrmse ? 20 * (log10(255 / sqrt(yrmse / mYuvSize))) : 0;
        // printf("psnr %.3f\n", mYPsnr[mCount - 1]);
        mPsnrCallback(mYPsnr[mCount - 1], mUsr);
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rcx
movq %rcx, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl $0x1, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl 0x50(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x50(%rcx)
cmpl 0x10(%rcx), %eax
jle 0x3674
movq -0x40(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0xffff, %ecx           # imm = 0xFFFF
movl %ecx, 0x10(%rax)
cmpl $0x0, (%rax)
je 0x35ea
movq -0x40(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x3625
movq -0x40(%rbp), %rax
movq 0x28(%rax), %rdi
movslq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2070
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
cmpq $0x0, 0x28(%rax)
jne 0x3623
movss 0x1c0f(%rip), %xmm0     # 0x5228
movss %xmm0, -0x4(%rbp)
jmp 0x382f
jmp 0x3625
movq -0x40(%rbp), %rax
cmpl $0x1, (%rax)
je 0x3637
movq -0x40(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x3672
movq -0x40(%rbp), %rax
movq 0x30(%rax), %rdi
movslq 0x10(%rax), %rsi
shlq $0x3, %rsi
callq 0x2070
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
cmpq $0x0, 0x30(%rax)
jne 0x3670
movss 0x1bc2(%rip), %xmm0     # 0x5228
movss %xmm0, -0x4(%rbp)
jmp 0x382f
jmp 0x3672
jmp 0x3674
movq -0x40(%rbp), %rax
cmpl $0x1, (%rax)
je 0x3686
movq -0x40(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x36e8
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl 0x4(%rdi), %edx
movq -0x20(%rbp), %rcx
movl 0x4(%rdi), %r8d
movl 0x4(%rdi), %r9d
movl 0x8(%rdi), %eax
movl %eax, (%rsp)
callq 0x3340
movq -0x40(%rbp), %rcx
cvtss2sd %xmm0, %xmm0
movq 0x30(%rcx), %rax
movl 0x50(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsd %xmm0, (%rax,%rdx,8)
addsd 0x40(%rcx), %xmm0
movsd %xmm0, 0x40(%rcx)
movq 0x60(%rcx), %rax
movq 0x30(%rcx), %rdx
movl 0x50(%rcx), %esi
subl $0x1, %esi
movslq %esi, %rsi
movsd (%rdx,%rsi,8), %xmm0
movq 0x68(%rcx), %rdi
callq *%rax
movq -0x40(%rbp), %rax
cmpl $0x0, (%rax)
je 0x36fe
movq -0x40(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x3827
xorps %xmm0, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x34(%rbp)
jne 0x3727
movq -0x40(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x48(%rbp)
jmp 0x3735
movq -0x40(%rbp), %rcx
movl 0x4(%rcx), %eax
imull 0x8(%rcx), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
movl -0x48(%rbp), %ecx
cmpl %ecx, %eax
jge 0x3789
movq -0x18(%rbp), %rax
movslq -0x38(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movq -0x20(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movzbl (%rcx,%rdx), %ecx
subl %ecx, %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movsd -0x30(%rbp), %xmm2
movsd -0x28(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x28(%rbp)
movl -0x34(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x370f
movsd -0x28(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x379b
jp 0x379b
jmp 0x37dc
movq -0x40(%rbp), %rax
movsd -0x28(%rbp), %xmm0
cvtsi2sdl 0xc(%rax), %xmm1
divsd %xmm1, %xmm0
callq 0x2110
movaps %xmm0, %xmm1
movsd 0x1a7b(%rip), %xmm0     # 0x5238
divsd %xmm1, %xmm0
callq 0x2150
movaps %xmm0, %xmm1
movsd 0x1a5f(%rip), %xmm0     # 0x5230
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x37e6
xorps %xmm0, %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x37e6
movq -0x40(%rbp), %rcx
movsd -0x50(%rbp), %xmm0
movq 0x28(%rcx), %rax
movl 0x50(%rcx), %edx
subl $0x1, %edx
movslq %edx, %rdx
movsd %xmm0, (%rax,%rdx,8)
addsd 0x38(%rcx), %xmm0
movsd %xmm0, 0x38(%rcx)
movq 0x58(%rcx), %rax
movq 0x28(%rcx), %rdx
movl 0x50(%rcx), %esi
subl $0x1, %esi
movslq %esi, %rsi
movsd (%rdx,%rsi,8), %xmm0
movq 0x68(%rcx), %rdi
callq *%rax
xorps %xmm0, %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x4(%rbp), %xmm0
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)