// File: /workspace/github_cpp_makefile_star2_O2/BartMassey[P]ancient-raytracer/poly.cc
// Function: poly::contains(point&)
int poly::contains( point &v )
{
  int pn = np;
  float xx = X(v);
  float yy = Y(v);
  int nr = 0;
  int i, j;
  float x0,x1,y0,y1,xl,xr,yi,yj;
  point *r[4];

  for( i = 0; i < pn; i++ ) {
    j = i + 1;
    if( j >= pn )
      j -= pn;
    yi = Y(get(i));
    yj = Y(get(j));
    if( yi < yy && yj >= yy ) {
      r[ nr++ ] = &get(i);
      r[ nr++ ] = &get(j);
    } else if( yi >= yy && yj < yy ) {
      r[ nr++ ] = &get(j);
      r[ nr++ ] = &get(i);
    }
  }
  /* if we haven't found a trapezoid, continue */
  if( nr < 4 )
    return 0;
  /* intercept first line */
  x0 = X(*r[0]);
  y0 = Y(*r[0]);
  x1 = X(*r[1]);
  y1 = Y(*r[1]);
  if( y1 - y0 < TINY ) {
    if( xx < x0 && xx < x1 )
      xl = MIN( x0, x1 );
    else if( xx > x0 && xx > x1 )
      xl = MAX( x0, x1 );
    else
      return 0;
  } else {
      xl = x0 + (x1 - x0) * (yy - y0) / (y1 - y0);
  }
  /* intercept second line */
  x0 = X(*r[2]);
  y0 = Y(*r[2]);
  x1 = X(*r[3]);
  y1 = Y(*r[3]);
  if( y1 - y0 < TINY ) {
    if( xx < x0 && xx < x1 )
      xr = MIN( x0, x1 );
    else if( xx > x0 && xx > x1 )
      xr = MAX( x0, x1 );
    else
      return 0;
  } else {
      xr = x0 + (x1 - x0) * (yy - y0) / (y1 - y0);
  }
  /* containment test */
  if( xl < xr && xl < xx && xx < xr )
    return 1;
  if( xl > xr && xl > xx && xx > xr )
    return 1;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movl 0x18(%rdi), %r13d
movq %rsi, %rdi
callq 0x3713
movaps %xmm0, 0x40(%rsp)
movq %r14, %rdi
callq 0x3754
movss %xmm0, 0xc(%rsp)
testl %r13d, %r13d
movl $0x0, %eax
cmovgl %r13d, %eax
movl %eax, 0x20(%rsp)
xorl %ebp, %ebp
movl $0x0, 0x8(%rsp)
cmpl %ebp, 0x20(%rsp)
je 0x30f9
movl %ebp, %r14d
leal 0x1(%r14), %ebp
cmpl %r13d, %ebp
movl %r13d, %r12d
movl $0x0, %eax
cmovll %eax, %r12d
movl %ebp, %r15d
subl %r12d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x50(%rax)
movq %rax, %rdi
callq 0x3754
movss %xmm0, 0x10(%rsp)
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %esi
callq *0x50(%rax)
movq %rax, %rdi
callq 0x3754
movss 0x10(%rsp), %xmm2
movss 0xc(%rsp), %xmm1
ucomiss %xmm2, %xmm1
jbe 0x30a3
ucomiss %xmm1, %xmm0
jae 0x30b1
ucomiss %xmm1, %xmm2
jb 0x3039
ucomiss %xmm0, %xmm1
jbe 0x3039
decl %ebp
jmp 0x30bc
movl %r14d, %ebp
subl %r12d, %ebp
incl %ebp
movl %r14d, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movl %r15d, %esi
callq *0x50(%rax)
movl 0x8(%rsp), %r12d
movl %r12d, %r15d
movq %rax, 0x50(%rsp,%r15,8)
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x50(%rax)
addl $0x2, %r12d
movl %r12d, 0x8(%rsp)
movq %rax, 0x58(%rsp,%r15,8)
incl %r14d
movl %r14d, %ebp
jmp 0x3039
xorl %ebx, %ebx
cmpl $0x4, 0x8(%rsp)
jb 0x3298
movq 0x50(%rsp), %r14
movq %r14, %rdi
callq 0x3713
movaps %xmm0, 0x10(%rsp)
movq %r14, %rdi
callq 0x3754
movss %xmm0, 0x8(%rsp)
movq 0x58(%rsp), %r14
movq %r14, %rdi
callq 0x3713
movss %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x3754
movss 0x8(%rsp), %xmm3
subss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2f09(%rip), %xmm2     # 0x6060
ucomisd %xmm1, %xmm2
jbe 0x317d
movaps 0x40(%rsp), %xmm0
movaps 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
movss 0x20(%rsp), %xmm2
jbe 0x31a9
ucomiss %xmm0, %xmm2
jbe 0x31a9
minss %xmm2, %xmm1
jmp 0x31bf
movaps 0x10(%rsp), %xmm2
movss 0x20(%rsp), %xmm4
subss %xmm2, %xmm4
movss 0xc(%rsp), %xmm1
subss %xmm3, %xmm1
mulss %xmm4, %xmm1
divss %xmm0, %xmm1
addss %xmm1, %xmm2
movaps %xmm2, 0x10(%rsp)
jmp 0x31c4
ucomiss %xmm1, %xmm0
jbe 0x3298
ucomiss %xmm2, %xmm0
jbe 0x3298
maxss %xmm2, %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x60(%rsp), %r14
movq %r14, %rdi
callq 0x3713
movaps %xmm0, 0x20(%rsp)
movq %r14, %rdi
callq 0x3754
movss %xmm0, 0x3c(%rsp)
movq 0x68(%rsp), %r14
movq %r14, %rdi
callq 0x3713
movss %xmm0, 0x8(%rsp)
movq %r14, %rdi
callq 0x3754
movss 0x3c(%rsp), %xmm3
subss %xmm3, %xmm0
cvtss2sd %xmm0, %xmm1
movsd 0x2e4b(%rip), %xmm2     # 0x6060
ucomisd %xmm1, %xmm2
jbe 0x323b
movaps 0x40(%rsp), %xmm0
movaps 0x20(%rsp), %xmm2
ucomiss %xmm0, %xmm2
movss 0x8(%rsp), %xmm3
jbe 0x32a9
ucomiss %xmm0, %xmm3
jbe 0x32a9
minss %xmm3, %xmm2
jmp 0x3265
movaps 0x20(%rsp), %xmm2
movss 0x8(%rsp), %xmm4
subss %xmm2, %xmm4
movss 0xc(%rsp), %xmm1
subss %xmm3, %xmm1
mulss %xmm4, %xmm1
divss %xmm0, %xmm1
addss %xmm1, %xmm2
movaps 0x40(%rsp), %xmm0
movaps 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm2
jbe 0x327e
ucomiss %xmm1, %xmm0
jbe 0x327e
ucomiss %xmm1, %xmm2
jbe 0x327e
pushq $0x1
popq %rbx
jmp 0x3298
ucomiss %xmm2, %xmm0
cmpltps %xmm1, %xmm2
cmpltps %xmm1, %xmm0
andps %xmm2, %xmm0
movd %xmm0, %eax
seta %cl
andb %al, %cl
movzbl %cl, %ebx
movl %ebx, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomiss %xmm2, %xmm0
jbe 0x3298
ucomiss %xmm3, %xmm0
movaps 0x10(%rsp), %xmm1
jbe 0x3298
maxss %xmm3, %xmm2
jmp 0x326a