// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
movl $0x4, %esi
movl $0x7, %edx
leaq -0x20(%rbp), %rcx
leaq -0x24(%rbp), %r8
callq 0x84b0
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
movl %eax, -0x10(%rbp)
movl $0x0, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
leaq 0xd2a2(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x7784
movl -0x20(%rbp), %esi
movl -0x20(%rbp), %edx
addl $0x4, %edx
subl $0x1, %edx
movl -0x24(%rbp), %ecx
movl -0x24(%rbp), %r8d
addl $0x7, %r8d
subl $0x1, %r8d
leaq 0x81b5(%rip), %rdi      # 0xf932
movb $0x0, %al
callq 0x3170
cmpl $0x0, -0x28(%rbp)
jle 0x7949
movl -0x24(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jge 0x77a1
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x40(%rbp), %eax
movl -0x24(%rbp), %ecx
addl $0x7, %ecx
cmpl %ecx, %eax
jge 0x7851
movl -0x20(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0x77dc
movl $0x0, -0x44(%rbp)
jmp 0x77de
movl -0x44(%rbp), %eax
movl -0x20(%rbp), %ecx
addl $0x4, %ecx
cmpl %ecx, %eax
jge 0x7841
movq -0x18(%rbp), %rax
movl -0x40(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x44(%rbp), %ecx
movslq %ecx, %rcx
movl 0x8(%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x44(%rbp), %eax
imull -0x48(%rbp), %eax
cvtsi2sd %eax, %xmm0
addsd -0x30(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
movl -0x40(%rbp), %eax
imull -0x48(%rbp), %eax
cvtsi2sd %eax, %xmm0
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movl -0x48(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x77de
jmp 0x7843
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x77b8
leaq 0xd1a0(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x7897
movsd 0x7e83(%rip), %xmm0     # 0xf6e8
mulsd -0x30(%rbp), %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd 0x7e6d(%rip), %xmm1     # 0xf6e8
mulsd -0x38(%rbp), %xmm1
cvtsi2sdl -0x3c(%rbp), %xmm2
divsd %xmm2, %xmm1
leaq 0x80cb(%rip), %rdi      # 0xf95b
movb $0x2, %al
callq 0x3170
movsd 0x7e59(%rip), %xmm0     # 0xf6f8
mulsd -0x30(%rbp), %xmm0
leaq 0xd49d(%rip), %rax      # 0x14d48
cvtsi2sdl (%rax), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x50(%rbp)
leaq 0xd47e(%rip), %rax      # 0x14d48
imull $0x5, (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x50(%rbp), %eax
addl %ecx, %eax
movl %eax, -0xc(%rbp)
movsd 0x7e11(%rip), %xmm0     # 0xf6f8
mulsd -0x38(%rbp), %xmm0
leaq 0xd455(%rip), %rax      # 0x14d48
cvtsi2sdl (%rax), %xmm1
mulsd %xmm1, %xmm0
cvtsi2sdl -0x3c(%rbp), %xmm1
divsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x4c(%rbp)
leaq 0xd436(%rip), %rax      # 0x14d48
imull $0x5, (%rax), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, %ecx
movl -0x4c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x8(%rbp)
leaq 0xd0ca(%rip), %rax      # 0x149f8
cmpl $0x0, (%rax)
je 0x7947
movl -0xc(%rbp), %esi
movl -0x8(%rbp), %edx
leaq 0x8037(%rip), %rdi      # 0xf977
movb $0x0, %al
callq 0x3170
jmp 0x7949
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x50, %rsp
popq %rbp
retq
nopw (%rax,%rax)