// File: hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::Clipper::AddOutPt(ClipperLib::TEdge*, ClipperLib::IntPoint const&)
OutPt* Clipper::AddOutPt(TEdge *e, const IntPoint &pt)
{
  bool ToFront = (e->Side == esLeft);
  if(  e->OutIdx < 0 )
  {
    OutRec *outRec = CreateOutRec();
    outRec->IsOpen = (e->WindDelta == 0);
    OutPt* newOp = new OutPt;
    outRec->Pts = newOp;
    newOp->Idx = outRec->Idx;
    newOp->Pt = pt;
    newOp->Next = newOp;
    newOp->Prev = newOp;
    if (!outRec->IsOpen)
      SetHoleState(e, outRec);
#ifdef use_xyz
    if (pt == e->Bot) newOp->Pt = e->Bot;
    else if (pt == e->Top) newOp->Pt = e->Top;
    else SetZ(newOp->Pt, *e);
#endif
    e->OutIdx = outRec->Idx; //nb: do this after SetZ !
    return newOp;
  } else
  {
    OutRec *outRec = m_PolyOuts[e->OutIdx];
    //OutRec.Pts is the 'Left-most' point & OutRec.Pts.Prev is the 'Right-most'
    OutPt* op = outRec->Pts;

    if (ToFront && (pt == op->Pt)) return op;
    else if (!ToFront && (pt == op->Prev->Pt)) return op->Prev;

    OutPt* newOp = new OutPt;
    newOp->Idx = outRec->Idx;
    newOp->Pt = pt;
    newOp->Next = op;
    newOp->Prev = op->Prev;
    newOp->Prev->Next = newOp;
    op->Prev = newOp;
    if (ToFront) outRec->Pts = newOp;
#ifdef use_xyz
    if (pt == e->Bot) newOp->Pt = e->Bot;
    else if (pt == e->Top) newOp->Pt = e->Top;
    else SetZ(newOp->Pt, *e);
#endif
    return newOp;
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x1, 0x4c(%rax)
sete %al
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x5c(%rax)
jge 0x176fb
movq -0x68(%rbp), %rdi
callq 0x18ab0
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movl 0x50(%rax), %eax
testl %eax, %eax
movq -0x30(%rbp), %rax
sete 0x5(%rax)
movl $0x28, %edi
callq 0x3280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x70(%rbp)
callq 0x20750
jmp 0x17656
movq -0x70(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x38(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x38(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x30(%rbp), %rax
testb $0x1, 0x5(%rax)
jne 0x176e1
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x187f0
jmp 0x176e1
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x3290
jmp 0x17844
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x5c(%rax)
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x17837
movq -0x68(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rax
movslq 0x5c(%rax), %rsi
callq 0x20d90
movq (%rax), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
testb $0x1, -0x21(%rbp)
je 0x1774d
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rsi
addq $0x8, %rsi
callq 0x20480
testb $0x1, %al
jne 0x17740
jmp 0x1774d
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x17837
testb $0x1, -0x21(%rbp)
jne 0x1777f
movq -0x20(%rbp), %rdi
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rsi
addq $0x8, %rsi
callq 0x20480
testb $0x1, %al
jne 0x1776e
jmp 0x1777f
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x8(%rbp)
jmp 0x17837
jmp 0x17781
movl $0x28, %edi
callq 0x3280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
callq 0x20750
jmp 0x1779c
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %ecx
movq -0x60(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rcx
movq -0x60(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x58(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq 0x20(%rax), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x60(%rbp), %rcx
movq -0x60(%rbp), %rax
movq 0x20(%rax), %rax
movq %rcx, 0x18(%rax)
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x20(%rax)
testb $0x1, -0x21(%rbp)
je 0x1782f
movq -0x60(%rbp), %rcx
movq -0x50(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x1782f
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
movl $0x28, %esi
callq 0x3290
jmp 0x17844
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3440
nopl (%rax)