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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *);
int /*<<< orphan*/ process_file(char *, int /*<<< orphan*/, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
void get_files_in(const char *root_name) {
  DIR *root;
  struct dirent *current_entry;
  char *directory_name;
  char next_root[PATH_MAX];
  struct stat file_stat;
  if (0) {
    printf("get_files_in(%s)\n", root_name);
  }
  if ((root = opendir(root_name))) {
    while ((current_entry = readdir(root))) {
      directory_name = current_entry->d_name;
      if (*directory_name != '.') {
        sprintf(next_root, "%s/%s", root_name, directory_name);
        stat(next_root, &file_stat);
        if (!S_ISDIR(file_stat.st_mode)) {
          process_file(next_root, file_stat.st_size, directory_name);
        }
        get_files_in(next_root);
      }
    }
  }
}


x86 assembly (clang, -O0):
<get_files_in>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     124f <get_files_in+0xdf>
jmp    11c4 <get_files_in+0x54>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     124a <get_files_in+0xda>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1245 <get_files_in+0xd5>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xdf7(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1070 <stat@plt>
mov    -0x34(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    123c <get_files_in+0xcc>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1050 <process_file@plt>
mov    -0x40(%rbp),%rdi
call   1030 <get_files_in@plt>
jmp    11c4 <get_files_in+0x54>
jmp    124f <get_files_in+0xdf>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_files_in>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e68(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1040 <opendir@plt>
test   %rax,%rax
je     121b <get_files_in+0xab>
mov    %rax,%r15
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     121b <get_files_in+0xab>
lea    -0x30(%rbp),%r13
jmp    11d5 <get_files_in+0x65>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1030 <get_files_in@plt>
mov    %r15,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     121b <get_files_in+0xab>
mov    (%rax),%r12
cmpb   $0x2e,(%r12)
je     11c8 <get_files_in+0x58>
mov    %rbx,%rdi
lea    0xe17(%rip),%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <stat@plt>
mov    -0x2c(%rbp),%edi
call   1060 <S_ISDIR@plt>
test   %eax,%eax
jne    11c0 <get_files_in+0x50>
mov    -0x30(%rbp),%esi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1050 <process_file@plt>
jmp    11c0 <get_files_in+0x50>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32, i32 }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define void @get_files_in(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.stat
store i8* %0, i8** %2
%9 = load i32, i32* @PATH_MAX
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %6
%12 = alloca i8, i64 %10
store i64 %10, i64* %7
%13 = load i8*, i8** %2
%14 = call i32* @opendir(i8* %13)
store i32* %14, i32** %3
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %46
16: ; preds = %1
br label %17
17: ; preds = %44, %16
%18 = load i32*, i32** %3
%19 = call %struct.dirent* @readdir(i32* %18)
store %struct.dirent* %19, %struct.dirent** %4
%20 = icmp ne %struct.dirent* %19, null
br i1 %20, label %21, label %45
21: ; preds = %17
%22 = load %struct.dirent*, %struct.dirent** %4
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
store i8* %24, i8** %5
%25 = load i8*, i8** %5
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 46
br i1 %28, label %29, label %44
29: ; preds = %21
%30 = load i8*, i8** %2
%31 = load i8*, i8** %5
%32 = call i32 @sprintf(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %30, i8* %31)
%33 = call i32 @stat(i8* %12, %struct.stat* %8)
%34 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 1
%35 = load i32, i32* %34
%36 = call i32 @S_ISDIR(i32 %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %43, label %38
38: ; preds = %29
%39 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%40 = load i32, i32* %39
%41 = load i8*, i8** %5
%42 = call i32 @process_file(i8* %12, i32 %40, i8* %41)
br label %43
43: ; preds = %38, %29
br label %44
44: ; preds = %43, %21
br label %17
45: ; preds = %17
br label %46
46: ; preds = %45, %1
%47 = load i8*, i8** %6
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32 }
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [6 x i8] c"%s/%s\00"
define void @get_files_in(i8* %0) {
%2 = alloca %struct.stat
%3 = load i32, i32* @PATH_MAX
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = bitcast %struct.stat* %2 to i8*
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %34, label %9
9: ; preds = %1
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %34, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%14 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %15
15: ; preds = %12, %31
%16 = phi %struct.dirent* [ %10, %12 ], [ %32, %31 ]
%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 %31, label %21
21: ; preds = %15
%22 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %18)
%23 = call i32 @stat(i8* %5, %struct.stat* %2)
%24 = load i32, i32* %13
%25 = call i32 @S_ISDIR(i32 %24)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = load i32, i32* %14
%29 = call i32 @process_file(i8* %5, i32 %28, i8* %18)
br label %30
30: ; preds = %27, %21
br label %31
31: ; preds = %30, %15
%32 = call %struct.dirent* @readdir(i32* %7)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %34, label %15
34: ; preds = %31, %9, %1
ret void
}