// File: /workspace/github_c_makefile_star2_O2/Matthias-Wandel[P]imgcomp/src/compare.c
// Function: LocateMotion
static TriggerInfo_t LocateMotion(ImgMap_t * DiffScaled)
{
    TriggerInfo_t retval;
    int widthSc = DiffScaled->w;

    int maxc, maxr, maxval;

    maxval = BlockFilterImgMap(DiffScaled, wind_w, wind_h, &maxc, &maxr);

    // Now search for the maximum inside a rectangular window.
    retval.DiffLevel = maxval/100;
    retval.x = retval.y = 0;

    // Work out where most of the motion was found inside the search window.
    if (Verbosity) printf("Window contents.  Cols %d-%d Rows %d-%d\n",maxc,maxc+wind_w-1,maxr, maxr+wind_h-1);
    if (maxval > 0){
        double xsum, ysum;
        int sum;
        int row = maxr;
        if (row < 0) row = 0;

        xsum = ysum = sum = 0;
        for (;row<maxr+wind_h;row++){
            int col = maxc;
            if (col < 0) col = 0;
            for(;col<maxc+wind_w;col++){
                int v = DiffScaled->values[row*widthSc+col];
                xsum += col*v;
                ysum += row*v;
                sum += v;
                //printf("%5d",DiffScaled->values[row*widthSc+col]);
            }
            //printf("\n");
        }
        if (Verbosity) printf("Exact col=%5.1f, row=%5.1f\n",xsum*1.0/sum, ysum*1.0/sum);
        retval.x = (int)(xsum*scalef*ScaleDenom/sum)+scalef*ScaleDenom/2;
        retval.y = (int)(ysum*scalef*ScaleDenom/sum)+scalef*ScaleDenom/2;
        if (Verbosity) printf("Picture coordinates: x,y = %d,%d\n",retval.x, retval.y);
    }

    return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r15
movslq (%rdi), %r13
pushq $0x4
popq %rsi
pushq $0x7
popq %rdx
leaq 0xc(%rsp), %rcx
leaq 0x8(%rsp), %r8
callq 0x6a82
movl %eax, %ebx
leaq 0xc7ad(%rip), %r12      # 0x129a8
cmpl $0x0, (%r12)
je 0x621f
movl 0xc(%rsp), %esi
leal 0x3(%rsi), %edx
movl 0x8(%rsp), %ecx
leal 0x6(%rcx), %r8d
leaq 0x6746(%rip), %rdi      # 0xc95e
xorl %eax, %eax
callq 0x3170
xorl %r14d, %r14d
testl %ebx, %ebx
jle 0x6301
movslq 0x8(%rsp), %rax
testl %eax, %eax
movl $0x0, %ecx
cmovgl %eax, %ecx
addq $0x7, %rax
movslq 0xc(%rsp), %rdx
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
addq $0x4, %rdx
movq %r13, %rdi
imulq %rcx, %rdi
leaq (%r15,%rdi,4), %rdi
addq $0x8, %rdi
shlq $0x2, %r13
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
cmpq %rax, %rcx
jge 0x62a9
movq %rsi, %r8
cmpq %rdx, %r8
jge 0x62a1
movl (%rdi,%r8,4), %r9d
movl %r8d, %r10d
imull %r9d, %r10d
cvtsi2sd %r10d, %xmm0
addsd %xmm0, %xmm3
addl %r9d, %r14d
imull %ecx, %r9d
cvtsi2sd %r9d, %xmm0
addsd %xmm0, %xmm2
incq %r8
jmp 0x6273
incq %rcx
addq %r13, %rdi
jmp 0x626b
cmpl $0x0, (%r12)
cvtsi2sd %r14d, %xmm4
je 0x6305
movapd %xmm3, %xmm0
divsd %xmm4, %xmm0
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
leaq 0x66bb(%rip), %rdi      # 0xc987
movb $0x2, %al
movsd %xmm2, 0x20(%rsp)
movsd %xmm3, 0x18(%rsp)
movsd %xmm4, 0x10(%rsp)
callq 0x3170
movsd 0x10(%rsp), %xmm4
movsd 0x18(%rsp), %xmm3
movsd 0x20(%rsp), %xmm2
cmpl $0x0, (%r12)
sete %cl
jmp 0x6307
xorl %ecx, %ecx
jmp 0x6368
movb $0x1, %cl
movsd 0x6401(%rip), %xmm0     # 0xc710
mulsd %xmm0, %xmm3
leaq 0xc9de(%rip), %rax      # 0x12cf8
movl (%rax), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm3
divsd %xmm4, %xmm3
cvttsd2si %xmm3, %r14d
leal (%rax,%rax,4), %eax
pushq $0x2
popq %rsi
cltd
idivl %esi
addl %eax, %r14d
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm4, %xmm2
cvttsd2si %xmm2, %ebp
addl %eax, %ebp
testb %cl, %cl
jne 0x6362
leaq 0x664d(%rip), %rdi      # 0xc9a3
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3170
shlq $0x20, %r14
movl %ebp, %ecx
pushq $0x64
popq %rsi
movl %ebx, %eax
cltd
idivl %esi
orq %r14, %rax
movq %rcx, %rdx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)