// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Grid.cpp
// Function: gaps::InterpolatedVertex(gaps::R3Grid const*, int, int, int, int, gaps::R3Mesh*, gaps::R3MeshVertex**, double)
static R3MeshVertex *
InterpolatedVertex(const R3Grid *grid, int ix0, int iy0, int iz0, int dim,
  R3Mesh *mesh, R3MeshVertex **vertices, RNScalar isolevel)
{
  // Check indices
  assert(dim < 3);
  int grid_index;
  int ix1 = (dim == 0) ? ix0+1 : ix0;
  int iy1 = (dim == 1) ? iy0+1 : iy0;
  int iz1 = (dim == 2) ? iz0+1 : iz0;
  assert(ix0 < grid->XResolution());
  assert(iy0 < grid->YResolution());
  assert(iz0 < grid->ZResolution());
  assert(ix1 < grid->XResolution());
  assert(iy1 < grid->YResolution());
  assert(iz1 < grid->ZResolution());
  grid->IndicesToIndex(ix0, iy0, iz0, grid_index);
  if (!vertices[3*grid_index+dim]) {
    RNScalar value0 = grid->GridValue(ix0, iy0, iz0);
    RNScalar value1 = grid->GridValue(ix1, iy1, iz1);
    RNScalar delta0 = fabs(value0 - isolevel);
    RNScalar delta1 = fabs(value1 - isolevel);
    RNScalar denom = delta0 + delta1;
    RNScalar t = (RNIsNotZero(denom)) ? delta0 / denom : 0.5;
    R3Point p0 = grid->WorldPosition(ix0, iy0, iz0);
    R3Point p1 = grid->WorldPosition(ix1, iy1, iz1);
    R3Point p = (1.0-t)*p0 + t*p1;
    vertices[3*grid_index+dim] = mesh->CreateVertex(p);
  }

  // Return vertex
  return vertices[3*grid_index+dim];
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdi, %r14
movq 0xd0(%rsp), %r11
movl 0x244(%rdi), %eax
movl 0x248(%rdi), %edi
movl %edi, %r15d
imull %ecx, %r15d
movl %eax, %r10d
imull %edx, %r10d
addl %esi, %r15d
addl %r10d, %r15d
leal (%r15,%r15,2), %r10d
addl %r8d, %r10d
movslq %r10d, %rbp
cmpq $0x0, (%r11,%rbp,8)
jne 0x3aaf3
xorl %r12d, %r12d
cmpl $0x2, %r8d
sete %r12b
addl %ecx, %r12d
xorl %r13d, %r13d
cmpl $0x1, %r8d
sete %r13b
movq %r9, 0x8(%rsp)
movl %esi, %ebx
adcl $0x0, %ebx
addl %edx, %r13d
movq 0x230(%r14), %r8
movslq %r15d, %r9
imull %r12d, %edi
imull %r13d, %eax
addl %ebx, %edi
addl %eax, %edi
movslq %edi, %rax
movsd (%r8,%r9,8), %xmm1
movhpd (%r8,%rax,8), %xmm1     # xmm1 = xmm1[0],mem[0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
subpd %xmm0, %xmm1
andpd 0x67892(%rip), %xmm1    # 0xa2270
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
addsd %xmm1, %xmm0
leaq 0xab1aa(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm2
movapd 0x67626(%rip), %xmm3    # 0xa2020
xorpd %xmm2, %xmm3
divsd %xmm0, %xmm1
cmpnltsd %xmm0, %xmm2
cmpnltsd %xmm3, %xmm0
movsd 0x6761c(%rip), %xmm3    # 0xa2030
andpd %xmm0, %xmm3
andnpd %xmm1, %xmm0
orpd %xmm0, %xmm3
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm2, %xmm3
movapd %xmm3, 0x10(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
leaq 0x80(%rsp), %r15
movq %r15, %rdi
callq 0x3ca26
movq %r15, %rdi
movq %r14, %rsi
callq 0x3d342
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %r12d, %xmm2
leaq 0x68(%rsp), %r12
movq %r12, %rdi
callq 0x3ca26
movq %r12, %rdi
movq %r14, %rsi
callq 0x3d342
movsd 0x6759f(%rip), %xmm0    # 0xa2038
subsd 0x10(%rsp), %xmm0
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x3d470
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movaps 0x10(%rsp), %xmm0
callq 0x3d470
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3d42a
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq 0xd0(%rsp), %r11
movq %rax, (%r11,%rbp,8)
movq (%r11,%rbp,8), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop