// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x3080
testq %rax, %rax
je 0x37dd
movq %rax, %r15
movq %rax, %rdi
callq 0x31a0
testq %rax, %rax
je 0x37d5
movq %rax, %r12
leaq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %r13
movq %r14, 0x8(%rsp)
addq $0x13, %r12
movq %r12, %rdi
callq 0x3604
testl %eax, %eax
je 0x37c1
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
leaq 0x14be(%rip), %rdx      # 0x4b67
movq %rbx, %rcx
movq %r12, %r8
xorl %eax, %eax
callq 0x30c0
cmpl $0x3ff, %eax            # imm = 0x3FF
jg 0x37c1
movq %r13, %rdi
xorl %esi, %esi
callq 0x3180
testq %rax, %rax
je 0x37c1
movq %rax, %rbp
cmpb $0x65, 0xb(%rax)
jne 0x37b9
movq %rbp, %rdi
addq $0x10, %rdi
callq 0x3200
movl %eax, %r12d
movslq 0x200(%r14), %rax
testq %rax, %rax
jle 0x3730
cmpl %r12d, (%r14)
je 0x37b9
movl $0x1, %esi
movq 0x10(%rsp), %rcx
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x3727
leaq 0x1(%rdx), %rsi
leaq 0x10(%rcx), %rdi
cmpl %r12d, (%rcx)
movq %rdi, %rcx
jne 0x370f
cmpq %rax, %rdx
jb 0x37b9
movq %rbp, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x31d0
movl %eax, %r14d
movl %eax, %edi
callq 0x3558
testl %eax, %eax
je 0x37ac
movabsq $0x80000000800, %rax    # imm = 0x80000000800
movq %rax, 0x18(%rsp)
movl $0x40084503, %esi       # imm = 0x40084503
movl %r14d, %edi
leaq 0x18(%rsp), %rdx
xorl %eax, %eax
callq 0x30f0
movq %r13, %rdi
callq 0x3220
movq 0x8(%rsp), %rcx
movslq 0x200(%rcx), %rcx
cmpq $0x1f, %rcx
jg 0x37b4
movq %rcx, %rdx
shlq $0x4, %rdx
movq 0x8(%rsp), %rsi
movl %r12d, (%rsi,%rdx)
movl %r14d, 0x4(%rsi,%rdx)
movq %rax, 0x8(%rsi,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0x200(%rsi)
jmp 0x37b4
movl %r14d, %edi
callq 0x3100
movq 0x8(%rsp), %r14
movq %rbp, %rdi
callq 0x3030
movq %r15, %rdi
callq 0x31a0
movq %rax, %r12
testq %rax, %rax
jne 0x3686
movq %r15, %rdi
callq 0x3110
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq