// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, -0x10(%rsp)
movslq 0x238(%rdi), %rax
testq %rax, %rax
jle 0x321e8
movq -0x10(%rsp), %rcx
movl 0x23c(%rcx), %edx
movl %edx, -0x4(%rsp)
movl 0x240(%rcx), %edx
movq $0x0, -0x20(%rsp)
xorpd %xmm0, %xmm0
movsd 0x6ff99(%rip), %xmm1    # 0xa2038
cmpl $0x0, -0x4(%rsp)
jle 0x321d4
movq -0x10(%rsp), %rcx
movq 0x230(%rcx), %r9
movl 0x248(%rcx), %r10d
movl 0x244(%rcx), %ecx
movl %ecx, -0x18(%rsp)
xorl %ebx, %ebx
movq -0x20(%rsp), %rcx
movl %ecx, %ebp
testl %edx, %edx
jle 0x321c4
movl -0x18(%rsp), %ecx
movl %ecx, %r14d
imull %ebx, %r14d
movq -0x20(%rsp), %rcx
leal (%r14,%rcx), %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl %r10d, %ecx
imull %r12d, %ecx
addl %r15d, %ecx
movslq %ecx, %rcx
movsd (%r9,%rcx,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x32114
jnp 0x321b8
testl %r13d, %r13d
js 0x321b5
leaq -0x1(%r12), %rcx
movslq %r13d, %rdi
cmpq %rdi, %rcx
jle 0x321b5
movl %r12d, %ecx
subl %r13d, %ecx
cmpl %esi, %ecx
jge 0x321b5
movl %r10d, %edi
imull %r13d, %edi
addl -0x20(%rsp), %edi
addl %r14d, %edi
movslq %edi, %rdi
movsd (%r9,%rdi,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x32157
jnp 0x321b8
leal 0x1(%r13), %edi
cmpq %rdi, %r12
jbe 0x321ad
xorps %xmm4, %xmm4
cvtsi2sd %ecx, %xmm4
movl %edi, %ecx
imull %r10d, %ecx
addl %ebp, %ecx
movl $0x1, %r11d
xorps %xmm5, %xmm5
cvtsi2sd %r11d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movslq %ecx, %rcx
movsd %xmm6, (%r9,%rcx,8)
leal (%rdi,%r11), %r8d
addl %r10d, %ecx
incq %r11
cmpq %r12, %r8
jne 0x32175
ucomisd %xmm0, %xmm3
jne 0x321b5
jnp 0x321b8
movl %r12d, %r13d
incq %r12
cmpq %rdx, %r12
jne 0x320f5
incl %ebx
addl -0x18(%rsp), %ebp
cmpl -0x4(%rsp), %ebx
jne 0x320d0
movq -0x20(%rsp), %rdi
incl %edi
movq %rdi, -0x20(%rsp)
cmpl %eax, %edi
jne 0x3209f
movq -0x10(%rsp), %rcx
movl 0x240(%rcx), %ecx
movl %ecx, -0x20(%rsp)
testl %ecx, %ecx
jle 0x32352
movq -0x10(%rsp), %rcx
movl 0x23c(%rcx), %edx
movq $0x0, -0x18(%rsp)
xorpd %xmm0, %xmm0
movsd 0x6fe19(%rip), %xmm1    # 0xa2038
testl %eax, %eax
jle 0x3233c
movq -0x10(%rsp), %rcx
movq 0x230(%rcx), %r9
movl 0x248(%rcx), %r10d
imull -0x18(%rsp), %r10d
movl 0x244(%rcx), %r11d
xorl %ebx, %ebx
movl %r10d, %ebp
testl %edx, %edx
jle 0x32330
leal (%r10,%rbx), %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl %r11d, %edi
imull %r15d, %edi
addl %r14d, %edi
movslq %edi, %rdi
movsd (%r9,%rdi,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x32280
jnp 0x32324
testl %r12d, %r12d
js 0x32321
leaq -0x1(%r15), %rdi
movslq %r12d, %r8
cmpq %r8, %rdi
jle 0x32321
movl %r15d, %r8d
subl %r12d, %r8d
cmpl %esi, %r8d
jge 0x32321
movl %r11d, %edi
imull %r12d, %edi
addl %r14d, %edi
movslq %edi, %rdi
movsd (%r9,%rdi,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x322bf
jnp 0x32324
leal 0x1(%r12), %edi
cmpq %rdi, %r15
jbe 0x32319
xorps %xmm4, %xmm4
cvtsi2sd %r8d, %xmm4
movl %edi, %r13d
imull %r11d, %r13d
addl %ebp, %r13d
movl $0x1, %r8d
xorps %xmm5, %xmm5
cvtsi2sd %r8d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movslq %r13d, %r13
movsd %xmm6, (%r9,%r13,8)
leal (%rdi,%r8), %ecx
addl %r11d, %r13d
incq %r8
cmpq %r15, %rcx
jne 0x322e1
ucomisd %xmm0, %xmm3
jne 0x32321
jnp 0x32324
movl %r15d, %r12d
incq %r15
cmpq %rdx, %r15
jne 0x32261
incl %ebx
incl %ebp
cmpl %eax, %ebx
jne 0x3224c
movq -0x18(%rsp), %rcx
incl %ecx
movq %rcx, -0x18(%rsp)
cmpl -0x20(%rsp), %ecx
jne 0x3221f
movq -0x10(%rsp), %rcx
movl 0x23c(%rcx), %ecx
movl %ecx, -0x18(%rsp)
testl %ecx, %ecx
jle 0x32493
xorl %r8d, %r8d
xorpd %xmm0, %xmm0
movsd 0x6fcc0(%rip), %xmm1    # 0xa2038
cmpl $0x0, -0x20(%rsp)
jle 0x32485
movq -0x10(%rsp), %rcx
movq 0x230(%rcx), %r9
movl 0x248(%rcx), %r10d
movl 0x244(%rcx), %r11d
imull %r8d, %r11d
xorl %ebx, %ebx
movl %r11d, %r14d
testl %eax, %eax
jle 0x32476
movl %r10d, %r15d
imull %ebx, %r15d
addl %r11d, %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
leal (%r15,%r12), %ecx
movslq %ecx, %rcx
movsd (%r9,%rcx,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x323da
jnp 0x3246a
testl %r13d, %r13d
js 0x32467
leaq -0x1(%r12), %rcx
movslq %r13d, %rdx
cmpq %rdx, %rcx
jle 0x32467
movl %r12d, %edx
subl %r13d, %edx
cmpl %esi, %edx
jge 0x32467
leal (%r15,%r13), %ecx
movslq %ecx, %rcx
movsd (%r9,%rcx,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x3240f
jnp 0x3246a
leal 0x1(%r13), %edi
cmpq %rdi, %r12
jbe 0x3245f
xorps %xmm4, %xmm4
cvtsi2sd %edx, %xmm4
leal (%r14,%r13), %ebp
movl $0x1, %edx
xorps %xmm5, %xmm5
cvtsi2sd %edx, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
leal (%rbp,%rdx), %ecx
movslq %ecx, %rcx
movsd %xmm6, (%r9,%rcx,8)
leal (%rdi,%rdx), %ecx
incq %rdx
cmpq %r12, %rcx
jne 0x32428
ucomisd %xmm0, %xmm3
jne 0x32467
jnp 0x3246a
movl %r12d, %r13d
incq %r12
cmpq %rax, %r12
jne 0x323c1
incl %ebx
addl %r10d, %r14d
cmpl -0x20(%rsp), %ebx
jne 0x323a6
incl %r8d
cmpl -0x18(%rsp), %r8d
jne 0x32378
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq