// File: /workspace/github_cpp_makefile_star2_O1/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, 0x30(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x40(%rsp)
movq %rdx, 0x28(%rsp)
movsd %xmm1, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdi, 0x48(%rsp)
cmpl $0x0, 0x14(%rsi)
jle 0x1c025
movq %rsi, %r13
leaq 0x18(%rsi), %rax
movq %rax, 0x58(%rsp)
xorl %r15d, %r15d
movq %rsi, 0x50(%rsp)
movq 0x8(%r13), %rax
movq (%rax,%r15,8), %rax
xorl %ecx, %ecx
cmpq %r13, 0x8(%rax)
setne %cl
movq 0x18(%rax,%rcx,8), %r12
testq %r12, %r12
je 0x1c015
movq 0x20(%r12), %rbp
cmpq %r13, 0x8(%rbp)
je 0x1bd11
cmpq %r13, 0x10(%rbp)
jne 0x1bd3e
movq 0x28(%r12), %rbp
cmpq %r13, 0x8(%rbp)
je 0x1bd22
cmpq %r13, 0x10(%rbp)
jne 0x1bd3e
movq 0x30(%r12), %rax
cmpq %r13, 0x8(%rax)
je 0x1bd3c
cmpq %r13, 0x10(%rax)
movl $0x0, %ebp
cmovneq %rax, %rbp
jmp 0x1bd3e
xorl %ebp, %ebp
movq 0x18(%rbp), %rax
movq %rax, %rcx
cmpq %r12, %rax
jne 0x1bd4e
movq 0x20(%rbp), %rcx
testq %rcx, %rcx
je 0x1c015
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %r12, %rax
setne %cl
sete %dl
movq 0x8(%rbp,%rdx,8), %rbx
movq 0x8(%rbp,%rcx,8), %r14
testb $0x4, 0xa8(%r12)
jne 0x1bd8a
movq 0x48(%rsp), %rdi
movq (%rdi), %rax
movq %r12, %rsi
callq *0x2c8(%rax)
leaq 0x38(%r12), %rsi
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
callq 0x3d4ce
addq $0x18, %rbx
addq $0x18, %r14
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3beaa
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
callq 0x3d4ce
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x3de12
movq %rbx, %rdi
callq 0x3d7e0
leaq 0x220(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
leaq 0xb0(%rsp), %rcx
callq 0x2ade0
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
callq 0x3ca36
leaq 0x268(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2a970
leaq 0x2c8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2aa1e
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x60(%rsp), %rbx
xorl %edx, %edx
callq 0x2a22e
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3c2a0
leaq 0x4cabee(%rip), %rdi    # 0x4e6a60
movq %rbx, %rsi
callq 0x49fde
movq 0x50(%rsp), %r13
movapd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd 0x86357(%rip), %xmm0    # 0xa21e8
addsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
jbe 0x1beb1
movsd 0x8(%rsp), %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x1c008
movslq 0x30(%rbp), %rax
movq 0x40(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jae 0x1c008
movq 0x18(%rbp), %rax
cmpq %r12, %rax
jne 0x1bed8
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x1befa
movslq 0xa4(%rax), %rax
movq 0x20(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jae 0x1c008
movl $0x190, %edi            # imm = 0x190
callq 0xe440
movq %rax, %r14
movl $0x190, %edx            # imm = 0x190
movq %rax, %rdi
xorl %esi, %esi
callq 0xe260
leaq 0x18(%r14), %rbx
movq %rbx, %rdi
callq 0x2a1e0
leaq 0x128(%r14), %rdi
movq %rdi, 0x38(%rsp)
callq 0x3bdd4
movq %r13, (%r14)
movq %r12, 0x8(%r14)
movq %rbp, 0x10(%r14)
leaq 0x20(%r14), %rdi
leaq 0x118(%rsp), %rsi
callq 0x2e19e
leaq 0x60(%rsp), %rbx
leaq 0xa0(%r14), %rdi
leaq 0x198(%rsp), %rsi
callq 0x2e19e
movq 0x218(%rsp), %rax
movq %rax, 0x120(%r14)
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x3cd94
leaq 0x140(%r14), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3dc6a
movq %r14, %rdi
addq $0x158, %rdi            # imm = 0x158
leaq 0x90(%rsp), %rsi
callq 0x3cd94
movsd 0xa8(%rsp), %xmm0
movsd %xmm0, 0x170(%r14)
movsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x178(%r14)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x180(%r14)
movq 0x28(%rsp), %rax
movq %rax, 0x188(%r14)
movq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x244da
movq 0x380(%rsp), %rdi
movl 0xc(%rdi), %edx
movq %r14, %rsi
callq 0x70682
leaq 0x110(%rsp), %rdi
callq 0x2a27c
incq %r15
movslq 0x14(%r13), %rax
cmpq %rax, %r15
jl 0x1bce1
addq $0x348, %rsp            # imm = 0x348
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movq %rbx, %rdi
callq 0x2a27c
jmp 0x1c047
movq %rax, %r15
movl $0x190, %esi            # imm = 0x190
movq %r14, %rdi
callq 0xe450
jmp 0x1c05d
jmp 0x1c05a
jmp 0x1c05a
movq %rax, %r15
leaq 0x110(%rsp), %rdi
callq 0x2a27c
movq %r15, %rdi
callq 0xe7e0