// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::PointSymmetryTransform(int)
void R2Grid::
PointSymmetryTransform(int radius)
{
  // Make copy of grid
  R2Grid copy(*this);
  copy.Normalize();

  // Brute force for now
  for (int j = 0; j < grid_resolution[1]; j++) {
    int y_radius = (j < grid_resolution[1]/2) ? j : grid_resolution[1]-1 - j;
    if ((radius > 0) && (y_radius > radius)) y_radius = radius;
    for (int i = 0; i < grid_resolution[0]; i++) {
      int x_radius = (i < grid_resolution[0]/2) ? i : grid_resolution[0]-1 - i;
      if ((radius > 0) && (x_radius > radius)) x_radius = radius;
      RNScalar dot = 0;
      RNScalar norm = 0;
      for (int t = -y_radius; t <= y_radius; t++) {
        for (int s = -x_radius; s <= x_radius; s++) {
          RNScalar value1 = GridValue(i-s, j-t);
          RNScalar value2 = GridValue(i+s, j+t);
          dot += 2 * value1 * value2;
          norm += value1 * value1; 
          norm += value2 * value2; 
        }
      }
      if (norm > 0) dot /= norm;
      SetGridValue(i, j, dot);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %esi, 0xc(%rsp)
movq %rdi, %rbx
leaq 0x78(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x51fb4
movq %r15, %rdi
callq 0x52c40
movl 0xc0(%rbx), %esi
movq %rbx, 0x18(%rsp)
movl 0xc4(%rbx), %r8d
pushq $0x2
popq %rcx
movl %r8d, %eax
cltd
idivl %ecx
movl %eax, %edi
movl %esi, %eax
cltd
idivl %ecx
xorl %ebx, %ebx
testl %esi, %esi
movl $0x0, %ecx
movl %esi, 0x14(%rsp)
cmovgl %esi, %ecx
movq %rcx, 0x50(%rsp)
cltq
movq %rax, 0x30(%rsp)
movslq %edi, %rax
movq %rax, 0x20(%rsp)
testl %r8d, %r8d
movl $0x0, %eax
movl %r8d, 0x10(%rsp)
cmovgl %r8d, %eax
movq %rax, 0x28(%rsp)
movabsq $-0x100000000, %r11     # imm = 0xFFFFFFFF00000000
cmpq 0x28(%rsp), %rbx
je 0x564f5
movl %ebx, %eax
notl %eax
addl 0x10(%rsp), %eax
cmpq 0x20(%rsp), %rbx
cmovll %ebx, %eax
movl 0xc(%rsp), %edx
cmpl %edx, %eax
movl %edx, %ecx
cmovll %eax, %ecx
testl %edx, %edx
cmovlel %eax, %ecx
movslq %ecx, %rax
movq %rax, 0x70(%rsp)
negl %ecx
movq 0x18(%rsp), %rax
movslq 0xc8(%rax), %rdx
imulq %rbx, %rdx
movslq %ecx, %rcx
shlq $0x3, %rdx
addq 0xb8(%rax), %rdx
movq %rdx, 0x48(%rsp)
movq %rcx, 0x40(%rsp)
leaq (%rbx,%rcx), %rax
shlq $0x3, %rax
movq %rax, 0x38(%rsp)
xorl %edx, %edx
xorl %edi, %edi
xorl %ecx, %ecx
cmpq 0x50(%rsp), %rcx
je 0x564ed
movl %ecx, %eax
notl %eax
addl 0x14(%rsp), %eax
cmpq 0x30(%rsp), %rcx
movq %rcx, 0x58(%rsp)
cmovll %ecx, %eax
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
movl %ecx, %esi
cmovll %eax, %esi
testl %ecx, %ecx
cmovlel %eax, %esi
movslq %esi, %r10
negl %esi
movq 0x18(%rsp), %rax
movq 0xb8(%rax), %rcx
movslq 0xc8(%rax), %rax
movslq %esi, %r9
movq 0x38(%rsp), %rsi
imulq %rax, %rsi
movq %rdi, 0x60(%rsp)
addq %rdi, %rsi
leaq (%rsi,%r9,8), %rsi
addq %rcx, %rsi
leaq (,%rax,8), %rbp
movq %r9, %rdi
shlq $0x20, %rdi
movq %rdx, 0x68(%rsp)
subq %rdi, %rdx
xorpd %xmm0, %xmm0
movq 0x40(%rsp), %r14
xorpd %xmm1, %xmm1
cmpq 0x70(%rsp), %r14
jg 0x5649e
movq %rbx, %r15
movq %rbx, %rdi
subq %r14, %rdi
imulq %rax, %rdi
leaq (%rcx,%rdi,8), %rbx
movq %rdx, %r12
movq %rsi, %r13
movq %r9, %r8
cmpq %r10, %r8
jg 0x56493
movq %r12, %rdi
sarq $0x1d, %rdi
movsd (%rbx,%rdi), %xmm2
movapd %xmm2, %xmm3
mulsd %xmm2, %xmm2
addsd %xmm1, %xmm2
movsd (%r13), %xmm1
addsd %xmm3, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm3, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
incq %r8
addq $0x8, %r13
addq %r11, %r12
jmp 0x56450
incq %r14
addq %rbp, %rsi
movq %r15, %rbx
jmp 0x5642f
movapd %xmm0, %xmm2
divsd %xmm1, %xmm2
xorpd %xmm3, %xmm3
cmpltsd %xmm1, %xmm3
andpd %xmm3, %xmm2
andnpd %xmm0, %xmm3
orpd %xmm2, %xmm3
movq 0x48(%rsp), %rax
movq 0x58(%rsp), %rcx
movlpd %xmm3, (%rax,%rcx,8)
incq %rcx
movq 0x60(%rsp), %rdi
addq $0x8, %rdi
movabsq $0x100000000, %rax      # imm = 0x100000000
movq 0x68(%rsp), %rdx
addq %rax, %rdx
jmp 0x563a8
incq %rbx
jmp 0x56338
leaq 0x78(%rsp), %rdi
callq 0x5216c
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop