// File: tomfunkhouser[P]gaps/apps/grdview/grdview.cpp
// Function: GLUTSpecial(int, int, int)
void GLUTSpecial(int key, int x, int y)
{
  // Invert y coordinate
  y = GLUTwindow_height - y;

  // Set useful variables
  static RNBoolean first = TRUE;
  static RNScalar threshold_step = 1;
  static RNInterval threshold_range(0,0);
  if (first) {
    RNInterval grid_range = grid->Range();
    threshold_step = grid->StandardDeviation() / 10;
    threshold_range.Reset(grid_range.Min() + 1.0E-20, grid_range.Max() - 1.0E-20);
    first = FALSE;
  }

  // Process keyboard button event 
  switch (key) {
  case GLUT_KEY_DOWN:
    grid_threshold -= threshold_step;
    if (grid_threshold < threshold_range.Min()) grid_threshold = threshold_range.Min();
    break;

  case GLUT_KEY_UP:
    grid_threshold += threshold_step;
    if (grid_threshold > threshold_range.Max()) grid_threshold = threshold_range.Max();
    break;

  case GLUT_KEY_LEFT:
    threshold_step /= 2;
    break;

  case GLUT_KEY_RIGHT:
    threshold_step *= 2;
    break;
  }

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

  // Remember modifiers 
  GLUTmodifiers = glutGetModifiers();

  // Redraw
  glutPostRedisplay();
}

// Assembly:
subq $0x58, %rsp
movl %edi, 0x54(%rsp)
movl %esi, 0x50(%rsp)
movl %edx, 0x4c(%rsp)
movl 0x18e86a(%rip), %eax    # 0x1b38e0
subl 0x4c(%rsp), %eax
movl %eax, 0x4c(%rsp)
cmpb $0x0, 0x19d27b(%rip)    # 0x1c2300
jne 0x250b8
leaq 0x19d272(%rip), %rdi    # 0x1c2300
callq 0x20f50
cmpl $0x0, %eax
je 0x250b8
leaq 0x19d251(%rip), %rdi    # 0x1c22f0
xorps %xmm1, %xmm1
movaps %xmm1, %xmm0
callq 0xec680
jmp 0x250ac
leaq 0x19d24d(%rip), %rdi    # 0x1c2300
callq 0x20500
cmpl $0x0, 0x18e825(%rip)    # 0x1b38e4
je 0x25168
movq 0x19d174(%rip), %rsi    # 0x1c2240
leaq 0x28(%rsp), %rdi
callq 0x4b780
movq 0x19d163(%rip), %rdi    # 0x1c2240
callq 0x26d30
movsd 0x139f66(%rip), %xmm1   # 0x15f050
divsd %xmm1, %xmm0
movsd %xmm0, 0x18e7f2(%rip)   # 0x1b38e8
leaq 0x28(%rsp), %rdi
callq 0x26d80
movsd 0x139f40(%rip), %xmm1   # 0x15f048
addsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x26d90
movaps %xmm0, %xmm1
movsd 0x20(%rsp), %xmm0
movsd 0x139f1b(%rip), %xmm2   # 0x15f048
subsd %xmm2, %xmm1
leaq 0x19d1b8(%rip), %rdi    # 0x1c22f0
callq 0x26d50
movl $0x0, 0x18e79d(%rip)    # 0x1b38e4
jmp 0x25168
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x40(%rsp)
movl %eax, 0x3c(%rsp)
leaq 0x19d1a2(%rip), %rdi    # 0x1c2300
callq 0x204e0
jmp 0x252c9
movl 0x54(%rsp), %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, 0x18(%rsp)
subl $0x3, %eax
ja 0x252a0
movq 0x18(%rsp), %rax
leaq 0x139f09(%rip), %rcx    # 0x15f094
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movsd 0x18e74c(%rip), %xmm1   # 0x1b38e8
movss 0x18e72c(%rip), %xmm0   # 0x1b38d0
cvtss2sd %xmm0, %xmm0
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18e718(%rip)   # 0x1b38d0
movss 0x18e710(%rip), %xmm0   # 0x1b38d0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x19d11f(%rip), %rdi    # 0x1c22f0
callq 0x26d80
movsd 0x10(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x251fa
leaq 0x19d107(%rip), %rdi    # 0x1c22f0
callq 0x26d80
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18e6d6(%rip)   # 0x1b38d0
jmp 0x252a0
movsd 0x18e6e1(%rip), %xmm1   # 0x1b38e8
movss 0x18e6c1(%rip), %xmm0   # 0x1b38d0
cvtss2sd %xmm0, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18e6ad(%rip)   # 0x1b38d0
movss 0x18e6a5(%rip), %xmm0   # 0x1b38d0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x19d0b4(%rip), %rdi    # 0x1c22f0
callq 0x26d90
movaps %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x25268
leaq 0x19d099(%rip), %rdi    # 0x1c22f0
callq 0x26d90
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x18e668(%rip)   # 0x1b38d0
jmp 0x252a0
movsd 0x18e676(%rip), %xmm0   # 0x1b38e8
movsd 0x139db6(%rip), %xmm1   # 0x15f030
divsd %xmm1, %xmm0
movsd %xmm0, 0x18e662(%rip)   # 0x1b38e8
jmp 0x252a0
movsd 0x139da0(%rip), %xmm0   # 0x15f030
mulsd 0x18e650(%rip), %xmm0   # 0x1b38e8
movsd %xmm0, 0x18e648(%rip)   # 0x1b38e8
movl 0x50(%rsp), %eax
movl %eax, 0x19d02e(%rip)    # 0x1c22d8
movl 0x4c(%rsp), %eax
movl %eax, 0x19d028(%rip)    # 0x1c22dc
callq 0xf6230
movl %eax, 0x19d02d(%rip)    # 0x1c22ec
callq 0xee000
addq $0x58, %rsp
retq
movq 0x40(%rsp), %rdi
callq 0x20ee0
nopw %cs:(%rax,%rax)