#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ evtest_info(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
void evtest_list(int verbose) {
  char *pathname = "/dev/input";
  DIR *dir = opendir(pathname);
  if (!dir) {
    perror(pathname);
  } else {
    struct dirent *el = 0;
    while ((el = readdir(dir)) != 0) {
      if (strncmp("event", el->d_name, 5) == 0) {
        int len = strlen(pathname) + 1 + strlen(el->d_name) + 1;
        char filename[len];
        filename[0] = '\0';
        strcat(filename, pathname);
        strcat(filename, "/");
        strcat(filename, el->d_name);
        evtest_info(filename, verbose);
      }
    }
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<evtest_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
lea    0xe6e(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bc <evtest_list+0x3c>
mov    -0x10(%rbp),%rdi
call   1090 <perror@plt>
jmp    1298 <evtest_list+0x118>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     128f <evtest_list+0x10f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    128a <evtest_list+0x10a>
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x44(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x44(%rbp),%ecx
mov    %eax,%edx
mov    %ecx,%eax
mov    %edx,%ecx
lea    0x2(%rax,%rcx,1),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
movb   $0x0,(%rdi)
mov    -0x10(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   10a0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   1080 <evtest_info@plt>
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
jmp    11c4 <evtest_list+0x44>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<evtest_list>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,-0x2c(%rbp)
lea    0xe68(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     128e <evtest_list+0x10e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1277 <evtest_list+0xf7>
mov    %rax,%r13
lea    0xe47(%rip),%r14
jmp    11e4 <evtest_list+0x64>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1277 <evtest_list+0xf7>
mov    0x0(%r13),%rsi
mov    %r14,%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d0 <evtest_list+0x50>
lea    0xdff(%rip),%rdi
call   1050 <strlen@plt>
mov    %rbx,%r12
mov    %eax,%ebx
mov    0x0(%r13),%rdi
call   1050 <strlen@plt>
mov    %rsp,%r15
add    %ebx,%eax
add    $0x2,%eax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rcx
mov    %rcx,%rbx
sub    %rax,%rbx
neg    %rax
mov    %rbx,%rsp
movb   $0x0,(%rcx,%rax,1)
mov    %rbx,%rdi
lea    0xdbf(%rip),%rsi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
lea    0xdc1(%rip),%rsi
call   10a0 <strcat@plt>
mov    0x0(%r13),%rsi
mov    %rbx,%rdi
call   10a0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rbx
mov    -0x2c(%rbp),%esi
call   1080 <evtest_info@plt>
mov    %r15,%rsp
jmp    11d0 <evtest_list+0x50>
mov    %rbx,%rdi
call   1060 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd6b(%rip),%rdi
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <perror@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"/dev/input\00"
@.str.1 = [6 x i8] c"event\00"
@.str.2 = [2 x i8] c"/\00"
define void @evtest_list(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i32 %0, i32* %2
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %3
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %4
%11 = load i32*, i32** %4
%12 = icmp ne i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %1
%14 = load i8*, i8** %3
%15 = call i32 @perror(i8* %14)
br label %56
16: ; preds = %1
store %struct.dirent* null, %struct.dirent** %5
br label %17
17: ; preds = %52, %16
%18 = load i32*, i32** %4
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %5
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %53
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %5
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %24, i32 5)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %52
27: ; preds = %21
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = add nsw i32 %29, 1
%31 = load %struct.dirent*, %struct.dirent** %5
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strlen(i8* %33)
%35 = add nsw i32 %30, %34
%36 = add nsw i32 %35, 1
store i32 %36, i32* %6
%37 = load i32, i32* %6
%38 = zext i32 %37 to i64
%39 = call i8* @llvm.stacksave()
store i8* %39, i8** %7
%40 = alloca i8, i64 %38
store i64 %38, i64* %8
%41 = getelementptr inbounds i8, i8* %40, i64 0
store i8 0, i8* %41
%42 = load i8*, i8** %3
%43 = call i32 @strcat(i8* %40, i8* %42)
%44 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%45 = load %struct.dirent*, %struct.dirent** %5
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i8*, i8** %46
%48 = call i32 @strcat(i8* %40, i8* %47)
%49 = load i32, i32* %2
%50 = call i32 @evtest_info(i8* %40, i32 %49)
%51 = load i8*, i8** %7
br label %52
52: ; preds = %27, %21
br label %17
53: ; preds = %17
%54 = load i32*, i32** %4
%55 = call i32 @closedir(i32* %54)
br label %56
56: ; preds = %53, %13
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [11 x i8] c"/dev/input\00"
@.str.1 = [6 x i8] c"event\00"
@.str.2 = [2 x i8] c"/\00"
define void @evtest_list(i32 %0) {
%2 = tail call i32* @opendir(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %32, label %9
7: ; preds = %1
%8 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %34
9: ; preds = %4, %29
%10 = phi %struct.dirent* [ %30, %29 ], [ %5, %4 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i8*, i8** %11
%13 = call i64 @strncmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %12, i32 5)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %29
15: ; preds = %9
%16 = call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%17 = load i8*, i8** %11
%18 = call i32 @strlen(i8* %17)
%19 = add i32 %16, 2
%20 = add i32 %19, %18
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
%23 = alloca i8, i64 %21
store i8 0, i8* %23
%24 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @strcat(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %11
%27 = call i32 @strcat(i8* %23, i8* %26)
%28 = call i32 @evtest_info(i8* %23, i32 %0)
br label %29
29: ; preds = %15, %9
%30 = call %struct.dirent* @readdir(i32* %2)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %32, label %9
32: ; preds = %29, %4
%33 = call i32 @closedir(i32* %2)
br label %34
34: ; preds = %32, %7
ret void
}