#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 isDir(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
void walker(char *basedir) {
  DIR *dir;
  struct dirent *dEnt;
  dir = opendir(basedir);
  if (dir != NULL) {
    while ((dEnt = readdir(dir)) != NULL) {
      if (strcmp(dEnt->d_name, ".") == 0 || strcmp(dEnt->d_name, "..") == 0) {
        continue;
      }
      char entpath[500] = "";
      strcat(entpath, basedir);
      strcat(entpath, "/");
      strcat(entpath, dEnt->d_name);
      if (isDir(entpath) == 1) {
        printf("\nDIR: %s\n", dEnt->d_name);
        walker(entpath);
      } else {
        printf("\nFILE: %s\n", dEnt->d_name);
      }
    }
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<walker>:
push   %rbp
mov    %rsp,%rbp
sub    $0x210,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     12b5 <walker+0x125>
jmp    11bc <walker+0x2c>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12ac <walker+0x11c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe20(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     120d <walker+0x7d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe02(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1212 <walker+0x82>
jmp    11bc <walker+0x2c>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x1f4,%edx
call   1050 <memset@plt>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10b0 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    0xdc0(%rip),%rsi
call   10b0 <strcat@plt>
lea    -0x210(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   10b0 <strcat@plt>
lea    -0x210(%rbp),%rdi
call   10a0 <isDir@plt>
cmp    $0x1,%eax
jne    1294 <walker+0x104>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd87(%rip),%rdi
call   1040 <printf@plt>
lea    -0x210(%rbp),%rdi
call   1090 <walker@plt>
jmp    12a7 <walker+0x117>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd6d(%rip),%rdi
call   1040 <printf@plt>
jmp    11bc <walker+0x2c>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x210,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<walker>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1f8,%rsp
mov    %rdi,%r14
call   1030 <opendir@plt>
test   %rax,%rax
je     1285 <walker+0xf5>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     127d <walker+0xed>
mov    %rax,%rbp
lea    0xe31(%rip),%r15
lea    0xe29(%rip),%r12
mov    %rsp,%rbx
jmp    1200 <walker+0x70>
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1090 <walker@plt>
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     127d <walker+0xed>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f0 <walker+0x60>
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11f0 <walker+0x60>
mov    $0x1f4,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
lea    0xdbd(%rip),%rsi
call   10b0 <strcat@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
call   10a0 <isDir@plt>
mov    0x0(%rbp),%rsi
cmp    $0x1,%eax
je     11dc <walker+0x4c>
lea    0xd9c(%rip),%rdi
call   1040 <printf@plt>
jmp    11f0 <walker+0x60>
mov    %r13,%rdi
call   1060 <closedir@plt>
add    $0x1f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [10 x i8] c"\0ADIR: %s\0A\00"
@.str.4 = [11 x i8] c"\0AFILE: %s\0A\00"
define void @walker(i8* %0) {
%2 = alloca [500 x i8]
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %38, label %5
5: ; preds = %1
%6 = call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %36, label %8
8: ; preds = %5
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %2, i64 0, i64 0
br label %10
10: ; preds = %8, %20
%11 = phi %struct.dirent* [ %6, %8 ], [ %21, %20 ]
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp eq i64 %14, 0
br i1 %15, label %20, label %16
16: ; preds = %10
%17 = load i8*, i8** %12
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %10, %16, %35
%21 = call %struct.dirent* @readdir(i32* %3)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %36, label %10
23: ; preds = %16
%24 = call i32 @strcat(i8* %9, i8* %0)
%25 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %12
%27 = call i32 @strcat(i8* %9, i8* %26)
%28 = call i32 @isDir(i8* %9)
%29 = icmp eq i32 %28, 1
%30 = load i8*, i8** %12
br i1 %29, label %31, label %33
31: ; preds = %23
%32 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %35
33: ; preds = %23
%34 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %30)
br label %35
35: ; preds = %33, %31
br label %20
36: ; preds = %20, %5
%37 = call i32 @closedir(i32* %3)
br label %38
38: ; preds = %36, %1
ret void
}