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

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getPath(char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ printfName(char *, struct dirent *, int);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
void listDir(char *root, DIR *d, int depth) {
  depth++;
  char *newRoot;
  char *httpServerName;
  DIR *nd;
  struct dirent *ep;
  while ((ep = readdir(d)) != NULL) {
    if (strstr(ep->d_name, "..") == NULL && strcmp(ep->d_name, ".") != 0) {
      httpServerName = ep->d_name;
      printfName(root, ep, depth);
      if (ep->d_type == DT_DIR) {
        newRoot = getPath(root, ep->d_name);
        nd = opendir(newRoot);
        if (nd != NULL) {
          listDir(newRoot, nd, depth);
        } else {
          printf("NULL-> %s\n", ep->d_name);
        }
        free(newRoot);
      }
    }
  }
  closedir(d);
}


x86 assembly (clang, -O0):
<listDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12a7 <listDir+0x107>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xe1f(%rip),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
jne    12a2 <listDir+0x102>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xe03(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12a2 <listDir+0x102>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <printfName@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2da9(%rip),%rcx
cmp    (%rcx),%rax
jne    129d <listDir+0xfd>
mov    -0x8(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
call   10b0 <getPath@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1281 <listDir+0xe1>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <listDir@plt>
jmp    1294 <listDir+0xf4>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xd74(%rip),%rdi
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
jmp    12a2 <listDir+0x102>
jmp    11bc <listDir+0x1c>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listDir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%r12
mov    %rsi,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     127c <listDir+0xdc>
mov    %rax,%r13
add    $0x1,%r15d
lea    0xe2d(%rip),%r14
jmp    1200 <listDir+0x60>
mov    0x0(%r13),%rsi
lea    0xe23(%rip),%rdi
call   1070 <printf@plt>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%r12
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     127c <listDir+0xdc>
mov    0x0(%r13),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
jne    11f0 <listDir+0x50>
mov    %rbp,%rdi
lea    0xde3(%rip),%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
je     11f0 <listDir+0x50>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %r15d,%edx
call   1040 <printfName@plt>
mov    0x8(%r13),%rax
mov    0x2d9f(%rip),%rcx
cmp    (%rcx),%rax
jne    11f0 <listDir+0x50>
mov    0x0(%r13),%rsi
mov    %r12,%rbp
mov    %r12,%rdi
call   10b0 <getPath@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     11d5 <listDir+0x35>
mov    %r12,%rdi
mov    %rax,%rsi
mov    %r15d,%edx
call   1060 <listDir@plt>
jmp    11e5 <listDir+0x45>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@.str = [3 x i8] c"..\00"
@.str.1 = [2 x i8] c".\00"
@DT_DIR = global i64 0
@.str.2 = [11 x i8] c"NULL-> %s\0A\00"
define void @listDir(i8* %0, i32* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca %struct.dirent*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i32 %2, i32* %6
%11 = load i32, i32* %6
%12 = add nsw i32 %11, 1
store i32 %12, i32* %6
br label %13
13: ; preds = %65, %3
%14 = load i32*, i32** %5
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %10
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %66
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %10
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32* @strstr(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %65
23: ; preds = %17
%24 = load %struct.dirent*, %struct.dirent** %10
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %65
29: ; preds = %23
%30 = load %struct.dirent*, %struct.dirent** %10
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i8*, i8** %31
store i8* %32, i8** %8
%33 = load i8*, i8** %4
%34 = load %struct.dirent*, %struct.dirent** %10
%35 = load i32, i32* %6
%36 = call i32 @printfName(i8* %33, %struct.dirent* %34, i32 %35)
%37 = load %struct.dirent*, %struct.dirent** %10
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 1
%39 = load i64, i64* %38
%40 = load i64, i64* @DT_DIR
%41 = icmp eq i64 %39, %40
br i1 %41, label %42, label %64
42: ; preds = %29
%43 = load i8*, i8** %4
%44 = load %struct.dirent*, %struct.dirent** %10
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i8* @getPath(i8* %43, i8* %46)
store i8* %47, i8** %7
%48 = load i8*, i8** %7
%49 = call i32* @opendir(i8* %48)
store i32* %49, i32** %9
%50 = load i32*, i32** %9
%51 = icmp ne i32* %50, null
br i1 %51, label %52, label %56
52: ; preds = %42
%53 = load i8*, i8** %7
%54 = load i32*, i32** %9
%55 = load i32, i32* %6
br label %61
56: ; preds = %42
%57 = load %struct.dirent*, %struct.dirent** %10
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %56, %52
%62 = load i8*, i8** %7
%63 = call i32 @free(i8* %62)
br label %64
64: ; preds = %61, %29
br label %65
65: ; preds = %64, %23, %17
br label %13
66: ; preds = %13
%67 = load i32*, i32** %5
%68 = call i32 @closedir(i32* %67)
ret void
}

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