// File: /workspace/github_cpp_makefile_star2_O3/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 $0xf8, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x28(%rsp), %rdi
movq %r14, %rsi
callq 0x59934
movslq 0xc0(%r14), %r8
movabsq $-0x3f8bf00000000000, %rcx # imm = 0xC074100000000000
testq %r8, %r8
movq %r14, (%rsp)
jle 0x5d2de
movq 0xb8(%r14), %rax
movslq 0xc4(%r14), %r10
movq %r10, %rdx
decq %rdx
movslq 0xc8(%r14), %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, %r8
jne 0x5d2cc
jmp 0x5d2e5
movl 0xc4(%r14), %r10d
testl %r10d, %r10d
jle 0x5d42d
movq (%rsp), %rdx
movq 0xb8(%rdx), %rax
movslq 0xc8(%rdx), %rdx
movl %r10d, %esi
shlq $0x3, %rdx
movq %rcx, (%rax)
movq %rcx, -0x8(%rax,%r8,8)
addq %rdx, %rax
decq %rsi
jne 0x5d307
cmpl $0x3, %r10d
jl 0x5d42d
decl %r10d
leal -0x1(%r8), %edx
movq 0xe0(%rsp), %rsi
movslq 0xf0(%rsp), %rdi
movl $0x1, %eax
movq %rax, 0x10(%rsp)
movsd 0x45c6e(%rip), %xmm0    # 0xa2fb8
leaq 0x4c4cf(%rip), %r9      # 0xa9820
movq %rdi, 0x8(%rsp)
movl $0x1, %r11d
movq %r8, 0x20(%rsp)
movq %r10, 0x18(%rsp)
cmpl $0x3, %r8d
jl 0x5d40d
movq %r11, %rcx
imulq %rdi, %rcx
movq (%rsp), %rax
movslq 0xc8(%rax), %r15
imulq %r11, %r15
shlq $0x3, %r15
addq 0xb8(%rax), %r15
leaq (%rsi,%rcx,8), %r12
movl $0x1, %r13d
movq 0x10(%rsp), %rax
movq 0x8(%rsp), %rcx
movsd (%r12,%r13,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x5d3b3
jnp 0x5d3ff
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movq %rax, %r8
movq %rcx, %r10
testl %ebx, %ebx
movq %r8, %rbp
cmoveq %r10, %rbp
movslq %ebp, %rbp
movsd (%rsi,%rbp,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5d3d9
jnp 0x5d3f5
mulsd (%r14,%r9), %xmm2
addsd %xmm2, %xmm1
incq %r10
addq %rdi, %r8
addq $0x8, %r14
cmpq $0x18, %r14
jne 0x5d3c0
jmp 0x5d3f9
movapd %xmm0, %xmm1
movsd %xmm1, (%r15,%r13,8)
incq %r13
incq %rcx
incq %rax
cmpq %rdx, %r13
jne 0x5d3a5
incq %r11
addq %rdi, 0x8(%rsp)
addq %rdi, 0x10(%rsp)
movq 0x18(%rsp), %r10
cmpq %r10, %r11
movq 0x20(%rsp), %r8
jne 0x5d366
leaq 0x28(%rsp), %rdi
callq 0x59b0c
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop