// File: 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:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x140(%rsp)
movsd %xmm0, 0x138(%rsp)
movq 0x140(%rsp), %rcx
movq %rcx, 0x80(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0x519(%rip), %rsi       # 0x1ec30
xorl %eax, %eax
movl %eax, %edx
movl $0x1, %r8d
callq 0x37b90
movl 0x150df4(%rip), %eax    # 0x16f520
addl $0x1, %eax
movl %eax, 0x150deb(%rip)    # 0x16f520
movl $0x0, 0xfc(%rsp)
movq 0x80(%rsp), %rdi
movl 0xfc(%rsp), %eax
movl %eax, 0x78(%rsp)
callq 0x135c0
movl %eax, 0x7c(%rsp)
jmp 0x1e75e
movl 0x78(%rsp), %eax
movl 0x7c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x1e84e
movq 0x80(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x36930
movq %rax, 0x70(%rsp)
jmp 0x1e789
movq 0x80(%rsp), %rdi
movq 0x70(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0xe0(%rsp), %rsi
callq 0x13cc0
movsd %xmm0, 0x68(%rsp)
jmp 0x1e7b3
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movsd 0xd8(%rsp), %xmm1
movsd 0x138(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1e836
movq 0x80(%rsp), %rdi
movq 0xe0(%rsp), %rsi
movl 0x150d30(%rip), %edx    # 0x16f520
callq 0x37c00
jmp 0x1e7f7
movq 0xe0(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x37c20
jmp 0x1e80e
jmp 0x1e836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x38280
jmp 0x1ec1f
jmp 0x1e838
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x1e740
jmp 0x1e850
leaq 0x100(%rsp), %rdi
callq 0x37e40
movl %eax, 0x64(%rsp)
jmp 0x1e863
movl 0x64(%rsp), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x1e878
jmp 0x1ec0a
leaq 0x100(%rsp), %rdi
callq 0x37e60
movq %rax, 0x58(%rsp)
jmp 0x1e88c
movq 0x80(%rsp), %rdi
movq 0x58(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rsi
movl $0x1, %edx
callq 0x36960
movq %rax, 0x50(%rsp)
jmp 0x1e8ba
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rax
movq %rax, 0xc8(%rsp)
movq 0xd0(%rsp), %rsi
xorl %edx, %edx
callq 0x37050
movq %rax, 0x48(%rsp)
jmp 0x1e8e5
movq 0x80(%rsp), %rdi
movq 0x48(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0xd0(%rsp), %rsi
movl $0x1, %edx
callq 0x37050
movq %rax, 0x40(%rsp)
jmp 0x1e913
movq 0x40(%rsp), %rax
movq %rax, 0xb8(%rsp)
cmpq $0x0, 0xc0(%rsp)
je 0x1e957
movq 0x80(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
movq 0xc0(%rsp), %rcx
callq 0x18410
movq %rax, 0x38(%rsp)
jmp 0x1e960
xorl %eax, %eax
movq %rax, 0x38(%rsp)
jmp 0x1e960
movq 0x38(%rsp), %rax
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb8(%rsp)
je 0x1e9a4
movq 0x80(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
movq 0xb8(%rsp), %rcx
callq 0x18410
movq %rax, 0x30(%rsp)
jmp 0x1e9ad
xorl %eax, %eax
movq %rax, 0x30(%rsp)
jmp 0x1e9ad
movq 0x30(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xb0(%rsp)
je 0x1ea1e
movq 0x80(%rsp), %rdi
movq 0xb0(%rsp), %rsi
callq 0x37f70
movl %eax, 0x2c(%rsp)
jmp 0x1e9e0
movl 0x2c(%rsp), %eax
cmpl 0x150b36(%rip), %eax    # 0x16f520
jne 0x1ea1e
movq 0xb0(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x37f90
jmp 0x1ea03
movq 0x80(%rsp), %rdi
movq 0xb0(%rsp), %rsi
xorl %edx, %edx
callq 0x37c00
jmp 0x1ea1c
jmp 0x1ea1e
cmpq $0x0, 0xa8(%rsp)
je 0x1ea82
movq 0x80(%rsp), %rdi
movq 0xa8(%rsp), %rsi
callq 0x37f70
movl %eax, 0x28(%rsp)
jmp 0x1ea44
movl 0x28(%rsp), %eax
cmpl 0x150ad2(%rip), %eax    # 0x16f520
jne 0x1ea82
movq 0xa8(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x37f90
jmp 0x1ea67
movq 0x80(%rsp), %rdi
movq 0xa8(%rsp), %rsi
xorl %edx, %edx
callq 0x37c00
jmp 0x1ea80
jmp 0x1ea82
movq 0x80(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq (%rdi), %rax
movq 0xa8(%rax), %rax
callq *%rax
movq %rax, 0x20(%rsp)
jmp 0x1eaa5
movq 0x20(%rsp), %rax
movq %rax, 0xa0(%rsp)
cmpq $0x0, 0xa0(%rsp)
jne 0x1eac2
jmp 0x1e850
movl $0x0, 0x9c(%rsp)
movq 0x80(%rsp), %rdi
movl 0x9c(%rsp), %eax
movl %eax, 0x18(%rsp)
movq 0xa0(%rsp), %rsi
callq 0x36b50
movl %eax, 0x1c(%rsp)
jmp 0x1eaf3
movl 0x18(%rsp), %eax
movl 0x1c(%rsp), %ecx
cmpl %ecx, %eax
jge 0x1ec05
movq 0x80(%rsp), %rdi
movq 0xa0(%rsp), %rsi
movl 0x9c(%rsp), %edx
callq 0x36ec0
movq %rax, 0x10(%rsp)
jmp 0x1eb26
movq 0x80(%rsp), %rdi
movq 0x10(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rsi
callq 0x37f70
movl %eax, 0xc(%rsp)
jmp 0x1eb4e
movl 0xc(%rsp), %eax
cmpl 0x1509c8(%rip), %eax    # 0x16f520
jne 0x1eb73
movq 0x90(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x38180
jmp 0x1eb71
jmp 0x1ebed
movq 0x80(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x13cc0
movsd %xmm0, (%rsp)
jmp 0x1eb8f
movsd (%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
movsd 0x88(%rsp), %xmm1
movsd 0x138(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x1ebeb
movq 0x80(%rsp), %rdi
movq 0x90(%rsp), %rsi
movl 0x150955(%rip), %edx    # 0x16f520
callq 0x37c00
jmp 0x1ebd2
movq 0x90(%rsp), %rsi
leaq 0x100(%rsp), %rdi
callq 0x37c20
jmp 0x1ebe9
jmp 0x1ebeb
jmp 0x1ebed
jmp 0x1ebef
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x1eacd
jmp 0x1e850
leaq 0x100(%rsp), %rdi
callq 0x38280
addq $0x148, %rsp            # imm = 0x148
retq
movq 0xf0(%rsp), %rdi
callq 0xf890
nopl (%rax)