// File: /workspace/github_cpp_makefile_star2_O1/tomfunkhouser[P]gaps/pkgs/R3Utils/R3SurfelViewer.cpp
// Function: gaps::R3SurfelViewer::Keyboard(int, int, int, int, int, int)
int R3SurfelViewer::
Keyboard(int x, int y, int key, int shift, int ctrl, int alt)
{
  // Initialize redraw status
  int redraw = 1;

  // Process debugging commands
  if (alt) {
    // Process debugging commands
    switch (key) {
    case 'A':
    case 'a':
      SetAxesVisibility(-1);
      break;
      
    case 'B':
      SetNodeBBoxVisibility(-1);
      break;

    case 'b':
      SetObjectOrientedBBoxVisibility(-1);
      break;

    case 'C':
      SetSurfelColorScheme((surfel_color_scheme + 1) % R3_SURFEL_VIEWER_NUM_COLOR_SCHEMES);
      break;

    case 'c':
      if (SurfelColorScheme() == R3_SURFEL_VIEWER_COLOR_BY_RGB)
        SetSurfelColorScheme(R3_SURFEL_VIEWER_COLOR_BY_ELEVATION);
      else if (SurfelColorScheme() == R3_SURFEL_VIEWER_COLOR_BY_ELEVATION)
        SetSurfelColorScheme(R3_SURFEL_VIEWER_COLOR_BY_OBJECT);
      else if (SurfelColorScheme() == R3_SURFEL_VIEWER_COLOR_BY_OBJECT)
        SetSurfelColorScheme(R3_SURFEL_VIEWER_COLOR_BY_CURRENT_LABEL);
      else SetSurfelColorScheme(R3_SURFEL_VIEWER_COLOR_BY_RGB);
      break;
      
    case 'D':
    case 'd':
      SetImagePointsVisibility(-1);
      SelectImage(selected_image, FALSE, FALSE);
      break;
      
    case 'E':
    case 'e':
      if (shape_draw_flags != 0) shape_draw_flags = 0;
      else shape_draw_flags = R3_SURFEL_DISC_DRAW_FLAG | R3_SURFEL_NORMAL_DRAW_FLAG;
      break;
      
    case 'F':
    case 'f':
      SetBackfacingVisibility(-1);
      break;

    case 'G':
    case 'g':
      if (ElevationRange().IsEmpty()) SetElevationRange(RNInterval(-FLT_MAX, 0.25));
      else SetElevationRange(RNnull_interval);
      break;
      
    case 'I':
      SetImagePlaneVisibility(-1);
      SelectImage(selected_image, FALSE, FALSE);
      break;

    case 'i':
      SetImageInsetVisibility(-1);
      SelectImage(selected_image, FALSE, FALSE);
      break;

    case 'L': 
    case 'l':
      SetHumanLabeledObjectVisibility(-1);
      break;
      
    case 'M':
    case 'm':
      subsampling_multiplier_when_mouse_down = (subsampling_multiplier_when_mouse_down <= 1) ? 8 : 1;
      break;
      
    case 'N':
    case 'n':
      SetNormalVisibility(-1);
      break;
      
    case 'O':
    case 'o':
      SetCenterPointVisibility(-1);
      break;
      
    case 'P':
    case 'p':
      SetSurfelVisibility(-1);
      break;

    case 'R':
    case 'r':
      SetObjectRelationshipVisibility(-1);
      break;

    // case 'S': // Save for toggling "selection" in sfllabel
    // case 's':
    //   break;

    // case 'T': // Reserve for toggling object label text in sfllabel
    // case 't':
    //  break;
      
    case 'V':
    case 'v':
      SetImageViewpointVisibility(-1);
      break;
      
    case 'W':
      UpdateWorkingSet(viewer);
      break;

    case 'w': {
      R3Point pick_position;
      R3SurfelNode *node = PickNode(x, y, &pick_position);
      if (node) SetCenterPoint(pick_position);
      break; }

    case 'X':
    case 'x':
      SetObjectPrincipalAxesVisibility(-1);
      break;
      
    case 'Y':
    case 'y':
      SetScanViewpointVisibility(-1);
      break;
      
    case 'Z':
    case 'z':
      SetViewingExtentVisibility(-1);
      break;
      
    case 'Q':
      // Print info about the currently selected image
      if (selected_image) {
        printf("%s\n", selected_image->Name());
        fflush(stdout);
      }
      break;
        
    case 'q': {
      // Print info about the node clicked
      R3Point pick_position(0,0,0);
      R3SurfelNode *node = PickNode(x, y, &pick_position);
      if (node) {
        SetCenterPoint(pick_position);
        printf("%g %g %g\n", pick_position[0], pick_position[1], pick_position[2]);
        while (node) {
          const char *node_name = (node->Name()) ? node->Name() : "-";
          R3SurfelObject *object = node->Object();
          const char *object_name = (object && (object->Name())) ? object->Name() : "-";
          char object_index[128];
          if (object) sprintf(object_index, "%d", object->SceneIndex());
          else sprintf(object_index, "%s", "-");
          R3SurfelLabel *ground_truth_label = (object) ? object->GroundTruthLabel() : NULL;
          const char *ground_truth_label_name = (ground_truth_label && (ground_truth_label->Name())) ? ground_truth_label->Name() : "-";
          R3SurfelLabel *current_label = (object) ? object->CurrentLabel() : NULL;
          const char *current_label_name = (current_label && (current_label->Name())) ? current_label->Name() : "-";
          printf("  %4d %4d %-30s  :  %-6s %-30s  :  %-30s %-30s\n",  
                 node->TreeLevel(), node->NParts(), node_name, 
                 object_index, object_name, 
                 current_label_name, ground_truth_label_name);
          node = node->Parent();        
        }
      }
      break; }

    case ';':
      SetFocusRadius(0.9 * FocusRadius());
      break;
      
    case '\'':
      SetFocusRadius(1.1 * FocusRadius());
      break;

    case ':':
      SetTargetResolution(0.9 * TargetResolution());
      break;

    case '"':
      SetTargetResolution(1.1 * TargetResolution());
      break;

    case ',': 
    case '.':
      if (!ElevationRange().IsEmpty()) {
        RNInterval range = ElevationRange();
        if (key == ',') range.SetMax(0.9 * range.Max());
        else if (key == '.') range.SetMax(1.1 * range.Max());
        SetElevationRange(range);
      }
      break;
      
    case '{':
    case '}': {
      // Set billboard depth
      RNScalar factor = (key == '{') ? 0.8 : 1.2;
      SetImagePlaneDepth(factor * ImagePlaneDepth());
      break; }

    case '<':
    case '>': {
      // Select next/prev image
      int image_index = (selected_image) ? selected_image->SceneIndex() : 0;
      if (key == '>') image_index++;
      else if (key == '<') image_index--;
      if (image_index < 0) image_index = 0;
      if (image_index > scene->NImages()-1) image_index = scene->NImages()-1;
      SelectImage(scene->Image(image_index), FALSE, FALSE);
      break; }

    case '_': 
      SetSubsamplingFactor(SubsamplingFactor() / 2);
      break;

    case '+': 
      SetSubsamplingFactor(SubsamplingFactor() * 2);
      break;

    case '-': 
      SetSurfelSize(0.8 * SurfelSize());
      break;

    case '=': 
      SetSurfelSize(1.25 * SurfelSize());
      break;

    default:
      redraw = 0;
      break;
    }
  }
  else if (ctrl) {
    switch(key) {
    case 'M':
    case 'm': // Enter
      if (image_inset_size < 0.5) SetImageInsetSize(0.8);
      else SetImageInsetSize(0.2);
      break;

    case 'R':
    case 'r':
      // Reset camera
      ResetCamera();
      break;

    default:
      redraw = 0;
      break;
    }
  }
  else {
    // Process other commands
    switch (key) {
    case R3_SURFEL_VIEWER_F1_KEY:
    case R3_SURFEL_VIEWER_F2_KEY:
    case R3_SURFEL_VIEWER_F3_KEY:
    case R3_SURFEL_VIEWER_F4_KEY: {
      int scale = key - R3_SURFEL_VIEWER_F1_KEY + 1;
      ZoomCamera(0.05 + 0.25*scale*scale);
      break; }

    case R3_SURFEL_VIEWER_F7_KEY:
      if (selected_image) SelectImage(selected_image, TRUE, TRUE);
      break;

    case R3_SURFEL_VIEWER_F8_KEY:
      ResetCamera();
      break;
      
    case R3_SURFEL_VIEWER_DOWN_KEY:
      SetImageInsetSize(0.8 * ImageInsetSize());
      break;

    case R3_SURFEL_VIEWER_UP_KEY:
      SetImageInsetSize(1.25 * ImageInsetSize());
      break;

    case R3_SURFEL_VIEWER_PAGE_UP_KEY: 
      if (viewing_extent.IsEmpty()) viewing_extent = scene->BBox();
      if (shift) viewing_extent[RN_LO][RN_Z] += 0.01 * scene->BBox().ZLength();
      else viewing_extent[RN_HI][RN_Z] += 0.01 * scene->BBox().ZLength();
      if (R3Contains(viewing_extent, scene->BBox())) viewing_extent = R3null_box;
      break;

    case R3_SURFEL_VIEWER_PAGE_DOWN_KEY: 
      if (viewing_extent.IsEmpty()) viewing_extent = scene->BBox();
      if (shift) viewing_extent[RN_LO][RN_Z] -= 0.01 * scene->BBox().ZLength();
      else viewing_extent[RN_HI][RN_Z] -= 0.01 * scene->BBox().ZLength();
      if (R3Contains(viewing_extent, scene->BBox())) viewing_extent = R3null_box;
      break;

    default:
      redraw = 0;
      break;
    }
  }

  // Remember mouse position 
  mouse_position[0] = x;
  mouse_position[1] = y;

  // Remember modifiers 
  shift_down = shift;
  ctrl_down = ctrl;
  alt_down = alt;

  // Return whether need redraw
  return redraw;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r9d, %ebx
movl %ecx, %ebp
movl %edx, %r15d
movq %rdi, %r14
movl 0x100(%rsp), %edx
xorl %r13d, %r13d
testl %edx, %edx
je 0x30a9a
leal -0x22(%rbp), %eax
cmpl $0x5b, %eax
ja 0x31408
leaq 0x10ab21(%rip), %rcx    # 0x13b55c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsd 0x158(%r14), %xmm0
movl $0x1, %r13d
ucomisd 0x160(%r14), %xmm0
ja 0x31408
movl %r8d, 0x10(%rsp)
movl %esi, %r12d
leaq 0x158(%r14), %rsi
leaq 0x40(%rsp), %rdi
callq 0xe9178
cmpl $0x2c, %ebp
je 0x31682
cmpl $0x2e, %ebp
jne 0x31696
movsd 0x10a933(%rip), %xmm0   # 0x13b3c8
jmp 0x3168a
testl %ebx, %ebx
je 0x30aba
cmpl $0x6c, %ebp
jg 0x30b22
cmpl $0x4d, %ebp
je 0x30b30
cmpl $0x52, %ebp
je 0x30b5d
jmp 0x31408
cmpl $0x427, %ebp            # imm = 0x427
jle 0x30b73
movl %r8d, 0x10(%rsp)
movl %esi, %r12d
leal -0x428(%rbp), %eax
cmpl $0x4, %eax
jae 0x30bcd
addl $0xfffffbd9, %ebp       # imm = 0xFFFFFBD9
cvtsi2sd %ebp, %xmm1
movsd 0x10a901(%rip), %xmm0   # 0x13b3f0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
addsd 0x10a8c1(%rip), %xmm0   # 0x13b3c0
movq (%r14), %rax
movq %r14, %rdi
callq *0x60(%rax)
movl $0x1, %r13d
movl 0x100(%rsp), %edx
movl %r12d, %esi
movl 0x10(%rsp), %r8d
jmp 0x31408
cmpl $0x72, %ebp
je 0x30b5d
cmpl $0x6d, %ebp
jne 0x31408
movl %r8d, %ebp
movl %esi, %r12d
movsd 0x10a4d2(%rip), %xmm0   # 0x13b010
ucomisd 0x2d8(%r14), %xmm0
movq (%r14), %rax
movq 0x88(%rax), %rax
jbe 0x30ba8
movsd 0x10a87d(%rip), %xmm0   # 0x13b3d8
jmp 0x30bb0
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x50(%rax)
jmp 0x313fa
addl $0xfffffbfe, %ebp       # imm = 0xFFFFFBFE
cmpl $0x6, %ebp
ja 0x31408
leaq 0x10ab43(%rip), %rax    # 0x13b6cc
movslq (%rax,%rbp,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movsd 0x2d8(%r14), %xmm0
mulsd 0x10a835(%rip), %xmm0   # 0x13b3d8
jmp 0x30ec1
movsd 0x10a870(%rip), %xmm0   # 0x13b420
movq %r14, %rdi
callq *%rax
movl $0x1, %r13d
movl 0x100(%rsp), %edx
movl %r12d, %esi
movl %ebp, %r8d
jmp 0x31408
cmpl $0x42e, %ebp            # imm = 0x42E
je 0x30f59
cmpl $0x42f, %ebp            # imm = 0x42F
movl %r12d, %esi
movl 0x10(%rsp), %r8d
jne 0x31408
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
movl 0x10(%rsp), %r8d
movl %r12d, %esi
movl 0x100(%rsp), %edx
jmp 0x31402
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x100(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xd0(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x130(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xe0(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xc8(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xb0(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x108(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x138(%rax)
jmp 0x313fa
movl %r8d, %ebp
movl %esi, %r12d
movsd 0x158(%r14), %xmm0
ucomisd 0x160(%r14), %xmm0
ja 0x31440
movq (%r14), %rax
leaq 0x597eee(%rip), %rsi    # 0x5c8c10
movq %r14, %rdi
jmp 0x3146c
cmpq $0x0, 0x458(%r14)
je 0x31474
movq $0x0, 0x458(%r14)
jmp 0x31402
movq 0x2d0(%r14), %rax
testq %rax, %rax
je 0x31481
movl 0x10(%rax), %eax
jmp 0x31483
xorl %eax, %eax
cmpl $0x7b, %ebp
sete %al
leaq 0x10a731(%rip), %rcx    # 0x13b4a0
movsd (%rcx,%rax,8), %xmm0
mulsd 0x2e0(%r14), %xmm0
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x90(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x120(%rax)
jmp 0x31365
cmpl $0x2, 0x490(%r14)
movl $0x1, %r13d
movl $0x8, %eax
cmovgel %r13d, %eax
movl %eax, 0x490(%r14)
jmp 0x31408
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xa8(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xa0(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x128(%rax)
jmp 0x313fa
movl %esi, 0x14(%rsp)
movl %r15d, 0x18(%rsp)
leaq 0x128(%r14), %r13
movsd 0x128(%r14), %xmm0
leaq 0x140(%r14), %r12
ucomisd 0x140(%r14), %xmm0
ja 0x30e88
movsd 0x130(%r14), %xmm0
ucomisd 0x148(%r14), %xmm0
ja 0x30e88
movsd 0x138(%r14), %xmm0
ucomisd 0x150(%r14), %xmm0
jbe 0x3151d
movl %r8d, %ebp
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x314f8
callq 0x3ff5c
movq %rax, %r15
jmp 0x314ff
movsd 0x2d8(%r14), %xmm0
mulsd 0x10a557(%rip), %xmm0   # 0x13b418
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x88(%rax)
jmp 0x313fa
movl %esi, 0x14(%rsp)
movl %r15d, 0x18(%rsp)
leaq 0x128(%r14), %r13
movsd 0x128(%r14), %xmm0
leaq 0x140(%r14), %r12
ucomisd 0x140(%r14), %xmm0
ja 0x30f31
movsd 0x130(%r14), %xmm0
ucomisd 0x148(%r14), %xmm0
ja 0x30f31
movsd 0x138(%r14), %xmm0
ucomisd 0x150(%r14), %xmm0
jbe 0x315a5
movl %r8d, %ebp
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x31580
callq 0x3ff5c
movq %rax, %r15
jmp 0x31587
movq 0x2d0(%r14), %rsi
testq %rsi, %rsi
je 0x314ed
movq (%r14), %rax
movl $0x1, %r13d
movq %r14, %rdi
movl $0x1, %edx
movl $0x1, %ecx
callq *0x1c0(%rax)
jmp 0x30b0e
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x110(%rax)
jmp 0x31365
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xd8(%rax)
jmp 0x313fa
movl %r8d, 0x10(%rsp)
movl %r15d, %ebp
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movl %esi, %r15d
callq 0xc531c
movq (%r14), %rax
movl $0x0, (%rsp)
movq %r14, %rdi
movl %r15d, %r12d
movl %r15d, %esi
movl %ebp, %r15d
movl %ebp, %edx
movq %r13, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq *0x1f8(%rax)
testq %rax, %rax
je 0x30b08
movq (%r14), %rax
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq *0x80(%rax)
jmp 0x30b08
movq 0x2d0(%r14), %rax
movl $0x1, %r13d
testq %rax, %rax
je 0x31408
movq 0x1c0(%rax), %rdi
movl %esi, %r12d
movl %r8d, %ebp
callq 0x27f20
movq 0x18de4d(%rip), %rax    # 0x1beea0
movq (%rax), %rdi
callq 0x27b00
movl %ebp, %r8d
movl %r12d, %esi
movl 0x100(%rsp), %edx
jmp 0x31408
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0xf0(%rax)
jmp 0x313fa
movsd 0x478(%r14), %xmm0
mulsd 0x10a2bc(%rip), %xmm0   # 0x13b358
jmp 0x31281
movsd 0x2e8(%r14), %xmm0
mulsd 0x10a366(%rip), %xmm0   # 0x13b418
jmp 0x31333
movl %r8d, 0x10(%rsp)
movl %ebx, 0x1c(%rsp)
movl %r15d, %ebx
leaq 0x28(%rsp), %r15
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorps %xmm2, %xmm2
movq %r15, %rdi
movl %esi, %ebp
callq 0xc531e
movq (%r14), %rax
movl $0x0, (%rsp)
movq %r14, 0x20(%rsp)
movq %r14, %rdi
movl %ebp, 0x14(%rsp)
movl %ebp, %esi
movl %ebx, 0x18(%rsp)
movl %ebx, %edx
movq %r15, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq *0x1f8(%rax)
testq %rax, %rax
je 0x31231
movq %rax, %r13
movq 0x20(%rsp), %rdi
movq (%rdi), %rax
leaq 0x28(%rsp), %r15
movq %r15, %rsi
callq *0x80(%rax)
movsd (%r15), %xmm0
movsd 0x8(%r15), %xmm1
movsd 0x10(%r15), %xmm2
leaq 0x10d4be(%rip), %rdi    # 0x13e602
movb $0x3, %al
callq 0x27080
leaq 0x10a768(%rip), %r14    # 0x13b8ba
movq 0xb8(%r13), %rbp
testq %rbp, %rbp
cmoveq %r14, %rbp
movq %r13, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x4013a
movq %rax, %r12
movq %r14, %r15
testq %rax, %rax
je 0x31186
movq 0x88(%r12), %r15
testq %r15, %r15
cmoveq %r14, %r15
testq %r12, %r12
je 0x311a5
movl 0x10(%r12), %edx
leaq 0x40(%rsp), %rdi
leaq 0x11840e(%rip), %rsi    # 0x1495aa
xorl %eax, %eax
callq 0x27140
jmp 0x311ac
movw $0x2d, 0x40(%rsp)
testq %r12, %r12
je 0x311bb
movq %r12, %rdi
callq 0x4708c
jmp 0x311bd
xorl %eax, %eax
movq %r14, %rbx
testq %rax, %rax
je 0x311d0
movq 0x60(%rax), %rbx
testq %rbx, %rbx
cmoveq %r14, %rbx
testq %r12, %r12
je 0x311df
movq %r12, %rdi
callq 0x47182
jmp 0x311e1
xorl %eax, %eax
movq %r14, %r12
testq %rax, %rax
je 0x311f4
movq 0x60(%rax), %r12
testq %r12, %r12
cmoveq %r14, %r12
movq %r13, %rdi
callq 0x40128
movl 0x3c(%r13), %edx
movq %rbx, 0x8(%rsp)
movq %r12, (%rsp)
leaq 0x10a6ac(%rip), %rdi    # 0x13b8bc
movl %eax, %esi
movq %rbp, %rcx
leaq 0x40(%rsp), %r8
movq %r15, %r9
xorl %eax, %eax
callq 0x27080
movq 0x28(%r13), %r13
testq %r13, %r13
jne 0x31152
movl $0x1, %r13d
movl 0x1c(%rsp), %ebx
movl 0x10(%rsp), %r8d
movl 0x18(%rsp), %r15d
movl 0x100(%rsp), %edx
movl 0x14(%rsp), %esi
movq 0x20(%rsp), %r14
jmp 0x31408
movsd 0x468(%r14), %xmm0
mulsd 0x10a15d(%rip), %xmm0   # 0x13b3c8
jmp 0x31309
movsd 0x478(%r14), %xmm0
mulsd 0x10a147(%rip), %xmm0   # 0x13b3c8
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x1d0(%rax)
jmp 0x313fa
movl 0x360(%r14), %eax
movl %eax, %ecx
incl %ecx
movslq %ecx, %rcx
imulq $-0x77777777, %rcx, %rcx # imm = 0x88888889
shrq $0x20, %rcx
addl %eax, %ecx
incl %ecx
movl %edx, %ebp
movl %ecx, %edx
shrl $0x1f, %edx
sarl $0x3, %ecx
addl %edx, %ecx
leal (%rcx,%rcx,4), %ecx
leal (%rcx,%rcx,2), %ecx
negl %ecx
movl %esi, %r12d
leal (%rax,%rcx), %esi
incl %esi
movq (%r14), %rax
movq %r14, %rdi
movl %r8d, %r13d
callq *0x158(%rax)
jmp 0x313fa
movl %esi, %r12d
movl 0x48c(%r14), %esi
addl %esi, %esi
jmp 0x313e9
movsd 0x468(%r14), %xmm0
mulsd 0x10a04f(%rip), %xmm0   # 0x13b358
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x1c8(%rax)
jmp 0x313fa
movsd 0x2e8(%r14), %xmm0
mulsd 0x10a0a5(%rip), %xmm0   # 0x13b3d8
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %esi, %r12d
movl %r8d, %r13d
callq *0x98(%rax)
jmp 0x313fa
movq (%r14), %rax
movq %r14, %rdi
movl %esi, %r12d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %edx, %ebp
movl %r8d, %r13d
callq *0x118(%rax)
movq 0x2d0(%r14), %rsi
movq (%r14), %rax
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x1c0(%rax)
jmp 0x313fa
movl %esi, %r12d
leaq 0x78(%r14), %rsi
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %r8d, %r13d
callq *0x318(%rax)
jmp 0x313fa
movl 0x360(%r14), %ecx
movq (%r14), %rax
movq 0x158(%rax), %rax
cmpl $0xc, %ecx
je 0x316b6
cmpl $0x5, %ecx
je 0x316a9
movl %r8d, %ebp
movl %esi, %r12d
movq %r14, %rdi
testl %ecx, %ecx
jne 0x316cd
movl $0xc, %esi
jmp 0x316cf
movl 0x48c(%r14), %eax
movl %esi, %r12d
movl %eax, %esi
shrl $0x1f, %esi
addl %eax, %esi
sarl %esi
movq (%r14), %rax
movq %r14, %rdi
movl %edx, %ebp
movl %r8d, %r13d
callq *0x1d8(%rax)
movl %r13d, %r8d
movl %r12d, %esi
movl %ebp, %edx
movl $0x1, %r13d
movl %esi, 0x4a8(%r14)
movl %r15d, 0x4ac(%r14)
movl %r8d, 0x4bc(%r14)
movl %ebx, 0x4c0(%r14)
movl %edx, 0x4c4(%r14)
movl %r13d, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r15d, %r13d
leaq 0x40(%rsp), %r15
movsd 0x109ef0(%rip), %xmm0   # 0x13b340
movsd 0x109f98(%rip), %xmm1   # 0x13b3f0
movq %r15, %rdi
callq 0xe916e
movq (%r14), %rax
movq %r14, %rdi
movq %r15, %rsi
movl %r13d, %r15d
callq *0x78(%rax)
jmp 0x30bb5
movq $0x12, 0x458(%r14)
jmp 0x31402
xorl %eax, %eax
cmpl $0x3c, %ebp
movl %esi, 0x14(%rsp)
movl %r8d, %r12d
je 0x3149a
cmpl $0x3e, %ebp
jne 0x314a0
movl %edx, %ebp
incl %eax
jmp 0x314a2
movl %edx, %ebp
decl %eax
jmp 0x314a2
movl %edx, %ebp
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq 0x8(%r14), %rcx
movl 0x9c(%rcx), %edx
leal -0x1(%rdx), %esi
cmpl %edx, %eax
cmovll %eax, %esi
movq (%r14), %rax
movq 0x90(%rcx), %rcx
movslq %esi, %rdx
movq (%rcx,%rdx,8), %rsi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x1c0(%rax)
movl $0x1, %r13d
movl %ebp, %edx
movl 0x14(%rsp), %esi
movl %r12d, %r8d
jmp 0x31408
movl $0x1, %r13d
jmp 0x30b15
leaq 0x196059(%rip), %r15    # 0x1c7558
leaq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0xc568c
addq $0x20, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xc568c
movl %ebp, %r8d
movq %r12, 0x20(%rsp)
movl %ebx, 0x1c(%rsp)
movl %r8d, 0x10(%rsp)
testl %r8d, %r8d
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl $0x150, %ecx            # imm = 0x150
movl $0x138, %ebx            # imm = 0x138
cmoveq %rcx, %rbx
movq (%rax), %rdi
leaq 0x196006(%rip), %r15    # 0x1c7558
movq %r15, %rax
testq %rdi, %rdi
je 0x3155f
callq 0x3ff5c
movq %r13, %rbp
leaq 0x120(%r14), %r12
movsd 0x30(%rax), %xmm0
subsd 0x18(%rax), %xmm0
mulsd 0x109ead(%rip), %xmm0   # 0x13b428
jmp 0x31603
leaq 0x195fd1(%rip), %r15    # 0x1c7558
leaq 0x8(%r15), %rsi
movq %r13, %rdi
callq 0xc568c
addq $0x20, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0xc568c
movl %ebp, %r8d
movq %r12, 0x20(%rsp)
movl %ebx, 0x1c(%rsp)
movl %r8d, 0x10(%rsp)
testl %r8d, %r8d
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl $0x150, %ecx            # imm = 0x150
movl $0x138, %ebx            # imm = 0x138
cmoveq %rcx, %rbx
movq (%rax), %rdi
leaq 0x195f7e(%rip), %r15    # 0x1c7558
movq %r15, %rax
testq %rdi, %rdi
je 0x315e7
callq 0x3ff5c
movq %r13, %rbp
leaq 0x120(%r14), %r12
movsd 0x30(%rax), %xmm0
subsd 0x18(%rax), %xmm0
mulsd 0x109a25(%rip), %xmm0   # 0x13b028
addsd (%r14,%rbx), %xmm0
movsd %xmm0, (%r14,%rbx)
movq 0x8(%r14), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x3162b
callq 0x3ff5c
movq %rax, %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8b6b0
movl $0x1, %r13d
testl %eax, %eax
je 0x31664
leaq 0x195f11(%rip), %r15    # 0x1c7558
leaq 0x8(%r15), %rsi
movq %rbp, %rdi
callq 0xc568c
addq $0x20, %r15
movq 0x20(%rsp), %rdi
movq %r15, %rsi
callq 0xc568c
movl 0x1c(%rsp), %ebx
movl 0x10(%rsp), %r8d
movl 0x18(%rsp), %r15d
movl 0x100(%rsp), %edx
movl 0x14(%rsp), %esi
jmp 0x31408
movsd 0x109cce(%rip), %xmm0   # 0x13b358
mulsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
movq (%r14), %rax
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq *0x78(%rax)
jmp 0x30b0e
movq %r14, %rdi
movl %esi, %r12d
movl $0x8, %esi
jmp 0x316c1
movq %r14, %rdi
movl %esi, %r12d
movl $0x5, %esi
movl %edx, %ebp
movl %r8d, %r13d
callq *%rax
jmp 0x313fa
xorl %esi, %esi
callq *%rax
jmp 0x30bb5