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

  // Mouse is going down
  if (state == GLUT_DOWN) {
    // Reset mouse drag
    GLUTmouse_drag = 0;

    // Process thumbwheel
    if (button == 3) viewer.ScaleWorld(center, 0.9);
    else if (button == 4) viewer.ScaleWorld(center, 1.1);
  }
  else if (button == 0) {
    // Check for double click  
    static RNBoolean double_click = FALSE;
    static RNTime last_mouse_up_time;
    double_click = (!double_click) && (last_mouse_up_time.Elapsed() < 0.4);
    last_mouse_up_time.Read();

    // Check for click (rather than drag)
    if (GLUTmouse_drag < 100) {
      // Reset selected indices
      selected_surface_index = -1;
      selected_image_index = -1;

      // Select image or surface
      selected_position = R3unknown_point;
      RGBDImage *selected_image = NULL;
      RGBDSurface *selected_surface = NULL;
      if (Pick(x, y, &selected_surface, &selected_image, &selected_position)) {
        // Remember selected indices
        if (!selected_image) selected_image = configuration.FindImage(selected_position);
        if (selected_surface) selected_surface_index = selected_surface->ConfigurationIndex();
        if (selected_image) selected_image_index = selected_image->ConfigurationIndex();
        
        // Print message
        if (selected_surface) {
          printf("Selected surface %d at %g %g %g\n", selected_surface->ConfigurationIndex(),
            selected_position.X(), selected_position.Y(), selected_position.Z());
        }
        if (selected_image) {
          printf("Selected image %d %s and %g %g %g\n", selected_image->ConfigurationIndex(), selected_image->Name(),
            selected_position.X(), selected_position.Y(), selected_position.Z());
        }
        
        // Set viewing center of rotation and scale if double-click
        // if (double_click) center = selected_position;
        center = selected_position;
      }
    }
    else {
      // Process rubber box 
      if (rubber_box_active) {
        DrawRubberBox();
        ProcessRubberBox();
        rubber_box_corners[0] = R2zero_point;
        rubber_box_corners[1] = R2zero_point;
        rubber_box_active = FALSE;
      }
    }
  }

  // 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 $0x168, %rsp            # imm = 0x168
movl %edx, %r12d
movl %esi, %r14d
movl %edi, %r15d
movl 0x140494(%rip), %ebp    # 0x1689e0
subl %ecx, %ebp
testl %esi, %esi
je 0x286ea
testl %r15d, %r15d
jne 0x28834
movb 0x145573(%rip), %al     # 0x16dad8
testb %al, %al
movl %r14d, 0x1c(%rsp)
je 0x28cd4
xorl %eax, %eax
cmpl $0x0, 0x145549(%rip)    # 0x16dac4
jne 0x2859a
leaq 0x145544(%rip), %rdi    # 0x16dac8
callq 0xa7c86
movsd 0xd3aaf(%rip), %xmm1    # 0xfc040
xorl %eax, %eax
ucomisd %xmm0, %xmm1
seta %al
movl %eax, 0x145524(%rip)    # 0x16dac4
leaq 0x145521(%rip), %rdi    # 0x16dac8
xorl %esi, %esi
callq 0x24000
cmpl $0x63, 0x1454f7(%rip)   # 0x16daac
jg 0x2872c
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x14041e(%rip)    # 0x1689e4
movl %eax, 0x14041c(%rip)    # 0x1689e8
leaq 0x145375(%rip), %rbx    # 0x16d948
leaq 0x148a16(%rip), %rsi    # 0x170ff0
movq %rbx, %rdi
callq 0x8905c
xorl %eax, %eax
leaq 0xc0(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x108(%rsp), %rdx
movq %rax, (%rdx)
movl %r12d, %r13d
movl %r12d, %edi
movl %ebp, %esi
movq %rbx, %r8
callq 0x28d8e
testl %eax, %eax
je 0x286e2
cmpq $0x0, 0xc0(%rsp)
jne 0x28638
leaq 0x14528c(%rip), %rdi    # 0x16d8b0
leaq 0x14531d(%rip), %rsi    # 0x16d948
callq 0x2f786
movq %rax, 0xc0(%rsp)
movq 0x108(%rsp), %rax
testq %rax, %rax
je 0x2864e
movl 0x10(%rax), %ecx
movl %ecx, 0x140396(%rip)    # 0x1689e4
movq 0xc0(%rsp), %rcx
testq %rcx, %rcx
je 0x28664
movl 0x10(%rcx), %ecx
movl %ecx, 0x140384(%rip)    # 0x1689e8
testq %rax, %rax
je 0x28692
movl 0x10(%rax), %esi
movsd 0x1452d4(%rip), %xmm0   # 0x16d948
movsd 0x1452d4(%rip), %xmm1   # 0x16d950
movsd 0x1452d4(%rip), %xmm2   # 0x16d958
leaq 0xd3b70(%rip), %rdi     # 0xfc1fb
movb $0x3, %al
callq 0x23080
movq 0xc0(%rsp), %rax
testq %rax, %rax
je 0x286cf
movl 0x10(%rax), %esi
movq 0x1d0(%rax), %rdx
movsd 0x145297(%rip), %xmm0   # 0x16d948
movsd 0x145297(%rip), %xmm1   # 0x16d950
movsd 0x145297(%rip), %xmm2   # 0x16d958
leaq 0xd3b54(%rip), %rdi     # 0xfc21c
movb $0x3, %al
callq 0x23080
leaq 0x1452c2(%rip), %rdi    # 0x16d998
leaq 0x14526b(%rip), %rsi    # 0x16d948
callq 0x8905c
movl %r13d, %r12d
jmp 0x2882f
movl $0x0, 0x1453b8(%rip)    # 0x16daac
testl %r15d, %r15d
je 0x28885
cmpl $0x4, %r15d
je 0x28814
cmpl $0x3, %r15d
jne 0x28834
leaq 0x145298(%rip), %rdi    # 0x16d9b0
leaq 0x145279(%rip), %rsi    # 0x16d998
movsd 0xd3931(%rip), %xmm0    # 0xfc058
jmp 0x2882a
cmpb $0x1, 0x145381(%rip)    # 0x16dab4
jne 0x2882f
movl %r12d, 0x2c(%rsp)
callq 0x283d4
leaq 0x148d4e(%rip), %rsi    # 0x171498
leaq 0x80(%rsp), %rbx
movq %rbx, %rdi
callq 0x9f798
leaq 0x1451ff(%rip), %rsi    # 0x16d960
movq %rbx, %rdi
callq 0x9feb4
leaq 0x145200(%rip), %rsi    # 0x16d970
leaq 0x80(%rsp), %rdi
callq 0x9feb4
movsd 0x98(%rsp), %xmm1
subsd 0x88(%rsp), %xmm1
movsd 0xd38b1(%rip), %xmm0    # 0xfc048
ucomisd %xmm1, %xmm0
ja 0x287b9
movsd 0xa0(%rsp), %xmm1
subsd 0x90(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x2888a
leaq 0xd4025(%rip), %rdi     # 0xfc7e5
callq 0x23ef0
movq 0x13f754(%rip), %rax    # 0x167f20
movq (%rax), %rdi
callq 0x23ad0
leaq 0x80(%rsp), %rdi
callq 0xa013c
leaq 0x145178(%rip), %rdi    # 0x16d960
leaq 0x149051(%rip), %rbx    # 0x171840
movq %rbx, %rsi
callq 0xa270e
leaq 0x145172(%rip), %rdi    # 0x16d970
movq %rbx, %rsi
callq 0xa270e
movb $0x0, 0x1452a7(%rip)    # 0x16dab4
movl 0x2c(%rsp), %r12d
jmp 0x2882f
leaq 0x145195(%rip), %rdi    # 0x16d9b0
leaq 0x145176(%rip), %rsi    # 0x16d998
movsd 0xd3826(%rip), %xmm0    # 0xfc050
callq 0x393cc
testl %r15d, %r15d
je 0x28881
xorl %eax, %eax
cmpl $0x1, %r15d
setne %al
incq %rax
xorl %ecx, %ecx
testl %r14d, %r14d
sete %cl
leaq 0x145269(%rip), %rdx    # 0x16dab8
movl %ecx, (%rdx,%rax,4)
callq 0xf3e60
movl %eax, 0x145253(%rip)    # 0x16dab0
movl %r12d, 0x145240(%rip)   # 0x16daa4
movl %ebp, 0x14523e(%rip)    # 0x16daa8
callq 0xeef18
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
jmp 0x28840
movl %r15d, %eax
jmp 0x28840
movl $0x6000, %edi           # imm = 0x6000
callq 0x23040
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movq 0x10(%rsp), %rax
leaq (%rax,%rbx), %rdi
callq 0x88cec
addq $0x18, %rbx
cmpq $0x6000, %rbx           # imm = 0x6000
jne 0x2889b
movq $0x0, 0x8(%rsp)
movl $0x2800, %r13d          # imm = 0x2800
leaq 0x108(%rsp), %r12
callq 0xaa204
xorps %xmm1, %xmm1
cvtsi2sdl 0x144fe7(%rip), %xmm1 # 0x16d8c4
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movq 0x144fcc(%rip), %rcx    # 0x16d8b8
cltq
movq (%rcx,%rax,8), %rbx
callq 0xaa204
movsd %xmm0, 0x40(%rsp)
movq %r12, %r14
xorps %xmm0, %xmm0
cvtsi2sdl 0x28(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
callq 0xaa204
movsd %xmm0, 0x30(%rsp)
movl 0x2c(%rbx), %r12d
leaq 0xc0(%rsp), %rdi
callq 0x88cec
movsd 0x40(%rsp), %xmm0
mulsd 0x20(%rsp), %xmm0
xorps %xmm2, %xmm2
cvtsi2sd %r12d, %xmm2
movsd 0x30(%rsp), %xmm1
mulsd %xmm2, %xmm1
movq %r14, %r12
movq %r14, %rdi
callq 0xa25d6
movq %r12, %rdi
leaq 0xc0(%rsp), %rsi
movq %rbx, %rdx
callq 0x2b49f
testl %eax, %eax
movl 0x1c(%rsp), %r14d
je 0x289d5
movq %r12, %rdi
leaq 0x145037(%rip), %rsi    # 0x16d9b0
leaq 0xc0(%rsp), %rdx
callq 0x3a1cc
leaq 0x80(%rsp), %rdi
movq %r12, %rsi
callq 0x9123b
testl %eax, %eax
je 0x289d5
movslq 0x8(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x8905c
xorl %eax, %eax
movq 0x8(%rsp), %rcx
cmpl $0x3ff, %ecx            # imm = 0x3FF
leal 0x1(%rcx), %ecx
setge %al
addl %eax, %eax
movq %rcx, 0x8(%rsp)
jmp 0x289da
movl $0x4, %eax
testb $0x3, %al
jne 0x289e7
decl %r13d
jne 0x288cd
movq 0x8(%rsp), %r12
cmpl $0x2, %r12d
jg 0x28a0d
leaq 0xd3daa(%rip), %rdi     # 0xfc7a3
callq 0x23ef0
movq 0x10(%rsp), %rdi
callq 0x23c60
jmp 0x287c5
leaq 0xa8(%rsp), %rdi
movl %r12d, %esi
movq 0x10(%rsp), %rbx
movq %rbx, %rdx
xorl %ecx, %ecx
callq 0x63fc1
leaq 0xc0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
movl %r12d, %edx
movq %rbx, %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x6404b
leaq 0x144fb1(%rip), %rsi    # 0x16da00
leaq 0x108(%rsp), %rdi
callq 0x8a41c
leaq 0xf0(%rsp), %r12
leaq 0x108(%rsp), %rsi
movq %r12, %rdi
callq 0x89a1e
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x28af4
leaq 0xd8(%rsp), %r13
leaq 0x50(%rsp), %rdi
movq %r13, %rsi
callq 0x8a41c
leaq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x8a41c
leaq 0x108(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x68(%rsp), %rcx
callq 0x83e10
leaq 0xc0(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x89f32
leaq 0x120(%rsp), %rsi
movq %r13, %rdi
callq 0x89f32
leaq 0x138(%rsp), %rsi
movq %r12, %rdi
callq 0x89f32
leaq 0x108(%rsp), %rdi
movq %r12, %rsi
callq 0x89796
leaq 0x108(%rsp), %rdi
callq 0x89aa8
leaq 0x144ed0(%rip), %rsi    # 0x16d9e8
leaq 0x50(%rsp), %rdi
callq 0x89796
leaq 0x68(%rsp), %rdi
leaq 0x108(%rsp), %rsi
leaq 0x50(%rsp), %rdx
callq 0x8a0da
leaq 0x68(%rsp), %rdi
callq 0x89aa8
leaq 0x150(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x8a0da
leaq 0x50(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x89f32
leaq 0x50(%rsp), %rdi
callq 0x89aa8
movq 0x8(%rsp), %rcx
cmpl $0x2, %ecx
movl $0x1, %eax
cmovgel %ecx, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x8(%rsp)
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r13d, %r13d
leaq 0x150(%rsp), %r12
movsd %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%r13), %rbx
movq %r12, %rdi
movq %rbx, %rsi
leaq 0xa8(%rsp), %rdx
callq 0x88f50
movq %r12, %rdi
leaq 0x68(%rsp), %rsi
callq 0x89a1e
movapd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
leaq 0xa8(%rsp), %rdx
callq 0x88f50
movq %r12, %rdi
leaq 0x50(%rsp), %rsi
callq 0x89a1e
movapd %xmm0, %xmm2
movapd 0xd34b4(%rip), %xmm0    # 0xfc0c0
movapd 0x40(%rsp), %xmm1
andpd %xmm0, %xmm1
andpd %xmm0, %xmm2
maxsd 0x20(%rsp), %xmm1
maxsd 0x30(%rsp), %xmm2
addq $0x18, %r13
movsd %xmm2, 0x30(%rsp)
movapd %xmm1, %xmm0
cmpq %r13, 0x8(%rsp)
jne 0x28bab
movapd %xmm2, 0x30(%rsp)
movapd %xmm1, 0x40(%rsp)
movq 0x10(%rsp), %rdi
callq 0x23c60
movl $0x78, %edi
callq 0x238e0
movq %rax, %r12
leaq 0xa8(%rsp), %rsi
leaq 0x68(%rsp), %rdx
leaq 0x50(%rsp), %rcx
movq %rax, %rdi
movapd 0x40(%rsp), %xmm0
movapd 0x30(%rsp), %xmm1
callq 0x79dd0
movl $0xa0, %edi
callq 0x238e0
movq %rax, %r13
movsd 0x144ebb(%rip), %xmm0   # 0x16db58
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x2fcde
leaq 0x144bff(%rip), %rdi    # 0x16d8b0
movq %r13, %rsi
callq 0x2b922
movl 0x144c15(%rip), %esi    # 0x16d8d4
decl %esi
leaq 0xd366c(%rip), %rdi     # 0xfc334
xorl %eax, %eax
callq 0x23080
jmp 0x287c5
leaq 0x144dfd(%rip), %rdi    # 0x16dad8
callq 0x24170
testl %eax, %eax
je 0x28572
leaq 0x144dd9(%rip), %rdi    # 0x16dac8
callq 0xa7c24
leaq 0x144ddd(%rip), %rdi    # 0x16dad8
callq 0x235c0
movl 0x1c(%rsp), %r14d
jmp 0x28572
movq %rax, %rbx
leaq 0x144dc4(%rip), %rdi    # 0x16dad8
callq 0x235a0
jmp 0x28d86
jmp 0x28d76
movq %rax, %rbx
movl $0xa0, %esi
movq %r13, %rdi
jmp 0x28d35
movq %rax, %rbx
movl $0x78, %esi
movq %r12, %rdi
callq 0x23900
jmp 0x28d79
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
jmp 0x28d76
movq %rax, %rbx
movl $0x6000, %esi           # imm = 0x6000
movq 0x10(%rsp), %rdi
callq 0x242e0
jmp 0x28d79
jmp 0x28d76
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xa013c
movq %rbx, %rdi
callq 0x24100