// File: /workspace/github_c_makefile_star2_O3/moefh[P]hed/src/input.c
// Function: read_key_seq
static int read_key_seq(char *seq, size_t len)
{
  if (len == 1 && seq[0] >= 32 && seq[0] < 127)
    return ALT_KEY(seq[0]);
  
  if (len == 2 && seq[0] == '[' && IS_LETTER(seq[1])) {
    switch (seq[1]) {
    case 'A': return KEY_ARROW_UP;
    case 'B': return KEY_ARROW_DOWN;
    case 'C': return KEY_ARROW_RIGHT;
    case 'D': return KEY_ARROW_LEFT;
    case 'H': return KEY_HOME;
    case 'F': return KEY_END;
    }
  }

  if (len == 3 && seq[0] == '[' && IS_DIGIT(seq[1]) && seq[2] == '~') {
    switch (seq[1]) {
    case '1': return KEY_HOME;
    case '2': return KEY_INS;
    case '3': return KEY_DEL;
    case '4': return KEY_END;
    case '5': return KEY_PAGE_UP;
    case '6': return KEY_PAGE_DOWN;
    case '7': return KEY_HOME;
    case '8': return KEY_END;
    }
  }

  if (len == 3 && seq[0] == '[' && IS_DIGIT(seq[1]) && seq[2] == '^') {
    switch (seq[1]) {
    case '1': return KEY_CTRL_HOME;
    case '2': return KEY_CTRL_INS;
    case '3': return KEY_CTRL_DEL;
    case '4': return KEY_CTRL_END;
    case '5': return KEY_CTRL_PAGE_UP;
    case '6': return KEY_CTRL_PAGE_DOWN;
    case '7': return KEY_CTRL_HOME;
    case '8': return KEY_CTRL_END;
    }
  }
  
  if (len == 5 && seq[0] == '[' && IS_DIGIT(seq[1]) && seq[2] == ';' && IS_DIGIT(seq[3])) {
    if (seq[1] == '1' && seq[3] == '5' && seq[4] == 'H') return KEY_CTRL_HOME;
    if (seq[1] == '1' && seq[3] == '5' && seq[4] == 'F') return KEY_CTRL_END;
  }
  
  if (len == 2 && seq[0] == 'O') {
    switch (seq[1]) {
    case 'F': return KEY_END;
    case 'H': return KEY_HOME;
    case 'P': return KEY_F1;
    case 'Q': return KEY_F2;
    case 'R': return KEY_F3;
    case 'S': return KEY_F4;
    }
  }

  if (len == 3 && seq[0] == '[' && seq[1] == '[' && IS_LETTER(seq[2])) {
    switch (seq[2]) {
    case 'A': return KEY_F1;
    case 'B': return KEY_F2;
    case 'C': return KEY_F3;
    case 'D': return KEY_F4;
    case 'E': return KEY_F5;
    }
  }

  if (len == 4 && seq[0] == '[' && IS_DIGIT(seq[1]) && IS_DIGIT(seq[2]) && seq[3] == '~') {
    if (seq[1] == '1' && seq[2] == '5') return KEY_F5;
    if (seq[1] == '1' && seq[2] == '7') return KEY_F6;
    if (seq[1] == '1' && seq[2] == '8') return KEY_F7;
    if (seq[1] == '1' && seq[2] == '9') return KEY_F8;
    if (seq[1] == '2' && seq[2] == '0') return KEY_F9;
    if (seq[1] == '2' && seq[2] == '1') return KEY_F10;
    if (seq[1] == '2' && seq[2] == '3') return KEY_F11;
    if (seq[1] == '2' && seq[2] == '4') return KEY_F12;
    
    if (seq[1] == '2' && seq[2] == '5') return KEY_SHIFT_F1;
    if (seq[1] == '2' && seq[2] == '6') return KEY_SHIFT_F2;
    if (seq[1] == '2' && seq[2] == '8') return KEY_SHIFT_F3;
    if (seq[1] == '2' && seq[2] == '9') return KEY_SHIFT_F4;
    if (seq[1] == '3' && seq[2] == '1') return KEY_SHIFT_F5;
    if (seq[1] == '3' && seq[2] == '2') return KEY_SHIFT_F6;
    if (seq[1] == '3' && seq[2] == '3') return KEY_SHIFT_F7;
    if (seq[1] == '3' && seq[2] == '4') return KEY_SHIFT_F8;
  }
  
  //err_msg(editor, "-> unrecognized key: %.*s", (int)len, seq);
  seq[len] = '\0';
  return KEY_BAD_SEQUENCE;
}

// Assembly:
leaq -0x1(%rsi), %rax
cmpq $0x4, %rax
ja 0x2c06
leaq 0x485e(%rip), %rcx      # 0x7234
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzbl (%rdi), %eax
leal -0x7f(%rax), %ecx
cmpb $-0x5f, %cl
jb 0x2c06
andl $0x1f, %eax
orl $0x112000, %eax         # imm = 0x112000
retq
cmpb $0x5b, (%rdi)
jne 0x2c06
movb 0x1(%rdi), %al
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x2c06
cmpb $0x3b, 0x2(%rdi)
jne 0x2c06
movb 0x3(%rdi), %cl
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x2c06
xorb $0x31, %al
xorb $0x35, %cl
orb %al, %cl
jne 0x2c06
movzbl 0x4(%rdi), %ecx
cmpl $0x46, %ecx
je 0x2bcd
movl $0x11101a, %eax         # imm = 0x11101A
cmpl $0x48, %ecx
je 0x29f6
jmp 0x2c06
cmpb $0x5b, (%rdi)
jne 0x2c06
movb 0x1(%rdi), %al
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x2b61
cmpb $0x7e, 0x2(%rdi)
jne 0x2b8c
leal -0x31(%rax), %ecx
cmpb $0x8, %cl
jae 0x2b8c
movzbl %cl, %eax
leaq 0x482b(%rip), %rcx      # 0x72b4
jmp 0x2ba2
cmpb $0x5b, (%rdi)
jne 0x2c06
movzbl 0x1(%rdi), %edx
leal -0x30(%rdx), %eax
cmpb $0x9, %al
ja 0x2c06
movzbl 0x2(%rdi), %ecx
leal -0x30(%rcx), %eax
cmpb $0x9, %al
ja 0x2c06
cmpb $0x7e, 0x3(%rdi)
jne 0x2c06
movl %edx, %r8d
xorb $0x31, %r8b
movl %ecx, %r9d
xorb $0x35, %r9b
movl $0x111022, %eax         # imm = 0x111022
orb %r8b, %r9b
je 0x29f6
cmpl $0x31, %edx
jne 0x2ba6
leal -0x37(%rcx), %eax
cmpb $0x3, %al
jae 0x2c06
addl $0x110fec, %ecx         # imm = 0x110FEC
jmp 0x2be0
movzbl (%rdi), %eax
cmpl $0x4f, %eax
je 0x2b3a
cmpl $0x5b, %eax
jne 0x2c06
movb 0x1(%rdi), %al
addb $-0x41, %al
cmpb $0x19, %al
ja 0x2c06
cmpb $0x8, %al
jae 0x2c06
movzbl %al, %eax
movl $0xaf, %ecx
btl %eax, %ecx
jae 0x2c06
leaq 0x475c(%rip), %rcx      # 0x7294
jmp 0x2ba2
movb 0x1(%rdi), %al
addb $-0x46, %al
cmpb $0xe, %al
jae 0x2c06
movzbl %al, %eax
movl $0x3c05, %ecx           # imm = 0x3C05
btl %eax, %ecx
jae 0x2c06
leaq 0x46e9(%rip), %rcx      # 0x7248
jmp 0x2ba2
cmpb $0x5b, %al
jne 0x2c06
movb 0x2(%rdi), %al
leal -0x41(%rax), %ecx
cmpb $0x1a, %cl
setb %dl
cmpb $0x5, %cl
setb %cl
testb %cl, %dl
je 0x2c06
movzbl %al, %eax
addl $0x110fdd, %eax         # imm = 0x110FDD
retq
cmpb $0x5e, 0x2(%rdi)
jne 0x2c06
addb $-0x31, %al
cmpb $0x8, %al
jae 0x2c06
movzbl %al, %eax
leaq 0x4732(%rip), %rcx      # 0x72d4
movl (%rcx,%rax,4), %eax
retq
cmpl $0x33, %edx
je 0x2bd3
cmpl $0x32, %edx
jne 0x2c06
leal -0x30(%rcx), %eax
cmpb $0x5, %al
jae 0x2be3
movzbl %al, %eax
movl $0x1b, %edx
btl %eax, %edx
jae 0x2be3
leaq 0x46b5(%rip), %rcx      # 0x7280
jmp 0x2ba2
movl $0x11101b, %eax         # imm = 0x11101B
retq
leal -0x31(%rcx), %eax
cmpb $0x4, %al
jae 0x2c06
addl $0x110ffd, %ecx         # imm = 0x110FFD
movl %ecx, %eax
retq
movl $0x11102a, %eax         # imm = 0x11102A
cmpl $0x35, %ecx
je 0x29f6
cmpl $0x36, %ecx
je 0x2c16
cmpl $0x38, %ecx
je 0x2c10
cmpl $0x39, %ecx
jne 0x2c06
movl $0x11102d, %eax         # imm = 0x11102D
retq
movb $0x0, (%rdi,%rsi)
movl $0x110001, %eax         # imm = 0x110001
retq
movl $0x11102c, %eax         # imm = 0x11102C
retq
movl $0x11102b, %eax         # imm = 0x11102B
retq