// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3MeshCreateGeodesicBeamsForVertex(gaps::R3Mesh const*, gaps::R3MeshVertex const*, double, double, gaps::R3MeshGeodesicBeam*, double*, double*, double*, gaps::RNHeap<gaps::R3MeshGeodesicBeam*>&, gaps::RNArray<gaps::R3MeshGeodesicBeam*>&)
static void
R3MeshCreateGeodesicBeamsForVertex(const R3Mesh *mesh, const R3MeshVertex *source, 
  RNLength max_distance, RNLength distance_to_source, R3MeshGeodesicBeam *parent,
  RNLength *vertex_distances, RNLength *edge_distances, RNLength *face_distances,
  RNHeap<R3MeshGeodesicBeam *>& heap, RNArray<R3MeshGeodesicBeam *>& beams)
{
  // Create beams through edges across faces adjacent to source
  for (int i = 0; i < mesh->VertexValence(source); i++) {
    R3MeshEdge *e = mesh->EdgeOnVertex(source, i);
    R3MeshFace *face = mesh->FaceOnEdge(e, source, RN_CCW);
    if (!face) continue;

    // Get edge across face from  source
    R3MeshEdge *edge = mesh->EdgeAcrossFace(face, source);
    if (!mesh->FaceAcrossEdge(edge, face)) continue;

    // Construct beam coordinate system
    R3MeshVertex *v_ccw = mesh->VertexOnFace(face, edge, RN_CCW);
    R3MeshVertex *v_cw = mesh->VertexOnFace(face, edge, RN_CW);
    R3Vector face_normal = mesh->FaceNormal(face);
    R3Span edge_span(mesh->VertexPosition(v_ccw), mesh->VertexPosition(v_cw));
    R3Vector edge_vector = edge_span.Vector();
    R3Vector edge_normal = face_normal % edge_vector; edge_normal.Normalize();
    R3Triad edge_triad(edge_vector, edge_normal, face_normal);
    R3Point source_position = mesh->VertexPosition(source);
    R3CoordSystem face_cs(source_position, edge_triad);
    R3Affine affine(face_cs.InverseMatrix(), 0);

    // Get edge span in beam coordinate system
    edge_span.Transform(affine);

    // Get lower bound on distance to edge along beam
    RNLength beam_distance = distance_to_source + R3Distance(R3zero_point, edge_span);
    if ((max_distance > 0) && (beam_distance > max_distance)) continue;

    // Check distance to edge
    if (beam_distance >= edge_distances[mesh->EdgeID(edge)]) continue;

    // Check distance to neighbor face
    R3MeshFace *neighbor_face = mesh->FaceAcrossEdge(edge, face);
    if ((neighbor_face) && (beam_distance >= face_distances[mesh->FaceID(neighbor_face)])) continue;

    // Create beam
    R3MeshGeodesicBeam *beam = new R3MeshGeodesicBeam();
    beam->source = source;
    beam->face = face;
    beam->edge = edge;
    beam->affine = affine;
    beam->span = edge_span;
    beam->distance = beam_distance;
    beam->distance_to_source = distance_to_source;
    beam->parent = parent;

    // Add beam to heap
    heap.Push(beam);
    beams.Insert(beam);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x348, %rsp            # imm = 0x348
movq %r9, 0x40(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, 0x48(%rsp)
movq %rdx, 0x38(%rsp)
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
leaq 0x18(%rsi), %rax
movq %rax, 0x58(%rsp)
xorl %ebp, %ebp
leaq 0xc0(%rsp), %rbx
movq %rsi, 0x50(%rsp)
movslq 0x14(%r12), %rax
cmpq %rax, %rbp
jge 0x19e5f
movq 0x8(%r12), %rax
movq (%rax,%rbp,8), %rax
xorl %ecx, %ecx
cmpq %r12, 0x8(%rax)
setne %cl
movq 0x18(%rax,%rcx,8), %r15
testq %r15, %r15
je 0x19e57
movq 0x28(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x221a0
movq 0x18(%rax), %rsi
movq %rsi, %rcx
cmpq %r15, %rsi
jne 0x19c20
movq 0x20(%rax), %rcx
testq %rcx, %rcx
je 0x19e57
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %r15, %rsi
setne %cl
sete %dl
movq 0x8(%rax,%rdx,8), %r14
movq %rax, 0x8(%rsp)
movq 0x8(%rax,%rcx,8), %r12
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x10dd0
leaq 0x60(%rsp), %r13
movq %r13, %rdi
movq %rax, %rsi
callq 0x3831c
addq $0x18, %r14
addq $0x18, %r12
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x37000
leaq 0xa8(%rsp), %r14
movq %r14, %rdi
leaq 0xd8(%rsp), %rsi
callq 0x3831c
leaq 0x90(%rsp), %r12
movq %r12, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x389be
movq %r12, %rdi
callq 0x3860e
leaq 0x110(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r12, %rdx
leaq 0x60(%rsp), %rcx
callq 0x281ea
leaq 0x78(%rsp), %r14
movq %r14, %rdi
movq 0x58(%rsp), %rsi
callq 0x37b5c
leaq 0x158(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
leaq 0x238(%rsp), %r13
callq 0x27d96
leaq 0x1b8(%rsp), %r14
movq %r14, %rdi
movq %r12, %rsi
callq 0x27e20
movq %r13, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x276a0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3739a
leaq 0x4c1d45(%rip), %rdi    # 0x4dba70
movq %rbx, %rsi
callq 0x432fc
movapd %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
ucomisd 0x794a3(%rip), %xmm0    # 0x931e8
addsd 0x18(%rsp), %xmm1
movq 0x50(%rsp), %r12
jbe 0x19d5e
ucomisd 0x20(%rsp), %xmm1
ja 0x19e4f
movq 0x8(%rsp), %rax
movslq 0x30(%rax), %rax
movq 0x48(%rsp), %rcx
ucomisd (%rcx,%rax,8), %xmm1
jae 0x19e4f
movsd %xmm1, 0x10(%rsp)
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
cmpq %r15, %rax
jne 0x19d94
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
testq %rax, %rax
movsd 0x10(%rsp), %xmm0
je 0x19db6
movslq 0xa4(%rax), %rax
movq 0x30(%rsp), %rcx
ucomisd (%rcx,%rax,8), %xmm0
jae 0x19e4f
movl $0x190, %edi            # imm = 0x190
callq 0xe450
movq %rax, %r14
movl $0x190, %edx            # imm = 0x190
movq %rax, %rdi
xorl %esi, %esi
callq 0xe270
movq %r14, %rdi
callq 0x21cc4
movq %r12, (%r14)
movq %r15, 0x8(%r14)
movq 0x8(%rsp), %rax
movq %rax, 0x10(%r14)
leaq 0x18(%r14), %rdi
movq %r13, %rsi
callq 0x21db8
movq %r14, %rdi
addq $0x128, %rdi            # imm = 0x128
movq %rbx, %rsi
callq 0x21dfa
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x178(%r14)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x180(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0x188(%r14)
movq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x21e2c
movq 0x380(%rsp), %rdi
movq %r14, %rsi
callq 0x22bfc
movq %r13, %rdi
callq 0x276ee
incq %rbp
jmp 0x19bd2
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x190, %esi            # imm = 0x190
movq %r14, %rdi
callq 0xe460
jmp 0x19e8a
jmp 0x19e87
jmp 0x19e87
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
callq 0x276ee
movq %rbx, %rdi
callq 0xe810