// File: /workspace/github_cpp_makefile_star2_O2/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 $0x78, %rsp
movq %rcx, -0x80(%rbp)
movl %edx, %edi
movq %rsi, -0x78(%rbp)
movl 0x10(%rbp), %esi
pushq $0x4
popq %rcx
movl %r9d, %eax
cltd
idivl %ecx
leal 0xc(,%rax,4), %eax
cltq
leaq 0x1e(,%rax,4), %rcx
andq $-0x10, %rcx
movq %rsp, %rax
subq %rcx, %rax
movq %rax, %rsp
movq %rsp, %rbx
subq %rcx, %rbx
movq %rbx, %rsp
sarl $0x2, %r9d
sarl $0x2, %esi
movslq %r9d, %r14
decl %r9d
movl %r8d, -0x3c(%rbp)
movslq %r8d, %rcx
movl %edi, -0x38(%rbp)
movslq %edi, %rdx
movl %r9d, -0x30(%rbp)
movslq %r9d, %rdi
movq %rdi, -0x90(%rbp)
movl %esi, -0x34(%rbp)
movslq %esi, %rsi
movq %rsi, -0x88(%rbp)
shlq $0x2, %rdx
movq %rdx, -0x48(%rbp)
shlq $0x2, %rcx
movq %rcx, -0x50(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x2c(%rbp)
pushq $0x1
popq %rcx
xorl %edx, %edx
cmpq -0x88(%rbp), %rcx
jge 0x2e5d
movslq %edx, %rdx
movq -0x48(%rbp), %r13
imulq %rdx, %r13
addq -0x78(%rbp), %r13
movq -0x50(%rbp), %r15
imulq %rdx, %r15
addq -0x80(%rbp), %r15
movq %rcx, -0x58(%rbp)
movq %rdx, -0x68(%rbp)
cmpq %rcx, %rdx
movq %rbx, -0x70(%rbp)
movq %rax, -0x60(%rbp)
jg 0x2dfd
movq %r15, -0x98(%rbp)
movq %r13, -0xa0(%rbp)
xorl %r12d, %r12d
cmpq %r14, %r12
jge 0x2dd2
movq %r13, %rsi
movl -0x38(%rbp), %edx
movq %r15, %rcx
movl -0x3c(%rbp), %r8d
movq %rbx, %r9
callq 0x2afc
addq $0x2, %r12
addq $0x20, %rbx
addq $0x8, %r13
addq $0x8, %r15
jmp 0x2da6
movq -0x68(%rbp), %rdx
incq %rdx
movq -0xa0(%rbp), %r13
addq -0x48(%rbp), %r13
movq -0x98(%rbp), %r15
addq -0x50(%rbp), %r15
movq -0x70(%rbp), %rax
movq -0x60(%rbp), %rbx
movq -0x58(%rbp), %rcx
jmp 0x2d84
movq %rax, %r12
movq %rbx, %r13
movl -0x30(%rbp), %ebx
xorl %r15d, %r15d
cmpq -0x90(%rbp), %r15
jge 0x2e45
cmpl $0x4, %ebx
pushq $0x4
popq %rcx
cmovll %ebx, %ecx
movq %r12, %rsi
movq %r13, %rdx
callq 0x2c12
movss -0x2c(%rbp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, -0x2c(%rbp)
addq $0x4, %r15
addl $-0x4, %ebx
addq $0x40, %r13
addq $0x40, %r12
jmp 0x2e09
movq -0x58(%rbp), %rcx
incq %rcx
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rdx
movq -0x70(%rbp), %rbx
jmp 0x2d58
movl -0x34(%rbp), %eax
decl %eax
imull -0x30(%rbp), %eax
cvtsi2ss %eax, %xmm1
movss -0x2c(%rbp), %xmm0
divss %xmm1, %xmm0
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq