// File: /workspace/github_c_makefile_star2_O0/Matthias-Wandel[P]imgcomp/src/compare_util.c
// Function: BlockFilterImgMap
int BlockFilterImgMap(const ImgMap_t * src, int fw, int fh, int * pmaxc, int * pmaxr)
{
	int w = src->w;
	int h = src->h;
	if (fw > w || fh > h){
		fprintf(stderr, "filter too big\n");
		return 0;
	}
    
    static ImgMap_t * dst_tmp = NULL;
    if (dst_tmp == NULL){
        dst_tmp = MakeImgMap(src->w, src->h); // All subsequent images same size.
    }
    

	// Sum horizontally and copy to dst_tmp
	fw -= 1;
	for (int r=0;r<h;r++){
		int sum=0;
		const int * row = &src->values[r*w];
		int * dstrow = &dst_tmp->values[r*w];
		int c;
		for (c=0;c<fw;c++){
			sum += row[c];
		}
		for (c=0;c<w-fw;c++){
			int ov = row[c];
			sum += row[c+fw];
			dstrow[c] = sum;
			sum -= ov;
		}
		for (;c<w;c++) dstrow[c] = 0; // Clear unused columns.
	}

	int maxr, maxc, maxv; // For maximum search while doing columns.
	maxr = maxc = maxv = 0;
	
	// Sum vertically.
	fh -= 1;
	int sums[w];
	memset(sums, 0, sizeof(sums));
	for (int r=0;r<fh;r++){
		int * row = &dst_tmp->values[r*w];
		for (int c=0;c<w;c++){
			sums[c] += row[c];
		}
	}
	for (int r=0;r<h-fh;r++){
		int * row = &dst_tmp->values[r*w];
		int * rowp = &dst_tmp->values[(r+fh)*w];
		for (int c=0;c<w;c++){
			int ov = row[c];
			int sum = sums[c]+rowp[c];
			row[c] = sum;
			if (sum > maxv){
				maxv = sum;
				maxr = r;
				maxc = c;
			}
			sums[c] = sum-ov;
		}
	}
	// Clear out unused rows.
	memset(&dst_tmp->values[(h-fh)*w],0,sizeof(dst_tmp->values[0])*w*fh);
	
	
	// Return location of peak
	//printf("max of %d found at %d,%d\n",maxv,maxc,maxr);
	if (pmaxr) *pmaxr = maxr;
	if (pmaxc) *pmaxc = maxc;
	return maxv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x30(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jg 0x84f0
movl -0x18(%rbp), %eax
cmpl -0x30(%rbp), %eax
jle 0x8514
movq 0xbaf9(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x74e5(%rip), %rsi      # 0xf9e6
movb $0x0, %al
callq 0x3290
movl $0x0, -0x4(%rbp)
jmp 0x88d5
cmpq $0x0, 0xcf8c(%rip)      # 0x154a8
jne 0x8537
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %esi
callq 0x7ff0
movq %rax, 0xcf71(%rip)      # 0x154a8
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x8652
movl $0x0, -0x38(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movl -0x34(%rbp), %ecx
imull -0x2c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq 0xcf2a(%rip), %rax      # 0x154a8
addq $0x8, %rax
movl -0x34(%rbp), %ecx
imull -0x2c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x85c2
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x859e
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl -0x2c(%rbp), %ecx
subl -0x14(%rbp), %ecx
cmpl %ecx, %eax
jge 0x861e
movq -0x40(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movl -0x4c(%rbp), %ecx
addl -0x14(%rbp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %edx
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x50(%rbp), %ecx
movl -0x38(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x85c9
jmp 0x8620
movl -0x4c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x8642
movq -0x48(%rbp), %rax
movslq -0x4c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x8620
jmp 0x8644
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x8547
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl -0x18(%rbp), %eax
decl %eax
movl %eax, -0x18(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %edx
movq %rsp, %rax
movq %rax, -0x68(%rbp)
leaq 0xf(,%rdx,4), %rax
andq $-0x10, %rax
movq %rsp, %rdi
subq %rax, %rdi
movq %rdi, -0xb0(%rbp)
movq %rdi, %rsp
movq %rdx, -0x70(%rbp)
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x31b0
movl $0x0, -0x74(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x872a
movq 0xcdec(%rip), %rax      # 0x154a8
addq $0x8, %rax
movl -0x74(%rbp), %ecx
imull -0x2c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x871d
movq -0xb0(%rbp), %rax
movq -0x80(%rbp), %rcx
movslq -0x84(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
movslq -0x84(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x86df
jmp 0x871f
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x86ad
movl $0x0, -0x88(%rbp)
movl -0x88(%rbp), %eax
movl -0x30(%rbp), %ecx
subl -0x18(%rbp), %ecx
cmpl %ecx, %eax
jge 0x8873
movq 0xcd59(%rip), %rax      # 0x154a8
addq $0x8, %rax
movl -0x88(%rbp), %ecx
imull -0x2c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movq 0xcd33(%rip), %rax      # 0x154a8
addq $0x8, %rax
movl -0x88(%rbp), %ecx
addl -0x18(%rbp), %ecx
imull -0x2c(%rbp), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0x885d
movq -0xb0(%rbp), %rax
movq -0x90(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0xa0(%rbp)
movslq -0x9c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x98(%rbp), %rcx
movslq -0x9c(%rbp), %rdx
addl (%rcx,%rdx,4), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %edx
movq -0x90(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0xa4(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jle 0x882c
movl -0xa4(%rbp), %eax
movl %eax, -0x5c(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x9c(%rbp), %eax
movl %eax, -0x58(%rbp)
movq -0xb0(%rbp), %rax
movl -0xa4(%rbp), %edx
subl -0xa0(%rbp), %edx
movslq -0x9c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x87a1
jmp 0x885f
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x8734
movq 0xcc2e(%rip), %rdi      # 0x154a8
addq $0x8, %rdi
movl -0x30(%rbp), %eax
subl -0x18(%rbp), %eax
imull -0x2c(%rbp), %eax
cltq
shlq $0x2, %rax
addq %rax, %rdi
movslq -0x2c(%rbp), %rdx
shlq $0x2, %rdx
movslq -0x18(%rbp), %rax
imulq %rax, %rdx
xorl %esi, %esi
callq 0x31b0
cmpq $0x0, -0x28(%rbp)
je 0x88b8
movl -0x54(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
cmpq $0x0, -0x20(%rbp)
je 0x88c8
movl -0x58(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movl -0x5c(%rbp), %eax
movl %eax, -0x4(%rbp)
movq -0x68(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax)