// File: /workspace/github_c_makefile_star2_O3/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 0x6d81
testl %eax, %eax
jne 0x65dc
movl $0x5, %edi
callq 0x7a73
callq 0x7a15
callq 0x54f8
callq 0x6f5f
leaq 0x10(%rsp), %rdi
callq 0x779c
testl %eax, %eax
je 0x65c6
xorl %ebp, %ebp
leaq 0x10(%rsp), %rbx
leaq 0x2de7(%rip), %r14      # 0x92c3
leaq 0x2e9d(%rip), %r15      # 0x9380
xorl %r13d, %r13d
xorl %r12d, %r12d
movzbl 0x10(%rsp), %eax
cmpl $0x3, %eax
je 0x659f
cmpl $0x2, %eax
je 0x656c
cmpl $0x1, %eax
jne 0x65b6
movzwl 0x12(%rsp), %eax
cmpw $0x11, %ax
jne 0x6519
testl %r13d, %r13d
jne 0x65c6
cmpw $0x3, %ax
jne 0x6545
testl %r13d, %r13d
je 0x6545
leal 0x1(%r12), %r13d
cmpl $0x3, %r12d
cmovgel %ebp, %r13d
movslq %r13d, %rax
movl (%r15,%rax,4), %edi
callq 0x7a73
movzwl 0x12(%rsp), %eax
movl %r13d, %r12d
xorl %r13d, %r13d
cmpw $0x18, %ax
sete %r13b
callq 0x7a15
callq 0x54f8
movq %rbx, %rdi
callq 0x63d4
movq %rbx, %rdi
callq 0x610c
jmp 0x65b1
callq 0x7a15
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 0x65b1
callq 0x7a15
callq 0x54f8
movq %rbx, %rdi
callq 0x632f
callq 0x6f5f
movq %rbx, %rdi
callq 0x779c
testl %eax, %eax
jne 0x64e9
callq 0x6d9d
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x5a0d(%rip), %rcx      # 0xbff0
movq (%rcx), %rdi
leaq 0x2d63(%rip), %rsi      # 0x9350
movl %eax, %edx
xorl %eax, %eax
callq 0x5170
movl $0x1, %eax
jmp 0x65cd
nopl (%rax)