// File: /workspace/github_c_makefile_star2_O1/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 %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
callq 0x6ddf
testl %eax, %eax
jne 0x65e2
movl $0x5, %edi
callq 0x7ac5
callq 0x7a67
callq 0x54f8
callq 0x6fbd
leaq 0x10(%rsp), %rdi
callq 0x77e6
testl %eax, %eax
je 0x65cc
xorl %ebp, %ebp
leaq 0x10(%rsp), %rbx
leaq 0x2dde(%rip), %r14      # 0x92c3
leaq 0x2e94(%rip), %r15      # 0x9380
xorl %r13d, %r13d
xorl %r12d, %r12d
movzbl 0x10(%rsp), %eax
cmpl $0x3, %eax
je 0x65a5
cmpl $0x2, %eax
je 0x6572
cmpl $0x1, %eax
jne 0x65bc
movzwl 0x12(%rsp), %eax
cmpw $0x11, %ax
jne 0x6522
testl %r13d, %r13d
jne 0x65cc
cmpw $0x3, %ax
jne 0x6549
testl %r13d, %r13d
je 0x6549
leal 0x1(%r12), %r13d
cmpl $0x3, %r12d
cmovgel %ebp, %r13d
movslq %r13d, %rax
movl (%r15,%rax,4), %edi
callq 0x7ac5
movl %r13d, %r12d
xorl %r13d, %r13d
cmpw $0x18, 0x12(%rsp)
sete %r13b
callq 0x7a67
callq 0x54f8
movq %rbx, %rdi
callq 0x63d4
movq %rbx, %rdi
callq 0x610c
jmp 0x65b7
callq 0x7a67
callq 0x54f8
movl 0x18(%rsp), %r9d
movl 0x1c(%rsp), %eax
movl %eax, (%rsp)
movl $0x3, %edi
movl $0x13, %esi
movl $0x8, %edx
xorl %ecx, %ecx
movq %r14, %r8
xorl %eax, %eax
callq 0x53ff
jmp 0x65b7
callq 0x7a67
callq 0x54f8
movq %rbx, %rdi
callq 0x632f
callq 0x6fbd
movq %rbx, %rdi
callq 0x77e6
testl %eax, %eax
jne 0x64f2
callq 0x6dfb
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5a07(%rip), %rcx      # 0xbff0
movq (%rcx), %rdi
leaq 0x2d5d(%rip), %rsi      # 0x9350
movl %eax, %edx
xorl %eax, %eax
callq 0x5170
movl $0x1, %eax
jmp 0x65d3
nop