// File: /workspace/github_cpp_makefile_star2_O1/zhangk145[P]video_envalue/Envaluer.cpp
// Function: Envaluer::compute_ssim(unsigned char*, int, unsigned char*, int, int, int)
float Envaluer::compute_ssim(uint8_t *pix1, int stride1,
                   uint8_t *pix2, int stride2,
                   int width, int height)
{
    int x, y, z;
    float ssim = 0.0;
    // printf("[%s:%d]==\n", __FUNCTION__, __LINE__);
    int (*sum0)[4] = (int (*)[4])x264_alloca(4 * (width/4+3) * sizeof(int));
    int (*sum1)[4] = (int (*)[4])x264_alloca(4 * (width/4+3) * sizeof(int));
    // void *sumTmp0 = (void *)sum0;
    // void *sumTmp1 = (void *)sum1;
    width >>= 2;
    height >>= 2;
    z = 0;
    // printf("[%s:%d]width:%d height:%d\n", __FUNCTION__, __LINE__, width, height);
    for( y = 1; y < height; y++ )
    {
        for( ; z <= y; z++ )
        {
            int (*t)[4] = sum0;
            sum0 = sum1;
            sum1 = t;
            // XCHG( , sum0, sum1 );
            for( x = 0; x < width; x+=2 )
                ssim_4x4x2_core( &pix1[4*(x+z*stride1)], stride1, &pix2[4*(x+z*stride2)], stride2, &sum0[x] );
        }
        for( x = 0; x < width-1; x += 4 ) {
            ssim += ssim_end4( sum0+x, sum1+x, X264_MIN(4,width-x-1) );
            // printf("[%s:%d]==ssim:%.3f\n", __FUNCTION__, __LINE__, ssim);
        }
    }
    // printf("[%s:%d]==\n", __FUNCTION__, __LINE__);
    return ssim / ((width-1) * (height-1));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, -0x88(%rbp)
movl %edx, -0x40(%rbp)
movq %rsi, -0x80(%rbp)
movl 0x10(%rbp), %ecx
leal 0x3(%r9), %eax
testl %r9d, %r9d
cmovnsl %r9d, %eax
andl $-0x4, %eax
addl $0xc, %eax
cltq
leaq 0x1e(,%rax,4), %rax
andq $-0x10, %rax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x50(%rbp)
movq %rdx, %rsp
movq %rsp, %r13
subq %rax, %r13
movq %r13, %rsp
sarl $0x2, %r9d
movq %r9, -0x48(%rbp)
sarl $0x2, %ecx
xorps %xmm1, %xmm1
movl %ecx, -0x3c(%rbp)
cmpl $0x2, %ecx
jl 0x2f6f
movq -0x48(%rbp), %rax
leal -0x1(%rax), %ecx
cltq
movq %rax, -0xb0(%rbp)
movslq -0x40(%rbp), %rax
movslq %r8d, %rdx
movl %ecx, -0x5c(%rbp)
movslq %ecx, %rcx
movq %rcx, -0x98(%rbp)
movl -0x3c(%rbp), %ecx
movq %rcx, -0x90(%rbp)
shlq $0x2, %rdx
movq %rdx, -0x68(%rbp)
shlq $0x2, %rax
movq %rax, -0x70(%rbp)
xorl %ecx, %ecx
movl $0x1, %eax
movl %r8d, -0x60(%rbp)
movq %rax, -0x78(%rbp)
movslq %ecx, %rdx
cmpq %rdx, %rax
jl 0x2efc
movss %xmm1, -0x2c(%rbp)
movq -0x68(%rbp), %rax
imulq %rdx, %rax
addq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rax
imulq %rdx, %rax
addq -0x80(%rbp), %rax
movq %rax, -0x58(%rbp)
movq %rdx, -0xa8(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq %r13, -0x50(%rbp)
cmpl $0x0, -0x48(%rbp)
movl -0x60(%rbp), %r14d
jle 0x2eba
movq -0x50(%rbp), %r15
movq -0x58(%rbp), %r13
movq -0x38(%rbp), %rbx
xorl %r12d, %r12d
movq %r13, %rsi
movl -0x40(%rbp), %edx
movq %rbx, %rcx
movl %r14d, %r8d
movq %r15, %r9
callq 0x2b84
movq -0xb0(%rbp), %rcx
addq $0x2, %r12
addq $0x8, %rbx
addq $0x8, %r13
addq $0x20, %r15
cmpq %rcx, %r12
jl 0x2e8a
movq -0xa8(%rbp), %rax
leaq 0x1(%rax), %rcx
movq -0x38(%rbp), %rdx
addq -0x68(%rbp), %rdx
movq %rdx, -0x38(%rbp)
movq -0x58(%rbp), %rdx
addq -0x70(%rbp), %rdx
movq %rdx, -0x58(%rbp)
movq -0xa0(%rbp), %rsi
movq %rsi, %r13
cmpq -0x78(%rbp), %rax
movq %rcx, %rdx
jl 0x2e5b
movq %rsi, %r13
movss -0x2c(%rbp), %xmm1
movq %rcx, -0x38(%rbp)
cmpl $0x2, -0x48(%rbp)
jl 0x2f51
movl -0x5c(%rbp), %ebx
movq -0x50(%rbp), %r15
movq %r13, %r14
xorl %r12d, %r12d
movss %xmm1, -0x2c(%rbp)
cmpl $0x4, %ebx
movl $0x4, %ecx
cmovll %ebx, %ecx
movq %r15, %rsi
movq %r13, %rdx
callq 0x2c8a
movss -0x2c(%rbp), %xmm1
addss %xmm0, %xmm1
addq $0x4, %r12
addq $0x40, %r13
addq $0x40, %r15
addl $-0x4, %ebx
cmpq -0x98(%rbp), %r12
jl 0x2f13
jmp 0x2f54
movq %r13, %r14
movq -0x78(%rbp), %rax
incq %rax
cmpq -0x90(%rbp), %rax
movq %r14, %r13
movq -0x38(%rbp), %rcx
jne 0x2e23
movq -0x48(%rbp), %rax
decl %eax
movl -0x3c(%rbp), %ecx
decl %ecx
imull %eax, %ecx
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
divss %xmm0, %xmm1
movaps %xmm1, %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq