// File: /workspace/github_c_makefile_star2_O3/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 0x2e58(%rip), %r15      # 0x8587
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 0x57de
leaq 0x2e06(%rip), %rdi      # 0x85ad
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 0x57ef
cmpb $0x0, 0x120(%rsp)
movq %r13, %rsi
leaq 0x2de9(%rip), %rax      # 0x85c1
cmoveq %rax, %rsi
jmp 0x57fe
callq 0x5030
movl (%rax), %edi
cmpl $0x2, %edi
je 0x582f
jmp 0x5ef7
movb $0x0, 0x120(%rsp)
leaq 0x2dc3(%rip), %rsi      # 0x85c1
leaq 0x2dad(%rip), %rdi      # 0x85b2
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 0x5856
leaq 0x305c(%rip), %rdi      # 0x8886
callq 0x5040
movl %ebx, %edi
callq 0x5070
incl %ebp
cmpl $0x20, %ebp
leaq 0x100(%rsp), %r14
leaq 0x120(%rsp), %r13
jne 0x577f
jmp 0x5ee3
movl 0x8(%rsp), %esi
cmpl $0x10001, %esi          # imm = 0x10001
jne 0x5880
movl %ebx, %edi
movq 0x28(%rsp), %rsi
movq %rsp, %rdx
xorl %eax, %eax
callq 0x5060
testl %eax, %eax
je 0x5890
leaq 0x2ff4(%rip), %rdi      # 0x8872
jmp 0x582a
leaq 0x2d47(%rip), %rdi      # 0x85ce
xorl %eax, %eax
callq 0x5050
jmp 0x582f
movzwl 0x2(%rsp), %esi
leaq 0x2d53(%rip), %rdi      # 0x85ef
xorl %eax, %eax
callq 0x5050
movzwl 0x4(%rsp), %esi
leaq 0x2d4f(%rip), %rdi      # 0x85fe
xorl %eax, %eax
callq 0x5050
movzwl 0x6(%rsp), %esi
leaq 0x2d4c(%rip), %rdi      # 0x860e
xorl %eax, %eax
callq 0x5050
movzwl (%rsp), %r14d
movl %r14d, %edi
callq 0x56db
testq %rax, %rax
leaq 0x2ce6(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x2d33(%rip), %rdi      # 0x861e
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 0x5ed7
movl $0x1, %r13d
movl %r13d, %eax
shrl $0x3, %eax
movzbl 0xc(%rsp,%rax), %eax
movl %r13d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5ce4
movl %r13d, %edi
callq 0x520c
testq %rax, %rax
leaq 0x2c80(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x2ce4(%rip), %rdi      # 0x8635
movl %r13d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
leal -0x1(%r13), %eax
cmpl $0x4, %eax
ja 0x5aa4
leaq 0x89a(%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 0x59b9
movl 0x10(%rsp), %esi
leaq 0x2cae(%rip), %rdi      # 0x864e
xorl %eax, %eax
callq 0x5050
movl 0x14(%rsp), %esi
leaq 0x2cb8(%rip), %rdi      # 0x866a
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 0x5ce4
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 0x5a8f
cmpl $0x60, %r15d
jne 0x5a58
movzbl 0xa0(%rsp,%rax), %eax
testl %eax, %edx
je 0x5a58
movl %r12d, %edi
callq 0x5269
testq %rax, %rax
jne 0x5a4f
movl %r12d, %edi
callq 0x5282
testq %rax, %rax
leaq 0x2b7b(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x2c31(%rip), %rdi      # 0x8687
jmp 0x5a82
movl %r12d, %edi
callq 0x5269
testq %rax, %rax
jne 0x5a7b
movl %r12d, %edi
callq 0x5282
testq %rax, %rax
leaq 0x2b4f(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x2c22(%rip), %rdi      # 0x86a4
movl %r12d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r12d
cmpl $0x2ff, %r12d           # imm = 0x2FF
jne 0x59f7
jmp 0x5cd7
cmpl $0x11, %r13d
je 0x5c27
cmpl $0x12, %r13d
jne 0x5ce4
movl %ebx, %edi
movq 0x20(%rsp), %rsi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5ce4
xorl %r15d, %r15d
movl $0x8001451a, %esi       # imm = 0x8001451A
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
movl %eax, %r12d
leaq 0x62e1(%rip), %r14      # 0xbdd8
movzbl 0x40(%rsp), %edx
movl $0x1, %eax
movl %r15d, %ecx
shll %cl, %eax
btl %r15d, %edx
jae 0x5b58
cmpl $0x1, %r12d
jne 0x5b37
movzbl 0xa0(%rsp), %ecx
testl %ecx, %eax
je 0x5b37
leaq 0x2aa1(%rip), %rdx      # 0x85c6
cmpl $0x2, %r15d
ja 0x5b2e
movq (%r14), %rdx
leaq 0x2cee(%rip), %rdi      # 0x8823
jmp 0x5b4e
leaq 0x2a88(%rip), %rdx      # 0x85c6
cmpl $0x2, %r15d
ja 0x5b47
movq (%r14), %rdx
leaq 0x2cf4(%rip), %rdi      # 0x8842
movl %r15d, %esi
xorl %eax, %eax
callq 0x5050
incl %r15d
addq $0x8, %r14
cmpl $0x7, %r15d
jne 0x5af7
jmp 0x5cd7
leaq 0x1000b(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5c27
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 0x5c11
cmpl $0x2, %r12d
jne 0x5be4
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x2bd7(%rip), %r14      # 0x87b7
testl %eax, %edx
jne 0x5beb
leaq 0x2bec(%rip), %r14      # 0x87d7
movl %r15d, %edi
callq 0x5662
testq %rax, %rax
leaq 0x29c9(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0x10, %r15d
jne 0x5ba8
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x2960(%rip), %r15      # 0x8587
leaq 0x10017(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5ce4
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 0x5cce
cmpl $0x2, %r12d
jne 0x5ca1
movzbl 0xa0(%rsp,%rax), %eax
leaq 0x2b53(%rip), %r14      # 0x87f0
testl %eax, %edx
jne 0x5ca8
leaq 0x2b65(%rip), %r14      # 0x880d
movl %r15d, %edi
callq 0x5691
testq %rax, %rax
leaq 0x290c(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
movq %r14, %rdi
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0xf, %r15d
jne 0x5c65
movl $0x8001451a, %r12d      # imm = 0x8001451A
leaq 0x28a3(%rip), %r15      # 0x8587
incl %r13d
cmpl $0x1f, %r13d
jne 0x591a
jmp 0x582f
leaq 0x70009(%r12), %rsi
movl %ebx, %edi
leaq 0xa0(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x8, %eax
jne 0x5cdd
xorl %r15d, %r15d
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0xa0(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5de7
movl %r15d, %edi
callq 0x564c
testq %rax, %rax
leaq 0x2880(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x298a(%rip), %rdi      # 0x86db
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 0x5de7
movl 0x40(%rsp), %esi
leaq 0x296c(%rip), %rdi      # 0x86f2
xorl %eax, %eax
callq 0x5050
movl 0x44(%rsp), %esi
leaq 0x2976(%rip), %rdi      # 0x870e
xorl %eax, %eax
callq 0x5050
movl 0x48(%rsp), %esi
leaq 0x2980(%rip), %rdi      # 0x872a
xorl %eax, %eax
callq 0x5050
movl 0x4c(%rsp), %esi
leaq 0x298a(%rip), %rdi      # 0x8746
xorl %eax, %eax
callq 0x5050
movl 0x50(%rsp), %esi
leaq 0x2994(%rip), %rdi      # 0x8762
xorl %eax, %eax
callq 0x5050
movl 0x54(%rsp), %esi
leaq 0x299e(%rip), %rdi      # 0x877e
xorl %eax, %eax
callq 0x5050
incq %r15
cmpq $0x3f, %r15
jne 0x5d17
jmp 0x5cdd
leaq 0xa(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x1, %eax
jne 0x5cdd
xorl %r15d, %r15d
leaq 0x445(%rip), %r14       # 0x6264
movzbl 0x40(%rsp), %eax
btl %r15d, %eax
jae 0x5e55
leaq 0x2795(%rip), %rdx      # 0x85c6
cmpl $0x5, %r15d
ja 0x5e44
movslq (%r14), %rdx
leaq 0x423(%rip), %rax       # 0x6264
addq %rax, %rdx
leaq 0x294f(%rip), %rdi      # 0x879a
movl %r15d, %esi
xorl %eax, %eax
callq 0x5050
incl %r15d
addq $0x4, %r14
cmpl $0x7, %r15d
jne 0x5e1f
jmp 0x5cdd
leaq 0x10008(%r12), %rsi
movl %ebx, %edi
leaq 0x40(%rsp), %rdx
xorl %eax, %eax
callq 0x5060
cmpl $0x2, %eax
jne 0x5cdd
xorl %r15d, %r15d
movl %r15d, %eax
shrl $0x3, %eax
movzbl 0x40(%rsp,%rax), %eax
movl %r15d, %ecx
andl $0x7, %ecx
btl %ecx, %eax
jae 0x5ec9
movl %r15d, %edi
callq 0x5636
testq %rax, %rax
leaq 0x2715(%rip), %rcx      # 0x85c6
cmoveq %rcx, %rax
leaq 0x27fe(%rip), %rdi      # 0x86ba
movl %r15d, %esi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5050
incl %r15d
cmpl $0xf, %r15d
jne 0x5e89
jmp 0x5cdd
leaq 0x297c(%rip), %rdi      # 0x885a
jmp 0x582a
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