// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movl %esi, 0x14(%rsp)
movq %rdi, %r15
leaq 0x14f0(%rip), %rsi      # 0x6411
leaq 0x14ed(%rip), %r12      # 0x6415
movq %rdi, 0x8(%rsp)
movl 0x49ad(%rip), %ebp      # 0x98e0
testq %rbp, %rbp
je 0x5381
movq 0x4995(%rip), %r14      # 0x98d8
movb (%r14), %al
cmpb $0x1b, %al
jne 0x52bb
cmpl $0x6, %ebp
jl 0x4f83
leal -0x1(%rbp), %eax
cmpq $0x2, %rax
movl $0x2, %ecx
cmovaeq %rcx, %rax
incq %rax
movb $0x1b, %cl
xorl %edx, %edx
cmpb %cl, (%r14,%rdx)
jne 0x4f83
movb 0x1(%rdx,%rsi), %cl
incq %rdx
cmpl %edx, %eax
jne 0x4f6a
testb %cl, %cl
je 0x50f0
xorl %eax, %eax
testl %ebp, %ebp
jle 0x51e4
leal -0x1(%rbp), %ecx
cmpq $0x2, %rcx
movl $0x2, %edx
cmovaeq %rdx, %rcx
incq %rcx
movb $0x1b, %dl
xorl %esi, %esi
leaq 0x13bd(%rip), %rdi      # 0x6368
cmpb %dl, (%r14,%rsi)
jne 0x4fc1
movb 0x1(%rsi,%r12), %dl
incq %rsi
cmpl %esi, %ecx
jne 0x4fab
testb %dl, %dl
je 0x4fec
xorl %ecx, %ecx
cmpl $0x1, %ebp
setne %cl
incl %ecx
movb $0x1b, %dl
xorl %esi, %esi
cmpb %dl, (%r14,%rsi)
jne 0x51e4
movb 0x1(%rsi,%rdi), %dl
incq %rsi
cmpl %esi, %ecx
jne 0x4fcf
testb %dl, %dl
jne 0x51e4
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r13d, %ecx
cmpl $-0x1, %r13d
cmovel %r15d, %r13d
movzbl (%r14,%r15), %edx
cmpl $0x3b, %edx
cmovnel %ecx, %r13d
cmovel %r15d, %ebx
orl $0x20, %edx
cmpl $0x6d, %edx
je 0x502b
incq %r15
cmpq %r15, %rbp
jne 0x4ffa
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
cmpl $-0x1, %r15d
je 0x51e4
cmpl $-0x1, %r13d
sete %cl
cmpl $-0x1, %ebx
sete %dl
orb %cl, %dl
cmpl %ebx, %r13d
sete %cl
orb %dl, %cl
jne 0x51e4
movslq %r15d, %rax
movb (%r14,%rax), %al
movb %al, 0x3(%rsp)
movb 0x2(%r14), %cl
movb %cl, 0x4(%rsp)
xorl %eax, %eax
cmpb $0x3c, %cl
sete %al
leaq (%r14,%rax), %rdi
addq $0x2, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
leal -0x20(%rax), %edx
cmpb $0x3c, 0x4(%rsp)
movslq %r13d, %rcx
leaq 0x1(%r14,%rcx), %rdi
cmovel %eax, %edx
movl %edx, 0x4(%rsp)
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
movq %rax, %r13
movslq %ebx, %rax
leaq (%r14,%rax), %rdi
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x3230
movl 0x4(%rsp), %esi
movl %esi, %ecx
andl $0x3, %ecx
leaq 0xfb3(%rip), %rdx       # 0x6080
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testb $0x40, %sil
movq 0x8(%rsp), %rcx
jne 0x51a0
movw $0xffe9, 0x2(%rcx)      # imm = 0xFFE9
jmp 0x51ae
movzbl 0x3(%r14), %ecx
leal -0x20(%rcx), %eax
andl $0x3, %ecx
leaq 0xf8e(%rip), %rdx       # 0x6090
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
testb $0x40, %al
jne 0x5164
movw $0xffe9, 0x2(%r15)      # imm = 0xFFE9
jmp 0x5174
movw $0xffe8, 0x2(%r15)      # imm = 0xFFE8
jmp 0x5174
movw $0xffe6, 0x2(%r15)      # imm = 0xFFE6
jmp 0x5174
testb $0x40, %al
jne 0x516d
movw $0xffe7, 0x2(%r15)      # imm = 0xFFE7
jmp 0x5174
movq 0x8(%rsp), %rcx
movw $0xffe8, 0x2(%rcx)      # imm = 0xFFE8
jmp 0x51ae
movq 0x8(%rsp), %rcx
movw $0xffe6, 0x2(%rcx)      # imm = 0xFFE6
jmp 0x51ae
testb $0x40, %sil
movq 0x8(%rsp), %rcx
jne 0x51a8
movw $0xffe7, 0x2(%rcx)      # imm = 0xFFE7
jmp 0x51ae
movw $0xffe5, 0x2(%r15)      # imm = 0xFFE5
jmp 0x5174
movw $0xffe4, 0x2(%r15)      # imm = 0xFFE4
movb $0x3, (%r15)
testb $0x20, %al
je 0x5181
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, %eax
jmp 0x51e4
movw $0xffe5, 0x2(%rcx)      # imm = 0xFFE5
jmp 0x51ae
movw $0xffe4, 0x2(%rcx)      # imm = 0xFFE4
cmpb $0x4d, 0x3(%rsp)
je 0x51bb
movw $0xffe6, 0x2(%rcx)      # imm = 0xFFE6
movb $0x3, (%rcx)
testb $0x20, %sil
je 0x51c8
orb $0x2, 0x1(%rcx)
movl $0xff, %edx
andl %edx, %r13d
decl %r13d
movl %r13d, 0x10(%rcx)
andl %edx, %eax
decl %eax
movl %eax, 0x14(%rcx)
incl %r15d
movl %r15d, %eax
testl %eax, %eax
movq 0x8(%rsp), %r15
movl 0x14(%rsp), %ebx
je 0x524a
testl %eax, %eax
jne 0x52f9
testb $0x1, %bl
jne 0x532f
testb $0x2, %bl
je 0x53d9
movb $0x1, 0x1(%r15)
movl 0x46ca(%rip), %eax      # 0x98e0
testl %eax, %eax
movl $0x1, %ecx
cmovlel %eax, %ecx
subl %ecx, %eax
movq 0x46af(%rip), %rdi      # 0x98d8
movslq %ecx, %rbx
leaq (%rdi,%rbx), %rsi
movslq %eax, %rdx
callq 0x31d0
subl %ebx, 0x46a2(%rip)      # 0x98e0
leaq 0x11cc(%rip), %rsi      # 0x6411
jmp 0x4f2d
movq 0x46df(%rip), %rcx      # 0x9930
movq (%rcx), %rdi
xorl %eax, %eax
testq %rdi, %rdi
je 0x51f1
xorl %edx, %edx
movb (%rdi), %sil
testl %ebp, %ebp
jle 0x528b
testb %sil, %sil
je 0x528b
movl $0x1, %r8d
cmpb %sil, -0x1(%r14,%r8)
jne 0x5290
movb (%rdi,%r8), %sil
testb %sil, %sil
je 0x528b
leaq 0x1(%r8), %r9
cmpl %ebp, %r8d
movq %r9, %r8
jl 0x526f
testb %sil, %sil
je 0x52a2
movq 0x8(%rcx,%rdx,8), %rdi
incq %rdx
testq %rdi, %rdi
jne 0x525d
jmp 0x51f1
movl $0x0, 0x4(%r15)
notl %edx
movw %dx, 0x2(%r15)
callq 0x30c0
jmp 0x51f1
cmpb $0x21, %al
setae %cl
cmpb $0x7f, %al
setne %dl
testb %dl, %cl
jne 0x5375
movl $0x0, 0x4(%r15)
movsbl (%r14), %eax
movw %ax, 0x2(%r15)
testl %ebp, %ebp
movl $0x1, %eax
cmovlel %ebp, %eax
subl %eax, %ebp
movslq %eax, %rbx
leaq (%r14,%rbx), %rsi
movslq %ebp, %rdx
movq %r14, %rdi
jmp 0x5366
setns %bl
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
movl 0x45d7(%rip), %eax      # 0x98e0
cmpl %ecx, %eax
cmovll %eax, %ecx
subl %ecx, %eax
movq 0x45c1(%rip), %rdi      # 0x98d8
movslq %ecx, %r14
leaq (%rdi,%r14), %rsi
movslq %eax, %rdx
callq 0x31d0
subl %r14d, 0x45b3(%rip)     # 0x98e0
jmp 0x5383
movl $0x0, 0x4(%r15)
movw $0x1b, 0x2(%r15)
movb $0x0, 0x1(%r15)
movl 0x4597(%rip), %eax      # 0x98e0
testl %eax, %eax
movl $0x1, %ecx
cmovlel %eax, %ecx
subl %ecx, %eax
movq 0x457c(%rip), %rdi      # 0x98d8
movslq %ecx, %rbx
leaq (%rdi,%rbx), %rsi
movslq %eax, %rdx
callq 0x31d0
subl %ebx, 0x456f(%rip)      # 0x98e0
movb $0x1, %bl
jmp 0x5383
movsbl %al, %edi
callq 0x5500
cmpl %eax, %ebp
jge 0x5394
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4(%r15), %rdi
movq %r14, %rsi
callq 0x5510
movw $0x0, 0x2(%r15)
movsbl (%r14), %edi
callq 0x5500
movb $0x1, %bl
testl %eax, %eax
jle 0x5383
movl 0x4524(%rip), %ecx      # 0x98e0
cmpl %eax, %ecx
cmovll %ecx, %eax
subl %eax, %ecx
movq 0x450e(%rip), %rdi      # 0x98d8
movslq %eax, %r14
leaq (%rdi,%r14), %rsi
movslq %ecx, %rdx
jmp 0x5321
leaq 0xfde(%rip), %rdi       # 0x63be
leaq 0xf8f(%rip), %rsi       # 0x6376
leaq 0xfe2(%rip), %rcx       # 0x63d0
movl $0x299, %edx            # imm = 0x299
callq 0x30e0