// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R2Shapes/R2Grid.cpp
// Function: gaps::R2Grid::FillHoles(int)
void R2Grid::
FillHoles(int max_hole_size)
{
  // Interpolate vertically
  for (int ix = 0; ix < XResolution(); ix++) {
    int iy0 = -1;
    for (int iy1 = 0; iy1 < YResolution(); iy1++) {
      if (GridValue(ix, iy1) != R2_GRID_UNKNOWN_VALUE) { 
        if ((iy0 >= 0) && (iy0 < iy1-1) && (iy1-iy0 < max_hole_size)) {
          RNScalar value0 = GridValue(ix, iy0);
          if (value0 == R2_GRID_UNKNOWN_VALUE) continue;
          RNScalar value1 = GridValue(ix, iy1);
          if (value1 == R2_GRID_UNKNOWN_VALUE) 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, value);
          }
        }
        iy0 = iy1;
      }
    }
  }

  // Interpolate horizontally
  for (int iy = 0; iy < YResolution(); iy++) {
    int ix0 = -1;
    for (int ix1 = 0; ix1 < XResolution(); ix1++) {
      if (GridValue(ix1, iy) != R2_GRID_UNKNOWN_VALUE) { 
        if ((ix0 >= 0) && (ix0 < ix1-1) && (ix1-ix0 < max_hole_size)) {
          RNScalar value0 = GridValue(ix0, iy);
          if (value0 == R2_GRID_UNKNOWN_VALUE) continue;
          RNScalar value1 = GridValue(ix1, iy);
          if (value1 == R2_GRID_UNKNOWN_VALUE) 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, value);
          }
        }
        ix0 = ix1;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movslq 0xc0(%rdi), %rax
movl 0xc4(%rdi), %ecx
testq %rax, %rax
jle 0x5af47
movq 0xb8(%rdi), %rdx
movslq 0xc8(%rdi), %r8
leaq (,%r8,8), %r9
xorl %r10d, %r10d
movsd 0x48161(%rip), %xmm0    # 0xa2fb8
movsd 0x471d9(%rip), %xmm1    # 0xa2038
movq %rdx, %r11
testl %ecx, %ecx
jle 0x5af37
leaq (%rdx,%r10,8), %rbx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq %r14, %r15
imulq %r8, %r15
movsd (%rbx,%r15,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5ae90
jnp 0x5af2b
testl %r12d, %r12d
setns %bpl
leaq -0x1(%r14), %r13
movslq %r12d, %r15
cmpq %r15, %r13
setg %r13b
andb %bpl, %r13b
cmpb $0x1, %r13b
jne 0x5af28
movl %r14d, %ebp
subl %r12d, %ebp
cmpl %esi, %ebp
jge 0x5af28
movl %r8d, %r13d
imull %r12d, %r13d
movslq %r13d, %r13
movsd (%rbx,%r13,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x5aed0
jnp 0x5af2b
incl %r12d
cmpq %r12, %r14
jbe 0x5af28
xorps %xmm4, %xmm4
cvtsi2sd %ebp, %xmm4
leaq 0x1(%r15), %r12
imulq %r9, %r12
addq %r11, %r12
addq $0x2, %r15
movl $0x1, %ebp
xorps %xmm5, %xmm5
cvtsi2sd %ebp, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movsd %xmm6, (%r12)
movl %r15d, %r13d
incl %ebp
addq %r9, %r12
incq %r15
cmpq %r14, %r13
jne 0x5aef3
movl %r14d, %r12d
incq %r14
cmpq %rcx, %r14
jne 0x5ae77
incq %r10
addq $0x8, %r11
cmpq %rax, %r10
jne 0x5ae62
testl %ecx, %ecx
jle 0x5b04c
movq 0xb8(%rdi), %rdx
movslq 0xc8(%rdi), %rdi
leaq (,%rdi,8), %r8
xorl %r9d, %r9d
movsd 0x48048(%rip), %xmm0    # 0xa2fb8
movsd 0x470c0(%rip), %xmm1    # 0xa2038
movq %rdx, %r10
testl %eax, %eax
jle 0x5b03d
movq %r9, %r11
imulq %rdi, %r11
leaq (%rdx,%r11,8), %r11
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movsd (%r11,%rbx,8), %xmm2
ucomisd %xmm0, %xmm2
jne 0x5afa8
jnp 0x5b031
testl %r14d, %r14d
setns %bpl
leaq -0x1(%rbx), %r12
movslq %r14d, %r15
cmpq %r15, %r12
setg %r12b
andb %bpl, %r12b
cmpb $0x1, %r12b
jne 0x5b02e
movl %ebx, %ebp
subl %r14d, %ebp
cmpl %esi, %ebp
jge 0x5b02e
movsd (%r11,%r15,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x5afdd
jnp 0x5b031
incl %r14d
cmpq %r14, %rbx
jbe 0x5b02e
xorps %xmm4, %xmm4
cvtsi2sd %ebp, %xmm4
leaq (%r10,%r15,8), %r14
addq $0x2, %r15
movl $0x1, %r12d
xorps %xmm5, %xmm5
cvtsi2sd %r12d, %xmm5
divsd %xmm4, %xmm5
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movsd %xmm6, (%r14,%r12,8)
movl %r15d, %r13d
incq %r12
incq %r15
cmpq %rbx, %r13
jne 0x5affa
movl %ebx, %r14d
incq %rbx
cmpq %rax, %rbx
jne 0x5af96
incq %r9
addq %r8, %r10
cmpq %rcx, %r9
jne 0x5af7b
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop