// File: hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::PointInPolygon(ClipperLib::IntPoint const&, std::vector<ClipperLib::IntPoint, std::allocator<ClipperLib::IntPoint>> const&)
int PointInPolygon (const IntPoint &pt, const Path &path)
{
  //returns 0 if false, +1 if true, -1 if pt ON polygon boundary
  //http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.5498&rep=rep1&type=pdf
  int result = 0;
  size_t cnt = path.size();
  if (cnt < 3) return 0;
  IntPoint ip = path[0];
  for(size_t i = 1; i <= cnt; ++i)
  {
    IntPoint ipNext = (i == cnt ? path[0] : path[i]);
    if (ipNext.Y == pt.Y)
    {
        if ((ipNext.X == pt.X) || (ip.Y == pt.Y && 
          ((ipNext.X > pt.X) == (ip.X < pt.X)))) return -1;
    }
    if ((ip.Y < pt.Y) != (ipNext.Y < pt.Y))
    {
      if (ip.X >= pt.X)
      {
        if (ipNext.X > pt.X) result = 1 - result;
        else
        {
          double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - 
            (double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
          if (!d) return -1;
          if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
        }
      } else
      {
        if (ipNext.X > pt.X)
        {
          double d = (double)(ip.X - pt.X) * (ipNext.Y - pt.Y) - 
            (double)(ipNext.X - pt.X) * (ip.Y - pt.Y);
          if (!d) return -1;
          if ((d > 0) == (ipNext.Y > ip.Y)) result = 1 - result;
        }
      }
    }
    ip = ipNext;
  } 
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rdi
callq 0xd900
movq %rax, -0x28(%rbp)
cmpq $0x3, -0x28(%rbp)
jae 0x11237
movl $0x0, -0x4(%rbp)
jmp 0x11521
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20460
movq (%rax), %rcx
movq %rcx, -0x38(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x30(%rbp)
movq $0x1, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
ja 0x1151b
movq -0x40(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0x11286
movq -0x18(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x20460
movq %rax, -0x68(%rbp)
jmp 0x11297
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x20460
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1130c
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x112fe
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x1130a
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
setg %al
andb $0x1, %al
movzbl %al, %eax
movq -0x38(%rbp), %rcx
movq -0x10(%rbp), %rdx
cmpq (%rdx), %rcx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x1130a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11521
jmp 0x1130c
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setl %al
andb $0x1, %al
movzbl %al, %eax
movq -0x48(%rbp), %rcx
movq -0x10(%rbp), %rdx
cmpq 0x8(%rdx), %rcx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x114fa
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x1142c
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x1136b
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x11427
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm2
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm1
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm3
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x113f1
jp 0x113f1
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11521
movsd -0x58(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movq -0x48(%rbp), %rcx
cmpq -0x30(%rbp), %rcx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x11425
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x11427
jmp 0x114f8
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x114f6
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm2
movq -0x50(%rbp), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm1
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm3
mulsd %xmm3, %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x114c0
jp 0x114c0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11521
movsd -0x60(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movq -0x48(%rbp), %rcx
cmpq -0x30(%rbp), %rcx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x114f4
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x114f6
jmp 0x114f8
jmp 0x114fa
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x1125b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)