// File: /workspace/github_cpp_makefile_star2_O3/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 0x30da
addq $0xffff, %rsi           # imm = 0xFFFF
movl %esi, 0x10(%rbx)
testl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
jne 0x30b2
movq 0x28(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x3195
movl (%rbx), %eax
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x30da
movq 0x30(%rbx), %rdi
movslq 0x10(%rbx), %rsi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x3195
movl (%rbx), %eax
leal -0x1(%rax), %ecx
cmpl $0x1, %ecx
ja 0x3127
movl 0x4(%rbx), %edx
movl 0x8(%rbx), %eax
movl %eax, (%rsp)
movq %r15, %rsi
movq %r14, %rcx
movl %edx, %r8d
movl %edx, %r9d
callq 0x2e1a
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 0x31ee
movslq 0xc(%rbx), %rax
testq %rax, %rax
jle 0x318f
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movzbl (%r15,%rcx), %edx
movzbl (%r14,%rcx), %esi
subl %esi, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
mulsd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rcx
cmpq %rcx, %rax
jne 0x3145
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x3174
jnp 0x31c5
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x319f
sqrtsd %xmm0, %xmm0
jmp 0x31a4
xorpd %xmm1, %xmm1
jmp 0x31c5
movss 0x10a3(%rip), %xmm0     # 0x4240
jmp 0x31ee
callq 0x20e0
movsd 0x109c(%rip), %xmm1     # 0x4248
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x2120
movapd %xmm0, %xmm1
mulsd 0x108b(%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