// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x10(%rbp), %rdi
callq 0x10af0
movq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x48, %rax
movq %rax, -0x68(%rbp)
addq $0x8, %rdi
callq 0x20d70
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x216e0
movq $0x0, -0x18(%rbp)
movq -0x70(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
addq $0x8, %rdi
callq 0x20d70
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x1503d
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0x20d90
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1a440
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0x5(%rax)
je 0x14f3e
cmpl $0x2, -0x24(%rbp)
jl 0x14f4e
movq -0x20(%rbp), %rax
testb $0x1, 0x5(%rax)
jne 0x14f53
cmpl $0x3, -0x24(%rbp)
jge 0x14f53
jmp 0x1502c
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x15160
movl $0x48, %edi
callq 0x3280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
callq 0x10c10
jmp 0x14f7b
movq -0x80(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rdi
addq $0x48, %rdi
leaq -0x30(%rbp), %rsi
callq 0x217e0
movq -0x30(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x30(%rax)
movq -0x30(%rbp), %rax
movl $0x0, 0x38(%rax)
movq -0x30(%rbp), %rdi
movslq -0x24(%rbp), %rsi
callq 0x21500
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x1502a
movq -0x30(%rbp), %rdi
movq -0x48(%rbp), %rsi
addq $0x8, %rsi
callq 0x21600
movq -0x48(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x14fdb
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
movl $0x48, %esi
callq 0x3290
jmp 0x1514d
jmp 0x1502c
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x14ee1
movq -0x70(%rbp), %rdi
movq -0x10(%rbp), %rax
addq $0x18, %rax
movq %rax, -0x88(%rbp)
addq $0x8, %rdi
callq 0x20d70
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x216e0
movq $0x0, -0x58(%rbp)
movq -0x70(%rbp), %rdi
movq -0x58(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x8, %rdi
callq 0x20d70
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x15144
movq -0x70(%rbp), %rdi
addq $0x8, %rdi
movq -0x58(%rbp), %rsi
callq 0x20d90
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x150c0
jmp 0x15133
movq -0x60(%rbp), %rax
testb $0x1, 0x5(%rax)
je 0x150e9
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rax
movb $0x1, 0x3c(%rax)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x10c90
jmp 0x15131
movq -0x60(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x1511e
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x10(%rax)
je 0x1511e
movq -0x60(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rax), %rdi
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x10c90
jmp 0x1512f
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x10(%rax), %rsi
callq 0x10c90
jmp 0x15131
jmp 0x15133
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0x15070
addq $0x90, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)