#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 {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int strlen(int /*<<< orphan*/);
void transverse_dir(char *path, void (*callback)(char *path, char *filename)) {
  DIR *dir;
  struct dirent *ent;
  int name_len;
  int mask;
  char *prefix[] = {"in_", "out_", "vis_"};
  char suffix[] = ".so";
  dir = opendir("plugins");
  for (;;) {
    ent = readdir(dir);
    if (ent == NULL)
      break;
    puts(ent->d_name);
    name_len = strlen(ent->d_name);
  }
  (void)closedir(dir);
}


x86 assembly (clang, -O0):
<transverse_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c99(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2c96(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0x2c93(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xe87(%rip),%eax
mov    %eax,-0x44(%rbp)
lea    0xe81(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11b7 <transverse_dir+0x67>
jmp    11d5 <transverse_dir+0x85>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1030 <puts@plt>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
call   1050 <strlen@plt>
mov    %eax,-0x24(%rbp)
jmp    119a <transverse_dir+0x4a>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<transverse_dir>:
push   %r14
push   %rbx
push   %rax
lea    0xea5(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     119e <transverse_dir+0x4e>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%rbx),%edi
call   1030 <puts@plt>
mov    (%rbx),%edi
call   1050 <strlen@plt>
mov    %r14,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1180 <transverse_dir+0x30>
mov    %r14,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [4 x i8] c"in_\00"
@.str.1 = [5 x i8] c"out_\00"
@.str.2 = [5 x i8] c"vis_\00"
@__const.transverse_dir.prefix = [3 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0)]
@__const.transverse_dir.suffix = [4 x i8] c".so\00"
@.str.3 = [8 x i8] c"plugins\00"
define void @transverse_dir(i8* %0, void (i8*, i8*)* %1) {
%3 = alloca i8*
%4 = alloca void (i8*, i8*)*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [3 x i8*]
%10 = alloca [4 x i8]
store i8* %0, i8** %3
store void (i8*, i8*)* %1, void (i8*, i8*)** %4
%11 = bitcast [3 x i8*]* %9 to i8*
%12 = bitcast [4 x i8]* %10 to i8*
%13 = call i32* @opendir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
store i32* %13, i32** %5
br label %14
14: ; preds = %20, %2
%15 = load i32*, i32** %5
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %6
%17 = load %struct.dirent*, %struct.dirent** %6
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %19, label %20
19: ; preds = %14
br label %29
20: ; preds = %14
%21 = load %struct.dirent*, %struct.dirent** %6
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @puts(i32 %23)
%25 = load %struct.dirent*, %struct.dirent** %6
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i32, i32* %26
%28 = call i32 @strlen(i32 %27)
store i32 %28, i32* %7
br label %14
29: ; preds = %19
%30 = load i32*, i32** %5
%31 = call i32 @closedir(i32* %30)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str.3 = [8 x i8] c"plugins\00"
define void @transverse_dir(i8* nocapture readnone %0, void (i8*, i8*)* nocapture readnone %1) {
%3 = tail call i32* @opendir(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%4 = tail call %struct.dirent* @readdir(i32* %3)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %15, label %6
6: ; preds = %2, %6
%7 = phi %struct.dirent* [ %13, %6 ], [ %4, %2 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @puts(i32 %9)
%11 = load i32, i32* %8
%12 = tail call i32 @strlen(i32 %11)
%13 = tail call %struct.dirent* @readdir(i32* %3)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %15, label %6
15: ; preds = %6, %2
%16 = tail call i32 @closedir(i32* %3)
ret void
}