// File: /workspace/github_cpp_makefile_star2_O1/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 0x50(%rdi), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x50(%rdi)
movslq 0x10(%rdi), %rsi
cmpl %esi, %eax
jl 0x3010
addq $0xffff, %rsi           # imm = 0xFFFF
movl %esi, 0x10(%rbx)
testl $0xfffffffd, (%rbx)     # imm = 0xFFFFFFFD
jne 0x2fe9
movq 0x28(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x30c8
movl (%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x3010
movq 0x30(%rbx), %rdi
movslq 0x10(%rbx), %rsi
shlq $0x3, %rsi
callq 0x2060
movq %rax, 0x30(%rbx)
testq %rax, %rax
je 0x30c8
movl (%rbx), %eax
decl %eax
cmpl $0x1, %eax
ja 0x305c
movl 0x4(%rbx), %edx
movl 0x8(%rbx), %eax
movl %eax, (%rsp)
movq %r15, %rsi
movq %r14, %rcx
movl %edx, %r8d
movl %edx, %r9d
callq 0x2d66
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)
xorpd %xmm0, %xmm0
testl $0xfffffffd, (%rbx)     # imm = 0xFFFFFFFD
jne 0x3121
movslq 0xc(%rbx), %rax
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
testq %rax, %rax
jle 0x30a2
xorl %ecx, %ecx
movzbl (%r15,%rcx), %edx
movzbl (%r14,%rcx), %esi
subl %esi, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
mulsd %xmm2, %xmm2
addsd %xmm2, %xmm1
incq %rcx
cmpq %rcx, %rax
jne 0x307f
ucomisd %xmm0, %xmm1
jne 0x30aa
jnp 0x30f8
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm1
jb 0x30d2
xorps %xmm0, %xmm0
sqrtsd %xmm1, %xmm0
jmp 0x30db
movss 0x1170(%rip), %xmm0     # 0x4240
jmp 0x3121
movapd %xmm1, %xmm0
callq 0x20e0
movsd 0x1165(%rip), %xmm1     # 0x4248
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
callq 0x2120
mulsd 0x1158(%rip), %xmm0     # 0x4250
movq 0x28(%rbx), %rax
movslq 0x50(%rbx), %rcx
movsd %xmm0, -0x8(%rax,%rcx,8)
addsd 0x38(%rbx), %xmm0
movsd %xmm0, 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
nop