// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %r15
leaq 0x12458(%rip), %r12     # 0x25bd8
leaq 0x111e9(%rip), %r13     # 0x24970
movq 0x12472(%rip), %rdx     # 0x25c00
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rdx, %rdx
je 0x13ce3
movq 0x12455(%rip), %rax     # 0x25bf8
movsbl (%rax), %ecx
cmpl $0x1b, %ecx
jne 0x13c1f
cmpq $0x1, %rdx
jne 0x137c4
movl 0x122e5(%rip), %eax     # 0x25aa0
andl $0x1, %eax
jne 0x13be3
movq %r15, %rdi
xorl %esi, %esi
callq 0x13cf4
movl %eax, %ebp
cmpl $-0x2, %eax
je 0x13bd2
testl %ebp, %ebp
je 0x13bd2
movq 0x12410(%rip), %rdi     # 0x25bf8
movq 0x12411(%rip), %rdx     # 0x25c00
testq %rdx, %rdx
je 0x13855
movq %r12, %r8
xorl %r14d, %r14d
xorl %ecx, %ecx
movq %r12, %rsi
movq 0x10(%rsi), %r9
testq %r9, %r9
je 0x1381e
movb (%rdi,%rcx), %r10b
movq 0x8(%rsi), %rax
cmpb %r10b, (%rax)
je 0x13820
addq $0x20, %rax
decq %r9
jne 0x13810
xorl %eax, %eax
movb $0x1, %r9b
testq %rax, %rax
je 0x13840
incq %r14
cmpl $0x0, 0x18(%rax)
je 0x13838
cmpq $0x0, 0x10(%rax)
je 0x1383b
xorl %r9d, %r9d
movq %rax, %rsi
jmp 0x13843
movq %r8, %rax
testb %r9b, %r9b
jne 0x1385b
incq %rcx
movq %rax, %r8
cmpq %rdx, %rcx
jne 0x137ff
jmp 0x1385b
movq %r12, %rax
xorl %r14d, %r14d
cmpl $0x0, 0x18(%rax)
je 0x1389b
movb $0x1, (%r15)
movl $0x0, 0x4(%r15)
movzwl 0x1c(%rax), %ecx
movw %cx, 0x2(%r15)
movb 0x1e(%rax), %al
movb %al, 0x1(%r15)
cmpq %r14, %rdx
cmovbq %rdx, %r14
subq %r14, %rdx
leaq (%rdi,%r14), %rsi
callq 0x6490
subq %r14, 0x12369(%rip)     # 0x25c00
xorl %ebp, %ebp
jmp 0x138b1
cmpq $0x0, 0x10(%rax)
sete %al
cmpq %r14, %rdx
seta %cl
orb %al, %cl
movzbl %cl, %ebp
orl $-0x2, %ebp
cmpl $-0x2, %ebp
je 0x13bd2
testl %ebp, %ebp
je 0x13bd2
movq %r15, 0x10(%rsp)
movq 0x12332(%rip), %r12     # 0x25c00
movq 0x12323(%rip), %r14     # 0x25bf8
movq %r13, %rbx
xorl %r13d, %r13d
movq (%rbx), %r15
movq %r15, %rdi
callq 0x6160
cmpq %rax, %r12
jb 0x138fd
movq %r15, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x6080
testl %eax, %eax
je 0x13910
incq %r13
addq $0x8, %rbx
cmpq $0x3, %r13
jne 0x138db
movl $0x3, %r13d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leal -0x1(%r13), %eax
cmpl $0x2, %eax
jb 0x13969
cmpl $0x3, %r13d
je 0x139e7
testl %r13d, %r13d
jne 0x139dd
cmpq $0x6, %r12
jb 0x139dd
movzbl 0x3(%r14), %ecx
leal -0x20(%rcx), %eax
andl $0x3, %ecx
leaq 0x8c97(%rip), %rdx      # 0x1c5e4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal -0x1c(,%rcx,4), %ecx
jmp 0x13b31
testq %r12, %r12
je 0x139ff
movq $-0x1, %rdx
xorl %eax, %eax
xorl %ecx, %ecx
movq $-0x1, %rbx
movq $-0x1, %r15
movzbl (%r14,%rax), %esi
cmpl $0x3b, %esi
jne 0x139a3
cmpq $-0x1, %rbx
cmovneq %rax, %r15
cmoveq %rax, %rbx
jmp 0x139c7
cmpq $-0x1, %rdx
jne 0x139c7
movl %esi, %edx
orl $0x20, %edx
cmpl $0x6d, %edx
jne 0x139c0
xorl %ecx, %ecx
cmpl $0x4d, %esi
sete %cl
movq %rax, %rdx
jmp 0x139c7
movq $-0x1, %rdx
incq %rax
cmpq %rax, %r12
jne 0x1398b
cmpq $-0x1, %rdx
sete %al
testl %ecx, %ecx
sete %cl
jmp 0x13a11
xorl %r12d, %r12d
xorl %edx, %edx
jmp 0x13b62
movq 0x10(%rsp), %r15
leaq 0x121e5(%rip), %r12     # 0x25bd8
leaq 0x10f76(%rip), %r13     # 0x24970
jmp 0x13bb0
movb $0x1, %al
movq $-0x1, %r15
movq $-0x1, %rbx
movb $0x1, %cl
xorl %r12d, %r12d
xorl %edx, %edx
testb %al, %al
jne 0x13b62
cmpq $-0x1, %rbx
je 0x13b62
cmpq $-0x1, %r15
je 0x13b62
movb %cl, 0xf(%rsp)
xorl %eax, %eax
cmpl $0x2, %r13d
sete %al
xorq $0x3, %rax
addq %rax, %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x6560
leal -0x20(%rax), %ebp
cmpl $0x2, %r13d
movq 0x12195(%rip), %rcx     # 0x25bf8
leaq 0x1(%rcx,%rbx), %rdi
cmovnel %eax, %ebp
xorl %esi, %esi
movl $0xa, %edx
callq 0x6560
movq %rax, %r14
movq 0x12177(%rip), %rax     # 0x25bf8
leaq (%rax,%r15), %rdi
incq %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x6560
movl %ebp, %ecx
andl $0x3, %ecx
leaq 0x8b34(%rip), %rdx      # 0x1c5d4
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
xorl %ecx, %ecx
testb $0x40, %bpl
sete %cl
leal -0x1c(,%rcx,4), %ecx
jmp 0x13ad9
movw $0xffe7, %cx            # imm = 0xFFE7
jmp 0x13ad9
movw $0xffe5, %cx            # imm = 0xFFE5
jmp 0x13ad9
xorl %ecx, %ecx
testb $0x40, %bpl
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe3, %ecx           # imm = 0xFFE3
movq 0x10(%rsp), %rdx
movw %cx, 0x2(%rdx)
movq 0x12117(%rip), %r12     # 0x25c00
cmpb $0x0, 0xf(%rsp)
je 0x13af6
movw $0xffe5, 0x2(%rdx)      # imm = 0xFFE5
testb $0x20, %bpl
je 0x13b00
orb $0x8, 0x1(%rdx)
movl $0xff, %ecx
andl %ecx, %r14d
decl %r14d
movl %r14d, 0x10(%rdx)
andl %ecx, %eax
decl %eax
jmp 0x13b5b
movw $0xffe7, %cx            # imm = 0xFFE7
jmp 0x13b31
movw $0xffe5, %cx            # imm = 0xFFE5
jmp 0x13b31
xorl %ecx, %ecx
testb $0x40, %al
sete %cl
leal (%rcx,%rcx,2), %ecx
addl $0xffe3, %ecx           # imm = 0xFFE3
movq 0x10(%rsp), %rdx
movw %cx, 0x2(%rdx)
testb $0x20, %al
je 0x13b42
orb $0x8, 0x1(%rdx)
movzbl 0x4(%r14), %eax
addl $-0x21, %eax
movl %eax, 0x10(%rdx)
movzbl 0x5(%r14), %eax
addl $-0x21, %eax
movl $0x6, %r12d
movl %eax, 0x14(%rdx)
xorl %ebp, %ebp
movb $0x1, %dl
testq %r12, %r12
je 0x13b95
movq %rdx, %rbx
movq 0x1208f(%rip), %rdx     # 0x25c00
cmpq %r12, %rdx
cmovbq %rdx, %r12
subq %r12, %rdx
movq 0x12076(%rip), %rdi     # 0x25bf8
leaq (%rdi,%r12), %rsi
callq 0x6490
movq %rbx, %rdx
subq %r12, 0x1206b(%rip)     # 0x25c00
testb %dl, %dl
movq 0x10(%rsp), %r15
leaq 0x10dcd(%rip), %r13     # 0x24970
je 0x13ba9
movb $0x3, (%r15)
leaq 0x12028(%rip), %r12     # 0x25bd8
testl %ebp, %ebp
je 0x13bd2
movq %r15, %rdi
movl $0x1, %esi
callq 0x13cf4
movl %eax, %ecx
negl %ecx
movl $0x0, %ebp
sbbl %ebp, %ebp
cmpl $-0x2, %eax
cmovel %eax, %ebp
cmpl $-0x2, %ebp
je 0x13ce3
testl %ebp, %ebp
je 0x13ce3
testb $0x1, 0x11eb6(%rip)     # 0x25aa0
jne 0x13c66
orb $0x1, 0x1(%r15)
movq 0x12008(%rip), %rdx     # 0x25c00
xorl %ebx, %ebx
testq %rdx, %rdx
setne %bl
subq %rbx, %rdx
movq 0x11fee(%rip), %rdi     # 0x25bf8
leaq (%rdi,%rbx), %rsi
callq 0x6490
subq %rbx, 0x11fe6(%rip)     # 0x25c00
jmp 0x13787
testl $0xffe0, %ecx           # imm = 0xFFE0
setne %sil
cmpb $0x7f, %cl
setne %dil
testb %sil, %dil
jne 0x13c88
movb $0x1, (%r15)
movl $0x0, 0x4(%r15)
movsbl (%rax), %ecx
movw %cx, 0x2(%r15)
orb $0x2, 0x1(%r15)
decq %rdx
leaq 0x1(%rax), %rsi
movq %rax, %rdi
callq 0x6490
decq 0x11f9c(%rip)           # 0x25c00
jmp 0x13ce1
movq $0x1b0001, (%r15)       # imm = 0x1B0001
movq 0x11f8c(%rip), %rdx     # 0x25c00
xorl %ebx, %ebx
testq %rdx, %rdx
setne %bl
subq %rbx, %rdx
movq 0x11f72(%rip), %rdi     # 0x25bf8
jmp 0x13cd1
movzbl %cl, %ecx
leaq 0x8a0e(%rip), %rbx      # 0x1c6a0
movzbl (%rcx,%rbx), %ecx
cmpq %rcx, %rdx
jb 0x13ce3
movb $0x1, (%r15)
leaq 0x4(%r15), %rdi
movq %rax, %rsi
callq 0x8545
movw $0x0, 0x2(%r15)
movq 0x11f3f(%rip), %rdi     # 0x25bf8
movzbl (%rdi), %eax
movzbl (%rax,%rbx), %ebx
movq 0x11f39(%rip), %rdx     # 0x25c00
cmpq %rbx, %rdx
cmovbq %rdx, %rbx
subq %rbx, %rdx
leaq (%rdi,%rbx), %rsi
callq 0x6490
subq %rbx, 0x11f1f(%rip)     # 0x25c00
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq