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

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

  // Write file
  for (int i = 0; i < cameras.NEntries(); i++) {
    Camera *camera = cameras.Kth(i);
    const R3CoordSystem& cs = camera->CoordSystem();
    R4Matrix matrix = cs.Matrix();
    fprintf(fp, "%g %g %g %g   %g %g %g %g  %g %g %g %g\n",
      matrix[0][0], matrix[0][1], matrix[0][2], matrix[0][3], 
      matrix[1][0], matrix[1][1], matrix[1][2], matrix[1][3], 
      matrix[2][0], matrix[2][1], matrix[2][2], matrix[2][3]);
  }

  // Close file
  fclose(fp);

  // Print statistics
  if (print_verbose) {
    printf("Wrote camera extrinsics 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 $0x148, %rsp            # imm = 0x148
movq %rdi, 0x138(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x11bad0
leaq 0x128(%rsp), %rdi
callq 0x321a0
movq 0x138(%rsp), %rdi
leaq 0x18cfe2(%rip), %rsi    # 0x1be97a
callq 0x23bd0
movq %rax, 0x120(%rsp)
cmpq $0x0, 0x120(%rsp)
jne 0x319d6
movq 0x138(%rsp), %rsi
leaq 0x189ec3(%rip), %rdi    # 0x1bb882
movb $0x0, %al
callq 0x120a50
movl $0x0, 0x144(%rsp)
jmp 0x31cac
movl $0x0, 0x11c(%rsp)
movl 0x11c(%rsp), %eax
movl %eax, 0x84(%rsp)
leaq 0x1fe18a(%rip), %rdi    # 0x22fb80
callq 0x32280
movl %eax, %ecx
movl 0x84(%rsp), %eax
cmpl %ecx, %eax
jge 0x31c2f
movl 0x11c(%rsp), %esi
leaq 0x1fe166(%rip), %rdi    # 0x22fb80
callq 0x36c40
movq %rax, 0x110(%rsp)
movq 0x110(%rsp), %rdi
callq 0x36d30
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xd02e0
movq 0x120(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x36d40
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x36d40
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x36d40
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x88(%rsp), %rdi
xorl %esi, %esi
callq 0x36d40
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x36d40
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x36d40
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x36d40
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x1, %esi
callq 0x36d40
movsd 0x18(%rax), %xmm0
movsd %xmm0, 0x60(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x36d40
movsd (%rax), %xmm0
movsd %xmm0, 0x68(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x36d40
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x36d40
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x78(%rsp)
leaq 0x88(%rsp), %rdi
movl $0x2, %esi
callq 0x36d40
movq 0x20(%rsp), %rdi
movsd 0x28(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0x40(%rsp), %xmm3
movsd 0x48(%rsp), %xmm4
movsd 0x50(%rsp), %xmm5
movsd 0x58(%rsp), %xmm6
movsd 0x60(%rsp), %xmm7
movsd 0x68(%rsp), %xmm11
movsd 0x70(%rsp), %xmm10
movsd 0x78(%rsp), %xmm9
movsd 0x18(%rax), %xmm8
leaq 0x189cb5(%rip), %rsi    # 0x1bb8ac
movsd %xmm11, (%rsp)
movsd %xmm10, 0x8(%rsp)
movsd %xmm9, 0x10(%rsp)
movsd %xmm8, 0x18(%rsp)
movb $0x8, %al
callq 0x23f00
movl 0x11c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x11c(%rsp)
jmp 0x319e1
movq 0x120(%rsp), %rdi
callq 0x239a0
cmpl $0x0, 0x1fdf71(%rip)    # 0x22fbb4
je 0x31ca1
movq 0x138(%rsp), %rsi
leaq 0x189c80(%rip), %rdi    # 0x1bb8d4
movb $0x0, %al
callq 0x23090
leaq 0x128(%rsp), %rdi
callq 0x11bb90
leaq 0x1897cb(%rip), %rdi    # 0x1bb43a
movb $0x1, %al
callq 0x23090
leaq 0x1fdf03(%rip), %rdi    # 0x22fb80
callq 0x32280
movl %eax, %esi
leaq 0x189874(%rip), %rdi    # 0x1bb4ff
movb $0x0, %al
callq 0x23090
movq 0x1f72f7(%rip), %rax    # 0x228f90
movq (%rax), %rdi
callq 0x23bc0
movl $0x1, 0x144(%rsp)
movl 0x144(%rsp), %eax
addq $0x148, %rsp            # imm = 0x148
retq
nopl (%rax,%rax)