// File: /workspace/github_cpp_makefile_star2_O2/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::BuildResult2(ClipperLib::PolyTree&)
void Clipper::BuildResult2(PolyTree& polytree)
{
    polytree.Clear();
    polytree.AllNodes.reserve(m_PolyOuts.size());
    //add each output polygon/contour to polytree ...
    for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++)
    {
        OutRec* outRec = m_PolyOuts[i];
        int cnt = PointCount(outRec->Pts);
        if ((outRec->IsOpen && cnt < 2) || (!outRec->IsOpen && cnt < 3)) continue;
        FixHoleLinkage(*outRec);
        PolyNode* pn = new PolyNode();
        //nb: polytree takes ownership of all the PolyNodes
        polytree.AllNodes.push_back(pn);
        outRec->PolyNd = pn;
        pn->Parent = 0;
        pn->Index = 0;
        pn->Contour.reserve(cnt);
        OutPt *op = outRec->Pts->Prev;
        for (int j = 0; j < cnt; j++)
        {
            pn->Contour.push_back(op->Pt);
            op = op->Prev;
        }
    }

    //fixup PolyNode links etc ...
    polytree.Childs.reserve(m_PolyOuts.size());
    for (PolyOutList::size_type i = 0; i < m_PolyOuts.size(); i++)
    {
        OutRec* outRec = m_PolyOuts[i];
        if (!outRec->PolyNd) continue;
        if (outRec->IsOpen) 
        {
          outRec->PolyNd->m_IsOpen = true;
          polytree.AddChild(*outRec->PolyNd);
        }
        else if (outRec->FirstLeft && outRec->FirstLeft->PolyNd) 
          outRec->FirstLeft->PolyNd->AddChild(*outRec->PolyNd);
        else
          polytree.AddChild(*outRec->PolyNd);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x79c0
movq %rbx, 0x10(%rsp)
leaq 0x48(%rbx), %r15
movq 0x10(%r14), %rsi
subq 0x8(%r14), %rsi
sarq $0x3, %rsi
movq %r15, %rdi
callq 0xf948
xorl %r13d, %r13d
pushq $0x2
popq %rbx
movq 0x8(%r14), %rax
movq 0x10(%r14), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %rsi, %r13
jae 0x9a21
movq (%rax,%r13,8), %r12
movq 0x18(%r12), %rdi
callq 0xc4b8
movl %eax, %ebp
movzbl 0x5(%r12), %eax
movl %ebx, %ecx
subl %eax, %ecx
cmpl %ecx, %ebp
jle 0x9a19
movq %r12, %rsi
callq 0x9a8c
pushq $0x48
popq %rdi
callq 0x3230
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x2d(%rax)
movq %rax, 0x8(%rsp)
movq %r15, %rdi
leaq 0x8(%rsp), %rsi
callq 0xf9de
movq 0x8(%rsp), %rdi
movq %rdi, 0x10(%r12)
andq $0x0, 0x30(%rdi)
andl $0x0, 0x38(%rdi)
movl %ebp, %esi
callq 0xf856
movq 0x18(%r12), %r12
subl $0x1, %ebp
jb 0x9a19
movq 0x20(%r12), %r12
movq 0x8(%rsp), %rdi
leaq 0x8(%r12), %rsi
callq 0xf8fe
jmp 0x99fe
incq %r13
jmp 0x9975
movq 0x10(%rsp), %r15
leaq 0x18(%r15), %rdi
callq 0xf948
xorl %ebx, %ebx
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jae 0x9a7d
movq (%rax,%rbx,8), %rax
movq 0x10(%rax), %rsi
testq %rsi, %rsi
je 0x9a78
cmpb $0x1, 0x5(%rax)
jne 0x9a5e
movb $0x1, 0x3c(%rsi)
jmp 0x9a70
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x9a70
movq 0x10(%rax), %rdi
testq %rdi, %rdi
jne 0x9a73
movq %r15, %rdi
callq 0x7a70
incq %rbx
jmp 0x9a31
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq