// File: /workspace/github_cpp_makefile_star2_O2/tomfunkhouser[P]gaps/apps/mshview/mshview.cpp
// Function: GLUTMouse(int, int, int, int)
void GLUTMouse(int button, int state, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;
  
  // Process mouse button event

  // Process mouse button event
  if ((button == GLUT_LEFT) && (state == GLUT_UP)) {
    // Check for double click  
    static RNBoolean double_click = FALSE;
    static RNTime last_mouse_down_time;
    double_click = (!double_click) && (last_mouse_down_time.Elapsed() < 0.4);
    last_mouse_down_time.Read();

    // Set world origin
    if (double_click) {
      R3Ray ray = viewer->WorldRay(x, y);
      RNScalar best_t = FLT_MAX;
      for (int m = 0; m < meshes.NEntries(); m++) {
        R3Mesh *mesh = meshes[m];
        if ((current_mesh != -1) && (m != current_mesh)) continue;
        R3MeshIntersection intersection;
        if (mesh->Intersection(ray, &intersection)) {
          if (intersection.t < best_t) {
            world_origin = intersection.point;
            best_t = intersection.t;
          }
        }
      }
    }
  }


  // Remember button state 
  int b = (button == GLUT_LEFT_BUTTON) ? 0 : ((button == GLUT_MIDDLE_BUTTON) ? 1 : 2);
  GLUTbutton[b] = (state == GLUT_DOWN) ? 1 : 0;

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

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

  // Redraw
  glutPostRedisplay();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edx, %ebx
movl %esi, %r15d
movl %edi, %r14d
movl 0x108d28(%rip), %ebp    # 0x12e9dc
subl %ecx, %ebp
movl %esi, %eax
xorl $0x1, %eax
orl %edi, %eax
jne 0x25def
movb 0x10e3af(%rip), %al     # 0x134078
testb %al, %al
je 0x25e3b
xorl %eax, %eax
cmpl $0x0, 0x10e38a(%rip)    # 0x134064
jne 0x25cf9
leaq 0x10e385(%rip), %rdi    # 0x134068
callq 0x7b58c
movsd 0x9f370(%rip), %xmm1    # 0xc5060
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x10e365(%rip)    # 0x134064
leaq 0x10e362(%rip), %rdi    # 0x134068
callq 0x26cbc
cmpl $0x0, 0x10e352(%rip)    # 0x134064
je 0x25def
movl %r15d, (%rsp)
movl %r14d, 0x4(%rsp)
movq 0x10e2d0(%rip), %rsi    # 0x133ff8
movl %ebx, 0xc(%rsp)
cvtsi2sd %ebx, %xmm0
movl %ebp, 0x8(%rsp)
cvtsi2sd %ebp, %xmm1
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x27b20
movsd 0x9f31b(%rip), %xmm0    # 0xc5068
movsd %xmm0, 0x10(%rsp)
leaq 0x38(%rsp), %r12
xorl %r14d, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x18(%rsp), %r13
movslq 0x10dba8(%rip), %rax    # 0x133914
cmpq %rax, %r14
jge 0x25dde
movl 0x108c59(%rip), %eax    # 0x12e9d0
cmpq %rbp, %rax
setne %cl
cmpq %rax, %r14
setne %al
testb %al, %cl
jne 0x25dd9
movq 0x10db7a(%rip), %rax    # 0x133908
movq (%rax,%r14,8), %rbx
movq %r12, %rdi
callq 0x6b146
movq (%rbx), %rax
movq %rbx, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq *0x170(%rax)
testl %eax, %eax
je 0x25dd9
movsd 0x10(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x25dd9
leaq 0x10db53(%rip), %rdi    # 0x133918
movq %r12, %rsi
callq 0x6b432
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
incq %r14
jmp 0x25d65
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %ebp
movl 0x4(%rsp), %r14d
movl (%rsp), %r15d
xorl %eax, %eax
cmpl $0x1, %r14d
setne %al
incl %eax
xorl %ecx, %ecx
testl %r15d, %r15d
sete %cl
testl %r14d, %r14d
cmovel %r14d, %eax
leaq 0x10e248(%rip), %rdx    # 0x134058
movl %ecx, (%rdx,%rax,4)
callq 0xbcafe
movl %ebx, 0x10e232(%rip)    # 0x134050
movl %ebp, 0x10e230(%rip)    # 0x134054
callq 0xb8060
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10e236(%rip), %rdi    # 0x134078
callq 0x22130
testl %eax, %eax
je 0x25cd1
leaq 0x10e212(%rip), %rdi    # 0x134068
callq 0x7b552
leaq 0x10e216(%rip), %rdi    # 0x134078
callq 0x215c0
jmp 0x25cd1
movq %rax, %rbx
leaq 0x10e202(%rip), %rdi    # 0x134078
callq 0x215a0
movq %rbx, %rdi
callq 0x220c0