// File: /workspace/github_cpp_makefile_star2_O3/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::FixupIntersectionOrder()
bool Clipper::FixupIntersectionOrder()
{
  //pre-condition: intersections are sorted Bottom-most first.
  //Now it's crucial that intersections are made only between adjacent edges,
  //so to ensure this the order of intersections may need adjusting ...
  CopyAELToSEL();
  std::sort(m_IntersectList.begin(), m_IntersectList.end(), IntersectListSort);
  size_t cnt = m_IntersectList.size();
  for (size_t i = 0; i < cnt; ++i) 
  {
    if (!EdgesAdjacent(*m_IntersectList[i]))
    {
      size_t j = i + 1;
      while (j < cnt && !EdgesAdjacent(*m_IntersectList[j])) j++;
      if (j == cnt)  return false;
      std::swap(m_IntersectList[i], m_IntersectList[j]);
    }
    SwapPositionsInSEL(m_IntersectList[i]->Edge1, m_IntersectList[i]->Edge2);
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbp
movq 0xa0(%rdi), %rax
movq %rax, 0xa8(%rdi)
testq %rax, %rax
je 0xd865
movq 0x78(%rax), %rcx
movq 0x80(%rax), %rdx
movq %rdx, 0x90(%rax)
movq %rcx, 0x88(%rax)
movq %rcx, %rax
testq %rcx, %rcx
jne 0xd844
movq 0x50(%rbp), %r14
movq 0x58(%rbp), %r15
cmpq %r15, %r14
je 0xd9dd
movq %r15, %rbx
subq %r14, %rbx
movq %rbx, %rax
sarq $0x3, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq 0x2f1(%rip), %rcx       # 0xdb88
movq %r14, %rdi
movq %r15, %rsi
callq 0x13025
leaq 0x8(%r14), %r12
cmpq $0x81, %rbx
jl 0xd975
movq %r15, 0x8(%rsp)
movq %rbp, 0x10(%rsp)
movl $0x8, %r13d
movq %r12, %rbp
movq %r14, %r15
movq %r15, %rcx
leaq (%r14,%r13), %r15
movq (%r14,%r13), %rbx
movq (%r14), %rdx
movq 0x18(%rbx), %rax
cmpq %rax, 0x18(%rdx)
jge 0xd8f4
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3340
movq %r14, %rcx
jmp 0xd914
movq (%rcx), %rdx
movq %r15, %rcx
cmpq %rax, 0x18(%rdx)
jge 0xd914
movq %rbp, %rcx
movq %rdx, (%rcx)
movq -0x10(%rcx), %rdx
addq $-0x8, %rcx
cmpq %rax, 0x18(%rdx)
jl 0xd903
movq %rbx, (%rcx)
addq $0x8, %r13
addq $0x8, %rbp
cmpq $0x80, %r13
jne 0xd8c9
subq $-0x80, %r14
movq 0x8(%rsp), %rdi
cmpq %rdi, %r14
movq 0x10(%rsp), %rbp
je 0xd9dd
movq -0x8(%r14), %rcx
movq (%r14), %rax
movq 0x18(%rax), %rdx
movq %r14, %rsi
cmpq %rdx, 0x18(%rcx)
jge 0xd967
movq %r14, %rsi
movq %rcx, (%rsi)
movq -0x10(%rsi), %rcx
addq $-0x8, %rsi
cmpq %rdx, 0x18(%rcx)
jl 0xd956
movq %rax, (%rsi)
addq $0x8, %r14
cmpq %rdi, %r14
jne 0xd93f
jmp 0xd9dd
cmpq %r15, %r12
je 0xd9dd
movq %r15, %rbx
movq %r14, %r13
movq %r13, %rdi
movq %r12, %r13
movq (%r12), %r15
movq (%r14), %rcx
movq 0x18(%r15), %rax
cmpq %rax, 0x18(%rcx)
jge 0xd9b1
movq %r13, %rdx
subq %r14, %rdx
subq %rdx, %rdi
addq $0x10, %rdi
movq %r14, %rsi
callq 0x3340
movq %r14, %rcx
jmp 0xd9d1
movq (%rdi), %rdx
movq %r13, %rcx
cmpq %rax, 0x18(%rdx)
jge 0xd9d1
movq %r13, %rcx
movq %rdx, (%rcx)
movq -0x10(%rcx), %rdx
addq $-0x8, %rcx
cmpq %rax, 0x18(%rdx)
jl 0xd9c0
movq %r15, (%rcx)
leaq 0x8(%r13), %r12
cmpq %rbx, %r12
jne 0xd980
movq 0x58(%rbp), %r14
movq 0x50(%rbp), %rax
subq %rax, %r14
je 0xdaaa
sarq $0x3, %r14
cmpq $0x1, %r14
movq %r14, %r15
adcq $0x0, %r15
movl $0x1, %r12d
xorl %eax, %eax
xorl %r13d, %r13d
cmpq %r12, %r14
movq %r12, %r8
cmovaq %r14, %r8
movq 0x50(%rbp), %rcx
movq (%rcx,%r13,8), %rdi
movq (%rdi), %rsi
movq 0x8(%rdi), %rdx
cmpq %rdx, 0x88(%rsi)
je 0xda8b
cmpq %rdx, 0x90(%rsi)
je 0xda8b
movq %r12, %rsi
movq %r13, %rdx
cmpq %r14, %rsi
jae 0xda63
movq (%rcx,%rsi,8), %r10
movq (%r10), %r9
movq 0x8(%r10), %r10
cmpq %r10, 0x88(%r9)
je 0xda68
incq %rsi
incq %rdx
cmpq %r10, 0x90(%r9)
jne 0xda39
jmp 0xda6b
movq %r8, %rdx
jmp 0xda6b
movq %rsi, %rdx
cmpq %r14, %rdx
je 0xdaac
movq (%rcx,%rdx,8), %rax
movq %rax, (%rcx,%r13,8)
movq %rdi, (%rcx,%rdx,8)
movq 0x50(%rbp), %rax
movq (%rax,%r13,8), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbp, %rdi
callq 0xd2a4
incq %r13
cmpq %r14, %r13
setae %al
incq %r12
cmpq %r15, %r13
jne 0xda08
jmp 0xdaac
movb $0x1, %al
andb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop