// File: /workspace/github_cpp_makefile_star2_O3/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::CollapseShortEdges(double)
void R3Mesh::
CollapseShortEdges(RNLength min_edge_length)
{
  // Create priority queue for short edges
  RNHeap<R3MeshEdge *> heap(EdgeLengthCallback, NULL, this, TRUE);
  R3mesh_mark++;

  // Add short edges to priority queue
  for (int i = 0; i < NEdges(); i++) {
    R3MeshEdge *edge = Edge(i);
    RNLength length = EdgeLength(edge);
    if (length < min_edge_length) {
      SetEdgeMark(edge, R3mesh_mark);
      heap.Push(edge);
    }
  }

  // Collapse edges in shortest to longest order
  while (!heap.IsEmpty()) {
    R3MeshEdge *edge = heap.Pop();
    assert(EdgeMark(edge) == R3mesh_mark);
    assert(IsEdgeOnMesh(edge));

    // Remove edges to be deleted from queue (e01, e11)
    R3MeshVertex *v1 = VertexOnEdge(edge, 1);
    R3MeshFace *f0 = FaceOnEdge(edge, 0);  
    R3MeshFace *f1 = FaceOnEdge(edge, 1);  
    R3MeshEdge *e01 = (f0) ? EdgeAcrossVertex(v1, edge, f0) : NULL;
    R3MeshEdge *e11 = (f1) ? EdgeAcrossVertex(v1, edge, f1) : NULL;
    if (e01 && (EdgeMark(e01) == R3mesh_mark)) { heap.Remove(e01); SetEdgeMark(e01, 0); }
    if (e11 && (EdgeMark(e11) == R3mesh_mark)) { heap.Remove(e11); SetEdgeMark(e11, 0); }

    // Collapse edge
    R3MeshVertex *vertex = CollapseEdge(edge);
    if (!vertex) continue;

    // Update adjacent edges
    for (int i = 0; i < VertexValence(vertex); i++) {
      R3MeshEdge *edge = EdgeOnVertex(vertex, i);
      if (EdgeMark(edge) == R3mesh_mark) {
        heap.Update(edge);
      }
      else {
        RNLength length = EdgeLength(edge);
        if (length < min_edge_length) {
          SetEdgeMark(edge, R3mesh_mark);
          heap.Push(edge);
        }
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movsd %xmm0, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $-0x1, 0x20(%rsp)
leaq 0x1ff(%rip), %rax       # 0x170d9
movq %rax, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
incl 0xce5c2(%rip)           # 0xe54b0
movq %rdi, 0x38(%rsp)
movl $0x1, 0x40(%rsp)
cmpl $0x0, 0x24(%rdi)
jle 0x17097
movq %rdi, %rbx
xorl %r12d, %r12d
leaq 0x10(%rsp), %r14
movq 0x18(%rbx), %rax
movq (%rax,%r12,8), %r15
testb $0x2, 0x38(%r15)
jne 0x16f2e
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0x2b8(%rax)
movsd 0x8(%rsp), %xmm0
ucomisd 0x28(%r15), %xmm0
jbe 0x16f51
movl 0xce56e(%rip), %eax     # 0xe54b0
movl %eax, 0x48(%r15)
movq %r14, %rdi
movq %r15, %rsi
callq 0x23b8e
incq %r12
movslq 0x24(%rbx), %rax
cmpq %rax, %r12
jl 0x16f10
cmpl $0x0, 0x18(%rsp)
je 0x17097
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x23ca2
movq %rax, %r15
movq 0x10(%rax), %r12
movq 0x18(%rax), %rcx
movq 0x20(%rax), %rbp
testq %rcx, %rcx
je 0x16f99
movq %r12, %rsi
movq %r15, %rdx
callq 0x13962
movq %rax, %r13
jmp 0x16f9c
xorl %r13d, %r13d
testq %rbp, %rbp
je 0x16fb4
movq %r12, %rsi
movq %r15, %rdx
movq %rbp, %rcx
callq 0x13962
movq %rax, %r12
jmp 0x16fb7
xorl %r12d, %r12d
testq %r13, %r13
je 0x16fdb
movl 0x48(%r13), %eax
cmpl 0xce4ea(%rip), %eax     # 0xe54b0
jne 0x16fdb
movq %r14, %rdi
movq %r13, %rsi
callq 0x23d48
movl $0x0, 0x48(%r13)
testq %r12, %r12
je 0x17001
movl 0x48(%r12), %eax
cmpl 0xce4c5(%rip), %eax     # 0xe54b0
jne 0x17001
movq %r14, %rdi
movq %r12, %rsi
callq 0x23d48
movl $0x0, 0x48(%r12)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
callq *0xa8(%rax)
movq %rax, %r15
testq %rax, %rax
je 0x1708c
cmpl $0x0, 0x14(%r15)
jle 0x1708c
xorl %r13d, %r13d
movq 0x8(%r15), %rax
movq (%rax,%r13,8), %r12
movl 0x48(%r12), %eax
cmpl 0xce47b(%rip), %eax     # 0xe54b0
jne 0x17044
movq %r14, %rdi
movq %r12, %rsi
callq 0x23e60
jmp 0x17080
testb $0x2, 0x38(%r12)
jne 0x1705b
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x2b8(%rax)
movsd 0x8(%rsp), %xmm0
ucomisd 0x28(%r12), %xmm0
jbe 0x17080
movl 0xce440(%rip), %eax     # 0xe54b0
movl %eax, 0x48(%r12)
movq %r14, %rdi
movq %r12, %rsi
callq 0x23b8e
incq %r13
movslq 0x14(%r15), %rax
cmpq %rax, %r13
jl 0x17022
cmpl $0x0, 0x18(%rsp)
jne 0x16f6d
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x170a6
callq 0xe5b0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x170bf
jmp 0x170bf
jmp 0x170bf
jmp 0x170bf
jmp 0x170bf
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x170d1
callq 0xe5b0
movq %rbx, %rdi
callq 0xe7e0