// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movq 0x18(%rsi), %r14
movq 0x20(%rsi), %r12
testq %r14, %r14
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x16d21
movq %rsi, %r15
movq %rdi, %rbx
movq 0x8(%rsi), %rbp
movq 0x10(%rsi), %r13
movq %rbp, %rsi
movq %r15, %rdx
movq %r14, %rcx
callq 0x13922
movq %rax, 0x38(%rsp)
movq %r13, %rsi
movq %r15, %rdx
movq %r14, 0x40(%rsp)
movq %r14, %rcx
callq 0x13922
movq %rax, %rcx
movq 0x8(%rax), %rax
movq %rax, (%rsp)
cmpq %r13, %rax
jne 0x16c9d
movq 0x10(%rcx), %rax
movq %rax, (%rsp)
movq %rcx, 0x28(%rsp)
movq %rbp, 0x8(%rsp)
movq %rbp, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x13922
movq %rax, 0x30(%rsp)
movq %r13, %rsi
movq %r15, %rdx
movq %r12, %rcx
callq 0x13922
movq 0x8(%rax), %r14
cmpq %r13, %r14
jne 0x16cd5
movq 0x10(%rax), %r14
movq (%rsp), %rbp
cmpq %r14, %rbp
movq 0x8(%rsp), %r9
je 0x16d28
movslq 0x14(%rbp), %r10
testq %r10, %r10
jle 0x16d28
movq 0x8(%rbp), %rdx
xorl %esi, %esi
movq (%rdx,%rsi,8), %rdi
cmpq %r14, 0x8(%rdi)
je 0x16d06
cmpq %r14, 0x10(%rdi)
setne %r8b
jmp 0x16d09
xorl %r8d, %r8d
testb %r8b, %r8b
cmoveq %rdi, %rcx
je 0x16d1c
incq %rsi
cmpq %rsi, %r10
jne 0x16cf2
xorl %ecx, %ecx
testq %rcx, %rcx
je 0x16d28
xorl %eax, %eax
jmp 0x16e59
movq %r12, 0x20(%rsp)
leaq 0x8(%r9), %r12
movq %r12, %rdi
movq %r15, %rsi
movq %r13, 0x10(%rsp)
movq %r9, %r13
movq %rax, 0x18(%rsp)
callq 0x70664
subq 0x8(%r13), %rax
shrq $0x3, %rax
movq %r12, %rdi
movl %eax, %esi
callq 0x707f6
movq 0x10(%rsp), %r13
leaq 0x8(%r13), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x70664
subq 0x8(%r13), %rax
shrq $0x3, %rax
movq %r12, %rdi
movl %eax, %esi
callq 0x707f6
leaq 0x8(%rbp), %rdi
movl 0x14(%rbp), %edx
movq %r15, %rsi
callq 0x70682
leaq 0x8(%r14), %rdi
movl 0x14(%r14), %edx
movq %r15, %rsi
callq 0x70682
movq %rbp, 0x8(%r15)
movq %r14, 0x10(%r15)
xorl %eax, %eax
movq %rax, 0x28(%r15)
movq %rax, 0x38(%r15)
movq (%rbx), %rax
movq %rbx, %rdi
movq 0x40(%rsp), %r12
movq %r12, %rsi
movq %rbp, %rdx
movq %r14, %rcx
movq %r13, %r8
movq %r15, %r9
pushq 0x28(%rsp)
pushq 0x20(%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 0x20(%rsp), %r12
movq %r12, %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq 0x8(%rsp), %r8
movq %r15, %r9
pushq 0x30(%rsp)
pushq 0x40(%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
callq *0x290(%rax)
movl $0x1, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq