// File: /workspace/github_c_makefile_star2_O0/moefh[P]hed/src/input.c
// Function: read_key
int read_key(int fd, char *seq, size_t max_seq_len)
{
  int nread;
  unsigned char c;
  while ((nread = read(fd, &c, 1)) != 1) {
    if (nread == -1 && errno != EAGAIN && errno != EINTR)
      return KEY_READ_ERROR;
    if (nread == -1 && errno == EINTR)
      return KEY_REDRAW;
  }

#define NEXT()        do { if (read(fd, &seq[len], 1) != 1) return read_key_seq(seq, len); len++; } while (0)
#define CUR           seq[len-1]
  
  size_t len = 0;
  if (c == '\x1b') {
    if (read(fd, &seq[len++], 1) != 1)
      return c;
    
    while (len < max_seq_len-3) {
      NEXT();
      if (CUR == '~' || CUR == '^' || IS_LETTER(CUR))
        return read_key_seq(seq, len);
      if (CUR == ';') {
        NEXT();
        continue;
      }
      //if (! IS_DIGIT(CUR)) return read_key_seq(seq, len);
    }
    return read_key_seq(seq, len);
  }
  //if (c >= 32) return -1;
  return c;
}

// Assembly:
subq $0x28, %rsp
movl %edi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movl 0x20(%rsp), %edi
leaq 0xb(%rsp), %rsi
movl $0x1, %edx
callq 0x2120
movl %eax, 0xc(%rsp)
cmpl $0x1, %eax
je 0x2af6
cmpl $-0x1, 0xc(%rsp)
jne 0x2ad6
callq 0x2040
cmpl $0xb, (%rax)
je 0x2ad6
callq 0x2040
cmpl $0x4, (%rax)
je 0x2ad6
movl $0xffffffff, 0x24(%rsp) # imm = 0xFFFFFFFF
jmp 0x2c87
cmpl $-0x1, 0xc(%rsp)
jne 0x2af4
callq 0x2040
cmpl $0x4, (%rax)
jne 0x2af4
movl $0x110002, 0x24(%rsp)   # imm = 0x110002
jmp 0x2c87
jmp 0x2a92
movq $0x0, (%rsp)
movzbl 0xb(%rsp), %eax
cmpl $0x1b, %eax
jne 0x2c7e
movl 0x20(%rsp), %edi
movq 0x18(%rsp), %rsi
movq (%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, (%rsp)
addq %rax, %rsi
movl $0x1, %edx
callq 0x2120
cmpq $0x1, %rax
je 0x2b45
movzbl 0xb(%rsp), %eax
movl %eax, 0x24(%rsp)
jmp 0x2c87
jmp 0x2b47
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x3, %rcx
cmpq %rcx, %rax
jae 0x2c6a
jmp 0x2b5f
movl 0x20(%rsp), %edi
movq 0x18(%rsp), %rsi
addq (%rsp), %rsi
movl $0x1, %edx
callq 0x2120
cmpq $0x1, %rax
je 0x2b93
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
callq 0x2c90
movl %eax, 0x24(%rsp)
jmp 0x2c87
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x7e, %eax
je 0x2bf7
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5e, %eax
je 0x2bf7
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x41, %eax
jl 0x2c0b
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x5a, %eax
jg 0x2c0b
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
callq 0x2c90
movl %eax, 0x24(%rsp)
jmp 0x2c87
movq 0x18(%rsp), %rax
movq (%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x3b, %eax
jne 0x2c65
jmp 0x2c23
movl 0x20(%rsp), %edi
movq 0x18(%rsp), %rsi
addq (%rsp), %rsi
movl $0x1, %edx
callq 0x2120
cmpq $0x1, %rax
je 0x2c54
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
callq 0x2c90
movl %eax, 0x24(%rsp)
jmp 0x2c87
movq (%rsp), %rax
addq $0x1, %rax
movq %rax, (%rsp)
jmp 0x2b47
jmp 0x2b47
movq 0x18(%rsp), %rdi
movq (%rsp), %rsi
callq 0x2c90
movl %eax, 0x24(%rsp)
jmp 0x2c87
movzbl 0xb(%rsp), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rsp), %eax
addq $0x28, %rsp
retq