// File: /workspace/github_c_makefile_star2_O1/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 0x2e60(%rip), %r15      # 0x858f
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
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 0x5817
leaq 0x2e0e(%rip), %rdi      # 0x85b5
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
jns 0x57ce
movb $0x0, 0x120(%rsp)
cmpb $0x0, 0x120(%rsp)
leaq 0x2dec(%rip), %rax      # 0x85c9
cmoveq %rax, %r13
leaq 0x2dd2(%rip), %rdi      # 0x85ba
movq %r13, %rsi
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 0x5828
leaq 0x307e(%rip), %rdi      # 0x888e
callq 0x5040
jmp 0x5860
callq 0x5030
movl (%rax), %edi
cmpl $0x2, %edi
je 0x5860
jmp 0x5eee
movl 0x8(%rsp), %esi
cmpl $0x10001, %esi          # imm = 0x10001
jne 0x5852
movl %ebx, %edi
movq 0x28(%rsp), %rsi
movq %rsp, %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
je 0x5887
leaq 0x302a(%rip), %rdi      # 0x887a
jmp 0x5810
leaq 0x2d7d(%rip), %rdi      # 0x85d6
xorl %eax, %eax
callq 0x5050
movl %ebx, %edi
callq 0x5070
incl %ebp
cmpl $0x20, %ebp
leaq 0x100(%rsp), %r14
leaq 0x120(%rsp), %r13
jne 0x577f
jmp 0x5eda
movzwl 0x2(%rsp), %esi
leaq 0x2d64(%rip), %rdi      # 0x85f7
xorl %eax, %eax
callq 0x5050
movzwl 0x4(%rsp), %esi
leaq 0x2d60(%rip), %rdi      # 0x8606
xorl %eax, %eax
callq 0x5050
movzwl 0x6(%rsp), %esi
leaq 0x2d5d(%rip), %rdi      # 0x8616
xorl %eax, %eax
callq 0x5050
movzwl (%rsp), %r14d
movl %r14d, %edi
callq 0x56db
testq %rax, %rax
leaq 0x2cf7(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x2d44(%rip), %rdi      # 0x8626
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 0x5ece
movl $0x1, %r13d
movl %r13d, %eax
shrl $0x3, %eax
movzbl 0xc(%rsp,%rax), %eax
movl %r13d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5cdb
movl %r13d, %edi
callq 0x520c
testq %rax, %rax
leaq 0x2c91(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x2cf5(%rip), %rdi      # 0x863d
movl %r13d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
leal -0x1(%r13), %eax
cmpl $0x4, %eax
ja 0x5a9b
leaq 0x8a3(%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 0x59b0
movl 0x10(%rsp), %esi
leaq 0x2cbf(%rip), %rdi      # 0x8656
xorl %eax, %eax
callq 0x5050
movl 0x14(%rsp), %esi
leaq 0x2cc9(%rip), %rdi      # 0x8672
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 0x5cdb
leaq 0x5efffe(%r12), %rsi
xorl %r12d, %r12d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r15d
movl %r12d, %eax
shrl $0x3, %eax
movl %r12d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r12d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5a86
cmpl $0x60, %r15d
jne 0x5a4f
movzbl 0xa0(%rsp,%rax), %eax
testl %eax, %edx
je 0x5a4f
movl %r12d, %edi
callq 0x5269
testq %rax, %rax
jne 0x5a46
movl %r12d, %edi
callq 0x5282
testq %rax, %rax
leaq 0x2b8c(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x2c42(%rip), %rdi      # 0x868f
jmp 0x5a79
movl %r12d, %edi
callq 0x5269
testq %rax, %rax
jne 0x5a72
movl %r12d, %edi
callq 0x5282
testq %rax, %rax
leaq 0x2b60(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x2c33(%rip), %rdi      # 0x86ac
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r12d
cmpl $0x2ff, %r12d           # imm = 0x2FF
jne 0x59ee
jmp 0x5cce
cmpl $0x11, %r13d
je 0x5c1e
cmpl $0x12, %r13d
jne 0x5cdb
movl %ebx, %edi
movq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5cdb
xorl %r15d, %r15d
movl $0x8001451a, %esi       # imm = 0x8001451A
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
leaq 0x62c2(%rip), %r14      # 0xbdb0
movzbl 0x40(%rsp), %edx
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
btl %r15d, %edx
jae 0x5b4f
cmpl $0x1, %r12d
jne 0x5b2e
movzbl 0xa0(%rsp), %ecx
testl %ecx, %eax
je 0x5b2e
leaq 0x2ab2(%rip), %rdx      # 0x85ce
cmpl $0x7, %r15d
ja 0x5b25
movq (%r14), %rdx
leaq 0x2cff(%rip), %rdi      # 0x882b
jmp 0x5b45
leaq 0x2a99(%rip), %rdx      # 0x85ce
cmpl $0x7, %r15d
ja 0x5b3e
movq (%r14), %rdx
leaq 0x2d05(%rip), %rdi      # 0x884a
movl %r15d, %esi
xorl %eax, %eax
callq 0x5050
incl %r15d
addq $0x8, %r14
cmpl $0x7, %r15d
jne 0x5aee
jmp 0x5cce
leaq 0x1000b(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5c1e
leaq 0x10001(%r12), %rsi
xorl %r15d, %r15d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
movl %r15d, %eax
shrl $0x3, %eax
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r15d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5c08
cmpl $0x2, %r12d
jne 0x5bdb
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x2be8(%rip), %r14      # 0x87bf
testl %eax, %edx
jne 0x5be2
leaq 0x2bfd(%rip), %r14      # 0x87df
movl %r15d, %edi
callq 0x5662
testq %rax, %rax
leaq 0x29da(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0x10, %r15d
jne 0x5b9f
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x2971(%rip), %r15      # 0x858f
leaq 0x10017(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5cdb
leaq 0xffff(%r12), %rsi
xorl %r15d, %r15d
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
movl %r15d, %eax
shrl $0x3, %eax
movl %r15d, %ecx
andb $0x7, %cl
movl $0x1, %edx
shll %cl, %edx
movzbl 0x40(%rsp,%rax), %ecx
movl %r15d, %esi
andl $0x7, %esi
btl %esi, %ecx
jae 0x5cc5
cmpl $0x2, %r12d
jne 0x5c98
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x2b64(%rip), %r14      # 0x87f8
testl %eax, %edx
jne 0x5c9f
leaq 0x2b76(%rip), %r14      # 0x8815
movl %r15d, %edi
callq 0x5691
testq %rax, %rax
leaq 0x291d(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0xf, %r15d
jne 0x5c5c
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x28b4(%rip), %r15      # 0x858f
incl %r13d
cmpl $0x1f, %r13d
jne 0x5911
jmp 0x5860
leaq 0x70009(%r12), %rsi
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x8, %eax
jne 0x5cd4
xorl %r15d, %r15d
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0xa0(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5dde
movl %r15d, %edi
callq 0x564c
testq %rax, %rax
leaq 0x2891(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x299b(%rip), %rdi      # 0x86e3
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 0x5dde
movl 0x40(%rsp), %esi
leaq 0x297d(%rip), %rdi      # 0x86fa
xorl %eax, %eax
callq 0x5050
movl 0x44(%rsp), %esi
leaq 0x2987(%rip), %rdi      # 0x8716
xorl %eax, %eax
callq 0x5050
movl 0x48(%rsp), %esi
leaq 0x2991(%rip), %rdi      # 0x8732
xorl %eax, %eax
callq 0x5050
movl 0x4c(%rsp), %esi
leaq 0x299b(%rip), %rdi      # 0x874e
xorl %eax, %eax
callq 0x5050
movl 0x50(%rsp), %esi
leaq 0x29a5(%rip), %rdi      # 0x876a
xorl %eax, %eax
callq 0x5050
movl 0x54(%rsp), %esi
leaq 0x29af(%rip), %rdi      # 0x8786
xorl %eax, %eax
callq 0x5050
incq %r15
cmpq $0x3f, %r15
jne 0x5d0e
jmp 0x5cd4
leaq 0xa(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5cd4
xorl %r15d, %r15d
leaq 0x44e(%rip), %r14       # 0x6264
movzbl 0x40(%rsp), %eax
btl %r15d, %eax
jae 0x5e4c
leaq 0x27a6(%rip), %rdx      # 0x85ce
cmpl $0x7, %r15d
ja 0x5e3b
movslq (%r14), %rdx
leaq 0x42c(%rip), %rax       # 0x6264
addq %rax, %rdx
leaq 0x2960(%rip), %rdi      # 0x87a2
movl %r15d, %esi
xorl %eax, %eax
callq 0x5050
incl %r15d
addq $0x4, %r14
cmpl $0x7, %r15d
jne 0x5e16
jmp 0x5cd4
leaq 0x10008(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5cd4
xorl %r15d, %r15d
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0x40(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5ec0
movl %r15d, %edi
callq 0x5636
testq %rax, %rax
leaq 0x2726(%rip), %rcx      # 0x85ce
cmoveq %rcx, %rax
leaq 0x280f(%rip), %rdi      # 0x86c2
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0xf, %r15d
jne 0x5e80
jmp 0x5cd4
leaq 0x298d(%rip), %rdi      # 0x8862
jmp 0x5810
xorl %eax, %eax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x100(%rsp), %rsi
callq 0x50e0