// File: /workspace/github_c_makefile_star2_O2/termbox[P]termbox/demo/keyboard.c
// Function: main
int main(int argc, char **argv)
{
    (void) argc; (void) argv;
    int ret;

    ret = tb_init();
    if (ret) {
        fprintf(stderr, "tb_init() failed with error code %d\n", ret);
        return 1;
    }

    tb_select_input_mode(TB_INPUT_ESC | TB_INPUT_MOUSE);
    struct tb_event ev;

    tb_clear();
    draw_keyboard();
    tb_present();
    int inputmode = 0;
    int ctrlxpressed = 0;

    while (tb_poll_event(&ev)) {
        switch (ev.type) {
        case TB_EVENT_KEY:
            if (ev.key == TB_KEY_CTRL_Q && ctrlxpressed) {
                tb_shutdown();
                return 0;
            }
            if (ev.key == TB_KEY_CTRL_C && ctrlxpressed) {
                static int chmap[] = {
                    TB_INPUT_ESC | TB_INPUT_MOUSE, /* 101 */
                    TB_INPUT_ALT | TB_INPUT_MOUSE, /* 110 */
                    TB_INPUT_ESC,                  /* 001 */
                    TB_INPUT_ALT,                  /* 010 */
                };
                inputmode++;
                if (inputmode >= 4) {
                    inputmode = 0;
                }
                tb_select_input_mode(chmap[inputmode]);
            }
            if (ev.key == TB_KEY_CTRL_X)
                ctrlxpressed = 1;
            else
                ctrlxpressed = 0;

            tb_clear();
            draw_keyboard();
            dispatch_press(&ev);
            pretty_print_press(&ev);
            tb_present();
            break;
        case TB_EVENT_RESIZE:
            tb_clear();
            draw_keyboard();
            pretty_print_resize(&ev);
            tb_present();
            break;
        case TB_EVENT_MOUSE:
            tb_clear();
            draw_keyboard();
            pretty_print_mouse(&ev);
            tb_present();
            break;
        default:
            break;
        }
    }
    tb_shutdown();
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x20, %rsp
callq 0x692a
testl %eax, %eax
jne 0x6239
pushq $0x5
popq %rdi
callq 0x743b
callq 0x7412
callq 0x54c6
callq 0x6acb
xorl %ebp, %ebp
leaq 0x8(%rsp), %rbx
leaq 0x221b(%rip), %r14      # 0x8380
xorl %r15d, %r15d
xorl %r12d, %r12d
movq %rbx, %rdi
callq 0x71da
testl %eax, %eax
je 0x6225
movzbl 0x8(%rsp), %eax
cmpl $0x3, %eax
je 0x61f5
cmpl $0x2, %eax
je 0x6209
cmpl $0x1, %eax
jne 0x616b
movzwl 0xa(%rsp), %eax
cmpw $0x11, %ax
jne 0x61a3
testl %r12d, %r12d
jne 0x6225
cmpw $0x3, %ax
jne 0x61ce
testl %r12d, %r12d
je 0x61ce
leal 0x1(%r15), %r12d
cmpl $0x3, %r15d
cmovgel %ebp, %r12d
movslq %r12d, %rax
movl (%r14,%rax,4), %edi
callq 0x743b
movzwl 0xa(%rsp), %eax
movl %r12d, %r15d
xorl %r12d, %r12d
cmpw $0x18, %ax
sete %r12b
callq 0x7412
callq 0x54c6
movq %rbx, %rdi
callq 0x6084
movq %rbx, %rdi
callq 0x5e2f
jmp 0x621b
callq 0x7412
callq 0x54c6
movq %rbx, %rdi
callq 0x5feb
jmp 0x621b
callq 0x7412
callq 0x54c6
movq %rbx, %rdi
callq 0x5fc5
callq 0x6acb
jmp 0x616b
callq 0x6936
xorl %eax, %eax
addq $0x20, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x4db0(%rip), %rcx      # 0xaff0
movq (%rcx), %rdi
leaq 0x2106(%rip), %rsi      # 0x8350
movl %eax, %edx
xorl %eax, %eax
callq 0x5170
pushq $0x1
popq %rax
jmp 0x622c