// File: exrok[P]evdoublebind/./src/inspector.cc
// Function: read_events(xkb_keymap*, xkb_state*, Keyboard*)
void read_events(xkb_keymap *keymap,xkb_state *state, Keyboard *input) {
    struct input_event buf[16];
    errno = 0;
    int rd = read(input->fd, buf, sizeof(buf));
    struct input_event *end = buf + (rd / sizeof(struct input_event));
    int after_scancode = 0;
    for(const struct input_event *curr = buf; curr < end; curr++){
        if (curr->type != EV_KEY || curr->value == V_KEY_REPEAT) continue;
        xkb_keycode_t keycode;
        xkb_keysym_t keysym;
        keycode = curr->code + 8;
        keysym = xkb_state_key_get_one_sym(state, keycode);
        char keysym_name[64];
        xkb_keysym_get_name(keysym, keysym_name, sizeof(keysym_name));
        const char * keyname = xkb_keymap_key_get_name(keymap, keycode);
        printf("[%s]{\n",input->name);
        printf("   EVDEV: keycode:%d name:%s;\n", curr->code, key_code_name(curr->code));
        print_mods(state);
        printf("   XKB: key[%d]:<%s> keysym:%s;\n",
               keycode, keyname,keysym_name);
        if (curr->value == V_KEY_DOWN)
            xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
        else if (curr->value == V_KEY_UP)
            xkb_state_update_key(state, keycode, XKB_KEY_UP);
        printf("}\n");
    }
}

// Assembly:
subq $0x228, %rsp            # imm = 0x228
movq %rdi, 0x220(%rsp)
movq %rsi, 0x218(%rsp)
movq %rdx, 0x210(%rsp)
callq 0x3040
movl $0x0, (%rax)
movq 0x210(%rsp), %rax
movl 0x4(%rax), %edi
leaq 0x90(%rsp), %rsi
movl $0x180, %edx            # imm = 0x180
callq 0x3130
movl %eax, 0x8c(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movslq 0x8c(%rsp), %rax
movl $0x18, %ecx
xorl %edx, %edx
divq %rcx
movq %rax, %rcx
movq 0x10(%rsp), %rax
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movl $0x0, 0x7c(%rsp)
leaq 0x90(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x80(%rsp), %rax
jae 0x3c2f
movq 0x70(%rsp), %rax
movzwl 0x10(%rax), %eax
cmpl $0x1, %eax
jne 0x3b05
movq 0x70(%rsp), %rax
cmpl $0x2, 0x14(%rax)
jne 0x3b0a
jmp 0x3c1c
movq 0x70(%rsp), %rax
movzwl 0x12(%rax), %eax
addl $0x8, %eax
movl %eax, 0x6c(%rsp)
movq 0x218(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x30c0
movl %eax, 0x68(%rsp)
movl 0x68(%rsp), %edi
leaq 0x20(%rsp), %rsi
movl $0x40, %edx
callq 0x3060
movq 0x220(%rsp), %rdi
movl 0x6c(%rsp), %esi
callq 0x31c0
movq %rax, 0x18(%rsp)
movq 0x210(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x2035(%rip), %rdi      # 0x5ba0
movb $0x0, %al
callq 0x3090
movq 0x70(%rsp), %rax
movzwl 0x12(%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x70(%rsp), %rax
movzwl 0x12(%rax), %edi
callq 0x3360
movl 0xc(%rsp), %esi
movq %rax, %rdx
leaq 0x200c(%rip), %rdi      # 0x5ba7
movb $0x0, %al
callq 0x3090
movq 0x218(%rsp), %rdi
callq 0x3940
movl 0x6c(%rsp), %esi
movq 0x18(%rsp), %rdx
leaq 0x20(%rsp), %rcx
leaq 0x2002(%rip), %rdi      # 0x5bc6
movb $0x0, %al
callq 0x3090
movq 0x70(%rsp), %rax
cmpl $0x1, 0x14(%rax)
jne 0x3bee
movq 0x218(%rsp), %rdi
movl 0x6c(%rsp), %esi
movl $0x1, %edx
callq 0x31a0
jmp 0x3c0e
movq 0x70(%rsp), %rax
cmpl $0x0, 0x14(%rax)
jne 0x3c0c
movq 0x218(%rsp), %rdi
movl 0x6c(%rsp), %esi
xorl %edx, %edx
callq 0x31a0
jmp 0x3c0e
leaq 0x1fd2(%rip), %rdi      # 0x5be7
movb $0x0, %al
callq 0x3090
movq 0x70(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x70(%rsp)
jmp 0x3ad9
addq $0x228, %rsp            # imm = 0x228
retq
nopw (%rax,%rax)