// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::Laplacian(int)
void R2Grid::
Laplacian(RNDimension dim)
{
  // Set up 1D Laplacian filter
  const RNScalar filter[3] = { -1, 2, -1 };

  // 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 3x1 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 k = -1; k <= 1; k++) {
          if (dim == 0) value = copy.GridValue(i + k, j);
          else value = copy.GridValue(i, j + k);
          if (value == R2_GRID_UNKNOWN_VALUE) { unknown = TRUE; break; }
          else sum += filter[k+1] * value;
        }
        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 $0x108, %rsp            # imm = 0x108
movl %esi, %ebx
movq %rdi, %r14
leaq 0x38(%rsp), %rdi
movq %r14, %rsi
callq 0x5a63c
movq %r14, 0x10(%rsp)
movslq 0xc0(%r14), %rdi
movabsq $-0x3f8bf00000000000, %rcx # imm = 0xC074100000000000
testq %rdi, %rdi
jle 0x5e089
movq 0x10(%rsp), %rsi
movq 0xb8(%rsi), %rax
movslq 0xc4(%rsi), %rdx
decq %rdx
movslq 0xc8(%rsi), %rsi
imulq %rdx, %rsi
leaq (%rax,%rsi,8), %rdx
xorl %esi, %esi
movq %rcx, (%rax,%rsi,8)
movq %rcx, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rdi
jne 0x5e079
movq 0x10(%rsp), %rax
movslq 0xc4(%rax), %rdx
movq %rdx, 0x8(%rsp)
testq %rdx, %rdx
jle 0x5e0cb
movq 0x10(%rsp), %rdx
movq 0xb8(%rdx), %rax
movslq 0xc8(%rdx), %rdx
shlq $0x3, %rdx
movq 0x8(%rsp), %rsi
movq %rcx, (%rax)
movq %rcx, -0x8(%rax,%rdi,8)
addq %rdx, %rax
decq %rsi
jne 0x5e0bb
cmpl $0x3, 0x8(%rsp)
jl 0x5e1f6
movq 0x8(%rsp), %rax
decl %eax
movq %rax, 0x8(%rsp)
leal -0x1(%rdi), %edx
movq 0xf0(%rsp), %rsi
movslq 0x100(%rsp), %rax
movl %eax, %r8d
movl $0x1, %ecx
movq %rcx, 0x20(%rsp)
movsd 0x44eae(%rip), %xmm0    # 0xa2fb8
leaq 0x4b70f(%rip), %r10     # 0xa9820
movq %rax, 0x28(%rsp)
movq %rax, 0x18(%rsp)
movl $0x1, %r15d
movq %rdi, 0x30(%rsp)
cmpl $0x3, %edi
jl 0x5e1cf
movq %r15, %rcx
imulq 0x28(%rsp), %rcx
movq 0x10(%rsp), %rax
movslq 0xc8(%rax), %r12
imulq %r15, %r12
shlq $0x3, %r12
addq 0xb8(%rax), %r12
leaq (%rsi,%rcx,8), %r13
movl $0x1, %ebp
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %rdi
movsd (%r13,%rbp,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5e175
jnp 0x5e1c1
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movq %rax, %r14
movq %rdi, %r11
testl %ebx, %ebx
movq %r14, %r9
cmoveq %r11, %r9
movslq %r9d, %r9
movsd (%rsi,%r9,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5e19b
jnp 0x5e1b7
mulsd (%rcx,%r10), %xmm2
addsd %xmm2, %xmm1
incq %r11
addq %r8, %r14
addq $0x8, %rcx
cmpq $0x18, %rcx
jne 0x5e181
jmp 0x5e1bb
movapd %xmm0, %xmm1
movsd %xmm1, (%r12,%rbp,8)
incq %rbp
incq %rdi
incq %rax
cmpq %rdx, %rbp
jne 0x5e166
incq %r15
movq 0x18(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
addq %r8, 0x20(%rsp)
cmpq 0x8(%rsp), %r15
movq 0x30(%rsp), %rdi
jne 0x5e126
leaq 0x38(%rsp), %rdi
callq 0x5a814
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq