// File: /workspace/github_cpp_makefile_star2_O3/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
movslq 0x238(%rdi), %rax
testq %rax, %rax
movq %rdi, -0x8(%rsp)
jle 0x3202e
movl 0x23c(%rdi), %ecx
movl %ecx, -0xc(%rsp)
movl 0x240(%rdi), %ecx
xorl %r8d, %r8d
xorpd %xmm0, %xmm0
movsd 0x70146(%rip), %xmm1    # 0xa2038
cmpl $0x0, -0xc(%rsp)
jle 0x3201b
movq -0x8(%rsp), %rdx
movq 0x230(%rdx), %r9
movl 0x248(%rdx), %r10d
movl 0x244(%rdx), %edx
movl %edx, -0x18(%rsp)
xorl %ebx, %ebx
movl %r8d, %ebp
testl %ecx, %ecx
jle 0x3200b
movl -0x18(%rsp), %edx
movl %edx, %r14d
imull %ebx, %r14d
leal (%r14,%r8), %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl %r10d, %edx
imull %r12d, %edx
addl %r15d, %edx
movslq %edx, %rdx
movsd (%r9,%rdx,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x31f5e
jnp 0x31fff
testl %r13d, %r13d
setns %dil
leaq -0x1(%r12), %r11
movslq %r13d, %rdx
cmpq %rdx, %r11
setg %r11b
andb %dil, %r11b
cmpb $0x1, %r11b
jne 0x31ffc
movl %r12d, %edi
subl %r13d, %edi
cmpl %esi, %edi
jge 0x31ffc
movl %r10d, %r11d
imull %r13d, %r11d
addl %r8d, %r11d
addl %r14d, %r11d
movslq %r11d, %r11
movsd (%r9,%r11,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x31fa5
jnp 0x31fff
incl %r13d
cmpq %r13, %r12
jbe 0x31ffc
xorps %xmm4, %xmm4
cvtsi2sd %edi, %xmm4
imull %r10d, %r13d
addl %ebp, %r13d
addq $0x2, %rdx
movl $0x1, %edi
xorps %xmm5, %xmm5
cvtsi2sd %edi, %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)
movl %edx, %r11d
addl %r10d, %r13d
incl %edi
incq %rdx
cmpq %r12, %r11
jne 0x31fc4
movl %r12d, %r13d
incq %r12
cmpq %rcx, %r12
jne 0x31f3f
incl %ebx
addl -0x18(%rsp), %ebp
cmpl -0xc(%rsp), %ebx
jne 0x31f1f
incl %r8d
cmpl %eax, %r8d
jne 0x31ef2
movq -0x8(%rsp), %rdi
jmp 0x32034
movl 0x240(%rdi), %ecx
movl 0x23c(%rdi), %edx
testl %ecx, %ecx
jle 0x3218a
movq $0x0, -0x18(%rsp)
xorpd %xmm0, %xmm0
movsd 0x6ffe1(%rip), %xmm1    # 0xa2038
testl %eax, %eax
jle 0x32176
movq -0x8(%rsp), %rdi
movq 0x230(%rdi), %r9
movl 0x248(%rdi), %r10d
imull -0x18(%rsp), %r10d
movl 0x244(%rdi), %r11d
xorl %ebx, %ebx
movl %r10d, %ebp
testl %edx, %edx
jle 0x3216a
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 0x320b8
jnp 0x3215e
testl %r12d, %r12d
setns %r13b
leaq -0x1(%r15), %r8
movslq %r12d, %rdi
cmpq %rdi, %r8
setg %r8b
andb %r13b, %r8b
cmpb $0x1, %r8b
jne 0x3215b
movl %r15d, %r13d
subl %r12d, %r13d
cmpl %esi, %r13d
jge 0x3215b
movl %r11d, %r8d
imull %r12d, %r8d
addl %r14d, %r8d
movslq %r8d, %r8
movsd (%r9,%r8,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x32100
jnp 0x3215e
incl %r12d
cmpq %r12, %r15
jbe 0x3215b
xorps %xmm4, %xmm4
cvtsi2sd %r13d, %xmm4
imull %r11d, %r12d
addl %ebp, %r12d
addq $0x2, %rdi
movl $0x1, %r13d
xorps %xmm5, %xmm5
cvtsi2sd %r13d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movslq %r12d, %r12
movsd %xmm6, (%r9,%r12,8)
movl %edi, %r8d
addl %r11d, %r12d
incl %r13d
incq %rdi
cmpq %r15, %r8
jne 0x32121
movl %r15d, %r12d
incq %r15
cmpq %rdx, %r15
jne 0x32099
incl %ebx
incl %ebp
cmpl %eax, %ebx
jne 0x32084
movq -0x18(%rsp), %rdi
incl %edi
movq %rdi, -0x18(%rsp)
cmpl %ecx, %edi
jne 0x32057
testl %edx, %edx
jle 0x322d0
movq $0x0, -0x18(%rsp)
xorpd %xmm0, %xmm0
movsd 0x6fe91(%rip), %xmm1    # 0xa2038
testl %ecx, %ecx
jle 0x322bc
movq -0x8(%rsp), %rdi
movq 0x230(%rdi), %r9
movl 0x248(%rdi), %r10d
movl 0x244(%rdi), %r11d
imull -0x18(%rsp), %r11d
xorl %ebx, %ebx
movl %r11d, %ebp
testl %eax, %eax
jle 0x322af
movl %r10d, %r14d
imull %ebx, %r14d
addl %r11d, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
leal (%r14,%r15), %edi
movslq %edi, %rdi
movsd (%r9,%rdi,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x32208
jnp 0x322a3
testl %r12d, %r12d
setns %r13b
leaq -0x1(%r15), %r8
movslq %r12d, %rdi
cmpq %rdi, %r8
setg %r8b
andb %r13b, %r8b
cmpb $0x1, %r8b
jne 0x322a0
movl %r15d, %r13d
subl %r12d, %r13d
cmpl %esi, %r13d
jge 0x322a0
leal (%r14,%r12), %r8d
movslq %r8d, %r8
movsd (%r9,%r8,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x32246
jnp 0x322a3
leal 0x1(%r12), %r8d
cmpq %r8, %r15
jbe 0x322a0
xorps %xmm4, %xmm4
cvtsi2sd %r13d, %xmm4
addl %ebp, %r12d
addq $0x2, %rdi
movl $0x1, %r13d
xorps %xmm5, %xmm5
cvtsi2sd %r13d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
leal (%r12,%r13), %r8d
movslq %r8d, %r8
movsd %xmm6, (%r9,%r8,8)
movl %edi, %r8d
incl %r13d
incq %rdi
cmpq %r15, %r8
jne 0x32265
movl %r15d, %r12d
incq %r15
cmpq %rax, %r15
jne 0x321ef
incl %ebx
addl %r10d, %ebp
cmpl %ecx, %ebx
jne 0x321d4
movq -0x18(%rsp), %rdi
incl %edi
movq %rdi, -0x18(%rsp)
cmpl %edx, %edi
jne 0x321a7
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop