// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::Convolve(double const (*) [3])
void R2Grid::
Convolve(const RNScalar filter[3][3]) 
{
  // Make temporary copy of grid
  R2Grid copy(*this);

  // Mark boundaries unknown
  for (int i = 0; i < XResolution(); i++) { 
    SetGridValue(i, 0, R2_GRID_UNKNOWN_VALUE);
    SetGridValue(i, YResolution()-1, R2_GRID_UNKNOWN_VALUE);
  }
  for (int j = 0; j < YResolution(); j++) { 
    SetGridValue(0, j, R2_GRID_UNKNOWN_VALUE);
    SetGridValue(XResolution()-1, j, R2_GRID_UNKNOWN_VALUE);
  }

  // Convolve grid with 3x3 filter
  for (int j = 1; j < YResolution()-1; j++) { 
    for (int i = 1; i < XResolution()-1; i++) { 
      RNScalar value = copy.GridValue(i, j);
      if (value != R2_GRID_UNKNOWN_VALUE) {
        RNScalar sum = 0;
        RNBoolean unknown = FALSE;
        for (int dj = -1; dj <= 1; dj++) {
          for (int di = -1; di <= 1; di++) {
            value = copy.GridValue(i + di, j + dj);
            if (value == R2_GRID_UNKNOWN_VALUE) { unknown = TRUE; break; }
            else sum += filter[dj+1][di+1] * value;
          }
          if (unknown) break; 
        }
        if (unknown) SetGridValue(i, j, R2_GRID_UNKNOWN_VALUE);
        else SetGridValue(i, j, sum);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x28(%rsp), %rdi
movq %rbx, %rsi
callq 0x5a63c
movq %rbx, 0x8(%rsp)
movslq 0xc0(%rbx), %r8
movabsq $-0x3f8bf00000000000, %rdx # imm = 0xC074100000000000
testq %r8, %r8
jle 0x5db1a
movq 0x8(%rsp), %rsi
movq 0xb8(%rsi), %rax
movslq 0xc4(%rsi), %rcx
decq %rcx
movslq 0xc8(%rsi), %rsi
imulq %rcx, %rsi
leaq (%rax,%rsi,8), %rcx
xorl %esi, %esi
movq %rdx, (%rax,%rsi,8)
movq %rdx, (%rcx,%rsi,8)
incq %rsi
cmpq %rsi, %r8
jne 0x5db0a
movq 0x8(%rsp), %rax
movslq 0xc4(%rax), %rcx
movq %rcx, (%rsp)
testq %rcx, %rcx
jle 0x5db5a
movq 0x8(%rsp), %rcx
movq 0xb8(%rcx), %rax
movslq 0xc8(%rcx), %rcx
shlq $0x3, %rcx
movq (%rsp), %rsi
movq %rdx, (%rax)
movq %rdx, -0x8(%rax,%r8,8)
addq %rcx, %rax
decq %rsi
jne 0x5db4a
cmpl $0x3, (%rsp)
jl 0x5dc79
movq (%rsp), %rax
decl %eax
movq %rax, (%rsp)
leal -0x1(%r8), %edx
movq 0xe0(%rsp), %rsi
movl 0xf0(%rsp), %edi
movslq %edi, %rax
movq %rax, 0x18(%rsp)
movl $0x1, %r9d
movq $0x0, 0x10(%rsp)
movsd 0x45418(%rip), %xmm0    # 0xa2fb8
movq %r8, 0x20(%rsp)
cmpl $0x3, %r8d
jl 0x5dc62
movq %r9, %rax
imulq 0x18(%rsp), %rax
movq 0x8(%rsp), %rcx
movslq 0xc8(%rcx), %r11
leaq (%rsi,%rax,8), %r15
imulq %r9, %r11
shlq $0x3, %r11
addq 0xb8(%rcx), %r11
movl $0x1, %r12d
movq 0x10(%rsp), %r10
movsd (%r15,%r12,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5dbf0
jnp 0x5dc57
xorpd %xmm1, %xmm1
movq $-0x1, %rcx
xorl %ebp, %ebp
movq %r14, %rbx
movq %r10, %r13
xorl %eax, %eax
leal (%rax,%r13), %r8d
movslq %r8d, %r8
movsd (%rsi,%r8,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5dc1a
jnp 0x5dc47
mulsd (%rbx,%rax,8), %xmm2
addsd %xmm2, %xmm1
incq %rax
cmpq $0x3, %rax
jne 0x5dc05
testq %rcx, %rcx
leaq 0x1(%rcx), %rax
setg %bpl
addq %rdi, %r13
addq $0x18, %rbx
movq %rax, %rcx
cmpq $0x2, %rax
jne 0x5dc03
testb $0x1, %bpl
jne 0x5dc51
movapd %xmm0, %xmm1
movsd %xmm1, (%r11,%r12,8)
incq %r12
incq %r10
cmpq %rdx, %r12
jne 0x5dbe2
incq %r9
addq %rdi, 0x10(%rsp)
cmpq (%rsp), %r9
movq 0x20(%rsp), %r8
jne 0x5dba5
leaq 0x28(%rsp), %rdi
callq 0x5a814
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop