// File: tomfunkhouser[P]gaps/apps/gapsview/gapsview.cpp
// Function: CreateViewer()
static R3Viewer *
CreateViewer(void)
{
  // Start statistics
  RNTime start_time;
  start_time.Read();

  // Get bounding box radius
  assert(!world_bbox.IsEmpty());
  RNLength r = world_bbox.DiagonalRadius();
  assert((r > 0.0) && RNIsFinite(r));

  // Setup camera view looking down the Z axis
  if (!initial_camera) initial_camera_origin = world_bbox.Centroid() - initial_camera_towards * (2.5 * r);;
  R3Camera camera(initial_camera_origin, initial_camera_towards, initial_camera_up, 0.4, 0.4, 0.01 * r, 100.0 * r);
  R2Viewport viewport(0, 0, GLUTwindow_width, GLUTwindow_height);
  R3Viewer *viewer = new R3Viewer(camera, viewport);

  // Print statistics
  if (print_verbose) {
    printf("Created viewer ...\n");
    printf("  Time = %.2f seconds\n", start_time.Elapsed());
    printf("  Origin = %g %g %g\n", camera.Origin().X(), camera.Origin().Y(), camera.Origin().Z());
    printf("  Towards = %g %g %g\n", camera.Towards().X(), camera.Towards().Y(), camera.Towards().Z());
    printf("  Up = %g %g %g\n", camera.Up().X(), camera.Up().Y(), camera.Up().Z());
    printf("  Fov = %g %g\n", camera.XFOV(), camera.YFOV());
    printf("  Near = %g\n", camera.Near());
    printf("  Far = %g\n", camera.Far());
    fflush(stdout);
  }

  // Return viewer
  return viewer;
}

// Assembly:
subq $0x1b8, %rsp            # imm = 0x1B8
leaq 0x1a8(%rsp), %rdi
callq 0x1c7070
leaq 0x1a8(%rsp), %rdi
callq 0x38bc0
leaq 0x2cff60(%rip), %rdi    # 0x2fe838
callq 0x38be0
movsd %xmm0, 0x1a0(%rsp)
cmpl $0x0, 0x2d03cb(%rip)    # 0x2fecb8
jne 0x2e959
leaq 0x170(%rsp), %rdi
leaq 0x2cff3a(%rip), %rsi    # 0x2fe838
callq 0x153430
movsd 0x23771d(%rip), %xmm0   # 0x266028
mulsd 0x1a0(%rsp), %xmm0
leaq 0x158(%rsp), %rdi
leaq 0x2cfe85(%rip), %rsi    # 0x2fe7a8
callq 0x181dc0
leaq 0x188(%rsp), %rdi
leaq 0x170(%rsp), %rsi
leaq 0x158(%rsp), %rdx
callq 0x180cf0
leaq 0x2cfe44(%rip), %rdi    # 0x2fe790
leaq 0x188(%rsp), %rsi
callq 0x180420
movsd 0x1a0(%rsp), %xmm3
movsd 0x2376c6(%rip), %xmm0   # 0x266030
movaps %xmm3, %xmm2
mulsd %xmm0, %xmm2
movsd 0x2376bf(%rip), %xmm0   # 0x266038
mulsd %xmm0, %xmm3
leaq 0x2cfe0c(%rip), %rsi    # 0x2fe790
leaq 0x2cfe1d(%rip), %rdx    # 0x2fe7a8
leaq 0x2cfe2e(%rip), %rcx    # 0x2fe7c0
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movsd 0x237699(%rip), %xmm1   # 0x266040
movaps %xmm1, %xmm0
callq 0xedc30
movl 0x2c113b(%rip), %ecx    # 0x2efaf0
movl 0x2c1138(%rip), %r8d    # 0x2efaf4
leaq 0xb8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
xorl %edx, %edx
movl %edx, %esi
callq 0xef140
movl $0xa8, %edi
callq 0x292e0
movq 0x40(%rsp), %rsi
movq 0x48(%rsp), %rdx
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x50(%rsp)
callq 0xea630
jmp 0x2e9f8
movq 0x50(%rsp), %rax
movq %rax, 0xb0(%rsp)
cmpl $0x0, 0x2d02b0(%rip)    # 0x2fecbc
je 0x2ec31
leaq 0x23799b(%rip), %rdi    # 0x2663b4
movb $0x0, %al
callq 0x290f0
leaq 0x1a8(%rsp), %rdi
callq 0x1c7130
leaq 0x237994(%rip), %rdi    # 0x2663c8
movb $0x1, %al
callq 0x290f0
leaq 0xc8(%rsp), %rdi
callq 0x38c00
movq %rax, %rdi
callq 0x38bb0
movsd %xmm0, 0x10(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x38c00
movq %rax, %rdi
callq 0x38c10
movsd %xmm0, 0x8(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x38c00
movq %rax, %rdi
callq 0x38c20
movsd 0x8(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
leaq 0x237943(%rip), %rdi    # 0x2663df
movb $0x3, %al
callq 0x290f0
leaq 0x88(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x38c30
leaq 0x88(%rsp), %rdi
callq 0x38c80
movsd %xmm0, 0x20(%rsp)
leaq 0x70(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x38c30
leaq 0x70(%rsp), %rdi
callq 0x38c90
movsd %xmm0, 0x18(%rsp)
leaq 0x58(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x38c30
leaq 0x58(%rsp), %rdi
callq 0x38ca0
movsd 0x18(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x20(%rsp), %xmm0
leaq 0x2378d5(%rip), %rdi    # 0x2663f4
movb $0x3, %al
callq 0x290f0
leaq 0xc8(%rsp), %rdi
callq 0x38cb0
movq %rax, %rdi
callq 0x38c80
movsd %xmm0, 0x30(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x38cb0
movq %rax, %rdi
callq 0x38c90
movsd %xmm0, 0x28(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x38cb0
movq %rax, %rdi
callq 0x38ca0
movsd 0x28(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
leaq 0x237883(%rip), %rdi    # 0x26640a
movb $0x3, %al
callq 0x290f0
leaq 0xc8(%rsp), %rdi
callq 0x38cd0
movsd %xmm0, 0x38(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x38ce0
movaps %xmm0, %xmm1
movsd 0x38(%rsp), %xmm0
leaq 0x23785d(%rip), %rdi    # 0x26641b
movb $0x2, %al
callq 0x290f0
leaq 0xc8(%rsp), %rdi
callq 0x38cf0
leaq 0x237851(%rip), %rdi    # 0x26642a
movb $0x1, %al
callq 0x290f0
leaq 0xc8(%rsp), %rdi
callq 0x38d00
leaq 0x237843(%rip), %rdi    # 0x266437
movb $0x1, %al
callq 0x290f0
movq 0x2c03c6(%rip), %rax    # 0x2eefc8
movq (%rax), %rdi
callq 0x29910
jmp 0x2ec31
movq 0x50(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
movl $0xa8, %esi
callq 0x291f0
jmp 0x2ec41
movq 0xb0(%rsp), %rax
addq $0x1b8, %rsp            # imm = 0x1B8
retq
movq 0xa8(%rsp), %rdi
callq 0x29c10
nop