// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
cmpq $0x1, %rsi
jne 0x29cf
movzbl (%rdi), %eax
leal -0x7f(%rax), %ecx
cmpb $-0x5f, %cl
jae 0x2a34
cmpq $0x2, %rsi
jne 0x2a00
cmpb $0x5b, (%rdi)
jne 0x2a00
movb 0x1(%rdi), %al
addb $-0x41, %al
cmpb $0x19, %al
ja 0x2a00
cmpb $0x8, %al
jae 0x2a00
movzbl %al, %eax
movl $0xaf, %ecx
btl %eax, %ecx
jae 0x2a00
leaq 0x4839(%rip), %rcx      # 0x7234
jmp 0x2ae3
cmpq $0x3, %rsi
jne 0x2a68
movb (%rdi), %al
cmpb $0x5b, %al
jne 0x2a68
movb 0x1(%rdi), %cl
leal -0x30(%rcx), %edx
cmpb $0x9, %dl
ja 0x2a41
cmpb $0x7e, 0x2(%rdi)
jne 0x2a41
addb $-0x31, %cl
cmpb $0x8, %cl
jae 0x2a41
movzbl %cl, %eax
leaq 0x4825(%rip), %rcx      # 0x7254
jmp 0x2ae3
andl $0x1f, %eax
orl $0x112000, %eax         # imm = 0x112000
jmp 0x2c75
cmpb $0x5b, %al
jne 0x2a68
movb 0x1(%rdi), %al
leal -0x30(%rax), %ecx
cmpb $0x9, %cl
ja 0x2a68
cmpb $0x5e, 0x2(%rdi)
jne 0x2a68
addb $-0x31, %al
cmpb $0x8, %al
jae 0x2a68
movzbl %al, %eax
leaq 0x480e(%rip), %rcx      # 0x7274
jmp 0x2ae3
cmpq $0x5, %rsi
jne 0x2abb
cmpb $0x5b, (%rdi)
jne 0x2abb
movb 0x1(%rdi), %cl
leal -0x30(%rcx), %eax
cmpb $0x9, %al
ja 0x2abb
cmpb $0x3b, 0x2(%rdi)
jne 0x2abb
movb 0x3(%rdi), %dl
leal -0x30(%rdx), %eax
cmpb $0x9, %al
ja 0x2abb
xorb $0x31, %cl
xorb $0x35, %dl
movl %ecx, %eax
orb %dl, %al
jne 0x2aa8
movl $0x11101a, %eax         # imm = 0x11101A
cmpb $0x48, 0x4(%rdi)
je 0x2c75
orb %dl, %cl
jne 0x2abb
movl $0x11101b, %eax         # imm = 0x11101B
cmpb $0x46, 0x4(%rdi)
je 0x2c75
cmpq $0x2, %rsi
jne 0x2aeb
cmpb $0x4f, (%rdi)
jne 0x2aeb
movb 0x1(%rdi), %al
addb $-0x46, %al
cmpb $0xe, %al
jae 0x2aeb
movzbl %al, %eax
movl $0x3c05, %ecx           # imm = 0x3C05
btl %eax, %ecx
jae 0x2aeb
leaq 0x47b1(%rip), %rcx      # 0x7294
movl (%rcx,%rax,4), %eax
jmp 0x2c75
cmpq $0x3, %rsi
jne 0x2b1f
cmpb $0x5b, (%rdi)
jne 0x2b1f
cmpb $0x5b, 0x1(%rdi)
jne 0x2b1f
movb 0x2(%rdi), %al
leal -0x41(%rax), %ecx
cmpb $0x1a, %cl
setb %dl
cmpb $0x5, %cl
setb %cl
testb %cl, %dl
je 0x2b1f
movzbl %al, %eax
addl $0x110fdd, %eax         # imm = 0x110FDD
jmp 0x2c75
cmpq $0x4, %rsi
jne 0x2c6c
cmpb $0x5b, (%rdi)
jne 0x2c6c
movb 0x1(%rdi), %cl
leal -0x30(%rcx), %eax
cmpb $0x9, %al
ja 0x2c6c
movb 0x2(%rdi), %dl
leal -0x30(%rdx), %eax
cmpb $0x9, %al
ja 0x2c6c
cmpb $0x7e, 0x3(%rdi)
jne 0x2c6c
movl %ecx, %r11d
xorb $0x31, %r11b
movl %edx, %r8d
xorb $0x35, %r8b
movl $0x111022, %eax         # imm = 0x111022
movl %r11d, %r9d
orb %r8b, %r9b
je 0x2c75
movl %edx, %r9d
xorb $0x37, %r9b
movl $0x111023, %eax         # imm = 0x111023
orb %r11b, %r9b
je 0x2c75
movl %edx, %r9d
xorb $0x38, %r9b
movl $0x111024, %eax         # imm = 0x111024
movl %r11d, %r10d
orb %r9b, %r10b
je 0x2c75
movl %edx, %r10d
xorb $0x39, %r10b
movl $0x111025, %eax         # imm = 0x111025
orb %r10b, %r11b
je 0x2c75
movl %ecx, %ebp
xorb $0x32, %bpl
movl %edx, %r11d
xorb $0x30, %r11b
movl $0x111026, %eax         # imm = 0x111026
orb %bpl, %r11b
je 0x2c75
movl %edx, %r14d
xorb $0x31, %r14b
movl $0x111027, %eax         # imm = 0x111027
movl %ebp, %r11d
orb %r14b, %r11b
je 0x2c75
movl %edx, %r11d
xorb $0x33, %r11b
movl $0x111028, %eax         # imm = 0x111028
movl %ebp, %ebx
orb %r11b, %bl
je 0x2c75
movl %edx, %ebx
xorb $0x34, %bl
movl $0x111029, %eax         # imm = 0x111029
movl %ebp, %r15d
orb %bl, %r15b
je 0x2c75
movl $0x11102a, %eax         # imm = 0x11102A
orb %bpl, %r8b
je 0x2c75
movl %edx, %r8d
xorb $0x36, %r8b
movl $0x11102b, %eax         # imm = 0x11102B
orb %bpl, %r8b
je 0x2c75
movl $0x11102c, %eax         # imm = 0x11102C
orb %bpl, %r9b
je 0x2c75
movl $0x11102d, %eax         # imm = 0x11102D
orb %r10b, %bpl
je 0x2c75
xorb $0x33, %cl
movl $0x11102e, %eax         # imm = 0x11102E
orb %cl, %r14b
je 0x2c75
xorb $0x32, %dl
movl $0x11102f, %eax         # imm = 0x11102F
orb %cl, %dl
je 0x2c75
movl $0x111030, %eax         # imm = 0x111030
orb %cl, %r11b
je 0x2c75
movl $0x111031, %eax         # imm = 0x111031
orb %bl, %cl
je 0x2c75
movb $0x0, (%rdi,%rsi)
movl $0x110001, %eax         # imm = 0x110001
popq %rbx
popq %r14
popq %r15
popq %rbp
retq