// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movl 0x118e50(%rip), %r14d   # 0x13f9bc
subl %ecx, %r14d
movl %esi, %eax
xorl $0x1, %eax
orl %edi, %eax
jne 0x26ca9
movb 0x11e4d6(%rip), %al     # 0x145058
testb %al, %al
je 0x26cf3
xorl %eax, %eax
cmpl $0x0, 0x11e4b1(%rip)    # 0x145044
jne 0x26bb2
leaq 0x11e4ac(%rip), %rdi    # 0x145048
callq 0x87a76
movsd 0xb54b7(%rip), %xmm1    # 0xdc060
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x11e48c(%rip)    # 0x145044
leaq 0x11e489(%rip), %rdi    # 0x145048
xorl %esi, %esi
callq 0x21fb0
cmpl $0x0, 0x11e477(%rip)    # 0x145044
je 0x26ca9
movl %r15d, 0x8(%rsp)
movq 0x11e3f9(%rip), %rsi    # 0x144fd8
movl %ebx, 0xc(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
leaq 0x58(%rsp), %rdi
callq 0x28a56
cmpl $0x0, 0x11dcf1(%rip)    # 0x1448f4
jle 0x26ca0
movsd 0xb5457(%rip), %xmm0    # 0xdc068
movsd %xmm0, 0x10(%rsp)
leaq 0x38(%rsp), %r15
xorl %r12d, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x118d85(%rip), %eax    # 0x13f9b0
cmpq %r13, %rax
setne %cl
cmpq %rax, %r12
setne %al
testb %al, %cl
jne 0x26c91
movq 0x11dca6(%rip), %rax    # 0x1448e8
movq (%rax,%r12,8), %rbx
movq %r15, %rdi
callq 0x75bac
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq *0x170(%rax)
testl %eax, %eax
je 0x26c91
movsd 0x10(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x26c91
leaq 0x11dc7b(%rip), %rdi    # 0x1448f8
movq %r15, %rsi
callq 0x75f1c
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
incq %r12
movslq 0x11dc59(%rip), %rax    # 0x1448f4
cmpq %rax, %r12
jl 0x26c25
movl 0xc(%rsp), %ebx
movl 0x8(%rsp), %r15d
xorl %eax, %eax
cmpl $0x1, %ebp
setne %al
incl %eax
xorl %ecx, %ecx
testl %r15d, %r15d
sete %cl
testl %ebp, %ebp
cmovel %ebp, %eax
leaq 0x11e371(%rip), %rdx    # 0x145038
movl %ecx, (%rdx,%rax,4)
callq 0xd3c50
movl %ebx, 0x11e35b(%rip)    # 0x145030
movl %r14d, 0x11e358(%rip)   # 0x145034
callq 0xced08
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11e35e(%rip), %rdi    # 0x145058
callq 0x22120
testl %eax, %eax
je 0x26b8a
leaq 0x11e33a(%rip), %rdi    # 0x145048
callq 0x87a14
leaq 0x11e33e(%rip), %rdi    # 0x145058
callq 0x215c0
jmp 0x26b8a
movq %rax, %rbx
leaq 0x11e32a(%rip), %rdi    # 0x145058
callq 0x215a0
movq %rbx, %rdi
callq 0x220b0