// File: BartMassey[P]ancient-raytracer/render.cc
// Function: trace(ray, model&, int)
point trace( ray r, model &m, int depth ) {
  object *p, *current = 0;
  intersection s, sb;

  if( depth > m.maxdepth ) {
    point value( m.bg );
    
    value.dilate(0);
    return value;
  }
  // find an object struct by the ray
  for( p = &m.scene; p; p = p->next() )
    if( p->intersect( r, s ) ) {
	sb = s;
	current = p;
	break;
    }
  if (!current) {
    point value( m.bg );
    
    value.dilate(0);
    return value;
  }
  // if there are other intersections,
  // choose the nearest
  for( p = p->next(); p; p = p->next() )
    if( p->intersect( r, s ) && s.t < sb.t ) {
      delete sb.normal;
      delete sb.at;
      sb = s;
      current = p;
    }
  // determine the pixel value
  point nr(r.at( sb.t ));
  point value( (current->get_texture()).value(
   *sb.at, nr, *sb.normal, m, depth + 1 ) );

  delete sb.normal;
  delete sb.at;
  value.dilate(1);
  return value;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rsi, -0x150(%rbp)
movq %rdi, -0x148(%rbp)
movq %rdi, %rax
movq %rax, -0x140(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq $0x0, -0x30(%rbp)
movl -0x1c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jle 0x23b9
movq -0x148(%rbp), %rdi
movb $0x0, -0x61(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2ef0
movq -0x148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x2f60
jmp 0x237f
movb $0x1, -0x61(%rbp)
testb $0x1, -0x61(%rbp)
jne 0x23b4
jmp 0x23a8
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
callq 0x2fd0
jmp 0x2766
movq -0x148(%rbp), %rdi
callq 0x2fd0
jmp 0x2756
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2483
movq -0x150(%rbp), %rsi
movq -0x28(%rbp), %rax
movq %rax, -0x168(%rbp)
leaq -0xc0(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x2fe0
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq -0x48(%rbp), %rdx
callq *%rax
movl %eax, -0x154(%rbp)
jmp 0x2418
leaq -0xc0(%rbp), %rdi
callq 0x3060
movl -0x154(%rbp), %eax
cmpl $0x0, %eax
je 0x246e
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x2483
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x3060
jmp 0x2766
jmp 0x2470
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq %rax, -0x28(%rbp)
jmp 0x23c5
cmpq $0x0, -0x30(%rbp)
jne 0x24f6
movq -0x148(%rbp), %rdi
movb $0x0, -0xc1(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x2ef0
movq -0x148(%rbp), %rdi
xorps %xmm0, %xmm0
callq 0x2f60
jmp 0x24b6
movb $0x1, -0xc1(%rbp)
testb $0x1, -0xc1(%rbp)
jne 0x24f1
jmp 0x24e5
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
callq 0x2fd0
jmp 0x2766
movq -0x148(%rbp), %rdi
callq 0x2fd0
jmp 0x2756
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x2634
movq -0x150(%rbp), %rsi
movq -0x28(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0x110(%rbp), %rdi
movq %rdi, -0x178(%rbp)
callq 0x2fe0
movq -0x180(%rbp), %rdi
movq -0x178(%rbp), %rsi
movq (%rdi), %rax
movq 0x28(%rax), %rax
leaq -0x48(%rbp), %rdx
callq *%rax
movl %eax, -0x16c(%rbp)
jmp 0x2557
movl -0x16c(%rbp), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x181(%rbp)
je 0x2580
movss -0x48(%rbp), %xmm1
movss -0x60(%rbp), %xmm0
ucomiss %xmm1, %xmm0
seta %al
movb %al, -0x181(%rbp)
movb -0x181(%rbp), %al
movb %al, -0x182(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3060
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x25a4
jmp 0x261f
movq -0x58(%rbp), %rax
movq %rax, -0x190(%rbp)
cmpq $0x0, %rax
je 0x25c2
movq -0x190(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x198(%rbp)
cmpq $0x0, %rax
je 0x25e0
movq -0x198(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x261f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x3060
jmp 0x2766
jmp 0x2621
movq -0x28(%rbp), %rdi
movq (%rdi), %rax
callq *0x30(%rax)
movq %rax, -0x28(%rbp)
jmp 0x2504
movq -0x150(%rbp), %rsi
movss -0x60(%rbp), %xmm0
leaq -0x130(%rbp), %rdi
callq 0x3090
movb $0x0, -0x131(%rbp)
movq -0x30(%rbp), %rdi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
movq %rax, -0x1a0(%rbp)
jmp 0x2669
movq -0x1a0(%rbp), %rsi
movq -0x148(%rbp), %rdi
movq -0x58(%rbp), %r8
movq -0x50(%rbp), %rdx
movq -0x18(%rbp), %r9
movl -0x1c(%rbp), %r10d
incl %r10d
movq (%rsi), %rax
movq 0x18(%rax), %rax
movq %rsp, %rcx
movl %r10d, (%rcx)
leaq -0x130(%rbp), %rcx
callq *%rax
jmp 0x26a2
movq -0x58(%rbp), %rax
movq %rax, -0x1a8(%rbp)
cmpq $0x0, %rax
je 0x26c0
movq -0x1a8(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x50(%rbp), %rax
movq %rax, -0x1b0(%rbp)
cmpq $0x0, %rax
je 0x26de
movq -0x1b0(%rbp), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movq -0x148(%rbp), %rdi
movss 0x8917(%rip), %xmm0     # 0xb004
callq 0x2f60
jmp 0x26f4
movb $0x1, -0x131(%rbp)
testb $0x1, -0x131(%rbp)
jne 0x273a
jmp 0x272e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x2748
movq -0x148(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
callq 0x2fd0
jmp 0x2748
movq -0x148(%rbp), %rdi
callq 0x2fd0
leaq -0x130(%rbp), %rdi
callq 0x2fd0
jmp 0x2756
leaq -0x130(%rbp), %rdi
callq 0x2fd0
jmp 0x2766
movq -0x140(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x21c0
nop