// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movl %esi, %ebx
movq %rdi, %r14
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x51fb4
movl 0xc0(%r14), %eax
movq 0xb8(%r14), %rdi
movl 0xc4(%r14), %esi
leal -0x1(%rsi), %ecx
movq %r14, (%rsp)
movl 0xc8(%r14), %edx
imull %ecx, %edx
movslq %edx, %rdx
xorl %r8d, %r8d
testl %eax, %eax
movl $0x0, %r9d
cmovgl %eax, %r9d
leaq (%rdi,%rdx,8), %r10
movabsq $-0x3f8bf00000000000, %rdx # imm = 0xC074100000000000
cmpq %r8, %r9
je 0x55541
movq %rdx, (%rdi,%r8,8)
movq %rdx, (%r10,%r8,8)
incq %r8
jmp 0x5552f
movq (%rsp), %r8
movq 0xb8(%r8), %rdi
movslq 0xc8(%r8), %r8
decl %eax
cltq
xorl %r9d, %r9d
testl %esi, %esi
cmovgl %esi, %r9d
shlq $0x3, %r8
subq $0x1, %r9
jb 0x55576
movq %rdx, (%rdi)
movq %rdx, (%rdi,%rax,8)
addq %r8, %rdi
jmp 0x55564
movslq %ecx, %rcx
movq %rcx, 0x8(%rsp)
pushq $0x1
popq %r8
xorl %r14d, %r14d
movsd 0x3e9db(%rip), %xmm0    # 0x93f68
leaq 0x4521c(%rip), %rdi     # 0x9a7b0
cmpq 0x8(%rsp), %r8
jge 0x55666
movq 0xd0(%rsp), %r9
movl 0xe0(%rsp), %r10d
movl %r10d, %ecx
imull %r8d, %ecx
movq (%rsp), %rdx
movslq 0xc8(%rdx), %r11
imulq %r8, %r11
movslq %ecx, %rcx
leaq (%r9,%rcx,8), %r15
shlq $0x3, %r11
addq 0xb8(%rdx), %r11
movl %r10d, %ecx
imull %r8d, %ecx
movl %r10d, %esi
movq %r14, 0x10(%rsp)
imull %r14d, %esi
incl %esi
pushq $0x1
popq %r13
cmpq %rax, %r13
jge 0x55656
movsd (%r15,%r13,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x55603
jnp 0x5564d
xorpd %xmm1, %xmm1
movl %esi, %edx
movl %ecx, %ebp
xorl %r14d, %r14d
cmpq $0x18, %r14
je 0x55647
testl %ebx, %ebx
movl %edx, %r12d
cmovel %ebp, %r12d
movslq %r12d, %r12
movsd (%r9,%r12,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5562e
jnp 0x55643
mulsd (%r14,%rdi), %xmm2
addsd %xmm2, %xmm1
addq $0x8, %r14
incl %ebp
addl %r10d, %edx
jmp 0x5560e
movapd %xmm0, %xmm1
movsd %xmm1, (%r11,%r13,8)
incq %r13
incl %ecx
incl %esi
jmp 0x555f0
incq %r8
movq 0x10(%rsp), %r14
incl %r14d
jmp 0x55594
leaq 0x18(%rsp), %rdi
callq 0x5216c
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq