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

  // Get pdb bounding box
  R3Box bbox = grid->GridBox();
  assert(!bbox.IsEmpty());
  RNLength r = bbox.DiagonalRadius();
  assert((r > 0.0) && RNIsFinite(r));

  // Setup camera view looking down the Z axis
  if (!initial_camera) initial_camera_origin = bbox.Centroid() - initial_camera_towards * (2.5 * r);;
  R3Camera camera(initial_camera_origin, initial_camera_towards, initial_camera_up, 0.4, 0.4, 0.1 * r, 1000.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 $0x238, %rsp            # imm = 0x238
movq %rdi, 0x230(%rsp)
leaq 0x220(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0xe8e20
movq 0x80(%rsp), %rdi
callq 0x27020
movq 0x230(%rsp), %rsi
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0x26cd0
movq 0x88(%rsp), %rdi
callq 0x27250
movsd %xmm0, 0x90(%rsp)
jmp 0x264a6
movsd 0x90(%rsp), %xmm0
movsd %xmm0, 0x1e0(%rsp)
cmpl $0x0, 0x19be55(%rip)    # 0x1c2314
jne 0x26557
leaq 0x1a0(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x38ee0
jmp 0x264dc
movsd 0x1e0(%rsp), %xmm0
movsd 0x138b73(%rip), %xmm1   # 0x15f060
mulsd %xmm1, %xmm0
leaq 0x19bd00(%rip), %rsi    # 0x1c21f8
leaq 0x188(%rsp), %rdi
callq 0x65c00
jmp 0x26507
leaq 0x1b8(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x188(%rsp), %rdx
callq 0x64b30
jmp 0x26526
leaq 0x19bcb3(%rip), %rdi    # 0x1c21e0
leaq 0x1b8(%rsp), %rsi
callq 0x64260
jmp 0x2653c
jmp 0x26557
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d8(%rsp)
movl %eax, 0x1d4(%rsp)
jmp 0x268bf
movsd 0x1e0(%rsp), %xmm3
movsd 0x138b00(%rip), %xmm0   # 0x15f068
movaps %xmm3, %xmm2
mulsd %xmm0, %xmm2
movsd 0x138af9(%rip), %xmm0   # 0x15f070
mulsd %xmm0, %xmm3
leaq 0x19bc5e(%rip), %rsi    # 0x1c21e0
leaq 0x19bc6f(%rip), %rdx    # 0x1c21f8
leaq 0x19bc80(%rip), %rcx    # 0x1c2210
leaq 0xf8(%rsp), %rdi
movsd 0x138ad8(%rip), %xmm1   # 0x15f078
movaps %xmm1, %xmm0
callq 0x2aaf0
jmp 0x265aa
movl 0x18d32c(%rip), %ecx    # 0x1b38dc
movl 0x18d329(%rip), %r8d    # 0x1b38e0
leaq 0xe8(%rsp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x2c160
jmp 0x265ca
movl $0xa8, %edi
callq 0x207d0
movq %rax, 0x78(%rsp)
jmp 0x265db
movq 0x78(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0xe8(%rsp), %rdx
callq 0x27370
jmp 0x265f7
movq 0x78(%rsp), %rax
movq %rax, 0xe0(%rsp)
cmpl $0x0, 0x19bd05(%rip)    # 0x1c2310
je 0x2689a
leaq 0x138e19(%rip), %rdi    # 0x15f431
xorl %eax, %eax
callq 0x20070
jmp 0x26621
leaq 0x220(%rsp), %rdi
callq 0xe8ee0
movsd %xmm0, 0x70(%rsp)
jmp 0x26636
movsd 0x70(%rsp), %xmm0
leaq 0x138d33(%rip), %rdi    # 0x15f376
movb $0x1, %al
callq 0x20070
jmp 0x2664c
leaq 0xf8(%rsp), %rdi
callq 0x26da0
movq %rax, 0x68(%rsp)
jmp 0x26660
movq 0x68(%rsp), %rdi
callq 0x26db0
movsd %xmm0, 0x58(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x26da0
movq %rax, 0x60(%rsp)
jmp 0x26684
movq 0x60(%rsp), %rdi
callq 0x26dc0
movsd %xmm0, 0x48(%rsp)
leaq 0xf8(%rsp), %rdi
callq 0x26da0
movq %rax, 0x50(%rsp)
jmp 0x266a8
movq 0x50(%rsp), %rdi
callq 0x26dd0
movsd 0x48(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x58(%rsp), %xmm0
leaq 0x138d7d(%rip), %rdi    # 0x15f445
movb $0x3, %al
callq 0x20070
jmp 0x266d1
leaq 0xc8(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x26de0
jmp 0x266e8
leaq 0xc8(%rsp), %rdi
callq 0x26e30
movsd %xmm0, 0x40(%rsp)
leaq 0xb0(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x26de0
jmp 0x26712
leaq 0xb0(%rsp), %rdi
callq 0x26e40
movsd %xmm0, 0x38(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0x26de0
jmp 0x2673c
leaq 0x98(%rsp), %rdi
callq 0x26e50
movsd 0x38(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x40(%rsp), %xmm0
leaq 0x138cfb(%rip), %rdi    # 0x15f45a
movb $0x3, %al
callq 0x20070
jmp 0x26768
leaq 0xf8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x26e60
movq %rax, %rdi
callq 0x26e30
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x30(%rsp)
callq 0x26e60
movq %rax, %rdi
callq 0x26e40
movq 0x20(%rsp), %rdi
movsd %xmm0, 0x28(%rsp)
callq 0x26e60
movq %rax, %rdi
callq 0x26e50
movsd 0x28(%rsp), %xmm1
movaps %xmm0, %xmm2
movsd 0x30(%rsp), %xmm0
leaq 0x138ca8(%rip), %rdi    # 0x15f470
movb $0x3, %al
callq 0x20070
jmp 0x267d1
leaq 0xf8(%rsp), %rdi
callq 0x27270
movsd %xmm0, 0x18(%rsp)
jmp 0x267e6
leaq 0xf8(%rsp), %rdi
callq 0x26e80
movaps %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
leaq 0x138c7e(%rip), %rdi    # 0x15f481
movb $0x2, %al
callq 0x20070
jmp 0x2680c
leaq 0xf8(%rsp), %rdi
callq 0x27280
movsd %xmm0, 0x10(%rsp)
jmp 0x26821
movsd 0x10(%rsp), %xmm0
leaq 0x138c62(%rip), %rdi    # 0x15f490
movb $0x1, %al
callq 0x20070
jmp 0x26837
leaq 0xf8(%rsp), %rdi
callq 0x27290
movsd %xmm0, 0x8(%rsp)
jmp 0x2684c
movsd 0x8(%rsp), %xmm0
leaq 0x138c44(%rip), %rdi    # 0x15f49d
movb $0x1, %al
callq 0x20070
jmp 0x26862
movq 0x18c727(%rip), %rax    # 0x1b2f90
movq (%rax), %rdi
callq 0x20980
jmp 0x26873
jmp 0x2689a
movq 0x78(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d8(%rsp)
movl %eax, 0x1d4(%rsp)
movl $0xa8, %esi
callq 0x207f0
jmp 0x268bf
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x1e8(%rsp), %rdi
callq 0x26bf0
movq (%rsp), %rax
addq $0x238, %rsp            # imm = 0x238
retq
leaq 0x1e8(%rsp), %rdi
callq 0x26bf0
movq 0x1d8(%rsp), %rdi
callq 0x20ee0
nopl (%rax)