// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::CreatePlyRangeGridFace(gaps::R3Mesh*, gaps::R3MeshVertex*, gaps::R3MeshVertex*, gaps::R3MeshVertex*, double)
static void
CreatePlyRangeGridFace(R3Mesh *mesh, 
  R3MeshVertex *v0, R3MeshVertex *v1, R3MeshVertex *v2, 
  RNScalar max_aspect_ratio = 8)
{
  // Get vertex positions
  const R3Point& p0 = mesh->VertexPosition(v0);
  const R3Point& p1 = mesh->VertexPosition(v1);
  const R3Point& p2 = mesh->VertexPosition(v2);

  // Get edge lengths
  RNScalar a = R3Distance(p0, p1);
  if (RNIsZero(a)) return;
  RNScalar b = R3Distance(p1, p2);
  if (RNIsZero(b)) return;
  RNScalar c = R3Distance(p2, p0);
  if (RNIsZero(c)) return;

  // Compute aspect ratio
  RNScalar s = (a + b + c) / 2.0;
  RNScalar da = s - a;
  if (RNIsZero(da)) return;
  RNScalar db = s - b;
  if (RNIsZero(db)) return;
  RNScalar dc = s - c;
  if (RNIsZero(dc)) return;
  RNScalar aspect = (a * b * c) / (8.0 * da * db * dc);
  if (aspect > max_aspect_ratio) return;

  // Check edge length ratios
  if (a < b) { RNScalar swap = a; a = b; b = swap; }
  if (a < c) { RNScalar swap = a; a = c; c = swap; }
  if (b < c) { RNScalar swap = b; b = c; c = swap; }
  if (a / c > max_aspect_ratio) return;

  // Create face
  mesh->CreateFace(v0, v1, v2);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, 0x20(%rsp)
leaq 0x18(%rsi), %r13
leaq 0x18(%rdx), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x49404
leaq 0xc50df(%rip), %rbx     # 0xe5b98
movsd (%rbx), %xmm2
movapd 0x8155b(%rip), %xmm1    # 0xa2020
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x20ad9
ucomisd %xmm0, %xmm2
jae 0x20bf0
movq 0x8(%rsp), %rax
leaq 0x18(%rax), %r12
movq %rbp, %rdi
movq %r12, %rsi
movsd %xmm0, 0x18(%rsp)
callq 0x49404
movsd (%rbx), %xmm2
movapd 0x81521(%rip), %xmm1    # 0xa2020
xorpd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x20b13
ucomisd %xmm0, %xmm2
jae 0x20bf0
movq %r12, %rdi
movq %r13, %rsi
movsd %xmm0, 0x10(%rsp)
callq 0x49404
movsd 0x10(%rsp), %xmm7
movsd 0x18(%rsp), %xmm6
movsd (%rbx), %xmm2
movapd 0x814e4(%rip), %xmm3    # 0xa2020
xorpd %xmm2, %xmm3
ucomisd %xmm3, %xmm0
jb 0x20b50
ucomisd %xmm0, %xmm2
jae 0x20bf0
movapd %xmm6, %xmm1
addsd %xmm7, %xmm1
addsd %xmm0, %xmm1
mulsd 0x814cc(%rip), %xmm1    # 0xa2030
movapd %xmm1, %xmm4
subsd %xmm6, %xmm4
ucomisd %xmm3, %xmm4
jb 0x20b78
ucomisd %xmm4, %xmm2
jae 0x20bf0
movapd %xmm1, %xmm5
subsd %xmm7, %xmm5
ucomisd %xmm3, %xmm5
jb 0x20b8c
ucomisd %xmm5, %xmm2
jae 0x20bf0
subsd %xmm0, %xmm1
ucomisd %xmm3, %xmm1
jb 0x20b9c
ucomisd %xmm1, %xmm2
jae 0x20bf0
movapd %xmm6, %xmm2
mulsd %xmm7, %xmm2
mulsd %xmm0, %xmm2
movsd 0x81648(%rip), %xmm3    # 0xa21f8
mulsd %xmm3, %xmm4
mulsd %xmm4, %xmm5
mulsd %xmm5, %xmm1
divsd %xmm1, %xmm2
ucomisd %xmm3, %xmm2
ja 0x20bf0
movapd %xmm6, %xmm1
minsd %xmm7, %xmm1
maxsd %xmm6, %xmm7
movapd %xmm7, %xmm2
minsd %xmm0, %xmm2
minsd %xmm2, %xmm1
maxsd %xmm7, %xmm0
divsd %xmm1, %xmm0
ucomisd 0x8160a(%rip), %xmm0    # 0xa21f8
jbe 0x20bff
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
movq 0x48(%rax), %rax
movq %r15, %rsi
movq %r14, %rdx
movq 0x8(%rsp), %rcx
xorl %r8d, %r8d
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmpq *%rax
nop