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

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

  // Convolve grid with filter
  for (int k = 1; k < ZResolution()-1; k++) {
    for (int j = 1; j < YResolution()-1; j++) { 
      for (int i = 1; i < XResolution()-1; i++) { 
        RNScalar sum = 0;
        for (int dk = -1; dk <= 1; dk++) {
          for (int dj = -1; dj <= 1; dj++) {
            for (int di = -1; di <= 1; di++) {
              RNScalar value = copy.GridValue(i + di, j + dj, k + dk);
              sum += filter[dk+1][dj+1][di+1] * value;
            }
          }
        }
        SetGridValue(i, j, k, sum);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, 0x58(%rsp)
movq %rdi, %rbx
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x2f120
movq %rbx, (%rsp)
movl 0x23c(%rbx), %r15d
testl %r15d, %r15d
jle 0x31701
movq (%rsp), %rdi
movl 0x240(%rdi), %eax
movq 0x230(%rdi), %rcx
movl 0x248(%rdi), %edx
movl 0x244(%rdi), %esi
movl 0x238(%rdi), %edi
decl %edi
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %r10d, %r10d
movq %rax, %r11
movl %r9d, %ebx
testl %eax, %eax
jle 0x316f6
movslq %ebx, %rbx
movq %r8, (%rcx,%rbx,8)
leal (%rdi,%rbx), %ebp
movslq %ebp, %r14
movq %r8, (%rcx,%r14,8)
addl %edx, %ebx
decq %r11
jne 0x316de
incl %r10d
addl %esi, %r9d
cmpl %r15d, %r10d
jne 0x316d4
movq (%rsp), %rax
movl 0x238(%rax), %eax
movq %rax, 0x8(%rsp)
testl %eax, %eax
jle 0x31769
movq (%rsp), %rdi
movl 0x240(%rdi), %eax
movq 0x230(%rdi), %rcx
movl 0x248(%rdi), %edx
leal -0x1(%r15), %esi
imull 0x244(%rdi), %esi
xorl %edi, %edi
xorl %r8d, %r8d
movq %rax, %r9
movl %r8d, %r10d
testl %eax, %eax
jle 0x3175f
movslq %r10d, %r10
movq %rdi, (%rcx,%r10,8)
leal (%rsi,%r10), %r11d
movslq %r11d, %r11
movq %rdi, (%rcx,%r11,8)
addl %edx, %r10d
decq %r9
jne 0x31745
incl %r8d
cmpl 0x8(%rsp), %r8d
jne 0x3173b
cmpl $0x0, 0x8(%rsp)
jle 0x317c1
movq (%rsp), %rsi
movq 0x230(%rsi), %rax
movl 0x244(%rsi), %ecx
movl 0x240(%rsi), %edx
decl %edx
imull 0x248(%rsi), %edx
xorl %esi, %esi
xorl %edi, %edi
movq %r15, %r8
movl %edi, %r9d
testl %r15d, %r15d
jle 0x317b9
movslq %r9d, %r9
movq %rsi, (%rax,%r9,8)
leal (%rdx,%r9), %r10d
movslq %r10d, %r10
movq %rsi, (%rax,%r10,8)
addl %ecx, %r9d
decq %r8
jne 0x3179f
incl %edi
cmpl 0x8(%rsp), %edi
jne 0x31794
movq (%rsp), %rax
movl 0x240(%rax), %eax
movq %rax, 0x10(%rsp)
cmpl $0x3, %eax
jl 0x31957
movq 0x10(%rsp), %rax
decl %eax
movq %rax, 0x10(%rsp)
leal -0x1(%r15), %eax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %rax
decl %eax
movq %rax, 0x50(%rsp)
movl $0x1, %eax
movq %rax, 0x20(%rsp)
movq $0x0, 0x18(%rsp)
movq %r15, 0x40(%rsp)
cmpl $0x3, %r15d
jl 0x3192e
movq 0x298(%rsp), %r10
movl 0x2b0(%rsp), %r11d
movl 0x2ac(%rsp), %r15d
movq (%rsp), %rax
movq 0x230(%rax), %rcx
movq %rcx, 0x60(%rsp)
movl 0x248(%rax), %r13d
imull 0x20(%rsp), %r13d
movl 0x244(%rax), %eax
movl %eax, 0x34(%rsp)
movl %r11d, %eax
imull 0x18(%rsp), %eax
movq %rax, 0x38(%rsp)
movl $0x1, %eax
movq %rax, 0x28(%rsp)
cmpl $0x3, 0x8(%rsp)
jl 0x31911
movl 0x34(%rsp), %ebp
imull 0x28(%rsp), %ebp
movl $0x1, %r9d
movq 0x38(%rsp), %rcx
xorpd %xmm0, %xmm0
movq $-0x1, %rax
movq 0x58(%rsp), %rsi
movq %rcx, %r8
movq %rsi, %rbx
movq %r8, %rdx
movq $-0x1, %r14
incq %r14
xorl %edi, %edi
leal (%rdx,%rdi), %r12d
movslq %r12d, %r12
movsd (%rbx,%rdi,8), %xmm1
mulsd (%r10,%r12,8), %xmm1
addsd %xmm1, %xmm0
incq %rdi
cmpq $0x3, %rdi
jne 0x318b6
addq %r15, %rdx
addq $0x18, %rbx
cmpq $0x2, %r14
jne 0x318b1
incq %rax
addq %r11, %r8
addq $0x48, %rsi
cmpq $0x2, %rax
jne 0x318a4
leal (%r9,%r13), %eax
addl %ebp, %eax
cltq
movq 0x60(%rsp), %rdx
movsd %xmm0, (%rdx,%rax,8)
incq %r9
incq %rcx
cmpq 0x50(%rsp), %r9
jne 0x31891
movq 0x28(%rsp), %rcx
incq %rcx
addq %r15, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
cmpq 0x48(%rsp), %rcx
jne 0x31872
movq 0x20(%rsp), %rcx
incq %rcx
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movq %rcx, 0x20(%rsp)
cmpq 0x10(%rsp), %rcx
movq 0x40(%rsp), %r15
jne 0x31812
leaq 0x68(%rsp), %rdi
callq 0x2f17c
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop