// File: /workspace/github_c_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x20, %rsp
movq %rdi, %r14
movslq (%rdi), %r12
leaq 0x4(%rsp), %rcx
movq %rsp, %r8
movl $0x4, %esi
movl $0x7, %edx
callq 0x70e7
movl %eax, %ebx
leaq 0xc23f(%rip), %r15      # 0x12998
cmpl $0x0, (%r15)
je 0x677b
movl 0x4(%rsp), %esi
leal 0x3(%rsi), %edx
movl (%rsp), %ecx
leal 0x6(%rcx), %r8d
leaq 0x61a2(%rip), %rdi      # 0xc916
xorl %eax, %eax
callq 0x3170
testl %ebx, %ebx
jle 0x68dc
movslq (%rsp), %rax
xorpd %xmm3, %xmm3
xorpd %xmm2, %xmm2
xorpd %xmm4, %xmm4
cmpq $-0x6, %rax
jl 0x6829
xorl %ecx, %ecx
testl %eax, %eax
movl $0x0, %esi
cmovgl %eax, %esi
movslq 0x4(%rsp), %rdx
testl %edx, %edx
movl $0x0, %edi
cmovgl %edx, %edi
movq %rdx, %r8
addq $0x3, %r8
addq $0x6, %rax
movq %r12, %r9
imulq %rsi, %r9
leaq (%r14,%r9,4), %r9
addq $0x8, %r9
shlq $0x2, %r12
cmpl $-0x3, %edx
jl 0x6813
movq %rdi, %r10
movl (%r9,%r10,4), %r11d
movl %r10d, %ebp
imull %r11d, %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
addsd %xmm0, %xmm3
addl %r11d, %ecx
imull %esi, %r11d
xorps %xmm0, %xmm0
cvtsi2sd %r11d, %xmm0
addsd %xmm0, %xmm2
leaq 0x1(%r10), %r11
cmpq %r8, %r10
movq %r11, %r10
jl 0x67de
leaq 0x1(%rsi), %r10
addq %r12, %r9
cmpq %rax, %rsi
movq %r10, %rsi
jl 0x67d6
xorps %xmm4, %xmm4
cvtsi2sd %ecx, %xmm4
cmpl $0x0, (%r15)
je 0x6871
movapd %xmm3, %xmm0
divsd %xmm4, %xmm0
movapd %xmm2, %xmm1
divsd %xmm4, %xmm1
leaq 0x60f9(%rip), %rdi      # 0xc93f
movb $0x2, %al
movsd %xmm2, 0x18(%rsp)
movsd %xmm3, 0x10(%rsp)
movsd %xmm4, 0x8(%rsp)
callq 0x3170
movsd 0x8(%rsp), %xmm4
movsd 0x10(%rsp), %xmm3
movsd 0x18(%rsp), %xmm2
movsd 0x5e8f(%rip), %xmm0     # 0xc708
mulsd %xmm0, %xmm3
leaq 0xc464(%rip), %rax      # 0x12ce8
movl (%rax), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
mulsd %xmm1, %xmm3
divsd %xmm4, %xmm3
cvttsd2si %xmm3, %r14d
leal (%rax,%rax,4), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm2
divsd %xmm4, %xmm2
cvttsd2si %xmm2, %ebp
addl %ecx, %r14d
addl %ecx, %ebp
cmpl $0x0, (%r15)
je 0x68d4
leaq 0x6093(%rip), %rdi      # 0xc95b
movl %r14d, %esi
movl %ebp, %edx
xorl %eax, %eax
callq 0x3170
shlq $0x20, %r14
movl %ebp, %edx
jmp 0x68e1
xorl %r14d, %r14d
xorl %edx, %edx
movslq %ebx, %rax
imulq $0x51eb851f, %rax, %rax # imm = 0x51EB851F
movq %rax, %rcx
shrq $0x3f, %rcx
sarq $0x25, %rax
addl %ecx, %eax
orq %r14, %rax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq