// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movl (%rdi), %eax
movl 0x50(%rdi), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x50(%rdi)
movslq 0x10(%rdi), %rsi
cmpl %esi, %ecx
jl 0x2efc
addq $0xffff, %rsi           # imm = 0xFFFF
movl %esi, 0x10(%rbx)
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x2ed4
movq 0x28(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x2fb1
movl (%rbx), %eax
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x2efc
movq 0x30(%rbx), %rdi
movslq 0x10(%rbx), %rsi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x2fb1
movl (%rbx), %eax
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x2f49
movl 0x4(%rbx), %edx
movl 0x8(%rbx), %eax
movl %eax, (%rsp)
movq %r15, %rsi
movq %r14, %rcx
movl %edx, %r8d
movl %edx, %r9d
callq 0x2cb8
cvtss2sd %xmm0, %xmm0
movq 0x30(%rbx), %rax
movslq 0x50(%rbx), %rcx
movsd %xmm0, -0x8(%rax,%rcx,8)
addsd 0x40(%rbx), %xmm0
movsd %xmm0, 0x40(%rbx)
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0x68(%rbx), %rdi
callq *0x60(%rbx)
movl (%rbx), %eax
xorpd %xmm0, %xmm0
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x300a
movl 0xc(%rbx), %eax
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %edx
cmovgl %eax, %edx
xorpd %xmm0, %xmm0
cmpq %rcx, %rdx
je 0x2f8d
movzbl (%r15,%rcx), %esi
movzbl (%r14,%rcx), %edi
subl %edi, %esi
cvtsi2sd %esi, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
jmp 0x2f6b
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2f99
jnp 0x2fe1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2fbb
sqrtsd %xmm0, %xmm0
jmp 0x2fc0
movss 0x1287(%rip), %xmm0     # 0x4240
jmp 0x300a
callq 0x20e0
movsd 0x1280(%rip), %xmm1     # 0x4248
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x2120
movapd %xmm0, %xmm1
mulsd 0x126f(%rip), %xmm1     # 0x4250
movq 0x28(%rbx), %rax
movslq 0x50(%rbx), %rcx
movsd %xmm1, -0x8(%rax,%rcx,8)
addsd 0x38(%rbx), %xmm1
movsd %xmm1, 0x38(%rbx)
movsd -0x8(%rax,%rcx,8), %xmm0
movq 0x68(%rbx), %rdi
callq *0x58(%rbx)
xorpd %xmm0, %xmm0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq