// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/apps/msh2pts/msh2pts.cpp
// Function: ComputeFaceSamplingWeights(gaps::R3Mesh*, gaps::R3MeshProperty*, double, double)
static RNScalar
ComputeFaceSamplingWeights(R3Mesh *mesh, R3MeshProperty *property,
  RNScalar curvature_exponent = 0, RNScalar curvature_max = RN_INFINITY)
{
  // Compute face weights
  RNScalar total_weight = 0;
  for (int i = 0; i < mesh->NFaces(); i++) {
    R3MeshFace *face = mesh->Face(i);

    // Initailize weight by face area
    RNScalar weight = mesh->FaceArea(face);

    // Scale weight by curvatures
    if (property) {
      // Compute average value of vertices
      R3MeshVertex *v0 = mesh->VertexOnFace(face, 0);
      R3MeshVertex *v1 = mesh->VertexOnFace(face, 1);
      R3MeshVertex *v2 = mesh->VertexOnFace(face, 2);
      RNScalar c0 = fabs(property->VertexValue(v0));
      RNScalar c1 = fabs(property->VertexValue(v1));
      RNScalar c2 = fabs(property->VertexValue(v2));
      weight *= 1.0 + (c0 + c1 + c2) / 3.0;
    }
    else if (curvature_exponent > 0) {
      // Compute curvature
      R3MeshVertex *v0 = mesh->VertexOnFace(face, 0);
      R3MeshVertex *v1 = mesh->VertexOnFace(face, 1);
      R3MeshVertex *v2 = mesh->VertexOnFace(face, 2);
      RNScalar c0 = fabs(mesh->VertexMeanCurvature(v0));
      RNScalar c1 = fabs(mesh->VertexMeanCurvature(v1));
      RNScalar c2 = fabs(mesh->VertexMeanCurvature(v2));
      RNScalar curvature = 0;
      curvature += (c0 < curvature_max) ? c0 : curvature_max;
      curvature += (c1 < curvature_max) ? c1 : curvature_max;
      curvature += (c2 < curvature_max) ? c2 : curvature_max;
      curvature /= 3.0;

      // Adjust weight
      weight *= pow(1.0 + curvature, curvature_exponent);
    }

    // Set face sampling weight
    mesh->SetFaceValue(face, weight);
    total_weight += weight;
  }

  // Delete property
  if (property) delete property;

  // Return total weight
  return total_weight;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm1, 0x10(%rsp)
movq %rsi, %rbx
cmpl $0x0, 0x34(%rdi)
jle 0x15952
movq %rdi, %r14
movsd %xmm0, 0x8(%rsp)
xorpd %xmm4, %xmm4
xorl %ebp, %ebp
xorpd %xmm3, %xmm3
movq 0x28(%r14), %rax
movq (%rax,%rbp,8), %r15
testb $0x2, 0xa8(%r15)
jne 0x157f5
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
movsd %xmm3, (%rsp)
callq *0x2c0(%rax)
xorpd %xmm4, %xmm4
movsd (%rsp), %xmm3
movsd 0x90(%r15), %xmm6
testq %rbx, %rbx
je 0x15866
movq 0x8(%r15), %rax
movq 0x10(%r15), %rcx
movq 0x18(%r15), %rdx
movslq 0x70(%rax), %rax
movq 0x410(%rbx), %rsi
movsd (%rsi,%rax,8), %xmm0
movapd 0x98879(%rip), %xmm5    # 0xae0a0
andpd %xmm5, %xmm0
movslq 0x70(%rcx), %rax
movsd (%rsi,%rax,8), %xmm1
andpd %xmm5, %xmm1
movslq 0x70(%rdx), %rax
movsd (%rsi,%rax,8), %xmm2
andpd %xmm5, %xmm2
addsd %xmm0, %xmm1
addsd %xmm2, %xmm1
divsd 0x98813(%rip), %xmm1    # 0xae068
addsd 0x987db(%rip), %xmm1    # 0xae038
mulsd %xmm1, %xmm6
jmp 0x15933
movsd 0x8(%rsp), %xmm0
ucomisd %xmm4, %xmm0
jbe 0x15933
movq 0x8(%r15), %rsi
movq 0x10(%r15), %r12
movq 0x18(%r15), %r13
movq %r14, %rdi
movsd %xmm3, (%rsp)
movsd %xmm6, 0x18(%rsp)
callq 0x296b4
movapd %xmm0, %xmm1
movapd 0x987ff(%rip), %xmm0    # 0xae0a0
andpd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x296b4
andpd 0x987e2(%rip), %xmm0    # 0xae0a0
movapd %xmm0, 0x20(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x296b4
andpd 0x987c9(%rip), %xmm0    # 0xae0a0
movsd 0x10(%rsp), %xmm1
movapd 0x30(%rsp), %xmm2
minsd %xmm1, %xmm2
addsd 0x98761(%rip), %xmm2    # 0xae050
movapd 0x20(%rsp), %xmm3
minsd %xmm1, %xmm3
addsd %xmm2, %xmm3
minsd %xmm1, %xmm0
addsd %xmm3, %xmm0
divsd 0x9875b(%rip), %xmm0    # 0xae068
addsd 0x98723(%rip), %xmm0    # 0xae038
movsd 0x8(%rsp), %xmm1
callq 0xe7e0
movsd 0x18(%rsp), %xmm6
xorpd %xmm4, %xmm4
movsd (%rsp), %xmm3
mulsd %xmm0, %xmm6
movsd %xmm6, 0xb0(%r15)
addsd %xmm6, %xmm3
incq %rbp
movslq 0x34(%r14), %rax
cmpq %rax, %rbp
jl 0x157c6
jmp 0x15956
xorpd %xmm3, %xmm3
testq %rbx, %rbx
je 0x1597a
movq %rbx, %rdi
movsd %xmm3, (%rsp)
callq 0x1a36c
movl $0x448, %esi            # imm = 0x448
movq %rbx, %rdi
callq 0xe460
movsd (%rsp), %xmm3
movapd %xmm3, %xmm0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq