// File: /workspace/github_c_makefile_star2_O2/glitchub[P]evdump/evls.c
// Function: main
int main(int argc, char *argv[])
{
    for (int ev = 0; ev < 32; ev++)
    {
        char device[32];
        sprintf(device, "/dev/input/event%d", ev);
        int fd = open(device, O_RDONLY);
        if (fd < 0)
        {
            if (errno != ENOENT) die("Can't open %s: %s\n", device, strerror(errno));
            goto next;
        }

        printf("%s:\n", device);

        char name[64];
        if (ioctl(fd, EVIOCGNAME(sizeof name), name) < 0) *name = 0;
        printf("    Name \"%s\"\n", *name ? name : "Name unknown");

        int version;
        if (ioctl(fd, EVIOCGVERSION, &version))
        {
            printf("    EVIOCGVERSION failed\n");
            goto next;
        }
        else if (version != EV_VERSION)
        {
            printf("    Unexpected stack version %d\n", version);
            goto next;
        }

        struct input_id id;
        if (ioctl(fd, EVIOCGID, &id))
        {
            printf("    EVIOCGID failed\n");
            goto next;
        }
        printf("    Vendor %d\n", id.vendor);
        printf("    Product %d\n", id.product);
        printf("    Version %d\n", id.version);
        printf("    Bus type %d is %s\n", id.bustype, ed_BUS(id.bustype)?:"unknown");

        uint8_t capabilities[(EV_MAX+7)/8];
        if (ioctl(fd, EVIOCGBIT(0, sizeof capabilities), capabilities) != sizeof capabilities)
        {
            printf("    EVIOCGBIT(0) failed\n");
            goto next;
        }

        for (int bit = 1; bit < EV_MAX; bit++) // note, skip bit 0 = EV_SYN
        if (set(capabilities, bit))
        {
            printf("    Capability %d is %s\n", bit, ed_EV(bit)?:"unknown");
            switch(bit)
            {
                case EV_KEY:
                {
                    uint32_t repeat[2];
                    if (!ioctl(fd, EVIOCGREP, &repeat))
                    {
                        printf("        Repeat delay %d mS\n", repeat[0]);
                        printf("        Repeat period %d mS\n", repeat[1]);
                    }
                    uint8_t supported[(KEY_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(supported)), supported) == sizeof supported)
                    {
                        int8_t status[(KEY_MAX+7)/8];
                        bool valid = (ioctl(fd, EVIOCGKEY(sizeof(status)), status) == sizeof status);
                        for (int bit = 0; bit < KEY_MAX; bit++)
                            if (set(supported, bit))
                            {
                                if (valid && set(status, bit))
                                    printf("        Active key %d is %s\n", bit, ed_KEY(bit)?:ed_BTN(bit)?:"unknown");
                                else
                                    printf("        Key %d is %s\n", bit, ed_KEY(bit)?:ed_BTN(bit)?:"unknown");
                            }
                    }
                    break;
                }
                case EV_REL:
                {
                    uint8_t supported[(REL_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_REL, sizeof supported), supported) == sizeof supported)
                        for (int bit = 0; bit < REL_MAX; bit++)
                            if (set(supported, bit))
                                printf("        Relative event %d is %s\n", bit, ed_REL(bit)?:"unknown");
                    break;
                }
                case EV_ABS:
                {
                    uint8_t supported[(ABS_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_ABS, sizeof(supported)), supported) == sizeof supported)
                        for (int bit = 0; bit < ABS_MAX; bit++)
                            if (set(supported, bit))
                            {
                                printf("        Axis %d is %s\n", bit, ed_ABS(bit)?:"unknown");
                                struct input_absinfo i;
                                if (!ioctl(fd, EVIOCGABS(bit), &i))
                                {
                                    printf("            Value     : %d\n", i.value);
                                    printf("            Minimum   : %d\n", i.minimum);
                                    printf("            Maximum   : %d\n", i.maximum);
                                    printf("            Fuzz      : %d\n", i.fuzz);
                                    printf("            Flat      : %d\n", i.flat);
                                    printf("            Resolution: %d\n", i.resolution);
                                }
                            }
                    break;
                }
                case EV_MSC:
                {
                    uint8_t supported[(MSC_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_MSC, sizeof supported), supported) == sizeof supported)
                        for (int bit = 0; bit < MSC_MAX; bit++)
                            if (set(supported, bit))
                                printf("        Misc event %d is %s\n", bit, ed_MSC(bit)?:"unknown");
                    break;
                }
                case EV_SW:
                {
                    uint8_t supported[(SW_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_SW, sizeof supported), supported) == sizeof supported)
                    {
                        uint8_t status[sizeof supported];
                        bool valid = (ioctl(fd, EVIOCGSW(sizeof(status)), status) == sizeof status);
                        for (int bit = 0; bit < SW_MAX; bit++)
                            if (set(supported, bit))
                            {
                                if (valid && set(status, bit))
                                    printf("        Active switch %d is %s\n", bit, ed_SW(bit)?:"unknown");
                                else
                                    printf("        Switch %d is %s\n", bit, ed_SW(bit)?:"unknown");
                            }
                    }
                }
                case EV_LED:
                {
                    uint8_t supported[(LED_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_LED, sizeof supported), supported) == sizeof supported)
                    {
                        uint8_t status[sizeof supported];
                        bool valid = (ioctl(fd, EVIOCGLED(sizeof(status)), status) == sizeof status);
                        for (int bit = 0; bit < LED_MAX; bit++)
                            if (set(supported, bit))
                            {
                                if (valid && set(status, bit))
                                    printf("        Active LED %d is %s\n", bit, ed_LED(bit)?:"unknown");
                                else
                                    printf("        LED %d is %s\n", bit, ed_LED(bit)?:"unknown");
                            }
                    }
                    break;
                }
                case EV_SND:
                {
                    uint8_t supported[(SND_MAX+7)/8];
                    if (ioctl(fd, EVIOCGBIT(EV_SND, sizeof supported), supported) == sizeof supported)
                    {
                        uint8_t status[sizeof supported];
                        bool valid = (ioctl(fd, EVIOCGSND(sizeof(status)), status) == sizeof status);
                        for (int bit = 0; bit < SND_MAX; bit++)
                            if (set(supported, bit))
                            {
                                if (valid && set(status, bit))
                                    printf("        Active sound %d is %s\n", bit, ed_SND(bit)?:"unknown");
                                else
                                    printf("        Sound %d is %s\n", bit, ed_SND(bit)?:"unknown");
                            }
                    }
                    break;
                }

            }
        }
        next: close(fd);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x2e80(%rip), %r15      # 0x856f
leaq 0x100(%rsp), %r14
leaq 0x3effec(%r12), %rax
movq %rax, 0x38(%rsp)
leaq 0x120(%rsp), %r13
leaq 0x2ffe7(%r12), %rax
movq %rax, 0x30(%rsp)
leaq 0x6ffe8(%r12), %rax
movq %rax, 0x28(%rsp)
leaq 0x30006(%r12), %rax
movq %rax, 0x18(%rsp)
leaq 0x18(%r12), %rax
movq %rax, 0x20(%rsp)
xorl %ebp, %ebp
cmpl $0x20, %ebp
je 0x5e8d
movq %r14, %rdi
movq %r15, %rsi
movl %ebp, %edx
xorl %eax, %eax
callq 0x50a0
movq %r14, %rdi
xorl %esi, %esi
xorl %eax, %eax
callq 0x5090
movl %eax, %ebx
testl %eax, %eax
js 0x57a7
leaq 0x2e25(%rip), %rdi      # 0x8595
movq %r14, %rsi
xorl %eax, %eax
callq 0x5050
movl %ebx, %edi
movq 0x38(%rsp), %rsi
movq %r13, %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
js 0x57b8
cmpb $0x0, 0x120(%rsp)
movq %r13, %rsi
leaq 0x2e08(%rip), %rax      # 0x85a9
cmoveq %rax, %rsi
jmp 0x57c7
callq 0x5030
movl (%rax), %edi
cmpl $0x2, %edi
je 0x57f8
jmp 0x5ea1
movb $0x0, 0x120(%rsp)
leaq 0x2de2(%rip), %rsi      # 0x85a9
leaq 0x2dcc(%rip), %rdi      # 0x859a
xorl %eax, %eax
callq 0x5050
movl %ebx, %edi
movq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
je 0x5816
leaq 0x307b(%rip), %rdi      # 0x886e
callq 0x5040
movl %ebx, %edi
callq 0x5070
incl %ebp
leaq 0x100(%rsp), %r14
leaq 0x120(%rsp), %r13
jmp 0x573f
movl 0x8(%rsp), %esi
cmpl $0x10001, %esi          # imm = 0x10001
jne 0x5840
movl %ebx, %edi
movq 0x28(%rsp), %rsi
movq %rsp, %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
je 0x5850
leaq 0x301c(%rip), %rdi      # 0x885a
jmp 0x57f3
leaq 0x2d6f(%rip), %rdi      # 0x85b6
xorl %eax, %eax
callq 0x5050
jmp 0x57f8
movzwl 0x2(%rsp), %esi
leaq 0x2d7b(%rip), %rdi      # 0x85d7
xorl %eax, %eax
callq 0x5050
movzwl 0x4(%rsp), %esi
leaq 0x2d77(%rip), %rdi      # 0x85e6
xorl %eax, %eax
callq 0x5050
movzwl 0x6(%rsp), %esi
leaq 0x2d74(%rip), %rdi      # 0x85f6
xorl %eax, %eax
callq 0x5050
movzwl (%rsp), %r14d
movl %r14d, %edi
callq 0x569b
testq %rax, %rax
leaq 0x2d0e(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2d5b(%rip), %rdi      # 0x8606
movl %r14d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
movl %ebx, %edi
movq 0x18(%rsp), %rsi
leaq 0xc(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x4, %eax
jne 0x5e81
pushq $0x1
popq %rax
movl %eax, %r13d
cmpl $0x1f, %r13d
je 0x57f8
movl %r13d, %eax
shrl $0x3, %eax
movzbl 0xc(%rsp,%rax), %eax
movl %r13d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5e79
movl %r13d, %edi
callq 0x51cc
testq %rax, %rax
leaq 0x2c9e(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2d02(%rip), %rdi      # 0x861d
movl %r13d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
leal -0x1(%r13), %eax
cmpl $0x4, %eax
ja 0x5a6c
leaq 0x8d0(%rip), %rcx       # 0x620c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x6ffe9(%r12), %rsi
movl %ebx, %edi
leaq 0x10(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
jne 0x5983
movl 0x10(%rsp), %esi
leaq 0x2ccc(%rip), %rdi      # 0x8636
xorl %eax, %eax
callq 0x5050
movl 0x14(%rsp), %esi
leaq 0x2cd6(%rip), %rdi      # 0x8652
xorl %eax, %eax
callq 0x5050
leaq 0x5f0007(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x60, %eax
jne 0x5e79
leaq 0x5efffe(%r12), %rsi
xorl %r12d, %r12d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r15d
cmpl $0x2ff, %r12d           # imm = 0x2FF
je 0x5e6c
movl %r12d, %eax
shrl $0x3, %eax
movl %r12d, %ecx
andb $0x7, %cl
pushq $0x1
popq %rdx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r12d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5a64
cmpl $0x60, %r15d
jne 0x5a2d
movzbl 0xa0(%rsp,%rax), %eax
testl %eax, %edx
je 0x5a2d
movl %r12d, %edi
callq 0x5229
testq %rax, %rax
jne 0x5a24
movl %r12d, %edi
callq 0x5242
testq %rax, %rax
leaq 0x2b8e(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2c44(%rip), %rdi      # 0x866f
jmp 0x5a57
movl %r12d, %edi
callq 0x5229
testq %rax, %rax
jne 0x5a50
movl %r12d, %edi
callq 0x5242
testq %rax, %rax
leaq 0x2b62(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2c35(%rip), %rdi      # 0x868c
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r12d
jmp 0x59c1
cmpl $0x11, %r13d
je 0x5dbc
cmpl $0x12, %r13d
jne 0x5e79
movl %ebx, %edi
movq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5e79
xorl %r15d, %r15d
movl $0x8001451a, %esi       # imm = 0x8001451A
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
cmpl $0x7, %r15d
je 0x5e6c
movzbl 0x40(%rsp), %edx
pushq $0x1
popq %rax
movl %r15d, %ecx
shll %cl, %eax
btl %r15d, %edx
jae 0x5b1b
cmpl $0x1, %r12d
jne 0x5aee
movzbl 0xa0(%rsp), %ecx
leaq 0x2d21(%rip), %r14      # 0x880b
testl %ecx, %eax
jne 0x5af5
leaq 0x2d35(%rip), %r14      # 0x882a
movl %r15d, %edi
callq 0x5685
testq %rax, %rax
leaq 0x2aa7(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
jmp 0x5ab8
leaq 0x1000b(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5dbc
leaq 0x10001(%r12), %rsi
xorl %r15d, %r15d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
cmpl $0x10, %r15d
je 0x5daf
movl %r15d, %eax
shrl $0x3, %eax
movl %r15d, %ecx
andb $0x7, %cl
pushq $0x1
popq %rdx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r15d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5bcf
cmpl $0x2, %r12d
jne 0x5ba2
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x2c01(%rip), %r14      # 0x879f
testl %eax, %edx
jne 0x5ba9
leaq 0x2c16(%rip), %r14      # 0x87bf
movl %r15d, %edi
callq 0x5622
testq %rax, %rax
leaq 0x29f3(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
jmp 0x5b5e
leaq 0x70009(%r12), %rsi
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x8, %eax
jne 0x5e72
xorl %r15d, %r15d
cmpq $0x3f, %r15
je 0x5e72
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0xa0(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5cd3
movl %r15d, %edi
callq 0x560c
testq %rax, %rax
leaq 0x297c(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2a86(%rip), %rdi      # 0x86c3
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
leaq (%r12,%r15), %rsi
addq $0x170026, %rsi         # imm = 0x170026
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
jne 0x5cd3
movl 0x40(%rsp), %esi
leaq 0x2a68(%rip), %rdi      # 0x86da
xorl %eax, %eax
callq 0x5050
movl 0x44(%rsp), %esi
leaq 0x2a72(%rip), %rdi      # 0x86f6
xorl %eax, %eax
callq 0x5050
movl 0x48(%rsp), %esi
leaq 0x2a7c(%rip), %rdi      # 0x8712
xorl %eax, %eax
callq 0x5050
movl 0x4c(%rsp), %esi
leaq 0x2a86(%rip), %rdi      # 0x872e
xorl %eax, %eax
callq 0x5050
movl 0x50(%rsp), %esi
leaq 0x2a90(%rip), %rdi      # 0x874a
xorl %eax, %eax
callq 0x5050
movl 0x54(%rsp), %esi
leaq 0x2a9a(%rip), %rdi      # 0x8766
xorl %eax, %eax
callq 0x5050
incq %r15
jmp 0x5bf9
leaq 0xa(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5e72
xorl %r15d, %r15d
cmpl $0x7, %r15d
je 0x5e72
movzbl 0x40(%rsp), %eax
btl %r15d, %eax
jae 0x5d39
movl %r15d, %edi
callq 0x563b
testq %rax, %rax
leaq 0x288d(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2a56(%rip), %rdi      # 0x8782
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
jmp 0x5cfa
leaq 0x10008(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5e72
xorl %r15d, %r15d
cmpl $0xf, %r15d
je 0x5e72
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0x40(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5daa
movl %r15d, %edi
callq 0x55f6
testq %rax, %rax
leaq 0x281c(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
leaq 0x2905(%rip), %rdi      # 0x86a2
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
jmp 0x5d60
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x27b3(%rip), %r15      # 0x856f
leaq 0x10017(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5e79
leaq 0xffff(%r12), %rsi
xorl %r15d, %r15d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
cmpl $0xf, %r15d
je 0x5e6c
movl %r15d, %eax
shrl $0x3, %eax
movl %r15d, %ecx
andb $0x7, %cl
pushq $0x1
popq %rdx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r15d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5e67
cmpl $0x2, %r12d
jne 0x5e3a
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x29a2(%rip), %r14      # 0x87d8
testl %eax, %edx
jne 0x5e41
leaq 0x29b4(%rip), %r14      # 0x87f5
movl %r15d, %edi
callq 0x5651
testq %rax, %rax
leaq 0x275b(%rip), %rcx      # 0x85ae
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
jmp 0x5dfa
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x26f6(%rip), %r15      # 0x856f
incl %r13d
jmp 0x58da
leaq 0x29ba(%rip), %rdi      # 0x8842
jmp 0x57f3
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x6150(%rip), %rax      # 0xbff8
movq (%rax), %rbx
callq 0x50c0
leaq 0x26cb(%rip), %rsi      # 0x8582
leaq 0x100(%rsp), %rdx
movq %rbx, %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x5080
pushq $0x1
popq %rdi
callq 0x50b0