// File: /workspace/github_c_makefile_star2_O2/adsr[P]phpspy/vendor/termbox2/termbox2.h
// Function: extract_event
static int extract_event(struct tb_event *event) {
    int rv;
    struct bytebuf_t *in = &global.in;

    if (in->len == 0) {
        return TB_ERR;
    }

    if (in->buf[0] == '\x1b') {
        // Escape sequence?
        // In TB_INPUT_ESC, skip if the buffer is a single escape char
        if (!((global.input_mode & TB_INPUT_ESC) && in->len == 1)) {
            if_ok_or_need_more_return(rv, extract_esc(event));
        }

        // Escape key?
        if (global.input_mode & TB_INPUT_ESC) {
            event->type = TB_EVENT_KEY;
            event->ch = 0;
            event->key = TB_KEY_ESC;
            event->mod = 0;
            bytebuf_shift(in, 1);
            return TB_OK;
        }

        // Recurse for alt key
        event->mod |= TB_MOD_ALT;
        bytebuf_shift(in, 1);
        return extract_event(event);
    }

    // ASCII control key?
    if ((uint16_t)in->buf[0] < TB_KEY_SPACE || in->buf[0] == TB_KEY_BACKSPACE2)
    {
        event->type = TB_EVENT_KEY;
        event->ch = 0;
        event->key = (uint16_t)in->buf[0];
        event->mod |= TB_MOD_CTRL;
        bytebuf_shift(in, 1);
        return TB_OK;
    }

    // UTF-8?
    if (in->len >= (size_t)tb_utf8_char_length(in->buf[0])) {
        event->type = TB_EVENT_KEY;
        tb_utf8_char_to_unicode(&event->ch, in->buf);
        event->key = 0;
        bytebuf_shift(in, tb_utf8_char_length(in->buf[0]));
        return TB_OK;
    }

    // Need more input
    return TB_ERR;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x12740(%rip), %rdx     # 0x25c00
pushq $-0x20
popq %r13
testq %rdx, %rdx
je 0x136cc
movq 0x12724(%rip), %rcx     # 0x25bf8
movsbl (%rcx), %eax
cmpl $0x1b, %eax
jne 0x136d3
movl 0x125ba(%rip), %eax     # 0x25aa0
cmpq $0x1, %rdx
sete %cl
testb %al, %cl
jne 0x13686
movq %rbx, %rdi
xorl %esi, %esi
callq 0x13969
cmpl $-0x2, %eax
je 0x1366f
testl %eax, %eax
je 0x1366f
movq 0x126e1(%rip), %r15     # 0x25bf8
movq 0x126e2(%rip), %r14     # 0x25c00
leaq 0x126b3(%rip), %rax     # 0x25bd8
xorl %r12d, %r12d
cmpq %r14, %r12
je 0x13570
movb (%r15,%r12), %sil
movq 0x10(%rax), %rdi
incq %rdi
movq %r13, %r8
decq %rdi
je 0x13573
leaq 0x20(%r8), %rcx
movq 0x8(%rax), %rdx
cmpb %sil, 0x20(%rdx,%r8)
movq %rcx, %r8
jne 0x1353b
incq %r12
leaq (%rdx,%rcx), %rax
cmpl $0x0, 0x18(%rdx,%rcx)
je 0x13528
cmpq $0x0, 0x10(%rdx,%rcx)
jne 0x13528
addq %rcx, %rdx
movq %rdx, %rax
jmp 0x13573
movq %r14, %r12
cmpl $0x0, 0x18(%rax)
jne 0x137a3
cmpq %r12, %r14
ja 0x1358d
cmpq $0x0, 0x10(%rax)
jne 0x13791
leaq 0x113dc(%rip), %rbp     # 0x24970
xorl %r13d, %r13d
cmpq $0x3, %r13
je 0x1364c
movq (%rbp), %r12
movq %r12, %rdi
callq 0x6160
cmpq %rax, %r14
jb 0x135c4
movq %r12, %rdi
movq %r15, %rsi
movq %rax, %rdx
callq 0x6080
testl %eax, %eax
je 0x135cd
incq %r13
addq $0x8, %rbp
jmp 0x13597
leal -0x1(%r13), %eax
cmpl $0x2, %eax
jae 0x13626
xorl %esi, %esi
pushq $-0x1
popq %rcx
movq %rcx, %rbp
movq %rcx, %r12
xorl %eax, %eax
cmpq %rax, %r14
je 0x13636
movzbl (%r15,%rax), %edx
cmpl $0x3b, %edx
jne 0x13600
cmpq $-0x1, %r12
cmovneq %rax, %rbp
cmoveq %rax, %r12
jmp 0x13621
cmpq $-0x1, %rcx
jne 0x13621
movl %edx, %ecx
orl $0x20, %ecx
cmpl $0x6d, %ecx
jne 0x1361e
xorl %esi, %esi
cmpl $0x4d, %edx
sete %sil
movq %rax, %rcx
jmp 0x13621
pushq $-0x1
popq %rcx
incq %rax
jmp 0x135e3
testl %r13d, %r13d
jne 0x1364c
cmpq $0x6, %r14
jb 0x1364c
jmp 0x13869
cmpq $-0x1, %rcx
je 0x1364c
cmpq $-0x1, %r12
je 0x1364c
cmpq $-0x1, %rbp
jne 0x137da
movq %rbx, %rdi
pushq $0x1
popq %rsi
callq 0x13969
movl %eax, %ecx
negl %eax
movl $0x0, %eax
sbbl %eax, %eax
cmpl $-0x2, %ecx
pushq $-0x20
popq %r13
je 0x13791
cmpl $-0x2, %eax
je 0x13794
testl %eax, %eax
je 0x13794
movl 0x1241a(%rip), %eax     # 0x25aa0
testb $0x1, %al
jne 0x13710
orb $0x1, 0x1(%rbx)
movq 0x12567(%rip), %rdx     # 0x25c00
xorl %r14d, %r14d
testq %rdx, %rdx
setne %r14b
subq %r14, %rdx
movq 0x1254b(%rip), %rdi     # 0x25bf8
leaq (%rdi,%r14), %rsi
callq 0x6490
movq 0x12543(%rip), %rdx     # 0x25c00
subq %r14, %rdx
movq %rdx, 0x12539(%rip)     # 0x25c00
jmp 0x134c4
pushq $-0x1
jmp 0x13793
testw $0xffe0, %ax            # imm = 0xFFE0
setne %sil
cmpb $0x7f, %al
setne %dil
testb %sil, %dil
jne 0x13732
movb $0x1, (%rbx)
andl $0x0, 0x4(%rbx)
movsbl (%rcx), %eax
movw %ax, 0x2(%rbx)
orb $0x2, 0x1(%rbx)
decq %rdx
leaq 0x1(%rcx), %rsi
movq %rcx, %rdi
callq 0x6490
decq 0x124f2(%rip)           # 0x25c00
jmp 0x1378d
movq $0x1b0001, (%rbx)       # imm = 0x1B0001
movq 0x124e2(%rip), %rdx     # 0x25c00
xorl %ebx, %ebx
testq %rdx, %rdx
setne %bl
subq %rbx, %rdx
movq 0x124c8(%rip), %rdi     # 0x25bf8
jmp 0x1377d
movzbl %al, %eax
leaq 0x7f64(%rip), %r14      # 0x1b6a0
movzbl (%rax,%r14), %esi
pushq $-0x1
popq %rax
cmpq %rsi, %rdx
jb 0x13794
movb $0x1, (%rbx)
leaq 0x4(%rbx), %rdi
movq %rcx, %rsi
callq 0x7d86
andw $0x0, 0x2(%rbx)
movq 0x12494(%rip), %rdi     # 0x25bf8
movzbl (%rdi), %eax
movzbl (%rax,%r14), %ebx
movq 0x1248d(%rip), %rdx     # 0x25c00
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
subq %rbx, %rdx
leaq (%rdi,%rbx), %rsi
callq 0x6490
subq %rbx, 0x12473(%rip)     # 0x25c00
xorl %eax, %eax
jmp 0x13794
pushq $-0x2
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, (%rbx)
andl $0x0, 0x4(%rbx)
movzwl 0x1c(%rax), %ecx
movw %cx, 0x2(%rbx)
movb 0x1e(%rax), %al
movb %al, 0x1(%rbx)
cmpq %r12, %r14
cmovbq %r14, %r12
subq %r12, %r14
leaq (%r15,%r12), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x6490
subq %r12, 0x12428(%rip)     # 0x25c00
jmp 0x1378d
movq %rsi, (%rsp)
xorl %eax, %eax
cmpq $0x2, %r13
sete %al
xorq $0x3, %rax
addq %rax, %r15
pushq $0xa
popq %rdx
movq %r15, %rdi
xorl %esi, %esi
movl %edx, %r15d
callq 0x6560
leal -0x20(%rax), %r14d
cmpq $0x2, %r13
movq 0x123eb(%rip), %rcx     # 0x25bf8
leaq 0x1(%rcx,%r12), %rdi
cmovnel %eax, %r14d
xorl %esi, %esi
movl %r15d, %r12d
movl %r15d, %edx
callq 0x6560
movq %rax, %r15
movq 0x123cb(%rip), %rax     # 0x25bf8
leaq (%rax,%rbp), %rdi
incq %rdi
xorl %esi, %esi
movl %r12d, %edx
callq 0x6560
movl %r14d, %esi
movl %r14d, %ecx
andl $0x3, %ecx
leaq 0x7d96(%rip), %rdx      # 0x1b5e4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %sil
sete %cl
leal -0x1c(,%rcx,4), %ecx
jmp 0x138b5
movzbl 0x3(%r15), %ecx
leal -0x20(%rcx), %eax
andl $0x3, %ecx
leaq 0x7d59(%rip), %rdx      # 0x1b5d4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal -0x1c(,%rcx,4), %ecx
jmp 0x1391b
movw $0xffe7, %cx            # imm = 0xFFE7
jmp 0x138b5
movw $0xffe5, %cx            # imm = 0xFFE5
jmp 0x138b5
xorl %ecx, %ecx
testb $0x40, %sil
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe3, %ecx           # imm = 0xFFE3
movq (%rsp), %rdx
movq 0x12340(%rip), %r14     # 0x25c00
testl %edx, %edx
movl $0xffe5, %edx           # imm = 0xFFE5
cmovnel %ecx, %edx
movw %dx, 0x2(%rbx)
testb $0x20, %sil
je 0x138d8
orb $0x8, 0x1(%rbx)
movl $0xff, %ecx
andl %ecx, %r15d
decl %r15d
movl %r15d, 0x10(%rbx)
andl %ecx, %eax
decl %eax
movl %eax, 0x14(%rbx)
testq %r14, %r14
je 0x13961
movq 0x122fe(%rip), %r15     # 0x25bf8
movq %r14, %r12
jmp 0x13941
movw $0xffe7, %cx            # imm = 0xFFE7
jmp 0x1391b
movw $0xffe5, %cx            # imm = 0xFFE5
jmp 0x1391b
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe3, %ecx           # imm = 0xFFE3
movw %cx, 0x2(%rbx)
testb $0x20, %al
je 0x13927
orb $0x8, 0x1(%rbx)
movzbl 0x4(%r15), %eax
addl $-0x21, %eax
movl %eax, 0x10(%rbx)
movzbl 0x5(%r15), %eax
addl $-0x21, %eax
movl %eax, 0x14(%rbx)
pushq $0x6
popq %r12
cmpq %r12, %r14
cmovbq %r14, %r12
subq %r12, %r14
leaq (%r15,%r12), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x6490
subq %r12, 0x1229f(%rip)     # 0x25c00
movb $0x3, (%rbx)
jmp 0x1378d