#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 stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
char *getcwd(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
void re_file(const char *fname) {
  DIR *dp = NULL;
  struct dirent *entry = NULL;
  struct stat sb;
  dp = opendir(fname);
  if (dp == NULL) {
    fprintf(stderr, "can not open directory <%s>\n", fname);
    return;
  }
  chdir(fname);
  while ((entry = readdir(dp)) != NULL) {
    if (entry->d_name[0] == '.' &&
        (entry->d_name[1] == '\0' ||
         (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
      continue;
    stat(entry->d_name, &sb);
    if (S_ISDIR(sb.st_mode)) {
      re_file(entry->d_name);
    } else {
      char path[PATH_MAX + 1];
      printf("%s/%s\n", getcwd(path, PATH_MAX), entry->d_name);
    }
  }
  chdir("..");
  closedir(dp);
  return;
}


x86 assembly (clang, -O0):
<re_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f2 <re_file+0x52>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe18(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1309 <re_file+0x169>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12f4 <re_file+0x154>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1266 <re_file+0xc6>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1261 <re_file+0xc1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1266 <re_file+0xc6>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    1266 <re_file+0xc6>
jmp    11fb <re_file+0x5b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <stat@plt>
mov    -0x20(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1299 <re_file+0xf9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   10c0 <re_file@plt>
jmp    12ef <re_file+0x14f>
mov    0x2d50(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
call   1070 <getcwd@plt>
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xd3a(%rip),%rdi
call   1050 <printf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    11fb <re_file+0x5b>
lea    0xd29(%rip),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<re_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     12a6 <re_file+0x106>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <chdir@plt>
mov    %r12,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1283 <re_file+0xe3>
mov    %rax,%rbx
lea    -0x30(%rbp),%r14
mov    0x2e07(%rip),%r13
jmp    1239 <re_file+0x99>
nopl   0x0(%rax,%rax,1)
mov    %rsp,%r15
mov    0x0(%r13),%eax
add    $0x1,%eax
mov    %rsp,%rdi
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rdi
mov    %rdi,%rsp
mov    0x0(%r13),%esi
call   1070 <getcwd@plt>
mov    (%rbx),%rdx
lea    0xdff(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
mov    %r15,%rsp
mov    %r12,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1283 <re_file+0xe3>
mov    (%rbx),%rdi
cmpb   $0x2e,(%rdi)
jne    1260 <re_file+0xc0>
movzbl 0x1(%rdi),%eax
test   %al,%al
je     1229 <re_file+0x89>
cmp    $0x2e,%al
jne    1260 <re_file+0xc0>
cmpb   $0x0,0x2(%rdi)
je     1229 <re_file+0x89>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rsi
call   10a0 <stat@plt>
mov    -0x30(%rbp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     11f0 <re_file+0x50>
mov    (%rbx),%rdi
call   10c0 <re_file@plt>
jmp    1229 <re_file+0x89>
lea    0xd9a(%rip),%rdi
call   1040 <chdir@plt>
mov    %r12,%rdi
call   1080 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd4a(%rip),%rsi
mov    %rbx,%rdx
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <fprintf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [29 x i8] c"can not open directory <%s>\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [7 x i8] c"%s/%s\0A\00"
@.str.2 = [3 x i8] c"..\00"
define void @re_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %2
store i32* null, i32** %3
store %struct.dirent* null, %struct.dirent** %4
%8 = load i8*, i8** %2
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %3
%10 = load i32*, i32** %3
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %16
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %2
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %87
16: ; preds = %1
%17 = load i8*, i8** %2
%18 = call i32 @chdir(i8* %17)
br label %19
19: ; preds = %82, %55, %16
%20 = load i32*, i32** %3
%21 = call %struct.dirent* @readdir(i32* %20)
store %struct.dirent* %21, %struct.dirent** %4
%22 = icmp ne %struct.dirent* %21, null
br i1 %22, label %23, label %83
23: ; preds = %19
%24 = load %struct.dirent*, %struct.dirent** %4
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8, i8* %26, i64 0
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp eq i32 %29, 46
br i1 %30, label %31, label %56
31: ; preds = %23
%32 = load %struct.dirent*, %struct.dirent** %4
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp eq i32 %37, 0
br i1 %38, label %55, label %39
39: ; preds = %31
%40 = load %struct.dirent*, %struct.dirent** %4
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = icmp eq i32 %45, 46
br i1 %46, label %47, label %56
47: ; preds = %39
%48 = load %struct.dirent*, %struct.dirent** %4
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8, i8* %50, i64 2
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %47, %31
br label %19
56: ; preds = %47, %39, %23
%57 = load %struct.dirent*, %struct.dirent** %4
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @stat(i8* %59, %struct.stat* %5)
%61 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%62 = load i32, i32* %61
%63 = call i64 @S_ISDIR(i32 %62)
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %69
65: ; preds = %56
%66 = load %struct.dirent*, %struct.dirent** %4
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
br label %82
69: ; preds = %56
%70 = load i32, i32* @PATH_MAX
%71 = add nsw i32 %70, 1
%72 = zext i32 %71 to i64
%73 = call i8* @llvm.stacksave()
store i8* %73, i8** %6
%74 = alloca i8, i64 %72
store i64 %72, i64* %7
%75 = load i32, i32* @PATH_MAX
%76 = call i8* @getcwd(i8* %74, i32 %75)
%77 = load %struct.dirent*, %struct.dirent** %4
%78 = getelementptr inbounds %struct.dirent, %struct.dirent* %77, i32 0, i32 0
%79 = load i8*, i8** %78
%80 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %76, i8* %79)
%81 = load i8*, i8** %6
br label %82
82: ; preds = %69, %65
br label %19
83: ; preds = %19
%84 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%85 = load i32*, i32** %3
%86 = call i32 @closedir(i32* %85)
br label %87
87: ; preds = %83, %12
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [29 x i8] c"can not open directory <%s>\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [7 x i8] c"%s/%s\0A\00"
@.str.2 = [3 x i8] c"..\00"
define void @re_file(i8* %0) {
%2 = alloca %struct.stat
%3 = bitcast %struct.stat* %2 to i8*
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %51
9: ; preds = %1
%10 = tail call i32 @chdir(i8* %0)
%11 = call %struct.dirent* @readdir(i32* %4)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %48, label %13
13: ; preds = %9
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %15
15: ; preds = %13, %28
%16 = phi %struct.dirent* [ %11, %13 ], [ %29, %28 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = load i8, i8* %18
%20 = icmp eq i8 %19, 46
br i1 %20, label %21, label %31
21: ; preds = %15
%22 = getelementptr inbounds i8, i8* %18, i64 1
%23 = load i8, i8* %22
switch i8 %23, label %31 [
i8 0, label %28
i8 46, label %24
]
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %18, i64 2
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %36, %38, %24, %21
%29 = call %struct.dirent* @readdir(i32* %4)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %48, label %15
31: ; preds = %21, %24, %15
%32 = call i32 @stat(i8* %18, %struct.stat* %2)
%33 = load i32, i32* %14
%34 = call i64 @S_ISDIR(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = load i8*, i8** %17
br label %28
38: ; preds = %31
%39 = load i32, i32* @PATH_MAX
%40 = add nsw i32 %39, 1
%41 = zext i32 %40 to i64
%42 = call i8* @llvm.stacksave()
%43 = alloca i8, i64 %41
%44 = load i32, i32* @PATH_MAX
%45 = call i8* @getcwd(i8* %43, i32 %44)
%46 = load i8*, i8** %17
%47 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %45, i8* %46)
br label %28
48: ; preds = %28, %9
%49 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%50 = call i32 @closedir(i32* %4)
br label %51
51: ; preds = %48, %6
ret void
}