// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::R3Grid::FillHoles(int)
void R3Grid::
FillHoles(int max_hole_size)
{
  // Interpolate in z
  for (int ix = 0; ix < XResolution(); ix++) {
    for (int iy = 0; iy < YResolution(); iy++) {
      int iz0 = -1;
      for (int iz1 = 0; iz1 < ZResolution(); iz1++) {
        if (GridValue(ix, iy, iz1) != 0.0) { 
          if ((iz0 >= 0) && (iz0 < iz1-1) && (iz1-iz0 < max_hole_size)) {
            RNScalar value0 = GridValue(ix, iy, iz0);
            if (value0 == 0.0) continue;
            RNScalar value1 = GridValue(ix, iy, iz1);
            if (value1 == 0.0) continue;
            for (int iz = iz0+1; iz < iz1; iz++) {
              RNScalar t = (double) (iz - iz0) / (double) (iz1 - iz0);
              RNScalar value = (1-t)*value0 + t*value1;
              SetGridValue(ix, iy, iz, value);
            }
          }
          iz0 = iz1;
        }
      }
    }
  }
  
  // Interpolate in y
  for (int iz = 0; iz < ZResolution(); iz++) {
    for (int ix = 0; ix < XResolution(); ix++) {
      int iy0 = -1;
      for (int iy1 = 0; iy1 < YResolution(); iy1++) {
        if (GridValue(ix, iy1, iz) != 0.0) { 
          if ((iy0 >= 0) && (iy0 < iy1-1) && (iy1-iy0 < max_hole_size)) {
            RNScalar value0 = GridValue(ix, iy0, iz);
            if (value0 == 0.0) continue;
            RNScalar value1 = GridValue(ix, iy1, iz);
            if (value1 == 0.0) continue;
            for (int iy = iy0+1; iy < iy1; iy++) {
              RNScalar t = (double) (iy - iy0) / (double) (iy1 - iy0);
              RNScalar value = (1-t)*value0 + t*value1;
              SetGridValue(ix, iy, iz, value);
            }
          }
          iy0 = iy1;
        }
      }
    }
  }
  
  // Interpolate in x
  for (int iy = 0; iy < YResolution(); iy++) {
    for (int iz = 0; iz < ZResolution(); iz++) {
      int ix0 = -1;
      for (int ix1 = 0; ix1 < XResolution(); ix1++) {
        if (GridValue(ix1, iy, iz) != 0.0) { 
          if ((ix0 >= 0) && (ix0 < ix1-1) && (ix1-ix0 < max_hole_size)) {
            RNScalar value0 = GridValue(ix0, iy, iz);
            if (value0 == 0.0) continue;
            RNScalar value1 = GridValue(ix1, iy, iz);
            if (value1 == 0.0) continue;
            for (int ix = ix0+1; ix < ix1; ix++) {
              RNScalar t = (double) (ix - ix0) / (double) (ix1 - ix0);
              RNScalar value = (1-t)*value0 + t*value1;
              SetGridValue(ix, iy, iz, value);
            }
          }
          ix0 = ix1;
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x238(%rdi), %ecx
movl 0x23c(%rdi), %eax
xorl %edx, %edx
testl %eax, %eax
movl $0x0, %r9d
movl %eax, -0x8(%rsp)
cmovgl %eax, %r9d
testl %ecx, %ecx
cmovlel %edx, %ecx
movl %ecx, -0x4(%rsp)
xorpd %xmm1, %xmm1
movsd 0x64ab3(%rip), %xmm0    # 0x93008
xorl %ebx, %ebx
movl 0x240(%rdi), %edx
testl %edx, %edx
movl $0x0, %eax
cmovlel %eax, %edx
cmpl -0x4(%rsp), %ebx
je 0x2e67a
movl %edx, %edx
xorl %ebp, %ebp
cmpl %r9d, %ebp
je 0x2e673
movq 0x230(%rdi), %r14
movl 0x248(%rdi), %r15d
movl 0x244(%rdi), %r12d
imull %ebp, %r12d
leal (%r12,%rbx), %r13d
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, %r8d
cmpq %rdx, %rax
je 0x2e66c
movl %r15d, %r10d
imull %eax, %r10d
addl %r13d, %r10d
movslq %r10d, %r10
movsd (%r14,%r10,8), %xmm2
ucomisd %xmm1, %xmm2
jne 0x2e5cd
jnp 0x2e664
testl %r8d, %r8d
setns %r11b
leaq -0x1(%rax), %rcx
movslq %r8d, %r10
cmpq %r10, %rcx
setg %cl
andb %r11b, %cl
cmpb $0x1, %cl
jne 0x2e661
movl %eax, %r11d
subl %r8d, %r11d
cmpl %esi, %r11d
jge 0x2e661
movl %r15d, %ecx
imull %r8d, %ecx
addl %ebx, %ecx
addl %r12d, %ecx
movslq %ecx, %rcx
movsd (%r14,%rcx,8), %xmm3
ucomisd %xmm1, %xmm3
jne 0x2e611
jnp 0x2e664
cvtsi2sd %r11d, %xmm4
incl %r8d
imull %r15d, %r8d
addl %r13d, %r8d
movabsq $0x1, %r11
leaq (%r10,%r11), %rcx
cmpq %rax, %rcx
jge 0x2e661
cvtsi2sd %r11d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm0, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movslq %r8d, %r8
movsd %xmm6, (%r14,%r8,8)
addl %r15d, %r8d
incq %r11
jmp 0x2e62a
movl %eax, %r8d
incq %rax
jmp 0x2e5a5
incl %ebp
jmp 0x2e575
incl %ebx
jmp 0x2e557
xorl %r8d, %r8d
xorpd %xmm1, %xmm1
movabsq $0x1, %r10
cmpl %edx, %r8d
je 0x2e7a0
movl 0x23c(%rdi), %eax
xorl %r11d, %r11d
testl %eax, %eax
movl $0x0, %ebx
movl %eax, -0x8(%rsp)
cmovgl %eax, %ebx
cmpl -0x4(%rsp), %r11d
je 0x2e798
movq 0x230(%rdi), %r14
movl 0x248(%rdi), %ebp
imull %r8d, %ebp
movl 0x244(%rdi), %r15d
addl %r11d, %ebp
xorl %r12d, %r12d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq %rbx, %r12
je 0x2e790
movl %r15d, %ecx
imull %r12d, %ecx
addl %ebp, %ecx
movslq %ecx, %rcx
movsd (%r14,%rcx,8), %xmm2
ucomisd %xmm1, %xmm2
jne 0x2e700
jnp 0x2e788
testl %eax, %eax
setns %cl
leaq -0x1(%r12), %r9
movslq %eax, %r13
cmpq %r13, %r9
setg %r9b
andb %cl, %r9b
cmpb $0x1, %r9b
jne 0x2e785
movl %r12d, %ecx
subl %eax, %ecx
cmpl %esi, %ecx
jge 0x2e785
movl %r15d, %r9d
imull %eax, %r9d
addl %ebp, %r9d
movslq %r9d, %r9
movsd (%r14,%r9,8), %xmm3
ucomisd %xmm1, %xmm3
jne 0x2e741
jnp 0x2e788
cvtsi2sd %ecx, %xmm4
incl %eax
imull %r15d, %eax
addl %ebp, %eax
movq %r10, %rcx
leaq (%rcx,%r13), %r9
cmpq %r12, %r9
jge 0x2e785
cvtsi2sd %ecx, %xmm5
divsd %xmm4, %xmm5
movapd %xmm0, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
cltq
movsd %xmm6, (%r14,%rax,8)
addl %r15d, %eax
incq %rcx
jmp 0x2e750
movl %r12d, %eax
incq %r12
jmp 0x2e6d9
incl %r11d
jmp 0x2e6ab
incl %r8d
jmp 0x2e68b
xorl %r8d, %r8d
movl -0x8(%rsp), %eax
testl %eax, %eax
cmovlel %r8d, %eax
movl %eax, -0x8(%rsp)
movl -0x4(%rsp), %ecx
xorpd %xmm1, %xmm1
movabsq $0x1, %r10
cmpl -0x8(%rsp), %r8d
je 0x2e8b8
xorl %r11d, %r11d
cmpl %edx, %r11d
je 0x2e8b0
movq 0x230(%rdi), %rbx
movl 0x248(%rdi), %ebp
imull %r11d, %ebp
movl 0x244(%rdi), %eax
imull %r8d, %eax
addl %ebp, %eax
xorl %r14d, %r14d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movl %r9d, %r15d
cmpq %rcx, %r14
je 0x2e8a8
leal (%rax,%r14), %ebp
movslq %ebp, %r12
movsd (%rbx,%r12,8), %xmm2
ucomisd %xmm1, %xmm2
jne 0x2e821
jnp 0x2e8a0
testl %r15d, %r15d
setns %bpl
leaq -0x1(%r14), %r13
movslq %r15d, %r12
cmpq %r12, %r13
setg %r13b
andb %bpl, %r13b
cmpb $0x1, %r13b
jne 0x2e89d
movl %r14d, %ebp
subl %r15d, %ebp
cmpl %esi, %ebp
jge 0x2e89d
leal (%rax,%r15), %r13d
movslq %r13d, %r9
movsd (%rbx,%r9,8), %xmm3
ucomisd %xmm1, %xmm3
jne 0x2e85e
jnp 0x2e8a0
cvtsi2sd %ebp, %xmm4
movq %r10, %r15
leaq (%r12,%r15), %r9
cmpq %r14, %r9
jge 0x2e89d
cvtsi2sd %r15d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm0, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
leal (%r15,%r13), %r9d
movslq %r9d, %r9
movsd %xmm6, (%rbx,%r9,8)
incq %r15
jmp 0x2e865
movl %r14d, %r15d
incq %r14
jmp 0x2e803
incl %r11d
jmp 0x2e7d1
incl %r8d
jmp 0x2e7c3
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop