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

  // Determine modifiers
  int modifiers = glutGetModifiers();
  int shift = (modifiers & GLUT_ACTIVE_SHIFT);
  int ctrl = (modifiers & GLUT_ACTIVE_CTRL);
  int alt = (modifiers & GLUT_ACTIVE_ALT);

  // Translate key
  int translated_key = key;
  switch (key) {
    case GLUT_KEY_PAGE_DOWN: translated_key = R3_SURFEL_VIEWER_PAGE_DOWN_KEY; break;
    case GLUT_KEY_PAGE_UP: translated_key = R3_SURFEL_VIEWER_PAGE_UP_KEY; break;
    case GLUT_KEY_DOWN: translated_key = R3_SURFEL_VIEWER_DOWN_KEY; break;
    case GLUT_KEY_UP: translated_key = R3_SURFEL_VIEWER_UP_KEY; break;
    case GLUT_KEY_LEFT: translated_key = R3_SURFEL_VIEWER_LEFT_KEY; break;
    case GLUT_KEY_RIGHT: translated_key = R3_SURFEL_VIEWER_RIGHT_KEY; break;
    case GLUT_KEY_HOME: translated_key = R3_SURFEL_VIEWER_HOME_KEY; break;
    case GLUT_KEY_END: translated_key = R3_SURFEL_VIEWER_END_KEY; break;
    case GLUT_KEY_INSERT: translated_key = R3_SURFEL_VIEWER_INSERT_KEY; break;
    case GLUT_KEY_F1: translated_key = R3_SURFEL_VIEWER_F1_KEY; break;
    case GLUT_KEY_F2: translated_key = R3_SURFEL_VIEWER_F2_KEY; break;
    case GLUT_KEY_F3: translated_key = R3_SURFEL_VIEWER_F3_KEY; break;
    case GLUT_KEY_F4: translated_key = R3_SURFEL_VIEWER_F4_KEY; break;
    case GLUT_KEY_F5: translated_key = R3_SURFEL_VIEWER_F5_KEY; break;
    case GLUT_KEY_F6: translated_key = R3_SURFEL_VIEWER_F6_KEY; break;
    case GLUT_KEY_F7: translated_key = R3_SURFEL_VIEWER_F7_KEY; break;
    case GLUT_KEY_F8: translated_key = R3_SURFEL_VIEWER_F8_KEY; break;
    case GLUT_KEY_F9: translated_key = R3_SURFEL_VIEWER_F9_KEY; break;
    case GLUT_KEY_F10: translated_key = R3_SURFEL_VIEWER_F10_KEY; break;
    case GLUT_KEY_F11: translated_key = R3_SURFEL_VIEWER_F11_KEY; break;
    case GLUT_KEY_F12: translated_key = R3_SURFEL_VIEWER_F12_KEY; break;
  }

  // Send keyboard event to viewer
  if (viewer->Keyboard(x, y, translated_key, shift, ctrl, alt)) {
    glutPostRedisplay();
  }
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movl %esi, %ebx
movl %edi, %r14d
movl 0x190ee9(%rip), %ebp    # 0x1bc9e4
subl %edx, %ebp
callq 0x1305b5
movl %eax, %r8d
andl $0x1, %r8d
movl %eax, %r9d
andl $0x2, %r9d
andl $0x4, %eax
leal -0x1(%r14), %ecx
cmpl $0xb, %ecx
ja 0x2bb37
leaq 0x10c521(%rip), %rdx    # 0x138044
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x428, %r14d           # imm = 0x428
jmp 0x2bbfb
leal -0x64(%r14), %ecx
cmpl $0x8, %ecx
ja 0x2bbfb
leaq 0x10c529(%rip), %rdx    # 0x138074
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x400, %r14d           # imm = 0x400
jmp 0x2bbfb
movl $0x433, %r14d           # imm = 0x433
jmp 0x2bbfb
movl $0x408, %r14d           # imm = 0x408
jmp 0x2bbfb
movl $0x42c, %r14d           # imm = 0x42C
jmp 0x2bbfb
movl $0x431, %r14d           # imm = 0x431
jmp 0x2bbfb
movl $0x401, %r14d           # imm = 0x401
jmp 0x2bbfb
movl $0x42a, %r14d           # imm = 0x42A
jmp 0x2bbfb
movl $0x402, %r14d           # imm = 0x402
jmp 0x2bbfb
movl $0x405, %r14d           # imm = 0x405
jmp 0x2bbfb
movl $0x403, %r14d           # imm = 0x403
jmp 0x2bbfb
movl $0x42b, %r14d           # imm = 0x42B
jmp 0x2bbfb
movl $0x42f, %r14d           # imm = 0x42F
jmp 0x2bbfb
movl $0x429, %r14d           # imm = 0x429
jmp 0x2bbfb
movl $0x407, %r14d           # imm = 0x407
jmp 0x2bbfb
movl $0x404, %r14d           # imm = 0x404
jmp 0x2bbfb
movl $0x42d, %r14d           # imm = 0x42D
jmp 0x2bbfb
movl $0x406, %r14d           # imm = 0x406
jmp 0x2bbfb
movl $0x42e, %r14d           # imm = 0x42E
jmp 0x2bbfb
movl $0x432, %r14d           # imm = 0x432
jmp 0x2bbfb
movl $0x430, %r14d           # imm = 0x430
movq 0x195d7e(%rip), %rdi    # 0x1c1980
movq (%rdi), %r10
movl %eax, (%rsp)
movl %ebx, %esi
movl %ebp, %edx
movl %r14d, %ecx
callq *0x40(%r10)
addq $0x10, %rsp
testl %eax, %eax
je 0x2bc24
popq %rbx
popq %r14
popq %rbp
jmp 0x12b6fc
popq %rbx
popq %r14
popq %rbp
retq