// File: 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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0xd900
subl $0x1, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jge 0x1bd2b
jmp 0x1c0d8
movl $0x48, %edi
callq 0x3280
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
callq 0x10c10
jmp 0x1bd46
movq -0x80(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x40(%rax)
movl -0x18(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x44(%rax)
cmpl $0x1, -0x18(%rbp)
je 0x1bd6e
cmpl $0x0, -0x18(%rbp)
jne 0x1bdec
jmp 0x1bd70
xorl %eax, %eax
cmpl $0x0, -0x1c(%rbp)
movb %al, -0x81(%rbp)
jle 0x1bdb4
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20460
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
callq 0x20460
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x20480
movb %al, -0x81(%rbp)
movb -0x81(%rbp), %al
testb $0x1, %al
jne 0x1bdc0
jmp 0x1bdea
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1bd70
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x48, %esi
callq 0x3290
jmp 0x1c0e1
jmp 0x1bdec
movq -0x28(%rbp), %rdi
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x21500
movq -0x28(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x10(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20460
movq -0x98(%rbp), %rdi
movq %rax, %rsi
callq 0x21600
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x1bf64
movq -0x28(%rbp), %rdi
movslq -0x38(%rbp), %rsi
callq 0x21aa0
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x20460
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x20710
testb $0x1, %al
jne 0x1be7f
jmp 0x1bf54
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x20460
movq -0xb0(%rbp), %rdi
movq %rax, %rsi
callq 0x21600
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x20460
movq 0x8(%rax), %rax
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq %rax, %rcx
movq -0xa8(%rbp), %rax
cmpq 0x8(%rcx), %rax
jg 0x1bf4c
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x20460
movq 0x8(%rax), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq %rax, %rcx
movq -0xb8(%rbp), %rax
cmpq 0x8(%rcx), %rax
jne 0x1bf52
movq -0x10(%rbp), %rdi
movslq -0x40(%rbp), %rsi
callq 0x20460
movq (%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq (%rcx), %rax
jge 0x1bf52
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x1bf54
jmp 0x1bf56
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x1be3a
cmpl $0x0, -0x18(%rbp)
jne 0x1bf70
cmpl $0x2, -0x38(%rbp)
jl 0x1bf7c
cmpl $0x0, -0x18(%rbp)
je 0x1bfaf
cmpl $0x0, -0x38(%rbp)
jge 0x1bfaf
movq -0x28(%rbp), %rax
movq %rax, -0xc8(%rbp)
cmpq $0x0, %rax
je 0x1bfaa
movq -0xc8(%rbp), %rdi
callq 0x20220
movq -0xc8(%rbp), %rdi
movl $0x48, %esi
callq 0x3290
jmp 0x1c0d8
movq -0x78(%rbp), %rdi
addq $0xb0, %rdi
movq -0x28(%rbp), %rsi
callq 0x10c90
cmpl $0x0, -0x18(%rbp)
je 0x1bfce
jmp 0x1c0d8
movq -0x78(%rbp), %rax
cmpq $0x0, 0xa0(%rax)
jge 0x1c00c
movslq -0x3c(%rbp), %rdx
leaq -0x50(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xcae0
movq -0x78(%rbp), %rax
movq -0x50(%rbp), %rcx
movq %rcx, 0xa0(%rax)
movq -0x48(%rbp), %rcx
movq %rcx, 0xa8(%rax)
jmp 0x1c0d8
movq -0x78(%rbp), %rax
movq %rax, %rdi
addq $0xb0, %rdi
addq $0x18, %rdi
movq 0xa0(%rax), %rax
movslq %eax, %rsi
callq 0x20200
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq (%rcx), %rdi
movq 0xa8(%rax), %rax
movslq %eax, %rsi
callq 0x21aa0
movq (%rax), %rcx
movq %rcx, -0x60(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq 0x8(%rax), %rax
cmpq -0x58(%rbp), %rax
jg 0x1c099
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq 0x8(%rax), %rax
cmpq -0x58(%rbp), %rax
jne 0x1c0d6
movq -0x28(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x21aa0
movq (%rax), %rax
cmpq -0x60(%rbp), %rax
jge 0x1c0d6
movq -0x78(%rbp), %rdi
addq $0xb0, %rdi
callq 0x10c70
subl $0x1, %eax
movslq %eax, %rsi
movslq -0x3c(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0xcae0
movq -0x78(%rbp), %rax
movq -0x70(%rbp), %rcx
movq %rcx, 0xa0(%rax)
movq -0x68(%rbp), %rcx
movq %rcx, 0xa8(%rax)
jmp 0x1c0d8
addq $0xd0, %rsp
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x3440
nopw (%rax,%rax)