// File: /workspace/github_cpp_makefile_star2_O3/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::ClipperBase::AddPath(std::vector<ClipperLib::IntPoint, std::allocator<ClipperLib::IntPoint>> const&, ClipperLib::PolyType, bool)
bool ClipperBase::AddPath(const Path &pg, PolyType PolyTyp, bool Closed)
{
#ifdef use_lines
  if (!Closed && PolyTyp == ptClip)
    throw clipperException("AddPath: Open paths must be subject.");
#else
  if (!Closed)
    throw clipperException("AddPath: Open paths have been disabled.");
#endif

  int highI = (int)pg.size() -1;
  if (Closed) while (highI > 0 && (pg[highI] == pg[0])) --highI;
  while (highI > 0 && (pg[highI] == pg[highI -1])) --highI;
  if ((Closed && highI < 2) || (!Closed && highI < 1)) return false;

  //create a new edge array ...
  TEdge *edges = new TEdge [highI +1];

  bool IsFlat = true;
  //1. Basic (first) edge initialization ...
  try
  {
    edges[1].Curr = pg[1];
    RangeTest(pg[0], m_UseFullRange);
    RangeTest(pg[highI], m_UseFullRange);
    InitEdge(&edges[0], &edges[1], &edges[highI], pg[0]);
    InitEdge(&edges[highI], &edges[0], &edges[highI-1], pg[highI]);
    for (int i = highI - 1; i >= 1; --i)
    {
      RangeTest(pg[i], m_UseFullRange);
      InitEdge(&edges[i], &edges[i+1], &edges[i-1], pg[i]);
    }
  }
  catch(...)
  {
    delete [] edges;
    throw; //range test fails
  }
  TEdge *eStart = &edges[0];

  //2. Remove duplicate vertices, and (when closed) collinear edges ...
  TEdge *E = eStart, *eLoopStop = eStart;
  for (;;)
  {
    if ((E->Curr == E->Next->Curr))
    {
      if (E == E->Next) break;
      if (E == eStart) eStart = E->Next;
      E = RemoveEdge(E);
      eLoopStop = E;
      continue;
    }
    if (E->Prev == E->Next) 
      break; //only two vertices
    else if (Closed &&
      SlopesEqual(E->Prev->Curr, E->Curr, E->Next->Curr, m_UseFullRange) && 
      (!m_PreserveCollinear ||
      !Pt2IsBetweenPt1AndPt3(E->Prev->Curr, E->Curr, E->Next->Curr)))
    {
      //Collinear edges are allowed for open paths but in closed paths
      //the default is to merge adjacent collinear edges into a single edge.
      //However, if the PreserveCollinear property is enabled, only overlapping
      //collinear edges (ie spikes) will be removed from closed paths.
      if (E == eStart) eStart = E->Next;
      E = RemoveEdge(E);
      E = E->Prev;
      eLoopStop = E;
      continue;
    }
    E = E->Next;
    if (E == eLoopStop) break;
  }

  if ((!Closed && (E == E->Next)) || (Closed && (E->Prev == E->Next)))
  {
    delete [] edges;
    return false;
  }

  if (!Closed)
  { 
    m_HasOpenPaths = true;
    eStart->Prev->OutIdx = Skip;
  }

  //3. Do second stage of edge initialization ...
  E = eStart;
  do
  {
    InitEdge2(*E, PolyTyp);
    E = E->Next;
    if (IsFlat && E->Curr.Y != eStart->Curr.Y) IsFlat = false;
  }
  while (E != eStart);

  //4. Finally, add edge bounds to LocalMinima list ...

  //Totally flat paths must be handled differently when adding them
  //to LocalMinima list to avoid endless loops etc ...
  if (IsFlat) 
  {
    if (Closed) 
    {
      delete [] edges;
      return false;
    }
    E->Prev->OutIdx = Skip;
    if (E->Prev->Bot.X < E->Prev->Top.X) ReverseHorizontal(*E->Prev);
    LocalMinima* locMin = new LocalMinima();
    locMin->Next = 0;
    locMin->Y = E->Bot.Y;
    locMin->LeftBound = 0;
    locMin->RightBound = E;
    locMin->RightBound->Side = esRight;
    locMin->RightBound->WindDelta = 0;
    while (E->Next->OutIdx != Skip)
    {
      E->NextInLML = E->Next;
      if (E->Bot.X != E->Prev->Top.X) ReverseHorizontal(*E);
      E = E->Next;
    }
    InsertLocalMinima(locMin);
    m_edges.push_back(edges);
	  return true;
  }

  m_edges.push_back(edges);
  bool clockwise;
  TEdge* EMin = 0;
  for (;;)
  {
    E = FindNextLocMin(E);
    if (E == EMin) break;
    else if (!EMin) EMin = E;

    //E and E.Prev now share a local minima (left aligned if horizontal).
    //Compare their slopes to find which starts which bound ...
    LocalMinima* locMin = new LocalMinima;
    locMin->Next = 0;
    locMin->Y = E->Bot.Y;
    if (E->Dx < E->Prev->Dx) 
    {
      locMin->LeftBound = E->Prev;
      locMin->RightBound = E;
      clockwise = false; //Q.nextInLML = Q.prev
    } else
    {
      locMin->LeftBound = E;
      locMin->RightBound = E->Prev;
      clockwise = true; //Q.nextInLML = Q.next
    }
    locMin->LeftBound->Side = esLeft;
    locMin->RightBound->Side = esRight;

    if (!Closed) locMin->LeftBound->WindDelta = 0;
    else if (locMin->LeftBound->Next == locMin->RightBound)
      locMin->LeftBound->WindDelta = -1;
    else locMin->LeftBound->WindDelta = 1;
    locMin->RightBound->WindDelta = -locMin->LeftBound->WindDelta;

    E = ProcessBound(locMin->LeftBound, clockwise);
    TEdge* E2 = ProcessBound(locMin->RightBound, !clockwise);

    if (locMin->LeftBound->OutIdx == Skip)
      locMin->LeftBound = 0;
    else if (locMin->RightBound->OutIdx == Skip)
      locMin->RightBound = 0;
    InsertLocalMinima(locMin);
    if (!clockwise) E = E2;
  }
  return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
testl %ecx, %ecx
je 0x9e26
movq (%rsi), %r12
movq 0x8(%rsi), %rax
subq %r12, %rax
shrq $0x4, %rax
cmpl $0x2, %eax
movq %rdi, 0x18(%rsp)
movl %edx, 0x5c(%rsp)
movq %rsi, 0x50(%rsp)
jl 0x98be
movq (%r12), %rcx
movq 0x8(%r12), %rdi
leal -0x1(%rax), %r14d
movq %r14, %r8
shlq $0x4, %r8
cmpq %rcx, (%r12,%r8)
jne 0x98c3
cmpq %rdi, 0x8(%r12,%r8)
jne 0x98c3
decl %eax
cmpl $0x1, %eax
jg 0x989a
xorl %r14d, %r14d
jmp 0x98c3
decl %eax
movl %eax, %r14d
leal -0x1(%r14), %eax
leal 0x1(%r14), %ecx
imulq $0x98, %rcx, %r13
addq $0x98, %r13
cltq
imulq $0x98, %rax, %rax
movq $-0x98, %rbx
subq %rax, %rbx
testl %r14d, %r14d
jle 0x9c9e
movl %r14d, %ebp
decl %r14d
movq %rbp, %r15
shlq $0x4, %r15
movq %r14, %rax
shlq $0x4, %rax
movq (%r12,%r15), %rcx
addq $-0x98, %r13
addq $0x98, %rbx
cmpq (%r12,%rax), %rcx
jne 0x992d
movq 0x8(%r12,%rax), %rax
cmpq %rax, 0x8(%r12,%r15)
je 0x98ec
testl %r14d, %r14d
je 0x9c9e
leal 0x1(%r14), %eax
movl %eax, 0x20(%rsp)
movq %r13, %rdi
callq 0x3030
xorps %xmm0, %xmm0
movq %rax, 0x28(%rsp)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
addq $0x98, %rax
addq $-0x98, %r13
jne 0x994e
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
movupd 0x10(%r12), %xmm0
movupd %xmm0, 0xa8(%rax)
movq 0x18(%rsp), %rax
addq $0x18, %rax
movq %r12, %rdi
movq %rax, %r12
movq %rax, %rsi
callq 0x9483
movq 0x50(%rsp), %r13
movq (%r13), %rdi
addq %r15, %rdi
movq %r12, %rsi
callq 0x9483
movq %r12, 0x30(%rsp)
movq 0x28(%rsp), %r12
leaq 0x98(%r12), %rax
movq %rax, 0x38(%rsp)
imulq $0x98, %rbp, %rax
movq %rax, 0x48(%rsp)
addq %r12, %rax
movq %rax, 0x10(%rsp)
movq (%r13), %rbp
movq %rbp, 0x40(%rsp)
movl $0x98, %edx
movq %r12, %rdi
xorl %esi, %esi
callq 0x3110
movq 0x38(%rsp), %rax
movq %rax, 0x60(%r12)
movq 0x10(%rsp), %rdi
movq %rdi, 0x68(%r12)
movups (%rbp), %xmm0
movups %xmm0, 0x10(%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x5c(%r12)
movq %r12, %rbp
subq %rbx, %rbp
movl $0x98, %edx
xorl %esi, %esi
callq 0x3110
movq 0x48(%rsp), %rax
movq %r12, 0x60(%r12,%rax)
movq %rbp, 0x68(%r12,%rax)
movq 0x40(%rsp), %rcx
movupd (%rcx,%r15), %xmm0
movupd %xmm0, 0x10(%r12,%rax)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, 0x5c(%r12,%rax)
movl %r14d, %r14d
imulq $0x98, %r14, %rax
leaq (%r12,%rax), %r15
addq $0x98, %r15
shlq $0x4, %r14
movq (%r13), %rdi
addq %r14, %rdi
movq 0x30(%rsp), %rsi
callq 0x9483
leaq -0x98(%r15), %rbx
leaq -0x130(%r15), %r12
movq (%r13), %rbp
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3110
movq %r15, -0x38(%r15)
movq %r12, -0x30(%r15)
movupd (%rbp,%r14), %xmm0
movupd %xmm0, -0x88(%r15)
movl $0xffffffff, -0x3c(%r15) # imm = 0xFFFFFFFF
movl 0x20(%rsp), %eax
decl %eax
addq $-0x10, %r14
movq %rbx, %r15
movl %eax, 0x20(%rsp)
cmpl $0x1, %eax
jg 0x9a71
movq 0x28(%rsp), %rax
movq %rax, %rsi
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movb 0x38(%rax), %dl
movb %dl, 0x38(%rsp)
movq 0x10(%rsi), %r15
movq 0x18(%rsi), %r14
movzbl 0x18(%rax), %eax
andl $0x1, %eax
movl %eax, 0x50(%rsp)
movq %rsi, %rbx
movq %rsi, 0x48(%rsp)
movq %rbx, %rdx
movq %r15, %r13
movq %r14, %rcx
movq 0x60(%rbx), %rbx
movq 0x10(%rbx), %r15
movq 0x18(%rbx), %r14
cmpq %r15, %r13
jne 0x9b30
cmpq %r14, %rcx
je 0x9c04
movq 0x68(%rdx), %r12
cmpq %rbx, %r12
je 0x9c3a
movq %rdx, 0x40(%rsp)
movq 0x10(%r12), %rbp
movq 0x18(%r12), %rsi
movl 0x50(%rsp), %eax
movl %eax, (%rsp)
movq %rbp, %rdi
movq %rsi, 0x20(%rsp)
movq %r13, %rdx
movq %rcx, 0x30(%rsp)
movq %r15, %r8
movq %r14, %r9
callq 0x8a01
testb %al, %al
je 0x9bc4
testb $0x1, 0x38(%rsp)
je 0x9bd4
movq %rbp, %rax
xorq %r15, %rax
movq 0x20(%rsp), %rcx
xorq %r14, %rcx
orq %rax, %rcx
je 0x9bd4
cmpq %r13, %rbp
jne 0x9b9d
movq 0x20(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0x9bd4
cmpq %r15, %rbp
jne 0x9bb4
movq 0x30(%rsp), %rcx
cmpq 0x20(%rsp), %rcx
setg %al
cmpq %r14, %rcx
jmp 0x9bbd
cmpq %rbp, %r13
setg %al
cmpq %r15, %r13
setge %cl
xorb %al, %cl
je 0x9bd4
movq 0x48(%rsp), %rsi
cmpq %rsi, %rbx
jne 0x9b0d
jmp 0x9c42
movq 0x10(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq %rax, %rcx
cmoveq %rbx, %rax
movq %rax, 0x10(%rsp)
movq %rbx, 0x60(%r12)
movq %r12, 0x68(%rbx)
movq $0x0, 0x68(%rcx)
movq 0x68(%rbx), %rsi
jmp 0x9ae6
cmpq %rbx, %rdx
je 0x9e1e
movq 0x10(%rsp), %rax
cmpq %rax, %rdx
cmoveq %rbx, %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rdx), %rax
movq %rbx, 0x60(%rax)
movq %rax, 0x68(%rbx)
movq $0x0, 0x68(%rdx)
movq %rbx, %rsi
jmp 0x9ae6
movq %rbx, %rax
movq %rdx, %rbx
jmp 0x9c46
movq 0x60(%rbx), %rax
movq 0x18(%rsp), %r15
movq 0x10(%rsp), %r13
cmpq %rax, 0x68(%rbx)
movl 0x5c(%rsp), %r12d
je 0x9c94
movb $0x1, %bpl
xorl %r14d, %r14d
movq %r13, %rbx
movq %rbx, %rdi
movl %r12d, %esi
callq 0x8e0d
movq 0x60(%rbx), %rbx
testb $0x1, %bpl
je 0x9c89
movq 0x18(%rbx), %rax
cmpq 0x18(%r13), %rax
movzbl %bpl, %ebp
cmovnel %r14d, %ebp
cmpq %r13, %rbx
jne 0x9c64
testb $0x1, %bpl
je 0x9caf
movq 0x28(%rsp), %rdi
callq 0x32a0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%r15), %rsi
cmpq 0x30(%r15), %rsi
je 0x9cc8
movq 0x28(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%r15)
jmp 0x9cd6
leaq 0x20(%r15), %rdi
leaq 0x60(%rsp), %rdx
callq 0x12728
movq %rbx, %rdi
callq 0x950e
movq %rax, %rbx
movb $0x1, %al
testq %rbx, %rbx
je 0x9ca0
leaq 0x10(%r15), %r13
xorl %ebp, %ebp
testq %rbp, %rbp
cmoveq %rbx, %rbp
movl $0x20, %edi
callq 0x3210
movq %rax, %r14
movq $0x0, 0x18(%rax)
movq 0x8(%rbx), %rax
movq %rax, (%r14)
movsd 0x40(%rbx), %xmm0
movq 0x68(%rbx), %rax
movsd 0x40(%rax), %xmm1
xorl %r12d, %r12d
xorl %edx, %edx
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x30(%rsp)
ucomisd %xmm0, %xmm1
seta %r12b
setbe %dl
movq %rax, %rsi
cmovbeq %rbx, %rsi
cmovbeq %rax, %rbx
movq %rsi, 0x8(%r14)
movq %rbx, 0x10(%r14)
movl $0x1, 0x4c(%rsi)
movl $0x2, 0x4c(%rbx)
xorl %eax, %eax
cmpq %rbx, 0x60(%rsi)
sete %al
leal -0x1(,%rax,2), %ecx
negl %eax
orl $0x1, %eax
movl %eax, 0x50(%rsi)
movl %ecx, 0x50(%rbx)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x9594
movq %rax, %r15
movq 0x10(%r14), %rsi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x9594
movq 0x8(%r14), %rcx
cmpl $-0x2, 0x5c(%rcx)
jne 0x9da6
leaq 0x8(%r14), %rcx
jmp 0x9db3
leaq 0x10(%r14), %rcx
movq (%rcx), %rdx
cmpl $-0x2, 0x5c(%rdx)
jne 0x9dba
movq $0x0, (%rcx)
movq (%r13), %rcx
movq %r13, %rdx
testq %rcx, %rcx
je 0x9df0
movq (%r14), %rsi
cmpq (%rcx), %rsi
jge 0x9de1
movq %rcx, %rdx
movq 0x18(%rcx), %rcx
testq %rcx, %rcx
je 0x9de6
cmpq (%rcx), %rsi
jl 0x9dce
jmp 0x9de8
movq %r13, %rdx
jmp 0x9dec
xorl %ecx, %ecx
addq $0x18, %rdx
movq %rcx, 0x18(%r14)
movsd 0x30(%rsp), %xmm0
ucomisd 0x20(%rsp), %xmm0
movq %r14, (%rdx)
cmovbeq %r15, %rax
movq %rax, %rdi
callq 0x950e
movq %rax, %rbx
cmpq %rbp, %rax
jne 0x9cee
movb $0x1, %al
jmp 0x9ca0
movq %rdx, %rax
jmp 0x9c3d
movl $0x28, %edi
callq 0x30f0
movq %rax, %r14
leaq 0xb954(%rip), %rsi      # 0x1578e
movq %rax, %rdi
callq 0x11cba
leaq 0x11f1f(%rip), %rsi     # 0x1bd68
leaq 0x7ea4(%rip), %rdx      # 0x11cf4
movq %r14, %rdi
callq 0x3370
movq %rax, %rbx
movq %r14, %rdi
callq 0x3170
jmp 0x9e86
jmp 0x9e67
movq %rax, %rdi
callq 0x30d0
movq 0x28(%rsp), %rdi
callq 0x32a0
callq 0x32d0
movq %rax, %rbx
callq 0x3350
movq %rbx, %rdi
callq 0x3380
movq %rax, %rdi
callq 0x11caf