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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int isDir(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
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: %lu\n", dEnt->d_ino);
        walker(entpath);
      } else {
        printf("\nFILE: %lu\n", dEnt->d_ino);
      }
    }
    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    0x8(%rax),%esi
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    0x8(%rax),%esi
lea    0xd6e(%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     1284 <walker+0xf4>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     127c <walker+0xec>
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     127c <walker+0xec>
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    0x8(%rbp),%esi
cmp    $0x1,%eax
je     11dc <walker+0x4c>
lea    0xd9e(%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*, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [11 x i8] c"\0ADIR: %lu\0A\00"
@.str.4 = [12 x i8] c"\0AFILE: %lu\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 1
%46 = load i32, i32* %45
%47 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %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 1
%52 = load i32, i32* %51
%53 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %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*, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [11 x i8] c"\0ADIR: %lu\0A\00"
@.str.4 = [12 x i8] c"\0AFILE: %lu\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 %39, label %5
5: ; preds = %1
%6 = call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %37, 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, %36
%21 = call %struct.dirent* @readdir(i32* %3)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %37, 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 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 1
%31 = load i32, i32* %30
br i1 %29, label %32, label %34
32: ; preds = %23
%33 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0), i32 %31)
br label %36
34: ; preds = %23
%35 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %31)
br label %36
36: ; preds = %34, %32
br label %20
37: ; preds = %20, %5
%38 = call i32 @closedir(i32* %3)
br label %39
39: ; preds = %37, %1
ret void
}