// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, 0x30(%rsp)
testl %ecx, %ecx
je 0x91f1
movq (%rsi), %r12
movq 0x8(%rsi), %rax
subq %r12, %rax
shrq $0x4, %rax
cmpl $0x2, %eax
movq %rsi, 0x20(%rsp)
movl %edx, 0x5c(%rsp)
jl 0x8d34
movq (%r12), %rcx
movq 0x8(%r12), %rdi
leal -0x1(%rax), %r14d
movq %r14, %rsi
shlq $0x4, %rsi
cmpq %rcx, (%r12,%rsi)
jne 0x8d39
cmpq %rdi, 0x8(%r12,%rsi)
jne 0x8d39
decl %eax
cmpl $0x1, %eax
jg 0x8d10
xorl %r14d, %r14d
jmp 0x8d39
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, %rbp
subq %rax, %rbp
testl %r14d, %r14d
jle 0x90b3
movl %r14d, %r15d
decl %r14d
movq %r15, %rbx
shlq $0x4, %rbx
movq %r14, %rax
shlq $0x4, %rax
movq (%r12,%rbx), %rcx
addq $-0x98, %r13
addq $0x98, %rbp
cmpq (%r12,%rax), %rcx
jne 0x8da3
movq 0x8(%r12,%rax), %rax
cmpq %rax, 0x8(%r12,%rbx)
je 0x8d62
testl %r14d, %r14d
je 0x90b3
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 0x8dbc
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
movupd 0x10(%r12), %xmm0
movupd %xmm0, 0xa8(%rax)
movq 0x30(%rsp), %rax
leaq 0x18(%rax), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x893b
movq 0x20(%rsp), %r12
movq (%r12), %rdi
addq %rbx, %rdi
movq %r13, %rsi
callq 0x893b
movq %r13, 0x38(%rsp)
movq 0x28(%rsp), %r13
leaq 0x98(%r13), %rax
movq %rax, 0x48(%rsp)
imulq $0x98, %r15, %r15
leaq (%r15,%r13), %rax
movq %rax, 0x40(%rsp)
movq (%r12), %r12
movq %r12, 0x50(%rsp)
movl $0x98, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x3120
movq 0x48(%rsp), %rax
movq %rax, 0x60(%r13)
movq 0x40(%rsp), %rdi
movq %rdi, 0x68(%r13)
movups (%r12), %xmm0
movups %xmm0, 0x10(%r13)
orl $-0x1, 0x5c(%r13)
movq %r13, %r12
subq %rbp, %r12
movl $0x98, %edx
xorl %esi, %esi
callq 0x3120
movq %r13, 0x60(%r13,%r15)
movq %r12, 0x68(%r13,%r15)
movq 0x50(%rsp), %rax
movupd (%rax,%rbx), %xmm0
movupd %xmm0, 0x10(%r13,%r15)
orl $-0x1, 0x5c(%r13,%r15)
movl %r14d, %r15d
imulq $0x98, %r15, %rax
leaq (%rax,%r13), %r12
addq $0x98, %r12
shlq $0x4, %r15
testl %r14d, %r14d
jle 0x8f31
movq 0x20(%rsp), %r13
movq (%r13), %rdi
addq %r15, %rdi
movq 0x38(%rsp), %rsi
callq 0x893b
leaq -0x98(%r12), %rbx
leaq -0x130(%r12), %rbp
movq (%r13), %r13
movl $0x98, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3120
movq %r12, -0x38(%r12)
movq %rbp, -0x30(%r12)
movupd (%r13,%r15), %xmm0
movupd %xmm0, -0x88(%r12)
orl $-0x1, -0x3c(%r12)
decl %r14d
addq $-0x10, %r15
movq %rbx, %r12
jmp 0x8ec6
movq 0x28(%rsp), %rax
movq %rax, %rcx
movq %rax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movb 0x38(%rax), %dl
movb %dl, 0x17(%rsp)
movq 0x10(%rcx), %r12
movq 0x18(%rcx), %r15
movzbl 0x18(%rax), %eax
andl $0x1, %eax
movl %eax, 0x50(%rsp)
movq %rcx, %rdx
movq %rcx, 0x48(%rsp)
movq 0x60(%rdx), %rbx
movq 0x10(%rbx), %r13
movq 0x18(%rbx), %rbp
cmpq %r13, %r12
jne 0x8f7b
cmpq %rbp, %r15
je 0x8ffa
movq 0x68(%rdx), %r14
cmpq %rbx, %r14
je 0x9059
movq %rdx, 0x40(%rsp)
movq 0x10(%r14), %rdi
movq 0x18(%r14), %rsi
movl 0x50(%rsp), %eax
movl %eax, (%rsp)
movq %rdi, 0x20(%rsp)
movq %rsi, 0x38(%rsp)
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0x7f57
testb %al, %al
je 0x8fe1
testb $0x1, 0x17(%rsp)
je 0x902d
movq 0x20(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movq %r13, %r8
movq %rbp, %r9
callq 0x87a3
testb %al, %al
je 0x902d
movq %rbp, %r15
movq %r13, %r12
movq %rbx, %rdx
movq 0x48(%rsp), %rcx
cmpq %rcx, %rbx
jne 0x8f65
jmp 0x9061
cmpq %rbx, %rdx
je 0x91e9
movq 0x18(%rsp), %rax
cmpq %rax, %rdx
cmoveq %rbx, %rax
movq %rax, 0x18(%rsp)
movq 0x68(%rdx), %rax
movq %rbx, 0x60(%rax)
movq %rax, 0x68(%rbx)
andq $0x0, 0x68(%rdx)
movq %rbx, %rcx
jmp 0x8f3e
movq 0x18(%rsp), %rax
movq 0x40(%rsp), %rcx
cmpq %rax, %rcx
cmoveq %rbx, %rax
movq %rax, 0x18(%rsp)
movq %rbx, 0x60(%r14)
movq %r14, 0x68(%rbx)
andq $0x0, 0x68(%rcx)
movq 0x68(%rbx), %rcx
jmp 0x8f3e
movq %rbx, %rax
movq %rdx, %rbx
jmp 0x9065
movq 0x60(%rbx), %rax
movq 0x18(%rsp), %r12
cmpq %rax, 0x68(%rbx)
movl 0x5c(%rsp), %r14d
je 0x90a9
movb $0x1, %bl
xorl %ebp, %ebp
movq %r12, %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x82f7
movq 0x60(%r15), %r15
testb $0x1, %bl
je 0x909f
movq 0x18(%r15), %rax
cmpq 0x18(%r12), %rax
movzbl %bl, %ebx
cmovnel %ebp, %ebx
cmpq %r12, %r15
jne 0x907c
testb $0x1, %bl
je 0x90c4
movq 0x28(%rsp), %rdi
callq 0x32c0
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rsp), %rax
leaq 0x20(%rax), %rdi
leaq 0x60(%rsp), %rsi
callq 0xf6d4
xorl %ebx, %ebx
pushq $0x20
popq %r14
movq %r15, %rdi
callq 0x89c5
cmpq %rbx, %rax
je 0x91e2
movq %rax, %r15
testq %rbx, %rbx
cmoveq %rax, %rbx
movq %r14, %rdi
callq 0x3230
movq %rax, %r12
andq $0x0, 0x18(%rax)
movq 0x8(%r15), %rax
movq %rax, (%r12)
movsd 0x40(%r15), %xmm0
movq 0x68(%r15), %rax
movsd 0x40(%rax), %xmm1
xorl %ebp, %ebp
xorl %edx, %edx
movsd %xmm0, 0x20(%rsp)
movsd %xmm1, 0x38(%rsp)
ucomisd %xmm0, %xmm1
seta %bpl
setbe %dl
movq %rax, %rsi
cmovbeq %r15, %rsi
cmovbeq %rax, %r15
movq %rsi, 0x8(%r12)
movq %r15, 0x10(%r12)
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 0x30(%rsp), %r15
movq %r15, %rdi
callq 0x8a40
movq %rax, %r13
movq 0x10(%r12), %rsi
movq %r15, %rdi
movl %ebp, %edx
callq 0x8a40
movq %rax, %r15
movq 0x8(%r12), %rax
cmpl $-0x2, 0x5c(%rax)
jne 0x91ae
leaq 0x8(%r12), %rax
jmp 0x91bc
leaq 0x10(%r12), %rax
movq (%rax), %rcx
cmpl $-0x2, 0x5c(%rcx)
jne 0x91c0
andq $0x0, (%rax)
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x8c9e
movsd 0x38(%rsp), %xmm0
ucomisd 0x20(%rsp), %xmm0
cmovbeq %r13, %r15
jmp 0x90dd
movb $0x1, %al
jmp 0x90b5
movq %rdx, %rax
jmp 0x905c
pushq $0x28
popq %rdi
callq 0x3100
movq %rax, %r14
leaq 0xa58b(%rip), %rsi      # 0x1378e
movq %rax, %rdi
callq 0xf67a
leaq 0x11b56(%rip), %rsi     # 0x1ad68
leaq 0x649b(%rip), %rdx      # 0xf6b4
movq %r14, %rdi
callq 0x3390
movq %rax, %rbx
movq %r14, %rdi
callq 0x3180
jmp 0x924f
jmp 0x9230
movq %rax, %rdi
callq 0x30d0
movq 0x28(%rsp), %rdi
callq 0x32c0
callq 0x3300
movq %rax, %rbx
callq 0x3370
movq %rbx, %rdi
callq 0x33a0
movq %rax, %rdi
callq 0x5a3a
nop