// File: exrok[P]evdoublebind/./src/inspector.cc
// Function: find_keyboard_in(KeyboardList&, char const*)
void find_keyboard_in(KeyboardList &keyboards, const char * path) {
    DIR *d;
    struct dirent *dir;
    struct Keyboard inputs[32] = {0}; //12 Slots
    int inputs_len = 0;
    char buf[1024]; //12 Slots
    d = opendir(path);
    if (d) {
        while ((dir = readdir(d)) != NULL) {
            if (kbd_suffix(dir->d_name)) {
                if (snprintf(buf,1024,"%s%s",path, dir->d_name) > 1023) {
                    continue;
                }
                char *input = realpath(buf, NULL);
                if (input == NULL) continue;
                if (input[11] == 'e') {
                    int event_number = atoi(input + 16);
                    if (!keyboards.contains_event_number(event_number)) {
                        int fd = open(input, O_RDONLY);
                        if (!is_keyboard(fd)){
                            close(fd);
                        } else {
                            unsigned int key_repeat[2] = {2048,2048};
                            ioctl(fd, EVIOCSREP, &key_repeat); //Disable Local Simulated Key repeat
                            keyboards.append(event_number, fd, strdup(buf));
                        }
                    }
                }
                free(input);
            }
        }
        closedir(d);
    }
}

// Assembly:
subq $0x668, %rsp            # imm = 0x668
movq %rdi, 0x660(%rsp)
movq %rsi, 0x658(%rsp)
leaq 0x440(%rsp), %rdi
xorl %esi, %esi
movl $0x200, %edx            # imm = 0x200
callq 0x30d0
movl $0x0, 0x43c(%rsp)
movq 0x658(%rsp), %rdi
callq 0x3070
movq %rax, 0x650(%rsp)
cmpq $0x0, 0x650(%rsp)
je 0x392f
jmp 0x37bc
movq 0x650(%rsp), %rdi
callq 0x31b0
movq %rax, 0x648(%rsp)
cmpq $0x0, %rax
je 0x3922
movq 0x648(%rsp), %rdi
addq $0x13, %rdi
callq 0x3700
cmpl $0x0, %eax
je 0x391d
leaq 0x30(%rsp), %rdi
movq 0x658(%rsp), %rcx
movq 0x648(%rsp), %r8
addq $0x13, %r8
movl $0x400, %esi            # imm = 0x400
leaq 0x234d(%rip), %rdx      # 0x5b67
movb $0x0, %al
callq 0x30b0
cmpl $0x3ff, %eax            # imm = 0x3FF
jle 0x382a
jmp 0x37bc
leaq 0x30(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3180
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x28(%rsp)
jne 0x384a
jmp 0x37bc
movq 0x28(%rsp), %rax
movsbl 0xb(%rax), %eax
cmpl $0x65, %eax
jne 0x3913
movq 0x28(%rsp), %rdi
addq $0x10, %rdi
callq 0x3210
movl %eax, 0x24(%rsp)
movq 0x660(%rsp), %rdi
movl 0x24(%rsp), %esi
callq 0x4170
testb $0x1, %al
jne 0x3911
movq 0x28(%rsp), %rdi
xorl %esi, %esi
movb $0x0, %al
callq 0x31e0
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %edi
callq 0x3620
cmpl $0x0, %eax
jne 0x38b2
movl 0x20(%rsp), %edi
callq 0x3100
jmp 0x390f
movq 0x2657(%rip), %rax      # 0x5f10
movq %rax, 0x18(%rsp)
movl 0x20(%rsp), %edi
movl $0x40084503, %esi       # imm = 0x40084503
leaq 0x18(%rsp), %rdx
movb $0x0, %al
callq 0x30f0
movq 0x660(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0x20(%rsp), %eax
movl %eax, 0x14(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x3230
movq 0x8(%rsp), %rdi
movl 0x10(%rsp), %esi
movl 0x14(%rsp), %edx
movq %rax, %rcx
callq 0x41e0
jmp 0x3911
jmp 0x3913
movq 0x28(%rsp), %rdi
callq 0x3030
jmp 0x37bc
movq 0x650(%rsp), %rdi
callq 0x3110
addq $0x668, %rsp            # imm = 0x668
retq
nopw (%rax,%rax)