// File: /workspace/github_cpp_makefile_star2_O1/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, %r12
movq %rsi, %rdi
callq 0x3080
testq %rax, %rax
je 0x3838
movq %rax, %r15
movq %rax, %rdi
callq 0x31a0
testq %rax, %rax
je 0x3830
movq %rax, %r14
leaq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
leaq 0x20(%rsp), %r13
movq %r12, 0x8(%rsp)
addq $0x13, %r14
movq %r14, %rdi
callq 0x3654
testl %eax, %eax
je 0x381c
movl $0x400, %esi            # imm = 0x400
movq %r13, %rdi
leaq 0x146d(%rip), %rdx      # 0x4b67
movq %rbx, %rcx
movq %r14, %r8
xorl %eax, %eax
callq 0x30c0
cmpl $0x3ff, %eax            # imm = 0x3FF
jg 0x381c
movq %r13, %rdi
xorl %esi, %esi
callq 0x3180
testq %rax, %rax
je 0x381c
movq %rax, %rbp
cmpb $0x65, 0xb(%rax)
jne 0x3814
movq %rbp, %rdi
addq $0x10, %rdi
callq 0x3200
movl %eax, %r14d
movslq 0x200(%r12), %rax
testq %rax, %rax
setg %cl
jle 0x3783
cmpl %r14d, (%r12)
je 0x3814
movl $0x1, %esi
movq 0x10(%rsp), %rcx
movq %rsi, %rdx
cmpq %rsi, %rax
je 0x377d
leaq 0x1(%rdx), %rsi
leaq 0x10(%rcx), %rdi
cmpl %r14d, (%rcx)
movq %rdi, %rcx
jne 0x3765
cmpq %rax, %rdx
setb %cl
testb %cl, %cl
jne 0x3814
movq %rbp, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x31d0
movl %eax, %r12d
movl %eax, %edi
callq 0x35a8
testl %eax, %eax
je 0x3807
movabsq $0x80000000800, %rax    # imm = 0x80000000800
movq %rax, 0x18(%rsp)
movl $0x40084503, %esi       # imm = 0x40084503
movl %r12d, %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 0x380f
movq %rcx, %rdx
shlq $0x4, %rdx
movq 0x8(%rsp), %rsi
movl %r14d, (%rsi,%rdx)
movl %r12d, 0x4(%rsi,%rdx)
movq %rax, 0x8(%rsi,%rdx)
leal 0x1(%rcx), %eax
movl %eax, 0x200(%rsi)
jmp 0x380f
movl %r12d, %edi
callq 0x3100
movq 0x8(%rsp), %r12
movq %rbp, %rdi
callq 0x3030
movq %r15, %rdi
callq 0x31a0
movq %rax, %r14
testq %rax, %rax
jne 0x36d7
movq %r15, %rdi
callq 0x3110
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq