// File: tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: ReadScene(char*)
static R3Scene *
ReadScene(char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Allocate scene
  R3Scene *scene = new R3Scene();
  if (!scene) {
    RNFail("Unable to allocate scene for %s\n", filename);
    return NULL;
  }

  // Read scene from file
  if (!scene->ReadFile(filename)) {
    delete scene;
    return NULL;
  }

  // Process scene
  if (remove_references) scene->RemoveReferences();
  if (remove_transformations) scene->RemoveTransformations();
  if (remove_hierarchy) scene->RemoveHierarchy();
  if (max_vertex_spacing > 0) scene->SubdivideTriangles(max_vertex_spacing);

  // Print statistics
  if (print_verbose) {
    printf("Read scene from %s ...\n", filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Nodes = %d\n", scene->NNodes());
    printf("  # Lights = %d\n", scene->NLights());
    printf("  # Materials = %d\n", scene->NMaterials());
    printf("  # Brdfs = %d\n", scene->NBrdfs());
    printf("  # Textures = %d\n", scene->NTextures());
    printf("  # Referenced scenes = %d\n", scene->NReferencedScenes());
    fflush(stdout);
  }

  // Return scene
  return scene;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x48(%rsp)
leaq 0x38(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xeeb80
movq 0x10(%rsp), %rdi
callq 0x2b680
movl $0x160, %edi            # imm = 0x160
callq 0x229e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
callq 0x2c260
jmp 0x2a47e
movq 0x18(%rsp), %rax
movq %rax, 0x30(%rsp)
cmpq $0x0, 0x30(%rsp)
jne 0x2a4d3
movq 0x48(%rsp), %rsi
leaq 0x163f7b(%rip), %rdi    # 0x18e417
movb $0x0, %al
callq 0xf3b00
movq $0x0, 0x50(%rsp)
jmp 0x2a66b
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
movl $0x160, %esi            # imm = 0x160
callq 0x22a00
jmp 0x2a675
movq 0x30(%rsp), %rdi
movq 0x48(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x2e8c0
cmpl $0x0, %eax
jne 0x2a522
movq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x2a514
movq 0x8(%rsp), %rdi
callq 0x2c4e0
movq 0x8(%rsp), %rdi
movl $0x160, %esi            # imm = 0x160
callq 0x22a00
movq $0x0, 0x50(%rsp)
jmp 0x2a66b
cmpl $0x0, 0x1d1803(%rip)    # 0x1fbd2c
je 0x2a535
movq 0x30(%rsp), %rdi
callq 0x2d290
cmpl $0x0, 0x1d17f8(%rip)    # 0x1fbd34
je 0x2a548
movq 0x30(%rsp), %rdi
callq 0x2d670
cmpl $0x0, 0x1d17e1(%rip)    # 0x1fbd30
je 0x2a55b
movq 0x30(%rsp), %rdi
callq 0x2d470
movsd 0x1d17d5(%rip), %xmm0   # 0x1fbd38
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2a57e
movq 0x30(%rsp), %rdi
movsd 0x1d17bf(%rip), %xmm0   # 0x1fbd38
callq 0x2d880
cmpl $0x0, 0x1d17a3(%rip)    # 0x1fbd28
je 0x2a661
movq 0x48(%rsp), %rsi
leaq 0x163ea1(%rip), %rdi    # 0x18e438
movb $0x0, %al
callq 0x22090
leaq 0x38(%rsp), %rdi
callq 0xeec40
leaq 0x163ea1(%rip), %rdi    # 0x18e450
movb $0x1, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2bf50
movl %eax, %esi
leaq 0x163e9e(%rip), %rdi    # 0x18e467
movb $0x0, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2b9f0
movl %eax, %esi
leaq 0x163e94(%rip), %rdi    # 0x18e477
movb $0x0, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2c020
movl %eax, %esi
leaq 0x163e8b(%rip), %rdi    # 0x18e488
movb $0x0, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2c040
movl %eax, %esi
leaq 0x163e85(%rip), %rdi    # 0x18e49c
movb $0x0, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2c060
movl %eax, %esi
leaq 0x163e7b(%rip), %rdi    # 0x18e4ac
movb $0x0, %al
callq 0x22090
movq 0x30(%rsp), %rdi
callq 0x2c080
movl %eax, %esi
leaq 0x163e74(%rip), %rdi    # 0x18e4bf
movb $0x0, %al
callq 0x22090
movq 0x1ca937(%rip), %rax    # 0x1f4f90
movq (%rax), %rdi
callq 0x22c00
movq 0x30(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
addq $0x58, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x23290
nop