// File: hzeller[P]gcode-multi-shell-extrude/third_party/clipper.cpp
// Function: ClipperLib::PointInPolygon(ClipperLib::IntPoint const&, ClipperLib::OutPt*)
int PointInPolygon (const IntPoint &pt, OutPt *op)
{
  //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;
  OutPt* startOp = op;
  for(;;)
  {
    if (op->Next->Pt.Y == pt.Y)
    {
        if ((op->Next->Pt.X == pt.X) || (op->Pt.Y == pt.Y && 
          ((op->Next->Pt.X > pt.X) == (op->Pt.X < pt.X)))) return -1;
    }
    if ((op->Pt.Y < pt.Y) != (op->Next->Pt.Y < pt.Y))
    {
      if (op->Pt.X >= pt.X)
      {
        if (op->Next->Pt.X > pt.X) result = 1 - result;
        else
        {
          double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - 
            (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
          if (!d) return -1;
          if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
        }
      } else
      {
        if (op->Next->Pt.X > pt.X)
        {
          double d = (double)(op->Pt.X - pt.X) * (op->Next->Pt.Y - pt.Y) - 
            (double)(op->Next->Pt.X - pt.X) * (op->Pt.Y - pt.Y);
          if (!d) return -1;
          if ((d > 0) == (op->Next->Pt.Y > op->Pt.Y)) result = 1 - result;
        }
      }
    } 
    op = op->Next;
    if (startOp == op) break;
  } 
  return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x115cd
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
je 0x115bf
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x115cb
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
setg %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq -0x10(%rbp), %rdx
cmpq (%rdx), %rcx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x115cb
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11846
jmp 0x115cd
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x8(%rcx), %rax
setl %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x10(%rcx), %rcx
movq -0x10(%rbp), %rdx
cmpq 0x8(%rdx), %rcx
setl %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x11823
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jl 0x11729
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x11644
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x11724
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm2
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm1
movq -0x18(%rbp), %rax
movq 0x10(%rax), %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, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x116e2
jp 0x116e2
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11846
movsd -0x30(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x10(%rcx), %rcx
movq -0x18(%rbp), %rdx
cmpq 0x10(%rdx), %rcx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x11722
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x11724
jmp 0x11821
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
jle 0x1181f
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm0
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x10(%rax), %rax
movq -0x10(%rbp), %rcx
subq 0x8(%rcx), %rax
cvtsi2sd %rax, %xmm2
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
subq (%rcx), %rax
cvtsi2sd %rax, %xmm1
movq -0x18(%rbp), %rax
movq 0x10(%rax), %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, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x117dd
jp 0x117dd
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x11846
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
seta %al
andb $0x1, %al
movzbl %al, %eax
movq -0x18(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x10(%rcx), %rcx
movq -0x18(%rbp), %rdx
cmpq 0x10(%rdx), %rcx
setg %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x1181d
movl $0x1, %eax
subl -0x1c(%rbp), %eax
movl %eax, -0x1c(%rbp)
jmp 0x1181f
jmp 0x11821
jmp 0x11823
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x28(%rbp), %rax
cmpq -0x18(%rbp), %rax
jne 0x1183b
jmp 0x11840
jmp 0x1154b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)