// File: /workspace/github_cpp_makefile_star2_O1/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, %r15
movq %rdi, %r14
movq %rsi, %rdi
callq 0x8730
leaq 0x48(%r15), %rbx
movq 0x10(%r14), %rsi
subq 0x8(%r14), %rsi
sarq $0x3, %rsi
movq %rbx, %rdi
callq 0x124ee
movq 0x8(%r14), %rax
movq 0x10(%r14), %rsi
subq %rax, %rsi
je 0xab23
xorl %ebp, %ebp
movq (%rax,%rbp,8), %r13
movq 0x18(%r13), %rax
movl $0x0, %r12d
testq %rax, %rax
je 0xaa50
xorl %r12d, %r12d
movq %rax, %rcx
incl %r12d
movq 0x18(%rcx), %rcx
cmpq %rax, %rcx
jne 0xaa44
movzbl 0x5(%r13), %eax
movl $0x2, %ecx
subl %eax, %ecx
cmpl %ecx, %r12d
jle 0xab06
movq %r13, %rsi
callq 0xabe4
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(%r15), %rsi
cmpq 0x58(%r15), %rsi
je 0xaaa2
movq %rax, (%rsi)
addq $0x8, 0x50(%r15)
jmp 0xaaaf
movq %rbx, %rdi
leaq 0x8(%rsp), %rdx
callq 0x13970
movq 0x8(%rsp), %rdi
movq %rdi, 0x10(%r13)
movq $0x0, 0x30(%rdi)
movl $0x0, 0x38(%rdi)
movslq %r12d, %rsi
callq 0x1241a
testl %r12d, %r12d
jle 0xab06
movq 0x18(%r13), %r13
movq 0x20(%r13), %r13
movq 0x8(%rsp), %rdi
leaq 0x8(%r13), %rdx
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0xaafc
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0xab01
callq 0x1270c
decl %r12d
jne 0xaad8
incq %rbp
movq 0x8(%r14), %rax
movq 0x10(%r14), %rsi
subq %rax, %rsi
sarq $0x3, %rsi
cmpq %rsi, %rbp
jb 0xaa2b
jmp 0xab27
sarq $0x3, %rsi
leaq 0x18(%r15), %rdi
movq %rdi, 0x10(%rsp)
callq 0x124ee
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0xabd4
xorl %r13d, %r13d
movq (%rax,%r13,8), %rax
movq 0x10(%rax), %rbp
testq %rbp, %rbp
je 0xabb9
cmpb $0x1, 0x5(%rax)
jne 0xab5f
movb $0x1, 0x3c(%rbp)
jmp 0xab8e
movq 0x8(%rax), %rax
testq %rax, %rax
je 0xab8e
movq 0x10(%rax), %rbx
testq %rbx, %rbx
je 0xab8e
leaq 0x18(%rbx), %rdi
movq 0x20(%rbx), %r12
subq 0x18(%rbx), %r12
movq %rbp, 0x8(%rsp)
leaq 0x8(%rsp), %rsi
callq 0x12bd0
jmp 0xabad
movq 0x20(%r15), %r12
subq 0x18(%r15), %r12
movq %rbp, 0x8(%rsp)
movq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x12bd0
movq %r15, %rbx
shrq $0x3, %r12
movq %rbx, 0x30(%rbp)
movl %r12d, 0x38(%rbp)
incq %r13
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %r13
jb 0xab46
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop