// File: /workspace/github_cpp_makefile_star2_O3/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)
movl 0x14(%rsi), %eax
testl %eax, %eax
jle 0x1c078
movq %rsi, %r13
leaq 0x18(%rsi), %rcx
movq %rcx, 0x58(%rsp)
xorl %r15d, %r15d
movq %rsi, 0x50(%rsp)
movq 0x8(%r13), %rcx
movq (%rcx,%r15,8), %rcx
xorl %edx, %edx
cmpq %r13, 0x8(%rcx)
setne %dl
movq 0x18(%rcx,%rdx,8), %r12
testq %r12, %r12
je 0x1c069
movq 0x20(%r12), %rbp
cmpq %r13, 0x8(%rbp)
je 0x1bd61
cmpq %r13, 0x10(%rbp)
jne 0x1bd8e
movq 0x28(%r12), %rbp
cmpq %r13, 0x8(%rbp)
je 0x1bd72
cmpq %r13, 0x10(%rbp)
jne 0x1bd8e
movq 0x30(%r12), %rcx
cmpq %r13, 0x8(%rcx)
je 0x1bd8c
cmpq %r13, 0x10(%rcx)
movl $0x0, %ebp
cmovneq %rcx, %rbp
jmp 0x1bd8e
xorl %ebp, %ebp
movq 0x18(%rbp), %rcx
movq %rcx, %rdx
cmpq %r12, %rcx
jne 0x1bd9e
movq 0x20(%rbp), %rdx
testq %rdx, %rdx
je 0x1c069
xorl %eax, %eax
xorl %edx, %edx
cmpq %r12, %rcx
setne %al
sete %dl
movq 0x8(%rbp,%rdx,8), %rbx
movq 0x8(%rbp,%rax,8), %r14
testb $0x4, 0xa8(%r12)
jne 0x1bdda
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 0x3cfd6
addq $0x18, %rbx
addq $0x18, %r14
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x3b9b6
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
callq 0x3cfd6
leaq 0xe0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
callq 0x3d8fa
movq %rbx, %rdi
callq 0x3d2dc
leaq 0x220(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
leaq 0xb0(%rsp), %rcx
callq 0x2ab98
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
callq 0x3c542
leaq 0x268(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x2a728
leaq 0x2c8(%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2a7d6
leaq 0x110(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x60(%rsp), %rbx
xorl %edx, %edx
callq 0x29fda
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3bdac
leaq 0x4cab9e(%rip), %rdi    # 0x4e6a60
movq %rbx, %rsi
callq 0x494e6
movq 0x50(%rsp), %r13
movapd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
ucomisd 0x86307(%rip), %xmm0    # 0xa21e8
addsd 0x10(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
jbe 0x1bf01
movsd 0x8(%rsp), %xmm0
ucomisd 0x18(%rsp), %xmm0
ja 0x1c058
movslq 0x30(%rbp), %rax
movq 0x40(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jae 0x1c058
movq 0x18(%rbp), %rax
cmpq %r12, %rax
jne 0x1bf28
movq 0x20(%rbp), %rax
testq %rax, %rax
je 0x1bf4a
movslq 0xa4(%rax), %rax
movq 0x20(%rsp), %rcx
movsd 0x8(%rsp), %xmm0
ucomisd (%rcx,%rax,8), %xmm0
jae 0x1c058
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 0x29f8c
leaq 0x128(%r14), %rdi
movq %rdi, 0x38(%rsp)
callq 0x3b8e0
movq %r13, (%r14)
movq %r12, 0x8(%r14)
movq %rbp, 0x10(%r14)
leaq 0x20(%r14), %rdi
leaq 0x118(%rsp), %rsi
callq 0x2dea2
leaq 0x60(%rsp), %rbx
leaq 0xa0(%r14), %rdi
leaq 0x198(%rsp), %rsi
callq 0x2dea2
movq 0x218(%rsp), %rax
movq %rax, 0x120(%r14)
movq 0x38(%rsp), %rdi
movq %rbx, %rsi
callq 0x3c89a
leaq 0x140(%r14), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3d752
movq %r14, %rdi
addq $0x158, %rdi            # imm = 0x158
leaq 0x90(%rsp), %rsi
callq 0x3c89a
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 0x242d0
movq 0x380(%rsp), %rdi
movl 0xc(%rdi), %edx
movq %r14, %rsi
callq 0x6f8a2
leaq 0x110(%rsp), %rdi
callq 0x2a028
movl 0x14(%r13), %eax
incq %r15
movslq %eax, %rcx
cmpq %rcx, %r15
jl 0x1bd31
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 0x2a028
jmp 0x1c09a
movq %rax, %r15
movl $0x190, %esi            # imm = 0x190
movq %r14, %rdi
callq 0xe450
jmp 0x1c0b0
jmp 0x1c0ad
jmp 0x1c0ad
movq %rax, %r15
leaq 0x110(%rsp), %rdi
callq 0x2a028
movq %r15, %rdi
callq 0xe7e0