// File: /workspace/github_cpp_makefile_star2_O1/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 0xdc79
movq 0x78(%rax), %rcx
movq 0x80(%rax), %rdx
movq %rdx, 0x90(%rax)
movq %rcx, 0x88(%rax)
movq %rcx, %rax
testq %rcx, %rcx
jne 0xdc58
movq 0x50(%rbp), %r14
movq 0x58(%rbp), %r15
cmpq %r15, %r14
je 0xde06
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 0x308(%rip), %rcx       # 0xdfb3
movq %r14, %rdi
movq %r15, %rsi
callq 0x135db
leaq 0x8(%r14), %r12
cmpq $0x81, %rbx
jl 0xdd97
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 0xdd08
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x3340
movq %r14, %rcx
jmp 0xdd2f
movq (%rcx), %rdx
movq %r15, %rcx
cmpq %rax, 0x18(%rdx)
jge 0xdd2f
movq %rbp, %rdx
leaq -0x8(%rdx), %rcx
movq -0x10(%rdx), %rsi
movq -0x8(%rdx), %rdi
movq %rdi, (%rdx)
movq %rcx, %rdx
cmpq %rax, 0x18(%rsi)
jl 0xdd17
movq %rbx, (%rcx)
addq $0x8, %r13
addq $0x8, %rbp
cmpq $0x80, %r13
jne 0xdcdd
subq $-0x80, %r14
movq 0x8(%rsp), %r9
cmpq %r9, %r14
movq 0x10(%rsp), %rbp
je 0xde06
movq -0x8(%r14), %rsi
movq (%r14), %rax
movq 0x18(%rax), %rcx
movq %r14, %rdx
cmpq %rcx, 0x18(%rsi)
jge 0xdd89
movq %r14, %rsi
leaq -0x8(%rsi), %rdx
movq -0x10(%rsi), %rdi
movq -0x8(%rsi), %r8
movq %r8, (%rsi)
movq %rdx, %rsi
cmpq %rcx, 0x18(%rdi)
jl 0xdd71
movq %rax, (%rdx)
addq $0x8, %r14
cmpq %r9, %r14
jne 0xdd5a
jmp 0xde06
cmpq %r15, %r12
je 0xde06
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 0xddd3
movq %r13, %rdx
subq %r14, %rdx
subq %rdx, %rdi
addq $0x10, %rdi
movq %r14, %rsi
callq 0x3340
movq %r14, %rcx
jmp 0xddfa
movq (%rdi), %rdx
movq %r13, %rcx
cmpq %rax, 0x18(%rdx)
jge 0xddfa
movq %r13, %rdx
leaq -0x8(%rdx), %rcx
movq -0x10(%rdx), %rsi
movq -0x8(%rdx), %rdi
movq %rdi, (%rdx)
movq %rcx, %rdx
cmpq %rax, 0x18(%rsi)
jl 0xdde2
movq %r15, (%rcx)
leaq 0x8(%r13), %r12
cmpq %rbx, %r12
jne 0xdda2
movq 0x58(%rbp), %r14
movq 0x50(%rbp), %rax
subq %rax, %r14
sete %al
je 0xded2
sarq $0x3, %r14
cmpq $0x1, %r14
movq %r14, %r15
adcq $0x0, %r15
movl $0x1, %r12d
xorl %r13d, %r13d
cmpq %r12, %r14
movq %r12, %rsi
cmovaq %r14, %rsi
movq 0x50(%rbp), %rcx
movq (%rcx,%r13,8), %rdx
movq (%rdx), %rdi
movq 0x8(%rdx), %r8
cmpq %r8, 0x88(%rdi)
je 0xdea6
cmpq %r8, 0x90(%rdi)
je 0xdea6
movq %r12, %r8
movq %r13, %rdi
cmpq %r14, %r8
jae 0xde8d
movq (%rcx,%r8,8), %r10
movq (%r10), %r9
movq 0x8(%r10), %r10
cmpq %r10, 0x88(%r9)
je 0xde92
incq %r8
incq %rdi
cmpq %r10, 0x90(%r9)
jne 0xde63
jmp 0xde95
movq %rsi, %rdi
jmp 0xde95
movq %r8, %rdi
cmpq %r14, %rdi
je 0xded2
movq (%rcx,%rdi,8), %rax
movq %rax, (%rcx,%r13,8)
movq %rdx, (%rcx,%rdi,8)
movq 0x50(%rbp), %rax
movq (%rax,%r13,8), %rax
movq (%rax), %rsi
movq 0x8(%rax), %rdx
movq %rbp, %rdi
callq 0xd6d6
incq %r13
cmpq %r14, %r13
setae %al
incq %r12
cmpq %r15, %r13
jne 0xde32
andb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop