// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/pkgs/R3Shapes/R3Mesh.cpp
// Function: gaps::R3Mesh::SwapEdge(gaps::R3MeshEdge*)
int R3Mesh::
SwapEdge(R3MeshEdge *edge)
{
  // Get vertices on edge
  R3MeshVertex *v[2];
  v[0] = edge->vertex[0];
  v[1] = edge->vertex[1];

  // Get faces on edge
  R3MeshFace *f[2];
  f[0] = edge->face[0];
  f[1] = edge->face[1];
  if (!f[0] || !f[1]) return 0;

  // Get edges and vertices across faces
  R3MeshEdge *ef[2][2] = { { NULL, NULL }, { NULL, NULL } };
  R3MeshVertex *vf[2] = { NULL, NULL };
  ef[0][0] = EdgeAcrossVertex(v[0], edge, f[0]);
  ef[0][1] = EdgeAcrossVertex(v[1], edge, f[0]);
  vf[0] = VertexAcrossEdge(ef[0][1], v[1]);
  assert(vf[0] == VertexAcrossEdge(ef[0][0], v[0]));
  ef[1][0] = EdgeAcrossVertex(v[0], edge, f[1]);
  ef[1][1] = EdgeAcrossVertex(v[1], edge, f[1]);
  vf[1] = VertexAcrossEdge(ef[1][1], v[1]);
  assert(vf[1] == VertexAcrossEdge(ef[1][0], v[0]));
  if (EdgeBetweenVertices(vf[0], vf[1])) return 0;

  // Update vertices
  v[0]->edges.Remove(edge);
  v[1]->edges.Remove(edge);
  vf[0]->edges.Insert(edge);
  vf[1]->edges.Insert(edge);

  // Update edge
  edge->vertex[0] = vf[0];
  edge->vertex[1] = vf[1];
  edge->length = 0;
  edge->flags = 0;

  // Update faces
  UpdateFaceRefs(f[0], vf[0], vf[1], v[1], edge, ef[1][1], ef[0][1]);
  UpdateFacePlane(f[0]);
  UpdateFaceBBox(f[0]);
  UpdateFaceRefs(f[1], vf[1], vf[0], v[0], edge, ef[0][0], ef[1][0]);
  UpdateFacePlane(f[1]);
  UpdateFaceBBox(f[1]);

  // Invalidate GL buffer objects
  InvalidateGLBufferObjects();

  // Return success
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x18(%rsi), %r12
movq 0x20(%rsi), %r14
testq %r12, %r12
setne %al
testq %r14, %r14
setne %cl
andb %al, %cl
xorl %ebx, %ebx
cmpb $0x1, %cl
jne 0x15b18
movq %rsi, %r15
movq %rdi, 0x30(%rsp)
movq 0x8(%rsi), %rbp
movq 0x10(%rsi), %r13
movq %rbp, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x12dd6
movq %rax, 0x28(%rsp)
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x12dd6
movq 0x8(%rax), %rcx
cmpq %r13, %rcx
jne 0x159d3
movq 0x10(%rax), %rcx
movq %rax, 0x18(%rsp)
movq %rcx, (%rsp)
movq %rbp, 0x8(%rsp)
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x12dd6
movq %rax, 0x20(%rsp)
movq %r13, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x12dd6
movq 0x8(%rax), %rbp
cmpq %r13, %rbp
jne 0x15a0f
movq 0x10(%rax), %rbp
movq %rax, 0x10(%rsp)
movq (%rsp), %rsi
movq %rbp, %rdx
callq 0x12d5a
testq %rax, %rax
jne 0x15b18
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rdi
movq %r15, %rsi
callq 0x22c04
leaq 0x8(%r13), %rdi
movq %r15, %rsi
callq 0x22c04
movq (%rsp), %rax
leaq 0x8(%rax), %rdi
movq %rax, %rbx
movq %r15, %rsi
callq 0x22bfc
leaq 0x8(%rbp), %rdi
movq %r15, %rsi
callq 0x22bfc
movq %rbx, %rdx
movq %rbx, 0x8(%r15)
movq %rbp, 0x10(%r15)
andq $0x0, 0x28(%r15)
andq $0x0, 0x38(%r15)
movq 0x30(%rsp), %rbx
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
movq %r15, %r9
pushq 0x18(%rsp)
pushq 0x18(%rsp)
callq *0x2d8(%rax)
addq $0x10, %rsp
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x2c8(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r12, %rsi
callq *0x2d0(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
movq %rbp, %rdx
movq (%rsp), %rcx
movq 0x8(%rsp), %r8
movq %r15, %r9
pushq 0x20(%rsp)
pushq 0x30(%rsp)
callq *0x2d8(%rax)
addq $0x10, %rsp
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x2c8(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *0x2d0(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x290(%rax)
pushq $0x1
popq %rbx
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop