// File: /workspace/github_cpp_makefile_star2_O3/hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::ClipperOffset::AddPath(std::vector<ClipperLib::IntPoint, std::allocator<ClipperLib::IntPoint>> const&, ClipperLib::JoinType, ClipperLib::EndType)
void ClipperOffset::AddPath(const Path& path, JoinType joinType, EndType endType)
{
  int highI = (int)path.size() - 1;
  if (highI < 0) return;
  PolyNode* newNode = new PolyNode();
  newNode->m_jointype = joinType;
  newNode->m_endtype = endType;

  //strip duplicate points from path and also get index to the lowest point ...
  if (endType == etClosedLine || endType == etClosedPolygon)
    while (highI > 0 && path[0] == path[highI]) highI--;
  newNode->Contour.reserve(highI + 1);
  newNode->Contour.push_back(path[0]);
  int j = 0, k = 0;
  for (int i = 1; i <= highI; i++)
    if (newNode->Contour[j] != path[i])
    {
      j++;
      newNode->Contour.push_back(path[i]);
      if (path[i].Y > newNode->Contour[k].Y ||
        (path[i].Y == newNode->Contour[k].Y &&
        path[i].X < newNode->Contour[k].X)) k = j;
    }
  if ((endType == etClosedPolygon && j < 2) || 
    (endType != etClosedPolygon && j < 0))
  {
    delete newNode;
    return;
  }
  m_polyNodes.AddChild(*newNode);

  //if this path's lowest pt is lower than all the others then update m_lowest
  if (endType != etClosedPolygon) return;
  if (m_lowest.X < 0)
    m_lowest = IntPoint(0, k);
  else
  {
    IntPoint ip = m_polyNodes.Childs[(int)m_lowest.X]->Contour[(int)m_lowest.Y];
    if (newNode->Contour[k].Y > ip.Y ||
      (newNode->Contour[k].Y == ip.Y &&
      newNode->Contour[k].X < ip.X))
      m_lowest = IntPoint(m_polyNodes.ChildCount() - 1, k);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movq (%rsi), %r13
movq 0x8(%rsi), %rbp
subq %r13, %rbp
shrq $0x4, %rbp
testl %ebp, %ebp
jle 0xec12
movl %ecx, %r12d
movq %rsi, %r15
leal -0x1(%rbp), %ebx
movl $0x48, %edi
movl %edx, 0x4(%rsp)
callq 0x3210
movq %rax, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movups %xmm0, 0x10(%rax)
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x2d(%rax)
movl 0x4(%rsp), %eax
movl %eax, 0x40(%r14)
movl %r12d, 0x44(%r14)
movl %r12d, 0x4(%rsp)
cmpl $0x1, %r12d
ja 0xea96
cmpl $0x1, %ebp
je 0xea96
movq (%r13), %rax
movq 0x8(%r13), %rcx
leal -0x1(%rbp), %ebx
movq %rbx, %rdx
shlq $0x4, %rdx
cmpq (%r13,%rdx), %rax
jne 0xea96
cmpq 0x8(%r13,%rdx), %rcx
jne 0xea96
decl %ebp
cmpl $0x1, %ebp
jg 0xea75
xorl %ebx, %ebx
leal 0x1(%rbx), %esi
movq %r14, %rdi
callq 0x11e70
movq (%r15), %rdx
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xeabb
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0xeac3
movq %r14, %rdi
callq 0x12168
testl %ebx, %ebx
je 0xeb63
movq (%r14), %rcx
movq (%r15), %rax
movl %ebx, %r13d
shlq $0x4, %r13
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r12d, %r12d
movslq %r12d, %rdx
shlq $0x4, %rdx
movq (%rcx,%rdx), %rsi
cmpq 0x10(%rax,%rbx), %rsi
jne 0xeafd
movq 0x18(%rax,%rbx), %rsi
cmpq %rsi, 0x8(%rcx,%rdx)
je 0xeb55
leaq (%rax,%rbx), %rdx
addq $0x10, %rdx
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xeb1c
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0xeb24
movq %r14, %rdi
callq 0x12168
incl %r12d
movq (%r15), %rax
movslq %ebp, %rsi
movq (%r14), %rcx
shlq $0x4, %rsi
leaq (%rcx,%rsi), %rdx
movq 0x8(%rcx,%rsi), %rsi
cmpq %rsi, 0x18(%rax,%rbx)
jle 0xeb49
movl %r12d, %ebp
jmp 0xeb55
jne 0xeb55
movq 0x10(%rax,%rbx), %rsi
cmpq (%rdx), %rsi
jl 0xeb44
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0xeadf
movslq %ebp, %rbx
jmp 0xeb68
xorl %r12d, %r12d
xorl %ebx, %ebx
movl 0x4(%rsp), %edx
testl %edx, %edx
sete %al
cmpl $0x2, %r12d
setl %cl
testb %cl, %al
jne 0xeb8e
testl %edx, %edx
setne %al
testl %r12d, %r12d
sets %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xebd2
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xeba3
movq 0x28(%r14), %rsi
subq %rdi, %rsi
callq 0x3220
movq (%r14), %rdi
testq %rdi, %rdi
je 0xebb7
movq 0x10(%r14), %rsi
subq %rdi, %rsi
callq 0x3220
movl $0x48, %esi
movq %r14, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3220
movq 0x8(%rsp), %rax
leaq 0xb0(%rax), %r15
movq 0xd0(%rax), %r12
subq 0xc8(%rax), %r12
leaq 0xc8(%rax), %rdi
shrq $0x3, %r12
leaq 0x10(%rsp), %rsi
movq %r14, (%rsi)
movl %edx, %ebp
callq 0x12614
movq %r15, 0x30(%r14)
movl %r12d, 0x38(%r14)
testl %ebp, %ebp
je 0xec21
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq 0xa0(%rax), %rcx
testq %rcx, %rcx
js 0xeca2
movq %rax, %rsi
movq 0xc8(%rax), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movslq 0xa8(%rsi), %rcx
movq (%rdx), %rdx
shlq $0x4, %rcx
movq 0x8(%rdx,%rcx), %rdi
movq (%r14), %r8
movq %rbx, %r9
shlq $0x4, %r9
leaq (%r8,%r9), %rsi
cmpq %rdi, 0x8(%r8,%r9)
jle 0xecb9
movq 0x8(%rsp), %rdx
movq 0xd0(%rdx), %rcx
subq %rax, %rcx
shlq $0x1d, %rcx
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
addq %rcx, %rax
sarq $0x20, %rax
movq %rax, 0xa0(%rdx)
movq %rbx, 0xa8(%rdx)
jmp 0xec12
movq $0x0, 0xa0(%rax)
movq %rbx, 0xa8(%rax)
jmp 0xec12
jne 0xec12
movq (%rdx,%rcx), %rcx
cmpq %rcx, (%rsi)
jge 0xec12
jmp 0xec6b