// File: /workspace/github_c_makefile_star2_O3/termbox[P]termbox/termbox.c
// Function: extract_event
static bool extract_event(struct tb_event *event, struct bytebuffer *inbuf,
                          int inputmode) {
    const char *buf = inbuf->buf;
    const int len = inbuf->len;
    if (len == 0)
        return false;

    if (buf[0] == '\033') {
        int n = parse_escape_seq(event, buf, len);
        if (n != 0) {
            bool success = true;
            if (n < 0) {
                success = false;
                n = -n;
            }
            bytebuffer_truncate(inbuf, n);
            return success;
        } else {
            // it's not escape sequence, then it's ALT or ESC,
            // check inputmode
            if (inputmode & TB_INPUT_ESC) {
                // if we're in escape mode, fill ESC event, pop
                // buffer, return success
                event->ch = 0;
                event->key = TB_KEY_ESC;
                event->mod = 0;
                bytebuffer_truncate(inbuf, 1);
                return true;
            } else if (inputmode & TB_INPUT_ALT) {
                // if we're in alt mode, set ALT modifier to
                // event and redo parsing
                event->mod = TB_MOD_ALT;
                bytebuffer_truncate(inbuf, 1);
                return extract_event(event, inbuf, inputmode);
            }
            assert(!"never got here");
        }
    }

    // if we're here, this is not an escape sequence and not an alt sequence
    // so, it's a FUNCTIONAL KEY or a UNICODE character

    // first of all check if it's a functional key
    if ((unsigned char)buf[0] <= TB_KEY_SPACE ||
        (unsigned char)buf[0] == TB_KEY_BACKSPACE2) {
        // fill event, pop buffer, return success */
        event->ch = 0;
        event->key = (uint16_t)buf[0];
        bytebuffer_truncate(inbuf, 1);
        return true;
    }

    // feh... we got utf8 here

    // check if there is all bytes
    if (len >= tb_utf8_char_length(buf[0])) {
        /* everything ok, fill event, pop buffer, return success */
        tb_utf8_char_to_unicode(&event->ch, buf);
        event->key = 0;
        bytebuffer_truncate(inbuf, tb_utf8_char_length(buf[0]));
        return true;
    }

    // event isn't recognized, perhaps there is not enough bytes in utf8
    // sequence
    return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl 0x4a13(%rip), %r13d     # 0x98e0
testl %r13d, %r13d
je 0x5135
movl %esi, %r12d
movq 0x4a50(%rip), %rax      # 0x9930
movq %rax, 0x10(%rsp)
movq %rdi, %r15
leaq 0x4(%rdi), %rax
movq %rax, 0x20(%rsp)
movq 0x49e0(%rip), %r14      # 0x98d8
movl 0x49e2(%rip), %esi      # 0x98e0
leaq 0x150c(%rip), %rdx      # 0x6411
leaq 0x1509(%rip), %rdi      # 0x6415
leaq 0x1455(%rip), %r8       # 0x6368
movq %r15, 0x8(%rsp)
movl %r12d, 0x1c(%rsp)
movb (%r14), %al
cmpb $0x1b, %al
jne 0x50ce
cmpl $0x6, %r13d
movq 0x10(%rsp), %r10
jl 0x4f51
movb $0x1b, %cl
xorl %eax, %eax
cmpb %cl, (%r14,%rax)
jne 0x4f51
movb 0x1(%rax,%rdx), %cl
incq %rax
cmpl $0x3, %eax
jne 0x4f37
testb %cl, %cl
je 0x5182
testl %r13d, %r13d
jle 0x4ffb
leal -0x1(%r13), %eax
cmpq $0x2, %rax
movl $0x2, %ecx
cmovaeq %rcx, %rax
incq %rax
movb $0x1b, %cl
xorl %edx, %edx
cmpb %cl, (%r14,%rdx)
jne 0x4f87
movb 0x1(%rdx,%rdi), %cl
incq %rdx
cmpl %edx, %eax
jne 0x4f72
testb %cl, %cl
je 0x4fad
movb $0x1b, %cl
movl $0x1, %eax
cmpb %cl, -0x1(%r14,%rax)
jne 0x4ffb
movb (%rax,%r8), %cl
testb %cl, %cl
je 0x4fa9
leaq 0x1(%rax), %rdx
cmpl %r13d, %eax
movq %rdx, %rax
jl 0x4f8e
testb %cl, %cl
jne 0x4ffb
movl %r13d, %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movzbl (%r14,%r12), %ecx
movl %ecx, %edx
orl $0x20, %edx
cmpl $0x6d, %edx
je 0x4fe9
cmpl $-0x1, %ebx
movl %ebx, %edx
cmovel %r12d, %edx
cmpb $0x3b, %cl
cmovel %r12d, %ebp
cmovel %edx, %ebx
incq %r12
cmpq %r12, %rax
jne 0x4fbd
jmp 0x4ffb
cmpl $-0x1, %ebx
je 0x4ffb
cmpl $-0x1, %ebp
je 0x4ffb
cmpl %ebp, %ebx
jne 0x51b0
movl %esi, %ebx
movq (%r10), %rdi
testq %rdi, %rdi
movq 0x8(%rsp), %rbp
je 0x5067
xorl %eax, %eax
movb (%rdi), %cl
testl %r13d, %r13d
jle 0x5036
testb %cl, %cl
je 0x5036
movl $0x1, %edx
cmpb %cl, -0x1(%r14,%rdx)
jne 0x503a
movb (%rdi,%rdx), %cl
testb %cl, %cl
je 0x5036
leaq 0x1(%rdx), %rsi
cmpl %r13d, %edx
movq %rsi, %rdx
jl 0x501c
testb %cl, %cl
je 0x5049
movq 0x8(%r10,%rax,8), %rdi
incq %rax
testq %rdi, %rdi
jne 0x500c
jmp 0x5067
movl $0x0, 0x4(%rbp)
notl %eax
movw %ax, 0x2(%rbp)
callq 0x30c0
movq %rax, %r12
testl %r12d, %r12d
jne 0x52fb
movl 0x1c(%rsp), %r12d
testb $0x1, %r12b
jne 0x50ef
testb $0x2, %r12b
je 0x533d
movq %rbp, %r15
movb $0x1, 0x1(%rbp)
testl %r13d, %r13d
movl $0x1, %eax
cmovlel %r13d, %eax
subl %eax, %r13d
movslq %eax, %rbp
leaq (%r14,%rbp), %rsi
movslq %r13d, %rdx
movq %r14, %rdi
callq 0x31d0
subl %ebp, %ebx
movl %ebx, 0x4834(%rip)      # 0x98e0
movl %ebx, %r13d
movl %ebx, %esi
leaq 0x1359(%rip), %rdx      # 0x6411
leaq 0x1356(%rip), %rdi      # 0x6415
leaq 0x12a2(%rip), %r8       # 0x6368
jne 0x4f1d
jmp 0x5135
cmpb $0x21, %al
setae %cl
cmpb $0x7f, %al
setne %dl
testb %dl, %cl
jne 0x5128
movl $0x0, 0x4(%r15)
movsbl (%r14), %eax
movw %ax, 0x2(%r15)
jmp 0x5100
movl $0x0, 0x4(%rbp)
movw $0x1b, 0x2(%rbp)
movb $0x0, 0x1(%rbp)
testl %r13d, %r13d
movl $0x1, %ebx
cmovlel %r13d, %ebx
subl %ebx, %r13d
movslq %ebx, %rsi
addq %r14, %rsi
movslq %r13d, %rdx
movq %r14, %rdi
callq 0x31d0
movb $0x1, %bpl
jmp 0x5326
movsbl %al, %edi
callq 0x5454
cmpl %eax, %r13d
jge 0x513c
xorl %ebp, %ebp
jmp 0x532c
movq 0x20(%rsp), %rdi
movq %r14, %rsi
callq 0x5464
movw $0x0, 0x2(%r15)
movsbl (%r14), %edi
callq 0x5454
testl %eax, %eax
jle 0x523d
movl %eax, %ebx
movl 0x4777(%rip), %eax      # 0x98e0
cmpl %ebx, %eax
cmovll %eax, %ebx
subl %ebx, %eax
movq 0x4761(%rip), %rdi      # 0x98d8
movslq %ebx, %rsi
addq %rdi, %rsi
movslq %eax, %rdx
jmp 0x511b
movzbl 0x3(%r14), %ecx
leal -0x20(%rcx), %eax
andl $0x3, %ecx
leaq 0xefc(%rip), %rdx       # 0x6090
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal -0x1b(,%rcx,4), %ecx
jmp 0x5261
movl %r12d, %eax
movb (%r14,%rax), %al
movb %al, 0x10(%rsp)
movb 0x2(%r14), %r15b
xorl %eax, %eax
cmpb $0x3c, %r15b
sete %al
leaq (%r14,%rax), %rdi
addq $0x2, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
leal -0x20(%rax), %r13d
cmpb $0x3c, %r15b
movslq %ebx, %rcx
leaq 0x1(%r14,%rcx), %rdi
cmovel %eax, %r13d
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
movq %rax, %r15
movslq %ebp, %rax
leaq (%r14,%rax), %rdi
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
movl %r13d, %ecx
andl $0x3, %ecx
leaq 0xe5e(%rip), %rdx       # 0x6080
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %r13b
sete %cl
leal -0x1b(,%rcx,4), %ecx
jmp 0x52b1
movb $0x1, %bpl
jmp 0x532c
movw $0xffe8, %cx            # imm = 0xFFE8
jmp 0x5261
movw $0xffe6, %cx            # imm = 0xFFE6
jmp 0x5261
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe4, %ecx           # imm = 0xFFE4
movw %cx, 0x2(%r15)
movb $0x3, (%r15)
testb $0x20, %al
je 0x5273
orb $0x2, 0x1(%r15)
movzbl 0x4(%r14), %eax
addl $-0x21, %eax
movl %eax, 0x10(%r15)
movzbl 0x5(%r14), %eax
addl $-0x21, %eax
movl %eax, 0x14(%r15)
movl $0x6, %r12d
jmp 0x52fb
movw $0xffe8, %cx            # imm = 0xFFE8
jmp 0x52b1
movw $0xffe6, %cx            # imm = 0xFFE6
jmp 0x52b1
xorl %ecx, %ecx
testb $0x40, %r13b
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe4, %ecx           # imm = 0xFFE4
movq 0x8(%rsp), %rsi
cmpb $0x4d, 0x10(%rsp)
movl $0xffe6, %edx           # imm = 0xFFE6
cmovel %ecx, %edx
movw %dx, 0x2(%rsi)
movb $0x3, (%rsi)
testb $0x20, %r13b
je 0x52d4
orb $0x2, 0x1(%rsi)
movl $0xff, %ecx
andl %ecx, %r15d
decl %r15d
movl %r15d, 0x10(%rsi)
andl %ecx, %eax
decl %eax
movl %eax, 0x14(%rsi)
incl %r12d
movl 0x45ec(%rip), %r13d     # 0x98e0
movq 0x45dd(%rip), %r14      # 0x98d8
testl %r12d, %r12d
setns %bpl
movl %r12d, %ebx
negl %ebx
cmovsl %r12d, %ebx
cmpl %ebx, %r13d
cmovll %r13d, %ebx
subl %ebx, %r13d
movslq %ebx, %rsi
addq %r14, %rsi
movslq %r13d, %rdx
movq %r14, %rdi
callq 0x31d0
subl %ebx, 0x45b4(%rip)      # 0x98e0
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x107a(%rip), %rdi      # 0x63be
leaq 0x102b(%rip), %rsi      # 0x6376
leaq 0x107e(%rip), %rcx      # 0x63d0
movl $0x299, %edx            # imm = 0x299
callq 0x30e0