// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
leaq 0x2eb85(%rip), %rax     # 0x3be98
addq $0x190, %rax            # imm = 0x190
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xd334
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd4ee
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x1b, %eax
jne 0xd3fd
movl 0x2eb83(%rip), %eax     # 0x3bed0
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd360
movq -0x20(%rbp), %rax
cmpq $0x1, 0x8(%rax)
je 0xd384
movq -0x10(%rbp), %rdi
callq 0xd500
movl %eax, -0x14(%rbp)
cmpl $0x0, %eax
je 0xd377
cmpl $-0x2, -0x14(%rbp)
jne 0xd382
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xd4ee
jmp 0xd384
movl 0x2eb46(%rip), %eax     # 0x3bed0
andl $0x1, %eax
cmpl $0x0, %eax
je 0xd3d0
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x10(%rbp), %rax
movw $0x1b, 0x2(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0x1(%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xd5a0
movl $0x0, -0x4(%rbp)
jmp 0xd4ee
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %ecx
orl $0x1, %ecx
movb %cl, 0x1(%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xd5a0
movq -0x10(%rbp), %rdi
callq 0xd300
movl %eax, -0x4(%rbp)
jmp 0xd4ee
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movzwl %ax, %eax
cmpl $0x20, %eax
jl 0xd41e
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
cmpl $0x7f, %eax
jne 0xd46d
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x2(%rax)
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %ecx
orl $0x2, %ecx
movb %cl, 0x1(%rax)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0xd5a0
movl $0x0, -0x4(%rbp)
jmp 0xd4ee
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %edi
callq 0x8d00
movl %eax, %ecx
movq -0x28(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jb 0xd4e7
movq -0x10(%rbp), %rax
movb $0x1, (%rax)
movq -0x10(%rbp), %rdi
addq $0x4, %rdi
movq -0x20(%rbp), %rax
movq (%rax), %rsi
callq 0x87e0
movq -0x10(%rbp), %rax
movw $0x0, 0x2(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %edi
callq 0x8d00
movq -0x30(%rbp), %rdi
movslq %eax, %rsi
callq 0xd5a0
movl $0x0, -0x4(%rbp)
jmp 0xd4ee
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)