// File: /workspace/github_cpp_makefile_star2_O3/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 0x116ea5(%rip), %r14d   # 0x13d9bc
subl %ecx, %r14d
movl %esi, %eax
xorl $0x1, %eax
orl %edi, %eax
jne 0x26c57
movb 0x11c52b(%rip), %al     # 0x143058
testb %al, %al
je 0x26ca1
xorl %eax, %eax
cmpl $0x0, 0x11c506(%rip)    # 0x143044
jne 0x26b5d
leaq 0x11c501(%rip), %rdi    # 0x143048
callq 0x8691a
movsd 0xb350c(%rip), %xmm1    # 0xda060
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x11c4e1(%rip)    # 0x143044
leaq 0x11c4de(%rip), %rdi    # 0x143048
xorl %esi, %esi
callq 0x21fa0
cmpl $0x0, 0x11c4cc(%rip)    # 0x143044
je 0x26c57
movl %r15d, 0x8(%rsp)
movq 0x11c44e(%rip), %rsi    # 0x142fd8
movl %ebx, 0xc(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
leaq 0x58(%rsp), %rdi
callq 0x28a06
movl 0x11bd47(%rip), %eax    # 0x1428f4
testl %eax, %eax
jle 0x26c4e
movsd 0xb34ab(%rip), %xmm0    # 0xda068
movsd %xmm0, 0x10(%rsp)
leaq 0x38(%rsp), %r15
xorl %r12d, %r12d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl 0x116dd9(%rip), %ecx    # 0x13d9b0
cmpq %r13, %rcx
setne %dl
cmpq %rcx, %r12
setne %cl
testb %cl, %dl
jne 0x26c43
movq 0x11bcfa(%rip), %rax    # 0x1428e8
movq (%rax,%r12,8), %rbx
movq %r15, %rdi
callq 0x74c90
movq (%rbx), %rax
movq %rbx, %rdi
leaq 0x58(%rsp), %rsi
leaq 0x18(%rsp), %rdx
callq *0x170(%rax)
testl %eax, %eax
je 0x26c3d
movsd 0x10(%rsp), %xmm0
ucomisd 0x50(%rsp), %xmm0
jbe 0x26c3d
leaq 0x11bccf(%rip), %rdi    # 0x1428f8
movq %r15, %rsi
callq 0x74ffa
movsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movl 0x11bcb1(%rip), %eax    # 0x1428f4
incq %r12
movslq %eax, %rcx
cmpq %rcx, %r12
jl 0x26bd1
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 0x11c3c3(%rip), %rdx    # 0x143038
movl %ecx, (%rdx,%rax,4)
callq 0xd1d11
movl %ebx, 0x11c3ad(%rip)    # 0x143030
movl %r14d, 0x11c3aa(%rip)   # 0x143034
callq 0xcce58
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x11c3b0(%rip), %rdi    # 0x143058
callq 0x22110
testl %eax, %eax
je 0x26b35
leaq 0x11c38c(%rip), %rdi    # 0x143048
callq 0x868b8
leaq 0x11c390(%rip), %rdi    # 0x143058
callq 0x215c0
jmp 0x26b35
movq %rax, %rbx
leaq 0x11c37c(%rip), %rdi    # 0x143058
callq 0x215a0
movq %rbx, %rdi
callq 0x220a0