// File: /workspace/github_cpp_makefile_star2_O3/BartMassey[P]ancient-raytracer/poly.cc
// Function: poly::intersect(ray, intersection&)
int poly::intersect( ray r, intersection &s ) {
  float b, t;
  
  r.transform( toi );
  
  // now we have the ray in object coords...
  point rd( r.d() );
  point ro( r.o() );
  
  b = Z( rd );
  if( fabs( b ) < TINY ) {
    // ray is parallel to plane, so no hit
    return 0;
  }
  t = -Z( ro ) / b;
  if( t < TINY ) {
    // ray is behind plane, so no hit
    return 0;
  }
  point i( ro + (rd * t) );
#if DEBUGLEVEL > 0
  assert( fabs( Z(i) ) < TINY );
#endif  
  if( !contains( i ) ) {
    // ray is outside poly
    return 0;
  }
#if DEBUGLEVEL > 0
  assert( cnormal );
#endif
  s.normal = new point( *cnormal );
  s.at = new point( X(i), Y(i) );
  s.t = t;

  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
leaq 0xc0(%rdi), %rsi
movq %r15, %rdi
callq 0x518c
movslq 0x30(%r15), %r13
testq %r13, %r13
jle 0x3bec
leaq 0x34(%r15), %rsi
leaq (,%r13,4), %rdx
leaq 0x64(%rsp), %rdi
callq 0x20a0
leaq 0x7c55(%rip), %rax      # 0xb848
movq %rax, 0x40(%rsp)
movslq 0x10(%r15), %r12
movl %r12d, 0x48(%rsp)
testq %r12, %r12
jle 0x3c1f
addq $0x14, %r15
leaq 0x4c(%rsp), %rdi
leaq (,%r12,4), %rdx
movq %r15, %rsi
callq 0x20a0
cmpl $0x2, %r13d
jle 0x3e63
movss 0x6c(%rsp), %xmm1
movaps 0x467a(%rip), %xmm0     # 0x82b0
andps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
xorl %ebp, %ebp
movsd 0x4429(%rip), %xmm2     # 0x8070
ucomisd %xmm0, %xmm2
ja 0x3e4f
movaps %xmm1, 0x10(%rsp)
cmpl $0x2, %r12d
jle 0x3e63
leaq 0x40(%rsp), %rdi
movl $0x2, %esi
callq 0x2d6e
movss (%rax), %xmm1
xorps 0x43c6(%rip), %xmm1     # 0x8040
divss 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd 0x43e1(%rip), %xmm2     # 0x8070
ucomisd %xmm0, %xmm2
ja 0x3e4f
leaq 0x84(%rsp), %r15
leaq (,%r13,4), %r12
leaq 0x64(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
movaps %xmm1, 0x10(%rsp)
callq 0x20a0
movaps 0x10(%rsp), %xmm1
xorl %eax, %eax
movss 0x84(%rsp,%rax,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x84(%rsp,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3cc5
leaq 0x7b5e(%rip), %rax      # 0xb848
movq %rax, 0x20(%rsp)
movslq 0x48(%rsp), %rbp
movl %ebp, 0x28(%rsp)
testq %rbp, %rbp
jle 0x3d50
leaq 0x4c(%rsp), %rsi
leaq 0x2c(%rsp), %rdi
movq %rbp, %rdx
shlq $0x2, %rdx
callq 0x20a0
leaq 0xa4(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x20a0
cmpl %r13d, %ebp
jne 0x3e82
xorl %eax, %eax
movss 0xa4(%rsp,%rax,4), %xmm0
addss 0x2c(%rsp,%rax,4), %xmm0
movss %xmm0, 0x2c(%rsp,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3d31
jmp 0x3d59
cmpl %r13d, %ebp
jne 0x3e82
movq (%r14), %rax
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq *0x58(%rax)
testl %eax, %eax
je 0x3e4d
movl $0x20, %edi
callq 0x20f0
movq 0x158(%r14), %rcx
leaq 0x7ac1(%rip), %rdx      # 0xb848
movq %rdx, (%rax)
movslq 0x8(%rcx), %rdx
movl %edx, 0x8(%rax)
testq %rdx, %rdx
jle 0x3dac
xorl %esi, %esi
movss 0xc(%rcx,%rsi,4), %xmm0
movss %xmm0, 0xc(%rax,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x3d98
movq %rax, 0x8(%rbx)
movl $0x20, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x20(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
testl %eax, %eax
jle 0x3ea1
leaq 0x20(%rsp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x20(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
cmpl $0x1, %eax
jle 0x3ec0
leaq 0x20(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %ebp
movl $0x1, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
leaq 0x7a27(%rip), %rax      # 0xb848
movq %rax, (%r14)
movl $0x2, 0x8(%r14)
movss 0xc(%rsp), %xmm1
movss %xmm1, 0xc(%r14)
movss %xmm0, 0x10(%r14)
movq %r14, 0x10(%rbx)
movaps 0x10(%rsp), %xmm0
movss %xmm0, (%rbx)
jmp 0x3e4f
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x44b7(%rip), %rdi      # 0x8321
leaq 0x4235(%rip), %rsi      # 0x80a6
leaq 0x44b3(%rip), %rcx      # 0x832b
movl $0x10e, %edx            # imm = 0x10E
callq 0x2080
leaq 0x4247(%rip), %rdi      # 0x80d0
leaq 0x4216(%rip), %rsi      # 0x80a6
leaq 0x426a(%rip), %rcx      # 0x8101
movl $0x66, %edx
callq 0x2080
leaq 0x4443(%rip), %rdi      # 0x82eb
leaq 0x41f7(%rip), %rsi      # 0x80a6
leaq 0x443f(%rip), %rcx      # 0x82f5
movl $0x104, %edx            # imm = 0x104
callq 0x2080
leaq 0x443f(%rip), %rdi      # 0x8306
leaq 0x41d8(%rip), %rsi      # 0x80a6
leaq 0x443b(%rip), %rcx      # 0x8310
movl $0x109, %edx            # imm = 0x109
callq 0x2080
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x21a0
nop