// File: tomfunkhouser[P]gaps/apps/scnview/scnview.cpp
// Function: ReadCameras(char const*)
static RNArray<R3Camera *> *
ReadCameras(const char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Get useful variables
  RNScalar neardist = 0.01 * scene->BBox().DiagonalRadius();
  RNScalar fardist = 100 * scene->BBox().DiagonalRadius();

  // Allocate array of cameras
  RNArray<R3Camera *> *cameras = new RNArray<R3Camera *>();
  if (!cameras) {
    RNFail("Unable to allocate cameras for %s\n", filename);
    return NULL;
  }

  // Open file
  FILE *fp = fopen(filename, "r");
  if (!fp) {
    RNFail("Unable to open cameras file %s\n", filename);
    delete cameras;
    return NULL;
  }

  // Read file
  RNScalar vx, vy, vz, tx, ty, tz, ux, uy, uz, xf, yf, value;
  while (fscanf(fp, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &vx, &vy, &vz, &tx, &ty, &tz, &ux, &uy, &uz, &xf, &yf, &value) == (unsigned int) 12) {
    R3Point viewpoint(vx, vy, vz);
    R3Vector towards(tx, ty, tz);
    R3Vector up(ux, uy, uz);
    R3Vector right = towards % up;
    towards.Normalize();
    up = right % towards;
    up.Normalize();
    R3Camera *camera = new R3Camera(viewpoint, towards, up, xf, yf, neardist, fardist);
    camera->SetValue(value);
    cameras->Insert(camera);
  }

  // Close file
  fclose(fp);

  // Print statistics
  if (print_verbose) {
    printf("Read cameras from %s ...\n", filename);
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  # Cameras = %d\n", cameras->NEntries());
    fflush(stdout);
  }

  // Return success
  return cameras;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rdi, 0x1b0(%rsp)
leaq 0x1a0(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0xeeb80
movq 0x80(%rsp), %rdi
callq 0x2b680
movq 0x1d1557(%rip), %rdi    # 0x1fbc18
callq 0x2b590
movq %rax, %rdi
callq 0x2b5b0
movsd 0x163962(%rip), %xmm1   # 0x18e038
mulsd %xmm1, %xmm0
movsd %xmm0, 0x198(%rsp)
movq 0x1d152e(%rip), %rdi    # 0x1fbc18
callq 0x2b590
movq %rax, %rdi
callq 0x2b5b0
movsd 0x163931(%rip), %xmm1   # 0x18e030
mulsd %xmm1, %xmm0
movsd %xmm0, 0x190(%rsp)
movl $0x10, %edi
callq 0x229e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x88(%rsp)
callq 0x2c0a0
jmp 0x2a72b
movq 0x88(%rsp), %rax
movq %rax, 0x188(%rsp)
cmpq $0x0, 0x188(%rsp)
jne 0x2a798
movq 0x1b0(%rsp), %rsi
leaq 0x163d86(%rip), %rdi    # 0x18e4db
movb $0x0, %al
callq 0xf3b00
movq $0x0, 0x1b8(%rsp)
jmp 0x2aad3
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
movl $0x10, %esi
callq 0x22a00
jmp 0x2aaec
movq 0x1b0(%rsp), %rdi
leaq 0x16aafc(%rip), %rsi    # 0x1952a3
callq 0x22c10
movq %rax, 0x170(%rsp)
cmpq $0x0, 0x170(%rsp)
jne 0x2a812
movq 0x1b0(%rsp), %rsi
leaq 0x163d30(%rip), %rdi    # 0x18e4fe
movb $0x0, %al
callq 0xf3b00
movq 0x188(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
je 0x2a801
movq 0x78(%rsp), %rdi
callq 0x2c0b0
movq 0x78(%rsp), %rdi
movl $0x10, %esi
callq 0x22a00
movq $0x0, 0x1b8(%rsp)
jmp 0x2aad3
jmp 0x2a814
movq 0x170(%rsp), %rdi
leaq 0x16415c(%rip), %rsi    # 0x18e97f
leaq 0x168(%rsp), %rdx
leaq 0x160(%rsp), %rcx
leaq 0x158(%rsp), %r8
leaq 0x150(%rsp), %r9
leaq 0x148(%rsp), %r13
leaq 0x140(%rsp), %r12
leaq 0x138(%rsp), %r15
leaq 0x130(%rsp), %r14
leaq 0x128(%rsp), %rbx
leaq 0x120(%rsp), %r11
leaq 0x118(%rsp), %r10
leaq 0x110(%rsp), %rax
movq %r13, (%rsp)
movq %r12, 0x8(%rsp)
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq %rbx, 0x20(%rsp)
movq %r11, 0x28(%rsp)
movq %r10, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movb $0x0, %al
callq 0x23370
cmpl $0xc, %eax
jne 0x2aa50
movsd 0x168(%rsp), %xmm0
movsd 0x160(%rsp), %xmm1
movsd 0x158(%rsp), %xmm2
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0xcc870
movsd 0x150(%rsp), %xmm0
movsd 0x148(%rsp), %xmm1
movsd 0x140(%rsp), %xmm2
leaq 0xe0(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xcd9d0
movsd 0x138(%rsp), %xmm0
movsd 0x130(%rsp), %xmm1
movsd 0x128(%rsp), %xmm2
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xcd9d0
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xce810
movq 0x60(%rsp), %rdi
callq 0xce130
movq 0x48(%rsp), %rsi
movq 0x60(%rsp), %rdx
leaq 0x98(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xce810
movq 0x50(%rsp), %rsi
movq 0x68(%rsp), %rdi
callq 0xce690
movq 0x68(%rsp), %rdi
callq 0xce130
movl $0x90, %edi
callq 0x229e0
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x70(%rsp)
movsd 0x120(%rsp), %xmm0
movsd 0x118(%rsp), %xmm1
movsd 0x198(%rsp), %xmm2
movsd 0x190(%rsp), %xmm3
callq 0x5d920
jmp 0x2a9eb
movq 0x70(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rdi
movsd 0x110(%rsp), %xmm0
callq 0x2c0c0
movq 0x188(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x2c0e0
jmp 0x2a814
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x180(%rsp)
movl %eax, 0x17c(%rsp)
movl $0x90, %esi
callq 0x22a00
jmp 0x2aaec
movq 0x170(%rsp), %rdi
callq 0x229d0
cmpl $0x0, 0x1d12c4(%rip)    # 0x1fbd28
je 0x2aac3
movq 0x1b0(%rsp), %rsi
leaq 0x163aa9(%rip), %rdi    # 0x18e51e
movb $0x0, %al
callq 0x22090
leaq 0x1a0(%rsp), %rdi
callq 0xeec40
leaq 0x1639c0(%rip), %rdi    # 0x18e450
movb $0x1, %al
callq 0x22090
movq 0x188(%rsp), %rdi
callq 0x2b8b0
movl %eax, %esi
leaq 0x163a8b(%rip), %rdi    # 0x18e538
movb $0x0, %al
callq 0x22090
movq 0x1ca4d5(%rip), %rax    # 0x1f4f90
movq (%rax), %rdi
callq 0x22c00
movq 0x188(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
movq 0x180(%rsp), %rdi
callq 0x23290
nopl (%rax)