// File: tomfunkhouser[P]gaps/apps/scn2cam/scn2cam.cpp
// Function: WriteCameras(char const*)
static int
WriteCameras(const char *filename)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

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

  // Write file
  for (int i = 0; i < cameras.NEntries(); i++) {
    Camera *camera = cameras.Kth(i);
    R3Point eye = camera->Origin();
    R3Vector towards = camera->Towards();
    R3Vector up = camera->Up();
    fprintf(fp, "%g %g %g  %g %g %g  %g %g %g  %g %g  %g\n",
      eye.X(), eye.Y(), eye.Z(),
      towards.X(), towards.Y(), towards.Z(),
      up.X(), up.Y(), up.Z(),
      camera->XFOV(), camera->YFOV(),
      camera->Value());
  }

  // Close file
  fclose(fp);

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

  // Return success
  return 1;
}

// Assembly:
subq $0x108, %rsp            # imm = 0x108
movq %rdi, 0xf8(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x11bad0
leaq 0xe8(%rsp), %rdi
callq 0x321a0
movq 0xf8(%rsp), %rdi
leaq 0x18d302(%rip), %rsi    # 0x1be97a
callq 0x23bd0
movq %rax, 0xe0(%rsp)
cmpq $0x0, 0xe0(%rsp)
jne 0x316b6
movq 0xf8(%rsp), %rsi
leaq 0x189e26(%rip), %rdi    # 0x1bb4c5
movb $0x0, %al
callq 0x120a50
movl $0x0, 0x104(%rsp)
jmp 0x3194b
movl $0x0, 0xdc(%rsp)
movl 0xdc(%rsp), %eax
movl %eax, 0x84(%rsp)
leaq 0x1fe4aa(%rip), %rdi    # 0x22fb80
callq 0x32280
movl %eax, %ecx
movl 0x84(%rsp), %eax
cmpl %ecx, %eax
jge 0x318ce
movl 0xdc(%rsp), %esi
leaq 0x1fe486(%rip), %rdi    # 0x22fb80
callq 0x36c40
movq %rax, 0xd0(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x332f0
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0xd9f80
movq 0xd0(%rsp), %rsi
leaq 0xa0(%rsp), %rdi
callq 0x34a10
movq 0xd0(%rsp), %rdi
callq 0x34a60
movq %rax, %rsi
leaq 0x88(%rsp), %rdi
callq 0xdb0e0
movq 0xe0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x34870
movsd %xmm0, 0x78(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x33190
movsd %xmm0, 0x28(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x34910
movsd %xmm0, 0x30(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x36d00
movsd %xmm0, 0x38(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x36d10
movsd %xmm0, 0x40(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x36d20
movsd %xmm0, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x36d00
movsd %xmm0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x36d10
movsd %xmm0, 0x58(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x36d20
movsd %xmm0, 0x60(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x36c00
movsd %xmm0, 0x68(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x36c10
movsd %xmm0, 0x70(%rsp)
movq 0xd0(%rsp), %rdi
callq 0x32550
movq 0x20(%rsp), %rdi
movsd 0x28(%rsp), %xmm1
movsd 0x30(%rsp), %xmm2
movsd 0x38(%rsp), %xmm3
movsd 0x40(%rsp), %xmm4
movsd 0x48(%rsp), %xmm5
movsd 0x50(%rsp), %xmm6
movsd 0x58(%rsp), %xmm7
movsd 0x60(%rsp), %xmm11
movsd 0x68(%rsp), %xmm10
movsd 0x70(%rsp), %xmm9
movaps %xmm0, %xmm8
movsd 0x78(%rsp), %xmm0
leaq 0x189faa(%rip), %rsi    # 0x1bb840
movsd %xmm11, (%rsp)
movsd %xmm10, 0x8(%rsp)
movsd %xmm9, 0x10(%rsp)
movsd %xmm8, 0x18(%rsp)
movb $0x8, %al
callq 0x23f00
movl 0xdc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xdc(%rsp)
jmp 0x316c1
movq 0xe0(%rsp), %rdi
callq 0x239a0
cmpl $0x0, 0x1fe2d2(%rip)    # 0x22fbb4
je 0x31940
movq 0xf8(%rsp), %rsi
leaq 0x189f76(%rip), %rdi    # 0x1bb869
movb $0x0, %al
callq 0x23090
leaq 0xe8(%rsp), %rdi
callq 0x11bb90
leaq 0x189b2c(%rip), %rdi    # 0x1bb43a
movb $0x1, %al
callq 0x23090
leaq 0x1fe264(%rip), %rdi    # 0x22fb80
callq 0x32280
movl %eax, %esi
leaq 0x189bd5(%rip), %rdi    # 0x1bb4ff
movb $0x0, %al
callq 0x23090
movq 0x1f7658(%rip), %rax    # 0x228f90
movq (%rax), %rdi
callq 0x23bc0
movl $0x1, 0x104(%rsp)
movl 0x104(%rsp), %eax
addq $0x108, %rsp            # imm = 0x108
retq
nopw (%rax,%rax)