// File: /workspace/github_cpp_makefile_star2_O3/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 0x83fc
leaq 0x48(%rbx), %rdi
movq 0x10(%r14), %rsi
subq 0x8(%r14), %rsi
sarq $0x3, %rsi
movq %rdi, 0x10(%rsp)
callq 0x11f44
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
movq %rcx, %rsi
subq %rax, %rsi
je 0xa828
xorl %r12d, %r12d
movq (%rax,%r12,8), %r13
movq 0x18(%r13), %rdx
testq %rdx, %rdx
je 0xa810
xorl %ebp, %ebp
movq %rdx, %rsi
movq %rbp, %r15
movq 0x18(%rsi), %rsi
decq %rbp
cmpq %rdx, %rsi
jne 0xa739
movzbl 0x5(%r13), %edx
movl $0x2, %esi
subl %edx, %esi
movl %ebp, %edx
notl %edx
cmpl %esi, %edx
jb 0xa810
movq %r13, %rsi
callq 0xa8ec
movl $0x48, %edi
callq 0x3210
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x2d(%rax)
movq %rax, 0x8(%rsp)
movq 0x50(%rbx), %rsi
cmpq 0x58(%rbx), %rsi
je 0xa79d
movq %rax, (%rsi)
addq $0x8, 0x50(%rbx)
jmp 0xa7ac
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x13398
movq 0x8(%rsp), %rdi
movq %rdi, 0x10(%r13)
movq $0x0, 0x30(%rdi)
movl $0x0, 0x38(%rdi)
negq %rbp
movq %rbp, %rsi
callq 0x11e70
movq 0x18(%r13), %r13
movl $0x1, %ebp
subl %r15d, %ebp
movq 0x20(%r13), %r13
movq 0x8(%rsp), %rdi
leaq 0x8(%r13), %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xa7ff
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0xa804
callq 0x12168
decl %ebp
jne 0xa7db
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
incq %r12
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %rsi, %r12
jb 0xa723
jmp 0xa82c
sarq $0x3, %rsi
leaq 0x18(%rbx), %rdi
movq %rdi, 0x10(%rsp)
callq 0x11f44
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0xa8dd
xorl %r13d, %r13d
movq %rbx, %r15
movq (%rax,%r13,8), %rax
movq 0x10(%rax), %rbp
testq %rbp, %rbp
je 0xa8c2
cmpb $0x1, 0x5(%rax)
jne 0xa86f
movb $0x1, 0x3c(%rbp)
movq 0x20(%rbx), %r12
subq 0x18(%rbx), %r12
jmp 0xa89f
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xa894
movq 0x10(%rax), %rbx
testq %rbx, %rbx
je 0xa894
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %r12
subq 0x18(%rbx), %r12
movq %rbp, 0x8(%rsp)
jmp 0xa8a9
movq %r15, %rbx
movq 0x20(%r15), %r12
subq 0x18(%r15), %r12
movq %rbp, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x12614
shrq $0x3, %r12
movq %rbx, 0x30(%rbp)
movl %r12d, 0x38(%rbp)
movq %r15, %rbx
incq %r13
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r13
jb 0xa84e
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq