// File: /workspace/github_cpp_makefile_star2_O1/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
movq %rdi, -0x10(%rsp)
movslq 0xc0(%rdi), %rax
testq %rax, %rax
jle 0x5bc63
movq -0x10(%rsp), %rdx
movl 0xc4(%rdx), %ecx
movq 0xb8(%rdx), %r11
movslq 0xc8(%rdx), %r8
leaq (,%r8,8), %r9
xorl %r10d, %r10d
movsd 0x4746b(%rip), %xmm0    # 0xa2fb8
movsd 0x47463(%rip), %xmm1    # 0xa2fb8
movsd 0x464db(%rip), %xmm2    # 0xa2038
movq %r11, -0x8(%rsp)
testl %ecx, %ecx
jle 0x5bc53
movq -0x8(%rsp), %rdx
leaq (%rdx,%r10,8), %rbx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movq %r14, %rdx
imulq %r8, %rdx
movsd (%rbx,%rdx,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x5bb94
jnp 0x5bc47
testl %r15d, %r15d
js 0x5bc44
leaq -0x1(%r14), %rdx
movslq %r15d, %r12
cmpq %r12, %rdx
jle 0x5bc44
movl %r14d, %edx
subl %r15d, %edx
cmpl %esi, %edx
jge 0x5bc44
movl %r8d, %ebp
imull %r15d, %ebp
movslq %ebp, %r12
movsd (%rbx,%r12,8), %xmm4
movapd %xmm3, %xmm5
cmpneqpd %xmm1, %xmm5
movapd %xmm4, %xmm6
cmpneqpd %xmm1, %xmm6
andpd %xmm5, %xmm6
movd %xmm6, %ebp
testb $0x1, %bpl
je 0x5bc47
leal 0x1(%r15), %r12d
cmpq %r12, %r14
jbe 0x5bc3e
xorps %xmm5, %xmm5
cvtsi2sd %edx, %xmm5
movq %r9, %r13
imulq %r12, %r13
addq %r11, %r13
movl $0x1, %edx
xorps %xmm6, %xmm6
cvtsi2sd %edx, %xmm6
divsd %xmm5, %xmm6
movapd %xmm2, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm3, %xmm6
mulsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, (%r13)
leal (%r12,%rdx), %edi
incq %rdx
addq %r9, %r13
cmpq %r14, %rdi
jne 0x5bc0a
testb $0x1, %bpl
je 0x5bc47
movl %r14d, %r15d
incq %r14
cmpq %rcx, %r14
jne 0x5bb7c
incq %r10
addq $0x8, %r11
cmpq %rax, %r10
jne 0x5bb62
movq -0x10(%rsp), %rdi
movslq 0xc4(%rdi), %rcx
testq %rcx, %rcx
jle 0x5bd9a
movq 0xb8(%rdi), %rdx
movslq 0xc8(%rdi), %rdi
leaq (,%rdi,8), %r8
xorl %r9d, %r9d
movsd 0x4731f(%rip), %xmm0    # 0xa2fb8
movsd 0x47317(%rip), %xmm1    # 0xa2fb8
movsd 0x4638f(%rip), %xmm2    # 0xa2038
movq %rdx, %r10
testl %eax, %eax
jle 0x5bd8b
movq %r9, %r11
imulq %rdi, %r11
leaq (%rdx,%r11,8), %r11
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movsd (%r11,%rbx,8), %xmm3
ucomisd %xmm0, %xmm3
jne 0x5bcd9
jnp 0x5bd7f
testl %r14d, %r14d
js 0x5bd7c
leaq -0x1(%rbx), %r15
movslq %r14d, %r12
cmpq %r12, %r15
jle 0x5bd7c
movl %ebx, %r12d
subl %r14d, %r12d
cmpl %esi, %r12d
jge 0x5bd7c
movl %r14d, %r15d
movsd (%r11,%r15,8), %xmm4
movapd %xmm3, %xmm5
cmpneqpd %xmm1, %xmm5
movapd %xmm4, %xmm6
cmpneqpd %xmm1, %xmm6
andpd %xmm5, %xmm6
movd %xmm6, %ebp
testb $0x1, %bpl
je 0x5bd7f
leal 0x1(%r14), %r13d
cmpq %r13, %rbx
jbe 0x5bd76
xorps %xmm5, %xmm5
cvtsi2sd %r12d, %xmm5
addq $0x2, %r15
movl $0x1, %r12d
xorps %xmm6, %xmm6
cvtsi2sd %r12d, %xmm6
divsd %xmm5, %xmm6
movapd %xmm2, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm3, %xmm6
mulsd %xmm4, %xmm7
addsd %xmm6, %xmm7
movsd %xmm7, -0x8(%r10,%r15,8)
movl %r15d, %r13d
incq %r15
incl %r12d
cmpq %rbx, %r13
jne 0x5bd41
testb $0x1, %bpl
je 0x5bd7f
movl %ebx, %r14d
incq %rbx
cmpq %rax, %rbx
jne 0x5bcc7
incq %r9
addq %r8, %r10
cmpq %rcx, %r9
jne 0x5bcac
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop