// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %rdx, 0x48(%rsp)
movq %rsi, %r15
movq %rdi, %r14
leaq 0xc0(%rdi), %rsi
movq %r15, %rdi
callq 0x51a0
movslq 0x30(%r15), %r13
testq %r13, %r13
jle 0x3c5d
leaq 0x34(%r15), %rsi
leaq (,%r13,4), %rdx
leaq 0x94(%rsp), %rdi
callq 0x20a0
leaq 0x8be4(%rip), %r12      # 0xc848
movq %r12, 0x70(%rsp)
movslq 0x10(%r15), %rbx
movl %ebx, 0x78(%rsp)
testq %rbx, %rbx
jle 0x3c8f
addq $0x14, %r15
leaq 0x7c(%rsp), %rdi
leaq (,%rbx,4), %rdx
movq %r15, %rsi
callq 0x20a0
cmpl $0x2, %r13d
jle 0x3edf
movss 0x9c(%rsp), %xmm1
movaps 0x55d7(%rip), %xmm0     # 0x9280
andps %xmm1, %xmm0
cvtss2sd %xmm0, %xmm0
xorl %ebp, %ebp
movsd 0x5366(%rip), %xmm2     # 0x9020
ucomisd %xmm0, %xmm2
ja 0x3ecb
movaps %xmm1, 0x10(%rsp)
cmpl $0x2, %ebx
jle 0x3edf
leaq 0x70(%rsp), %rdi
movl $0x2, %esi
callq 0x2dc0
movss (%rax), %xmm1
xorps 0x5344(%rip), %xmm1     # 0x9030
divss 0x10(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtss2sd %xmm1, %xmm0
movsd 0x531f(%rip), %xmm2     # 0x9020
ucomisd %xmm0, %xmm2
ja 0x3ecb
movq %r12, 0x50(%rsp)
movl %r13d, 0x58(%rsp)
testl %r13d, %r13d
movaps %xmm1, 0x10(%rsp)
jle 0x3d58
leaq 0x5c(%rsp), %rdi
leaq (,%r13,4), %rdx
leaq 0x94(%rsp), %rsi
callq 0x20a0
movaps 0x10(%rsp), %xmm1
xorl %eax, %eax
movss 0x5c(%rsp,%rax,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x5c(%rsp,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x3d40
movq %r12, 0x28(%rsp)
movslq 0x78(%rsp), %r15
movl %r15d, 0x30(%rsp)
testq %r15, %r15
jle 0x3d83
leaq 0x7c(%rsp), %rsi
leaq 0x34(%rsp), %rdi
leaq (,%r15,4), %rdx
callq 0x20a0
movq %r12, 0xa8(%rsp)
movl %r13d, 0xb0(%rsp)
testl %r13d, %r13d
jle 0x3db1
leaq 0x5c(%rsp), %rsi
leaq 0xb4(%rsp), %rdi
movq %r13, %rdx
shlq $0x2, %rdx
callq 0x20a0
cmpl %r13d, %r15d
jne 0x3efe
testl %r15d, %r15d
jle 0x3dde
xorl %eax, %eax
movss 0xb4(%rsp,%rax,4), %xmm0
addss 0x34(%rsp,%rax,4), %xmm0
movss %xmm0, 0x34(%rsp,%rax,4)
incq %rax
cmpq %rax, %r15
jne 0x3dc1
movq (%r14), %rax
leaq 0x28(%rsp), %rsi
movq %r14, %rdi
callq *0x58(%rax)
testl %eax, %eax
je 0x3ec9
movl $0x20, %edi
callq 0x20f0
movq 0x158(%r14), %rcx
movq %r12, (%rax)
movslq 0x8(%rcx), %rdx
movl %edx, 0x8(%rax)
testq %rdx, %rdx
jle 0x3e2a
xorl %esi, %esi
movss 0xc(%rcx,%rsi,4), %xmm0
movss %xmm0, 0xc(%rax,%rsi,4)
incq %rsi
cmpq %rsi, %rdx
jne 0x3e16
movq 0x48(%rsp), %rbx
movq %rax, 0x8(%rbx)
movl $0x20, %edi
callq 0x20f0
movq %rax, %r14
leaq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
testl %eax, %eax
jle 0x3f1d
leaq 0x28(%rsp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x28(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
cmpl $0x1, %eax
jle 0x3f3c
leaq 0x28(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %ebp
movl $0x1, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
movq %r12, (%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 0x3ecb
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x540b(%rip), %rdi      # 0x92f1
leaq 0x5181(%rip), %rsi      # 0x906e
leaq 0x5407(%rip), %rcx      # 0x92fb
movl $0x10e, %edx            # imm = 0x10E
callq 0x2080
leaq 0x5193(%rip), %rdi      # 0x9098
leaq 0x5162(%rip), %rsi      # 0x906e
leaq 0x51b6(%rip), %rcx      # 0x90c9
movl $0x66, %edx
callq 0x2080
leaq 0x5397(%rip), %rdi      # 0x92bb
leaq 0x5143(%rip), %rsi      # 0x906e
leaq 0x5393(%rip), %rcx      # 0x92c5
movl $0x104, %edx            # imm = 0x104
callq 0x2080
leaq 0x5393(%rip), %rdi      # 0x92d6
leaq 0x5124(%rip), %rsi      # 0x906e
leaq 0x538f(%rip), %rcx      # 0x92e0
movl $0x109, %edx            # imm = 0x109
callq 0x2080
movq %rax, %rbx
movl $0x20, %esi
movq %r14, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x21a0
nop