// File: tomfunkhouser[P]gaps/apps/scninfo/scninfo.cpp
// Function: PrintReference(gaps::R3SceneReference*, int, int)
static int
PrintReference(R3SceneReference *reference, int index, int level)
{
  // Construct indent
  char indent[4096] = { '\0' };
  for (int i = 0; i < level; i++) {
    strcat(indent, "  ");
  }

  // Print reference stuff
  const R3Scene *referenced_scene = reference->ReferencedScene();
  const char *name = (referenced_scene) ? referenced_scene->Root()->Name() : NULL;
  const char *filename = (referenced_scene) ? referenced_scene->Filename() : NULL;
  printf("%sReference %d\n", indent, index);
  if (name) printf("%s  Name = %s\n", indent, name);
  if (filename) printf("%s  Filename = %s\n", indent, filename);
  printf("%s  # Materials = %d\n", indent, reference->NMaterials());
  for (int i = 0; i < reference->NMaterials(); i++) {
    R3Material *material = reference->Material(i);
    const R3Brdf *brdf = (material) ? material->Brdf() : NULL;
    const R2Texture *texture = (material) ? material->Texture() : NULL;
    RNRgb diffuse = (brdf) ? brdf->Diffuse() : RNRgb(0.5, 0.5, 0.5);
    const char *texture_name = (texture) ? texture->Name() : "None";
    printf("%s    %d (%g %g %g) %s\n", indent, i, diffuse.R(), diffuse.G(), diffuse.B(), texture_name);
  } 
  printf("\n");

  // Return success
  return 1;
}

// Assembly:
subq $0x10d8, %rsp           # imm = 0x10D8
movq %rdi, 0x10d0(%rsp)
movl %esi, 0x10cc(%rsp)
movl %edx, 0x10c8(%rsp)
leaq 0xc0(%rsp), %rdi
xorl %esi, %esi
movl $0x1000, %edx           # imm = 0x1000
callq 0x224b0
movl $0x0, 0xbc(%rsp)
movl 0xbc(%rsp), %eax
cmpl 0x10c8(%rsp), %eax
jge 0x29593
leaq 0xc0(%rsp), %rdi
leaq 0x1662e6(%rip), %rsi    # 0x18f861
callq 0x23230
movl 0xbc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xbc(%rsp)
jmp 0x2955c
movq 0x10d0(%rsp), %rdi
callq 0x2aab0
movq %rax, 0xb0(%rsp)
cmpq $0x0, 0xb0(%rsp)
je 0x295cf
movq 0xb0(%rsp), %rdi
callq 0x29b30
movq %rax, %rdi
callq 0x29c60
movq %rax, 0x58(%rsp)
jmp 0x295d8
xorl %eax, %eax
movq %rax, 0x58(%rsp)
jmp 0x295d8
movq 0x58(%rsp), %rax
movq %rax, 0xa8(%rsp)
cmpq $0x0, 0xb0(%rsp)
je 0x29604
movq 0xb0(%rsp), %rdi
callq 0x2aac0
movq %rax, 0x50(%rsp)
jmp 0x2960d
xorl %eax, %eax
movq %rax, 0x50(%rsp)
jmp 0x2960d
movq 0x50(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xc0(%rsp), %rsi
movl 0x10cc(%rsp), %edx
leaq 0x162e0a(%rip), %rdi    # 0x18c43a
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0xa8(%rsp)
je 0x29660
leaq 0xc0(%rsp), %rsi
movq 0xa8(%rsp), %rdx
leaq 0x162df1(%rip), %rdi    # 0x18c44a
movb $0x0, %al
callq 0x22090
cmpq $0x0, 0xa0(%rsp)
je 0x29689
leaq 0xc0(%rsp), %rsi
movq 0xa0(%rsp), %rdx
leaq 0x162dd7(%rip), %rdi    # 0x18c459
movb $0x0, %al
callq 0x22090
leaq 0xc0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x10d0(%rsp), %rdi
callq 0x2aae0
movq 0x48(%rsp), %rsi
movl %eax, %edx
leaq 0x162dbb(%rip), %rdi    # 0x18c46c
movb $0x0, %al
callq 0x22090
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0x44(%rsp)
movq 0x10d0(%rsp), %rdi
callq 0x2aae0
movl %eax, %ecx
movl 0x44(%rsp), %eax
cmpl %ecx, %eax
jge 0x29868
movq 0x10d0(%rsp), %rdi
movl 0x9c(%rsp), %esi
callq 0x2ab00
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x29724
movq 0x90(%rsp), %rdi
callq 0x2ab30
movq %rax, 0x38(%rsp)
jmp 0x2972d
xorl %eax, %eax
movq %rax, 0x38(%rsp)
jmp 0x2972d
movq 0x38(%rsp), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x29759
movq 0x90(%rsp), %rdi
callq 0x2ab40
movq %rax, 0x30(%rsp)
jmp 0x29762
xorl %eax, %eax
movq %rax, 0x30(%rsp)
jmp 0x29762
movq 0x30(%rsp), %rax
movq %rax, 0x80(%rsp)
cmpq $0x0, 0x88(%rsp)
je 0x29796
movq 0x88(%rsp), %rdi
callq 0x2ab50
movq %rax, %rsi
leaq 0x68(%rsp), %rdi
callq 0xed170
jmp 0x297ae
leaq 0x68(%rsp), %rdi
movsd 0x16286d(%rip), %xmm2   # 0x18c010
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0xed1b0
cmpq $0x0, 0x80(%rsp)
je 0x297cd
movq 0x80(%rsp), %rdi
callq 0x2ab60
movq %rax, 0x28(%rsp)
jmp 0x297db
leaq 0x162a3f(%rip), %rax    # 0x18c213
movq %rax, 0x28(%rsp)
jmp 0x297db
movq 0x28(%rsp), %rax
movq %rax, 0x60(%rsp)
leaq 0xc0(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x9c(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2ab70
movsd %xmm0, 0x20(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2ab80
movsd %xmm0, 0x18(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x2ab90
movq 0x8(%rsp), %rsi
movl 0x14(%rsp), %edx
movsd 0x18(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
movq 0x60(%rsp), %rcx
leaq 0x162c37(%rip), %rdi    # 0x18c482
movb $0x3, %al
callq 0x22090
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x296c3
leaq 0x169e93(%rip), %rdi    # 0x193702
movb $0x0, %al
callq 0x22090
movl $0x1, %eax
addq $0x10d8, %rsp           # imm = 0x10D8
retq
nopw %cs:(%rax,%rax)
nopl (%rax)