// File: /workspace/github_cpp_makefile_star2_O1/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 0xefe3
movq %rsi, %r15
movl %ecx, %r12d
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 0xee66
cmpl $0x1, %ebp
je 0xee66
movq (%r13), %rax
movq 0x8(%r13), %rcx
leal -0x1(%rbp), %ebx
movq %rbx, %rdx
shlq $0x4, %rdx
cmpq (%r13,%rdx), %rax
jne 0xee66
cmpq 0x8(%r13,%rdx), %rcx
jne 0xee66
decl %ebp
cmpl $0x1, %ebp
jg 0xee45
xorl %ebx, %ebx
leal 0x1(%rbx), %esi
movq %r14, %rdi
callq 0x1241a
movq (%r15), %rdx
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xee8b
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0xee93
movq %r14, %rdi
callq 0x1270c
testl %ebx, %ebx
jle 0xef33
movl %ebx, %r13d
shlq $0x4, %r13
addq $0x10, %r13
xorl %ebp, %ebp
movl $0x10, %ebx
xorl %r12d, %r12d
movslq %r12d, %rax
movq (%r14), %rcx
shlq $0x4, %rax
movq (%r15), %rdx
movq (%rcx,%rax), %rsi
cmpq (%rdx,%rbx), %rsi
jne 0xeed3
movq 0x8(%rdx,%rbx), %rsi
cmpq %rsi, 0x8(%rcx,%rax)
je 0xef25
addq %rbx, %rdx
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0xeeed
movups (%rdx), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%r14)
jmp 0xeef5
movq %r14, %rdi
callq 0x1270c
incl %r12d
movq (%r15), %rax
movslq %ebp, %rdx
movq (%r14), %rsi
shlq $0x4, %rdx
leaq (%rsi,%rdx), %rcx
movq 0x8(%rsi,%rdx), %rdx
cmpq %rdx, 0x8(%rax,%rbx)
jle 0xef1a
movl %r12d, %ebp
jmp 0xef25
jne 0xef25
movq (%rax,%rbx), %rax
cmpq (%rcx), %rax
jl 0xef15
addq $0x10, %rbx
cmpq %rbx, %r13
jne 0xeeb0
movslq %ebp, %r15
jmp 0xef39
xorl %r12d, %r12d
xorl %r15d, %r15d
movl 0x4(%rsp), %edx
testl %edx, %edx
sete %al
cmpl $0x2, %r12d
setl %cl
testb %cl, %al
jne 0xef5f
testl %edx, %edx
setne %al
testl %r12d, %r12d
sets %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0xefa3
movq 0x18(%r14), %rdi
testq %rdi, %rdi
je 0xef74
movq 0x28(%r14), %rsi
subq %rdi, %rsi
callq 0x3220
movq (%r14), %rdi
testq %rdi, %rdi
je 0xef88
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
movl %edx, %ebp
leaq 0xb0(%rax), %rbx
movq 0xd0(%rax), %r12
subq 0xc8(%rax), %r12
leaq 0xc8(%rax), %rdi
shrq $0x3, %r12
leaq 0x10(%rsp), %rsi
movq %r14, (%rsi)
callq 0x12bd0
movq %rbx, 0x30(%r14)
movl %r12d, 0x38(%r14)
testl %ebp, %ebp
je 0xeff2
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rcx
movq 0xa0(%rcx), %rax
testq %rax, %rax
js 0xf076
movq %rcx, %rdx
movq 0xc8(%rcx), %rcx
cltq
movq (%rcx,%rax,8), %rcx
movslq 0xa8(%rdx), %rax
movq (%rcx), %rcx
shlq $0x4, %rax
movq 0x8(%rcx,%rax), %rsi
movq (%r14), %rdi
movq %r15, %r8
shlq $0x4, %r8
leaq (%rdi,%r8), %rdx
cmpq %rsi, 0x8(%rdi,%r8)
jle 0xf08d
movq 0x8(%rsp), %rdx
movq 0xd0(%rdx), %rax
subq 0xc8(%rdx), %rax
shlq $0x1d, %rax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
addq %rax, %rcx
sarq $0x20, %rcx
movq %rcx, 0xa0(%rdx)
movq %r15, 0xa8(%rdx)
jmp 0xefe3
movq $0x0, 0xa0(%rcx)
movq %r15, 0xa8(%rcx)
jmp 0xefe3
jne 0xefe3
movq (%rcx,%rax), %rax
cmpq %rax, (%rdx)
jge 0xefe3
jmp 0xf03b