// File: /workspace/github_c_makefile_star2_O3/jonof[P]jftekwar/src/tekmsc.c
// Function: domenuinput
void
domenuinput(void)
{
     int c,keystate;
     int  tries;
     struct menu *mptr = 0;

     if (activemenu == 255) {
          return;
     }
     if (activemenu == HELPSCREEN) {
          if (keystatus[1]) {
               keystatus[1]=0;
               playsound( S_BEEP ,0,0,0,ST_IMMEDIATE);
               if (menudirect) {
                    activemenu=255;
                    menudirect=0;
               }
          }
          return;
     }
     if (loctypemode) {
          while (keyfifoplc != keyfifoend) {
               c=keyfifo[keyfifoplc];
               keystate=keyfifo[(keyfifoplc+1)&(KEYFIFOSIZ-1)];
               keyfifoplc=((keyfifoplc+2)&(KEYFIFOSIZ-1));
               if (keystate != 0) {
                    if (c == 0x01) {              // ESC key
                         keystatus[1]=0;
                         locmessagelen=0;
                         loctypemode=0;
                    }
                    if (c == 0x0E) {              // backspace key
                         keystatus[14]=0;
                         if (locmessagelen == 0) {
                              break;
                         }
                         locmessagelen--;
                         lockeybuf[locmessagelen]=0;
                    }
                    if (c == 0x1C || c == 0x9C) { // enter keys
                         keystatus[0x1C]=keystatus[0x9C]=0;
                         if (locmessagelen > 0) {
                              strncpy(loadsavenames[selopt-1],lockeybuf,
                                   MAXLOADSAVESIZE);
                              locmessagelen=0;
                         }
                         loctypemode=0;
                         if( option[4] == 0 ) {
                              savegame(selopt);
                         }
                         activemenu=255;
                         break;
                    }
                    if (locmessagelen < (MAXLOADSAVESIZE-1) && c < 128) {
                         if (keystatus[0x2A] || keystatus[0x36]) {
                              c=scantoascwithshift[c];
                         }
                         else {
                              c=scantoasc[c];
                         }
                         if (c != 0) {
                              if (isalpha(c) || isdigit(c) || c == ' ') {
                                   lockeybuf[locmessagelen++]=toupper(c);
                                   lockeybuf[locmessagelen]=0;
                              }
                         }
                    }
               }
          }
          return;
     }
     mptr=&menu[activemenu][selopt];
     if (keystatus[1]) {
          keystatus[1]=0;
          playsound( S_BEEP ,0,0,0,ST_IMMEDIATE);
          if (menudirect) {
               activemenu=255;
               menudirect=0;
          }
          else {
               activemenu=mptr->backmenu;
          }
          selopt=lastselopt[activemenu];
          if (activemenu == 0) {
               activemenu=255;
          }
     }
     else if (keystatus[keys[0]]) {     // up arrow
          keystatus[keys[0]]=0;
          playsound( S_BOOP ,0,0,0,ST_IMMEDIATE);
          tries=0;
          while (tries < MAXSUBOPTIONS) {
               selopt--;
               if (selopt <= 0) {
                    selopt=5;
               }
               lastselopt[activemenu]=selopt;
               if (menu[activemenu][selopt].label != NULL) {
                    break;
               }
               tries++;
          }
     }
     else if (keystatus[keys[1]]) {     // down arrow
          keystatus[keys[1]]=0;
          playsound( S_BOOP ,0,0,0,ST_IMMEDIATE);
          tries=0;
          while (tries < MAXSUBOPTIONS) {
               selopt++;
               if (selopt > 5) {
                    selopt=1;
               }
               lastselopt[activemenu]=selopt;
               if (menu[activemenu][selopt].label != NULL) {
                    break;
               }
               tries++;
          }
     }
     else if (activemenu == 4) {
          if (keystatus[21] != 0) {                    // "Y" key
               switch (activemenu) {
               case 4:
                    gameover=1;
                    //playsound( ??? ,0,0,0,ST_IMMEDIATE);
                    break;
               case 5:
                    //endgame=1;
                    activemenu=255;
                    break;
               }
          }
          else if (keystatus[49] != 0) {               // "N" key
               activemenu=255;
          }
     }
     else if (keystatus[0x1C] || keystatus[0x9C]) {    // enter key
          keystatus[0x1C]=keystatus[0x9C]=0;
          playsound( S_MENUSOUND2 ,0,0,0,ST_IMMEDIATE);
          if (mptr->tomenu != 0) {
               activemenu=mptr->tomenu;
               selopt=lastselopt[activemenu];
               redrawborders=1;
          }
          else {
               switch (activemenu) {
               case 1:
                    break;
               case 2:
                    difficulty=selopt;
                    newgame(boardfilename);
                    activemenu=255;
                    break;
               case 3:
                    if (selopt == 3) {
                         if (strcmp(headbobstr,"HEAD BOB ON") == 0) {
                              strcpy(headbobstr,"HEAD BOB OFF");
                              headbobon=0;
                         }
                         else {
                              strcpy(headbobstr,"HEAD BOB ON");
                              headbobon=1;
                         }
                    }
                    break;
               case 5:                                 // day/night mission
                    loadnewgame=selopt;
                    break;
               case 6:                                 // load game
                    stopallsounds();
                    if( option[4] == 0 ) {
                         loadgame(selopt);
                    }
                    activemenu=255;
                    break;
               case 7:                                 // save game
                    keystatus[0x1C]=keystatus[0x9C]=0;
                    loctypemode=1;
                    keyfifoplc=keyfifoend;
                    if (strcmp(loadsavenames[selopt-1],"-EMPTY-") != 0) {
                         strncpy(lockeybuf,loadsavenames[selopt-1],
                              MAXLOADSAVESIZE);
                         locmessagelen=(int)strlen(lockeybuf);
                    }
                    else {
                         memset(lockeybuf,0,sizeof(lockeybuf));
                         locmessagelen=0;
                    }
                    break;
               }
          }
     }
     else if (activemenu == 8 || activemenu == 9) {
          if (keystatus[0x4B] || keystatus[0xCB]) {    // left arrow key
               keystatus[0x4B]=keystatus[0xCB]=0;
               switch (selopt) {
               case 1:
                    if (activemenu == 8) {
                         if (soundv > 0) {
                              soundv--;
                              soundmastervolume(soundv<<11);
                         }
                    }
                    else {
                         if (mousesensitivity > 0) {
                              mousesensitivity--;
                         }
                    }
                    break;
               case 2:
                    if (musicv > 0) {
                         musicv--;
                         songmastervolume(musicv<<3);
                    }
                    break;
               }
               playsound( S_MENUSOUND1 ,0,0,0,ST_IMMEDIATE);
          }
          else if (keystatus[0x4D] || keystatus[0xCD]) {    // right arrow key
               keystatus[0x4D]=keystatus[0xCD]=0;
               switch (selopt) {
               case 1:
                    if (activemenu == 8) {
                         if (soundv < 16) {
                              soundv++;
                              soundmastervolume(soundv<<11);
                         }
                    }
                    else {
                         if (mousesensitivity < 16) {
                              mousesensitivity++;
                         }
                    }
                    break;
               case 2:
                    if (musicv < 16) {
                         musicv++;
                         songmastervolume(musicv<<3);
                    }
                    break;
               }
               playsound( S_MENUSOUND1 ,0,0,0,ST_IMMEDIATE);
          }
     }
     else if (keystatus[16]) {
          keystatus[16]=0;
          gameover=1;
     }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movslq 0x117b2a(%rip), %rax    # 0x12f4f4
cmpq $0xff, %rax
je 0x17d99
cmpl $0x63, %eax
jne 0x17a2c
leaq 0x31773e(%rip), %rax    # 0x32f120
cmpb $0x0, 0x1(%rax)
je 0x17d99
movb $0x0, 0x1(%rax)
movl $0x36, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
cmpl $0x0, 0x11944f(%rip)    # 0x130e5c
je 0x17d99
movl $0xff, 0x117ad7(%rip)   # 0x12f4f4
movl $0x0, 0x119435(%rip)    # 0x130e5c
jmp 0x17d99
cmpl $0x0, 0x1195d1(%rip)    # 0x131004
je 0x17b80
leaq 0x317594(%rip), %rax    # 0x32efd4
movl (%rax), %ebp
leaq 0x317587(%rip), %rdx    # 0x32efd0
movl (%rdx), %r15d
cmpl %ebp, %r15d
je 0x17d99
movl 0x1195c4(%rip), %r13d   # 0x131020
leaq 0x3176bd(%rip), %rsi    # 0x32f120
movb 0x36(%rsi), %al
orb 0x2a(%rsi), %al
setne 0x7(%rsp)
leaq 0x31756b(%rip), %rdi    # 0x32efe0
leaq 0x11958c(%rip), %r12    # 0x131008
movslq %r15d, %r15
movslq (%rdi,%r15,4), %rax
leal 0x1(%r15), %ecx
andl $0x3f, %ecx
addl $0x2, %r15d
andl $0x3f, %r15d
movl %r15d, (%rdx)
cmpl $0x0, (%rdi,%rcx,4)
je 0x17b72
cmpl $0xe, %eax
je 0x17ac0
cmpl $0x1, %eax
jne 0x17ae3
movb $0x0, 0x1(%rsi)
xorl %r13d, %r13d
movl %r13d, 0x119569(%rip)   # 0x131020
movl %r13d, 0x119546(%rip)   # 0x131004
jmp 0x17af4
movb $0x0, 0xe(%rsi)
testl %r13d, %r13d
je 0x17d99
movslq %r13d, %rcx
leaq -0x1(%rcx), %r13
movl %r13d, 0x119545(%rip)   # 0x131020
movb $0x0, -0x1(%rcx,%r12)
jmp 0x17af4
movl %eax, %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
cmpl $0x1c, %ecx
je 0x17d28
cmpl $0xa, %r13d
jg 0x17b72
cmpl $0x7f, %eax
jg 0x17b72
leaq 0xba00a(%rip), %rcx     # 0xd1b10
cmpb $0x0, 0x7(%rsp)
je 0x17b14
leaq 0xba07c(%rip), %rcx     # 0xd1b90
movsbl (%rcx,%rax), %ebx
testl %ebx, %ebx
je 0x17b72
movslq %ebx, %r14
callq 0x81c0
movq (%rax), %rax
movzwl (%rax,%r14,2), %eax
btl $0xa, %eax
jb 0x17b3e
cmpb $0x20, %bl
je 0x17b3e
andl $0x800, %eax            # imm = 0x800
je 0x17b5d
movl %ebx, %edi
callq 0x8260
movslq %r13d, %rcx
leaq 0x1(%rcx), %r13
movl %r13d, 0x1194cd(%rip)   # 0x131020
movb %al, (%rcx,%r12)
movb $0x0, 0x1(%rcx,%r12)
leaq 0x31746c(%rip), %rdx    # 0x32efd0
leaq 0x3175b5(%rip), %rsi    # 0x32f120
leaq 0x31746e(%rip), %rdi    # 0x32efe0
cmpl %ebp, %r15d
jne 0x17a7c
jmp 0x17d99
movslq 0xbaa6d(%rip), %rcx     # 0xd25f4
leaq (%rax,%rax,2), %rdx
shlq $0x6, %rdx
leaq 0xba1da(%rip), %rbx     # 0xd1d70
movq %rcx, %r15
shlq $0x5, %r15
addq %rbx, %r15
addq %rdx, %r15
leaq 0x317576(%rip), %r14    # 0x32f120
cmpb $0x0, 0x1(%r14)
je 0x17bfe
movb $0x0, 0x1(%r14)
movl $0x36, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
cmpl $0x0, 0x119289(%rip)    # 0x130e5c
je 0x17c7d
movl $0xff, 0x117911(%rip)   # 0x12f4f4
movl $0x0, 0x11926f(%rip)    # 0x130e5c
movl 0xbadb9(%rip), %eax     # 0xd29ac
movl %eax, 0xba9fb(%rip)     # 0xd25f4
jmp 0x17d99
leaq 0xb9d7b(%rip), %rdx     # 0xd1980
movslq (%rdx), %rsi
cmpb $0x0, (%r14,%rsi)
je 0x17ca6
movb $0x0, (%r14,%rsi)
movl $0x37, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
movl 0xba9c0(%rip), %ecx     # 0xd25f4
movslq 0x1178b9(%rip), %rax    # 0x12f4f4
movl $0x5, %edx
leaq (%rax,%rax,2), %rsi
shlq $0x6, %rsi
addq %rsi, %rbx
movl $0x5, %esi
cmpl $0x2, %ecx
leal -0x1(%rcx), %ecx
cmovll %edx, %ecx
movslq %ecx, %r8
shlq $0x5, %r8
subl $0x1, %esi
setb %dil
cmpq $0x0, 0x8(%r8,%rbx)
jne 0x17d16
testb %dil, %dil
je 0x17c50
jmp 0x17d16
movsbq 0x19(%r15), %rax
movl %eax, 0x11786c(%rip)    # 0x12f4f4
leaq 0xba921(%rip), %rcx     # 0xd25b0
movl (%rcx,%rax,4), %ecx
movl %ecx, 0xba95c(%rip)     # 0xd25f4
testq %rax, %rax
jne 0x17d99
jmp 0x17d8f
movslq 0x4(%rdx), %rdx
cmpb $0x0, (%r14,%rdx)
je 0x17da8
movb $0x0, (%r14,%rdx)
movl $0x1, %ebp
movl $0x37, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
movl 0xba919(%rip), %ecx     # 0xd25f4
movslq 0x117812(%rip), %rax    # 0x12f4f4
movl $0x5, %edx
leaq (%rax,%rax,2), %rsi
shlq $0x6, %rsi
addq %rsi, %rbx
cmpl $0x5, %ecx
leal 0x1(%rcx), %ecx
cmovgel %ebp, %ecx
movslq %ecx, %rdi
shlq $0x5, %rdi
subl $0x1, %edx
setb %sil
cmpq $0x0, 0x8(%rdi,%rbx)
jne 0x17d16
testb %sil, %sil
je 0x17cf2
movl %ecx, 0xba8d8(%rip)     # 0xd25f4
leaq 0xba88d(%rip), %rdx     # 0xd25b0
movl %ecx, (%rdx,%rax,4)
jmp 0x17d99
xorl %eax, %eax
movb %al, 0x9c(%rsi)
movb %al, 0x1c(%rsi)
testl %r13d, %r13d
jle 0x17d6d
movslq 0xba8b5(%rip), %rax     # 0xd25f4
leaq (%rax,%rax,2), %rax
leaq 0x119276(%rip), %rcx    # 0x130fc0
leaq (%rcx,%rax,4), %rdi
addq $-0xc, %rdi
leaq 0x1192af(%rip), %rsi    # 0x131008
movl $0xc, %edx
callq 0x8210
movl $0x0, 0x1192b3(%rip)    # 0x131020
movl $0x0, 0x11928d(%rip)    # 0x131004
leaq 0xb9bfa(%rip), %rax     # 0xd1978
cmpb $0x0, 0x4(%rax)
jne 0x17d8f
movl 0xba86a(%rip), %edi     # 0xd25f4
callq 0x12b47
movl $0xff, 0x11775b(%rip)   # 0x12f4f4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x4, %eax
jne 0x17dc1
cmpb $0x0, 0x15(%r14)
je 0x17e7a
movb $0x1, 0x11773a(%rip)    # 0x12f4f9
jmp 0x17d99
movb 0x9c(%r14), %dl
orb 0x1c(%r14), %dl
je 0x17e22
xorl %eax, %eax
movb %al, 0x9c(%r14)
movb %al, 0x1c(%r14)
movl $0x35, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
callq 0x1c370
movsbl 0x18(%r15), %eax
testl %eax, %eax
je 0x17e9f
movl %eax, 0x1176f0(%rip)    # 0x12f4f4
cltq
leaq 0xba7a3(%rip), %rcx     # 0xd25b0
movl (%rcx,%rax,4), %eax
movl %eax, 0xba7de(%rip)     # 0xd25f4
movb $0x1, 0x1191e0(%rip)    # 0x130ffd
jmp 0x17d99
movl %eax, %edx
andl $-0x2, %edx
cmpl $0x8, %edx
jne 0x17e8a
movb 0xcb(%r14), %dl
orb 0x4b(%r14), %dl
je 0x17ede
xorl %edx, %edx
movb %dl, 0xcb(%r14)
movb %dl, 0x4b(%r14)
cmpl $0x2, %ecx
je 0x17f3b
cmpl $0x1, %ecx
jne 0x180d0
cmpl $0x8, %eax
jne 0x18071
movl 0xba791(%rip), %edi     # 0xd25fc
testl %edi, %edi
jle 0x180d0
decl %edi
jmp 0x17f28
cmpb $0x0, 0x31(%r14)
jne 0x17d8f
jmp 0x17d99
cmpb $0x0, 0x10(%r14)
je 0x17d99
movb $0x0, 0x10(%r14)
jmp 0x17db8
movl 0x11764f(%rip), %eax    # 0x12f4f4
addl $-0x2, %eax
cmpl $0x5, %eax
ja 0x17d99
leaq 0x77630(%rip), %rcx     # 0x8f4e8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0xba72d(%rip), %eax     # 0xd25f4
movl %eax, 0x119157(%rip)    # 0x131024
leaq 0xcd93c(%rip), %rdi     # 0xe5810
callq 0x1705b
jmp 0x17d8f
movb 0xcd(%r14), %dl
orb 0x4d(%r14), %dl
je 0x17d99
xorl %edx, %edx
movb %dl, 0xcd(%r14)
movb %dl, 0x4d(%r14)
cmpl $0x2, %ecx
je 0x1807f
cmpl $0x1, %ecx
jne 0x180d0
cmpl $0x8, %eax
jne 0x180bd
movl 0xba6df(%rip), %edi     # 0xd25fc
cmpl $0xf, %edi
jg 0x180d0
incl %edi
movl %edi, 0xba6ce(%rip)     # 0xd25fc
shll $0xb, %edi
callq 0x1c705
jmp 0x180d0
movl 0xba6b7(%rip), %eax     # 0xd25f8
testl %eax, %eax
jle 0x180d0
leal -0x1(%rax), %ecx
movl %ecx, 0xba6a6(%rip)     # 0xd25f8
leal -0x8(,%rax,8), %edi
jmp 0x1809a
movl 0xba690(%rip), %eax     # 0xd25f4
movl %eax, 0x119096(%rip)    # 0x131000
jmp 0x17d99
cmpl $0x3, 0xba67e(%rip)     # 0xd25f4
jne 0x17d99
movabsq $0x424f422044414548, %rax # imm = 0x424F422044414548
movq 0xb9dd3(%rip), %rcx     # 0xd1d60
xorq %rax, %rcx
movl 0xb9dd2(%rip), %edx     # 0xd1d68
xorq $0x4e4f20, %rdx         # imm = 0x4E4F20
orq %rcx, %rdx
je 0x180f4
movq %rax, 0xb9db3(%rip)     # 0xd1d60
movl $0x4e4f20, 0xb9db1(%rip) # imm = 0x4E4F20
leaq 0xba922(%rip), %rax     # 0xd28e0
movl $0x1, (%rax)
jmp 0x17d99
xorl %eax, %eax
callq 0x1c7f3
leaq 0xb99a1(%rip), %rax     # 0xd1978
cmpb $0x0, 0x4(%rax)
jne 0x17d8f
movl 0xba60d(%rip), %edi     # 0xd25f4
callq 0x11ea4
jmp 0x17d8f
xorl %ebp, %ebp
movb %bpl, 0x9c(%r14)
movb %bpl, 0x1c(%r14)
movl $0x1, 0x118ffc(%rip)    # 0x131004
leaq 0x316fc5(%rip), %rax    # 0x32efd4
movl (%rax), %eax
leaq 0x316fb8(%rip), %rcx    # 0x32efd0
movl %eax, (%rcx)
movslq 0xba5d3(%rip), %rax     # 0xd25f4
leaq (%rax,%rax,2), %rax
leaq 0x118f94(%rip), %rcx    # 0x130fc0
leaq (%rcx,%rax,4), %rbx
addq $-0xc, %rbx
leaq 0x77ae8(%rip), %rsi     # 0x8fb23
movq %rbx, %rdi
callq 0x8c40
testl %eax, %eax
je 0x180a1
leaq 0x118fba(%rip), %r14    # 0x131008
movl $0xc, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x8210
movq %r14, %rdi
callq 0x85a0
movl %eax, 0x118fb4(%rip)    # 0x131020
jmp 0x17d99
movl 0x118fa5(%rip), %eax    # 0x13101c
testl %eax, %eax
jle 0x180d0
decl %eax
jmp 0x180ca
movl 0xba573(%rip), %eax     # 0xd25f8
cmpl $0xf, %eax
jg 0x180d0
leal 0x1(%rax), %ecx
movl %ecx, 0xba565(%rip)     # 0xd25f8
leal 0x8(,%rax,8), %edi
callq 0x1c704
jmp 0x180d0
movl %ebp, 0x118f69(%rip)    # 0x131010
movq $0x0, 0x118f56(%rip) # 0x131008
movl %ebp, 0x118f68(%rip)    # 0x131020
jmp 0x17d99
movl 0x118f59(%rip), %eax    # 0x13101c
cmpl $0xf, %eax
jg 0x180d0
incl %eax
movl %eax, 0x118f4c(%rip)    # 0x13101c
movl $0x34, %edi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movl $0x1, %r8d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1c370
movabsq $0x46464f20424f42, %rcx # imm = 0x46464F20424F42
movq %rcx, 0xb9c60(%rip)     # 0xd1d65
movq %rax, 0xb9c54(%rip)     # 0xd1d60
leaq 0xba7cd(%rip), %rax     # 0xd28e0
movl $0x0, (%rax)
jmp 0x17d99