// File: /workspace/github_cpp_makefile_star2_O1/cloudinary[P]fuif/transform/2dmatch.h
// Function: find_good_match(Image&, int, int, int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&)
pixel_type find_good_match(Image &img, int c0, int cn, int x, int y, offsets &ot) {
    int max_count=100;   // this is the minimal match size (number of nontrivial matching pixels) to consider
    int best_z=0;
    int w = img.channel[c0].w;
    int h = img.channel[c0].h;
    for (int z=1; z<ot.size(); z++) {
            if (!matches(img,c0,cn,x,y,z,ot,true)) continue;
            int count=0;
            int yy=0;
            for (; y+yy<h; yy++) {
                int xl=0;
                for (; x+xl>=0; xl--) {
                    // if it matches                              // and if it's a nontrivial pixel (not equal to its left neighbor)
                    if (matches(img,c0,cn,x+xl,y+yy,z,ot,true)) { if (!matches(img,c0,cn,x+xl,y+yy,1,ot,true)) count++; }       // then count it
                    else break;
                }
                xl++;
                int xr=1;
                for (; x+xr<w; xr++) {
                    if (matches(img,c0,cn,x+xr,y+yy,z,ot,true)) { if (!matches(img,c0,cn,x+xl,y+yy,1,ot,true)) count++; }
                    else break;
                }
                xr--;
                if (!xl && !xr) break;
                if (xr-xl < 8) break; // minimum 8 pixels wide
            }
            if (yy < 7) break; //minimum 8 pixels high
            if (count>max_count) { max_count=count; best_z=z; }
    }
    if (best_z) v_printf(6,"Found good match at %i,%i with offset %i (x+=%i,y+=%i) and count %i\n",x,y,best_z,ot[best_z].first,ot[best_z].second,max_count);
    return best_z;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r8d, %r14d
movl %edx, %r15d
movq (%r9), %rax
movq 0x8(%r9), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movq %rdx, 0x60(%rsp)
cmpq $0x2, %rdx
movq %rax, 0x58(%rsp)
jb 0xc009
movq %r9, %rbx
movq (%rdi), %rax
movslq %esi, %rdx
shlq $0x6, %rdx
movl 0x18(%rax,%rdx), %r8d
movl 0x1c(%rax,%rdx), %eax
leal 0x1(%rcx), %edx
movl %edx, 0x38(%rsp)
movl %ecx, %edx
notl %edx
movl %edx, 0x24(%rsp)
movl %r8d, %edx
subl %ecx, %edx
movl %edx, 0x34(%rsp)
movl %eax, 0x30(%rsp)
subl %r14d, %eax
movl %eax, 0x20(%rsp)
movl %ecx, %eax
movl %r8d, 0x3c(%rsp)
subl %r8d, %eax
movl %eax, 0x40(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x64, %eax
movq %rax, 0x28(%rsp)
movl $0x1, %r9d
movq %r14, 0x48(%rsp)
movq %rcx, 0x8(%rsp)
movq %rbx, 0x18(%rsp)
movl %r15d, (%rsp)
movq %rdi, %r12
movl %esi, %ebp
movl %r15d, %edx
movl %r14d, %r8d
movq %r9, 0x10(%rsp)
pushq $0x1
pushq %rbx
callq 0xbbdb
addq $0x10, %rsp
testb %al, %al
je 0xbfa6
xorl %eax, %eax
movl $0x0, %r15d
cmpl %r14d, 0x30(%rsp)
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r12, %rdi
movq 0x10(%rsp), %r9
jle 0xbfc2
xorl %eax, %eax
xorl %r15d, %r15d
movq %rax, 0x50(%rsp)
leal (%rax,%r14), %ebp
testl %ecx, %ecx
js 0xbec1
xorl %r12d, %r12d
leal (%rcx,%r12), %ebx
movl (%rsp), %edx
movl %ebx, %ecx
movl %esi, %r14d
movq %rdi, %r13
movl %ebp, %r8d
pushq $0x1
pushq 0x20(%rsp)
callq 0xbbdb
addq $0x10, %rsp
testb %al, %al
je 0xbec9
movq %r13, %rdi
movl %r14d, %esi
movl (%rsp), %edx
movl %ebx, %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq $0x1
pushq 0x20(%rsp)
callq 0xbbdb
addq $0x10, %rsp
xorb $0x1, %al
movzbl %al, %eax
addl %eax, %r15d
decl %r12d
cmpl 0x24(%rsp), %r12d
movq 0x8(%rsp), %rcx
movl %r14d, %esi
movq %r13, %rdi
movq 0x10(%rsp), %r9
jg 0xbe4e
movl 0x24(%rsp), %eax
movl %eax, %r12d
jmp 0xbed9
movl $0x1, %r12d
jmp 0xbedc
movq 0x8(%rsp), %rcx
movl %r14d, %esi
movq %r13, %rdi
movq 0x10(%rsp), %r9
incl %r12d
xorl %ebx, %ebx
movl 0x38(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0xbf7b
leal (%r12,%rcx), %eax
movl %eax, 0x44(%rsp)
movl $0x1, %ebx
addl %ebx, %ecx
movl (%rsp), %edx
movl %esi, %r13d
movq %rdi, %r14
movl %ebp, %r8d
pushq $0x1
pushq 0x20(%rsp)
callq 0xbbdb
addq $0x10, %rsp
testb %al, %al
je 0xbf69
movq %r14, %rdi
movl %r13d, %esi
movl (%rsp), %edx
movl 0x44(%rsp), %ecx
movl %ebp, %r8d
movl $0x1, %r9d
pushq $0x1
pushq 0x20(%rsp)
callq 0xbbdb
addq $0x10, %rsp
xorb $0x1, %al
movzbl %al, %eax
addl %eax, %r15d
incl %ebx
movl 0x40(%rsp), %eax
addl %ebx, %eax
movq 0x8(%rsp), %rcx
movl %r13d, %esi
movq %r14, %rdi
movq 0x10(%rsp), %r9
jne 0xbef9
movl 0x34(%rsp), %eax
movl %eax, %ebx
jmp 0xbf79
movq 0x8(%rsp), %rcx
movl %r13d, %esi
movq %r14, %rdi
movq 0x10(%rsp), %r9
decl %ebx
movq 0x48(%rsp), %r14
movl %r12d, %eax
orl %ebx, %eax
je 0xbfb7
subl %r12d, %ebx
cmpl $0x8, %ebx
movq 0x50(%rsp), %rax
jl 0xbfbc
incl %eax
cmpl 0x20(%rsp), %eax
jne 0xbe3e
movl 0x20(%rsp), %eax
jmp 0xbfbc
movq 0x8(%rsp), %rcx
movl %ebp, %esi
movq %r12, %rdi
movq 0x10(%rsp), %r9
jmp 0xbff9
movq 0x50(%rsp), %rax
cmpl $0x7, %eax
setae %al
movq 0x28(%rsp), %r10
cmpl %r10d, %r15d
cmovlel %r10d, %r15d
movl 0x4(%rsp), %r8d
movl %r8d, %edx
cmovgl %r9d, %edx
testb %al, %al
cmovnel %edx, %r8d
movl %r8d, 0x4(%rsp)
cmovnel %r15d, %r10d
movq %r10, 0x28(%rsp)
movq 0x18(%rsp), %rbx
movl (%rsp), %r15d
je 0xc01b
incq %r9
cmpq 0x60(%rsp), %r9
jne 0xbdf3
jmp 0xc01b
movl $0x64, %eax
movq %rax, 0x28(%rsp)
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %ebx
testl %ebx, %ebx
je 0xc059
movslq %ebx, %rax
movq 0x58(%rsp), %rdx
movl (%rdx,%rax,8), %r9d
movl 0x4(%rdx,%rax,8), %r10d
leaq 0x19e3d(%rip), %rsi     # 0x25e78
movl $0x6, %edi
movl %ecx, %edx
movl %r14d, %ecx
movl %ebx, %r8d
xorl %eax, %eax
pushq 0x28(%rsp)
pushq %r10
callq 0x1d0d6
addq $0x10, %rsp
movl %ebx, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq