// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::DoSimplePolygons()
void Clipper::DoSimplePolygons()
{
  PolyOutList::size_type i = 0;
  while (i < m_PolyOuts.size()) 
  {
    OutRec* outrec = m_PolyOuts[i++];
    OutPt* op = outrec->Pts;
    if (!op) continue;
    do //for each Pt in Polygon until duplicate found do ...
    {
      OutPt* op2 = op->Next;
      while (op2 != outrec->Pts) 
      {
        if ((op->Pt == op2->Pt) && op2->Next != op && op2->Prev != op) 
        {
          //split the polygon into two ...
          OutPt* op3 = op->Prev;
          OutPt* op4 = op2->Prev;
          op->Prev = op4;
          op4->Next = op;
          op2->Prev = op3;
          op3->Next = op2;

          outrec->Pts = op;
          OutRec* outrec2 = CreateOutRec();
          outrec2->Pts = op2;
          UpdateOutPtIdxs(*outrec2);
          if (Poly2ContainsPoly1(outrec2->Pts, outrec->Pts))
          {
            //OutRec2 is contained by OutRec1 ...
            outrec2->IsHole = !outrec->IsHole;
            outrec2->FirstLeft = outrec;
          }
          else
            if (Poly2ContainsPoly1(outrec->Pts, outrec2->Pts))
          {
            //OutRec1 is contained by OutRec2 ...
            outrec2->IsHole = outrec->IsHole;
            outrec->IsHole = !outrec2->IsHole;
            outrec2->FirstLeft = outrec->FirstLeft;
            outrec->FirstLeft = outrec2;
          } else
          {
            //the 2 polygons are separate ...
            outrec2->IsHole = outrec->IsHole;
            outrec2->FirstLeft = outrec->FirstLeft;
          }
          op2 = op; //ie get ready for the Next iteration
        }
        op2 = op2->Next;
      }
      op = op->Next;
    }
    while (op != outrec->Pts);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorl %edx, %edx
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rdx
jae 0xa973
movq (%rax,%rdx,8), %rbp
incq %rdx
movq 0x18(%rbp), %r13
testq %r13, %r13
je 0xa847
movq %rdx, 0x8(%rsp)
movq %r13, %r14
leaq 0x18(%r14), %r12
movq %r12, 0x10(%rsp)
movq (%r12), %r12
cmpq %r13, %r12
je 0xa958
movq 0x8(%r14), %rax
cmpq 0x8(%r12), %rax
jne 0xa94f
movq 0x10(%r12), %rax
cmpq %rax, 0x10(%r14)
jne 0xa94f
cmpq %r14, 0x18(%r12)
je 0xa94f
movq 0x20(%r12), %rax
cmpq %r14, %rax
je 0xa94f
movq 0x20(%r14), %rcx
movq %rax, 0x20(%r14)
movq %r14, 0x18(%rax)
movq %rcx, 0x20(%r12)
movq %r12, 0x18(%rcx)
movq %r14, 0x18(%rbp)
movq %rbx, %rdi
callq 0xb734
movq %rax, %r15
movq %r12, 0x18(%rax)
movq %rax, %rdi
callq 0xfa42
movq 0x18(%r15), %r12
movq 0x18(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x7eb3
testb %al, %al
je 0xa91a
movb 0x4(%rbp), %al
xorb $0x1, %al
movb %al, 0x4(%r15)
movq %rbp, 0x8(%r15)
jmp 0xa94c
movq %r13, %rdi
movq %r12, %rsi
callq 0x7eb3
movb 0x4(%rbp), %cl
movb %cl, 0x4(%r15)
testb %al, %al
je 0xa944
xorb $0x1, %cl
movb %cl, 0x4(%rbp)
movq 0x8(%rbp), %rax
movq %rax, 0x8(%r15)
movq %r15, 0x8(%rbp)
jmp 0xa94c
movq 0x8(%rbp), %rax
movq %rax, 0x8(%r15)
movq %r14, %r12
addq $0x18, %r12
jmp 0xa880
movq 0x10(%rsp), %rax
movq (%rax), %r14
cmpq %r13, %r14
jne 0xa877
movq 0x8(%rsp), %rdx
jmp 0xa847
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq