// File: /workspace/github_cpp_makefile_star2_O1/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 $0x58, %rsp
testl %ecx, %ecx
je 0xa125
movl %edx, %ebp
movq %rdi, %r14
movq (%rsi), %r12
movq %rsi, %r15
movq 0x8(%rsi), %rcx
subq %r12, %rcx
shrq $0x4, %rcx
cmpl $0x2, %ecx
jl 0x9bd0
movq (%r12), %rdx
movq 0x8(%r12), %rsi
leal -0x1(%rcx), %eax
movq %rax, %rdi
shlq $0x4, %rdi
cmpq %rdx, (%r12,%rdi)
jne 0x9bd4
cmpq %rsi, 0x8(%r12,%rdi)
jne 0x9bd4
decl %ecx
cmpl $0x1, %ecx
jg 0x9bae
xorl %eax, %eax
jmp 0x9bd4
decl %ecx
movl %ecx, %eax
movl %eax, %edi
sarl $0x1f, %edi
andl %eax, %edi
testl %eax, %eax
jle 0x9c08
movl %eax, %ecx
shlq $0x4, %rcx
decl %eax
movq %rax, %rdx
shlq $0x4, %rdx
movq (%r12,%rcx), %rsi
cmpq (%r12,%rdx), %rsi
jne 0x9c04
movq 0x8(%r12,%rdx), %rdx
cmpq %rdx, 0x8(%r12,%rcx)
je 0x9bdb
incl %eax
movl %eax, %edi
cmpl $0x2, %edi
jl 0x9fc8
movq %rdi, %r13
leal 0x1(%rdi), %eax
imulq $0x98, %rax, %rbx
movq %rbx, %rdi
callq 0x3030
xorl %ecx, %ecx
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax,%rcx)
movups %xmm0, 0x20(%rax,%rcx)
movups %xmm0, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq $0x98, %rcx
cmpq %rcx, %rbx
jne 0x9c2b
movl %ebp, 0x40(%rsp)
movq %rax, 0x18(%rsp)
movupd 0x10(%r12), %xmm0
movupd %xmm0, 0xa8(%rax)
movq %r14, 0x20(%rsp)
leaq 0x18(%r14), %rbx
movq %r12, %rdi
movq %rbx, %rsi
callq 0x97a3
movq %r13, %r14
movl %r14d, %r12d
movq %r12, %rax
shlq $0x4, %rax
movq (%r15), %rdi
movq %rax, 0x10(%rsp)
addq %rax, %rdi
movq %rbx, %rsi
callq 0x97a3
movq %rbx, 0x28(%rsp)
movq 0x18(%rsp), %rbx
movl $0x98, %eax
leaq (%rbx,%rax), %rbp
imulq $0x98, %r12, %r12
leaq (%rbx,%r12), %r13
movq (%r15), %rax
movq %rax, 0x38(%rsp)
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3110
movq %rbp, 0x60(%rbx)
movq %r13, 0x68(%rbx)
movq %r13, %rdi
movq 0x38(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x10(%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x5c(%rbx)
decl %r14d
movslq %r14d, %rax
movq %r15, %r13
imulq $0x98, %rax, %rbp
addq %rbx, %rbp
movq (%r15), %r15
movl $0x98, %edx
xorl %esi, %esi
callq 0x3110
movq %rbx, 0x60(%rbx,%r12)
movq %rbp, 0x68(%rbx,%r12)
movq 0x10(%rsp), %rax
movupd (%r15,%rax), %xmm0
movupd %xmm0, 0x10(%rbx,%r12)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x5c(%rbx,%r12)
leaq 0x1(%r14), %rbx
imulq $0x98, %r14, %r12
movl $0x98, %eax
addq %rax, %r12
shlq $0x4, %r14
movq %r14, %rbp
movq (%r13), %rdi
addq %rbp, %rdi
movq 0x28(%rsp), %rsi
callq 0x97a3
movq 0x18(%rsp), %rax
leaq (%rax,%r12), %r15
movq $-0x98, %rcx
leaq (%r15,%rcx), %rdi
leaq (%rax,%r12), %r14
addq $-0x130, %r14           # imm = 0xFED0
movq (%r13), %rax
movq %rax, 0x10(%rsp)
movl $0x98, %edx
xorl %esi, %esi
callq 0x3110
movq %r15, 0xf8(%r14)
movq %r14, 0x100(%r14)
movq 0x10(%rsp), %rax
movupd (%rax,%rbp), %xmm0
movupd %xmm0, 0xa8(%r14)
movl $0xffffffff, 0xf4(%r14) # imm = 0xFFFFFFFF
decq %rbx
movq $-0x98, %rax
addq %rax, %r12
addq $-0x10, %rbp
cmpq $0x1, %rbx
jg 0x9d4c
movq 0x18(%rsp), %rax
movq %rax, %rcx
movq %rax, 0x48(%rsp)
movq %rax, 0x30(%rsp)
movq 0x20(%rsp), %rax
movb 0x38(%rax), %dl
movb %dl, 0xf(%rsp)
movzbl 0x18(%rax), %eax
andl $0x1, %eax
movl %eax, 0x44(%rsp)
movq %rcx, %rbx
movq %rcx, 0x50(%rsp)
movq 0x60(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq 0x10(%rsi), %r12
cmpq %r12, %rdx
jne 0x9e28
movq 0x18(%rsi), %rax
cmpq %rax, 0x18(%rbx)
je 0x9f34
movq 0x68(%rbx), %r14
cmpq %rsi, %r14
je 0x9f67
movq 0x10(%r14), %r15
movq 0x18(%r14), %r13
movq 0x18(%rbx), %rcx
movq %rsi, 0x10(%rsp)
movq 0x18(%rsi), %rbp
movl 0x44(%rsp), %eax
movl %eax, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
movq %rdx, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
movq %r12, %r8
movq %rbp, %r9
callq 0x8d2a
testb %al, %al
je 0x9ee9
testb $0x1, 0xf(%rsp)
je 0x9f01
movq %r15, %rax
xorq %r12, %rax
movq %r13, %rcx
xorq %rbp, %rcx
orq %rax, %rcx
je 0x9f01
movq 0x38(%rsp), %rdx
movq %rdx, %rax
xorq %r12, %rax
movq %r15, %rcx
xorq %rdx, %rcx
movq %r13, %rdx
movq 0x28(%rsp), %rdi
xorq %rdi, %rdx
movq %rbp, %rsi
xorq %rdi, %rsi
orq %rax, %rsi
sete %al
orq %rcx, %rdx
je 0x9f01
testb %al, %al
jne 0x9f01
cmpq %r12, %r15
jne 0x9ed2
movq 0x28(%rsp), %rax
cmpq %r13, %rax
setg %cl
cmpq %rbp, %rax
jmp 0x9ee0
movq 0x38(%rsp), %rax
cmpq %r15, %rax
setg %cl
cmpq %r12, %rax
setge %al
xorb %cl, %al
testb %al, %al
je 0x9f01
movq 0x10(%rsp), %rdx
movq %rdx, %rbx
movq 0x50(%rsp), %rcx
cmpq %rcx, %rdx
jne 0x9e09
jmp 0x9f6a
movq 0x30(%rsp), %rax
cmpq %rax, %rbx
movq 0x10(%rsp), %rcx
cmoveq %rcx, %rax
movq %rax, 0x30(%rsp)
movq %rcx, 0x60(%r14)
movq 0x60(%rbx), %rax
movq %r14, 0x68(%rax)
movq $0x0, 0x68(%rbx)
movq 0x68(%rax), %rcx
jmp 0x9dea
cmpq %rsi, %rbx
je 0x9f67
movq 0x30(%rsp), %rax
cmpq %rax, %rbx
cmoveq %rsi, %rax
movq %rax, 0x30(%rsp)
movq 0x68(%rbx), %rax
movq %rsi, 0x60(%rax)
movq 0x60(%rbx), %rcx
movq %rax, 0x68(%rcx)
movq $0x0, 0x68(%rbx)
jmp 0x9dea
movq %rbx, %rdx
movq 0x68(%rdx), %rax
cmpq 0x60(%rdx), %rax
je 0x9fb9
movb $0x1, %bl
xorl %ebp, %ebp
movq 0x30(%rsp), %r12
movq %r12, %r14
movl 0x40(%rsp), %r15d
movq %r14, %rdi
movl %r15d, %esi
callq 0x9140
movq 0x60(%r14), %r14
testb $0x1, %bl
je 0x9fa8
movq 0x18(%r14), %rax
cmpq 0x18(%r12), %rax
movzbl %bl, %ebx
cmovnel %ebp, %ebx
cmpq %r12, %r14
jne 0x9f85
testb $0x1, %bl
je 0x9fdb
movq 0x18(%rsp), %rdi
jmp 0x9fbe
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x9fc8
callq 0x32a0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rcx
movq 0x28(%rcx), %rsi
cmpq 0x30(%rcx), %rsi
je 0x9ff9
movq 0x18(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x28(%rcx)
jmp 0xa007
leaq 0x20(%rcx), %rdi
leaq 0x18(%rsp), %rdx
callq 0x12cdc
movq %r14, %rdi
callq 0x9835
movb $0x1, %bpl
testq %rax, %rax
je 0x9fca
movq %rax, %r15
xorl %r12d, %r12d
movq 0x20(%rsp), %r13
testq %r12, %r12
cmoveq %r15, %r12
movl $0x20, %edi
callq 0x3210
movq %rax, %r14
movq $0x0, 0x18(%rax)
movq 0x8(%r15), %rax
movq %rax, (%r14)
movsd 0x40(%r15), %xmm0
movq 0x68(%r15), %rax
movsd 0x40(%rax), %xmm1
xorl %ebx, %ebx
xorl %edx, %edx
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x28(%rsp)
ucomisd %xmm0, %xmm1
seta %bl
setbe %dl
movq %rax, %rsi
cmovbeq %r15, %rsi
cmovbeq %rax, %r15
movq %rsi, 0x8(%r14)
movq %r15, 0x10(%r14)
movl $0x1, 0x4c(%rsi)
movl $0x2, 0x4c(%r15)
xorl %eax, %eax
cmpq %r15, 0x60(%rsi)
sete %al
leal -0x1(,%rax,2), %ecx
negl %eax
orl $0x1, %eax
movl %eax, 0x50(%rsi)
movl %ecx, 0x50(%r15)
movq %r13, %rdi
callq 0x98c6
movq %rax, %r15
movq 0x10(%r14), %rsi
movq %r13, %rdi
movl %ebx, %edx
callq 0x98c6
movq %rax, %rbx
movq 0x8(%r14), %rax
cmpl $-0x2, 0x5c(%rax)
jne 0xa0d8
leaq 0x8(%r14), %rax
jmp 0xa0e5
leaq 0x10(%r14), %rax
movq (%rax), %rcx
cmpl $-0x2, 0x5c(%rcx)
jne 0xa0ec
movq $0x0, (%rax)
movq 0x20(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x9b42
movsd 0x28(%rsp), %xmm0
ucomisd 0x10(%rsp), %xmm0
cmovbeq %r15, %rbx
movq %rbx, %rdi
callq 0x9835
movq %rax, %r15
cmpq %r12, %rax
jne 0xa022
jmp 0x9fca
movl $0x28, %edi
callq 0x30f0
movq %rax, %r14
leaq 0xb5e5(%rip), %rsi      # 0x1571e
movq %rax, %rdi
callq 0x1225c
leaq 0x11c20(%rip), %rsi     # 0x1bd68
leaq 0x8147(%rip), %rdx      # 0x12296
movq %r14, %rdi
callq 0x3370
movq %rax, %rbx
movq %r14, %rdi
callq 0x3170
jmp 0xa18a
jmp 0xa166
movq %rax, %rdi
callq 0x30d0
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0xa17d
callq 0x32a0
callq 0x32d0
movq %rax, %rbx
callq 0x3350
movq %rbx, %rdi
callq 0x3380
movq %rax, %rdi
callq 0x12251