// File: /workspace/github_cpp_makefile_star2_O3/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), %edi
movl 0x248(%r14), %r15d
movl %r15d, %r10d
imull %ecx, %r10d
movl %edi, %eax
imull %edx, %eax
addl %esi, %r10d
addl %eax, %r10d
leal (%r10,%r10,2), %eax
addl %r8d, %eax
movslq %eax, %rbp
movq (%r11,%rbp,8), %rax
testq %rax, %rax
jne 0x3a69f
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), %rax
movslq %r10d, %r8
imull %r12d, %r15d
imull %r13d, %edi
addl %ebx, %r15d
addl %edi, %r15d
movslq %r15d, %rdi
movsd (%rax,%r8,8), %xmm1
movhpd (%rax,%rdi,8), %xmm1    # xmm1 = xmm1[0],mem[0]
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
subpd %xmm0, %xmm1
andpd 0x67ce6(%rip), %xmm1    # 0xa2270
pshufd $0xee, %xmm1, %xmm0     # xmm0 = xmm1[2,3,2,3]
addsd %xmm1, %xmm0
leaq 0xab5fe(%rip), %rax     # 0xe5b98
movsd (%rax), %xmm2
movapd 0x67a7a(%rip), %xmm3    # 0xa2020
xorpd %xmm2, %xmm3
divsd %xmm0, %xmm1
cmpnltsd %xmm0, %xmm2
cmpnltsd %xmm3, %xmm0
movsd 0x67a70(%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 0x3c532
movq %r15, %rdi
movq %r14, %rsi
callq 0x3ce48
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 0x3c532
movq %r12, %rdi
movq %r14, %rsi
callq 0x3ce48
movsd 0x679f3(%rip), %xmm0    # 0xa2038
subsd 0x10(%rsp), %xmm0
leaq 0x38(%rsp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x3cf76
leaq 0x20(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
movaps 0x10(%rsp), %xmm0
callq 0x3cf76
leaq 0x50(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3cf30
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq %r12, %rsi
xorl %edx, %edx
callq *0x20(%rax)
movq 0xd0(%rsp), %rcx
movq %rax, (%rcx,%rbp,8)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop