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

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ process_file(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int process_dir(const char *path) {
  char dirA[PATH_MAX + 1];
  char fname[PATH_MAX + 1];
  char rpath[PATH_MAX + 1];
  char *pathsep = "/";
  DIR *dp;
  struct dirent *ep;
  dp = opendir(path);
  if (NULL != dp) {
    while (ep = readdir(dp)) {
      strcpy(fname, ep->d_name);
      if ((0 < strcmp(fname, ".")) && (0 < strcmp(fname, ".."))) {
        strcpy(rpath, path);
        strcat(rpath, pathsep);
        strcat(rpath, fname);
        process_file(rpath);
      }
    }
    (void)closedir(dp);
  } else {
    fprintf(stderr, "Can't open: %s\n", path);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<process_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rsp,%rdx
mov    %rdx,-0x18(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,%rsp
mov    %rcx,-0x20(%rbp)
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
add    $0x1,%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
lea    0xe00(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x40(%rbp)
xor    %eax,%eax
cmp    -0x40(%rbp),%rax
je     12c8 <process_dir+0x148>
jmp    1222 <process_dir+0xa2>
mov    -0x40(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
je     12ba <process_dir+0x13a>
mov    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x60(%rbp),%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    12b5 <process_dir+0x135>
mov    -0x60(%rbp),%rdi
lea    0xd90(%rip),%rsi
call   1070 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jge    12b5 <process_dir+0x135>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x58(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   10a0 <strcat@plt>
mov    -0x60(%rbp),%rsi
mov    -0x58(%rbp),%rdi
call   10a0 <strcat@plt>
mov    -0x58(%rbp),%rdi
call   1050 <process_file@plt>
jmp    1222 <process_dir+0xa2>
mov    -0x40(%rbp),%rdi
call   1060 <closedir@plt>
jmp    12f4 <process_dir+0x174>
mov    0x2d09(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd29(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    1302 <process_dir+0x182>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<process_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
call   1040 <opendir@plt>
test   %rax,%rax
je     1257 <process_dir+0xd7>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     124b <process_dir+0xcb>
lea    0xe27(%rip),%r13
jmp    11ed <process_dir+0x6d>
xchg   %ax,%ax
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     124b <process_dir+0xcb>
mov    (%rax),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jle    11e0 <process_dir+0x60>
mov    %rbx,%rdi
lea    0xdf0(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jle    11e0 <process_dir+0x60>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rdi
lea    0xdcf(%rip),%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcat@plt>
mov    %r15,%rdi
call   1050 <process_file@plt>
jmp    11e0 <process_dir+0x60>
mov    %r12,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
jmp    1274 <process_dir+0xf4>
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
mov    %r14,%rdx
call   1080 <fprintf@plt>
mov    $0x1,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"Can't open: %s\0A\00"
define i32 @process_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca %struct.dirent*
%11 = alloca i32
store i8* %0, i8** %3
%12 = load i32, i32* @PATH_MAX
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %4
%16 = alloca i8, i64 %14
store i64 %14, i64* %5
%17 = load i32, i32* @PATH_MAX
%18 = add nsw i32 %17, 1
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %6
%21 = load i32, i32* @PATH_MAX
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = alloca i8, i64 %23
store i64 %23, i64* %7
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %8
%25 = load i8*, i8** %3
%26 = call i32* @opendir(i8* %25)
store i32* %26, i32** %9
%27 = load i32*, i32** %9
%28 = icmp ne i32* null, %27
br i1 %28, label %29, label %55
29: ; preds = %1
br label %30
30: ; preds = %51, %29
%31 = load i32*, i32** %9
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %10
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %52
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %10
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @strcpy(i8* %20, i8* %37)
%39 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%40 = icmp slt i64 0, %39
br i1 %40, label %41, label %51
41: ; preds = %34
%42 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp slt i64 0, %42
br i1 %43, label %44, label %51
44: ; preds = %41
%45 = load i8*, i8** %3
%46 = call i32 @strcpy(i8* %24, i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @strcat(i8* %24, i8* %47)
%49 = call i32 @strcat(i8* %24, i8* %20)
%50 = call i32 @process_file(i8* %24)
br label %51
51: ; preds = %44, %41, %34
br label %30
52: ; preds = %30
%53 = load i32*, i32** %9
%54 = call i32 @closedir(i32* %53)
br label %59
55: ; preds = %1
%56 = load i32, i32* @stderr
%57 = load i8*, i8** %3
%58 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %57)
store i32 1, i32* %2
store i32 1, i32* %11
br label %60
59: ; preds = %52
store i32 0, i32* %2
store i32 1, i32* %11
br label %60
60: ; preds = %59, %55
%61 = load i8*, i8** %4
%62 = load i32, i32* %2
ret i32 %62
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [2 x i8] c"/\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@stderr = global i32 0
@.str.3 = [16 x i8] c"Can't open: %s\0A\00"
define i32 @process_dir(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = add nsw i32 %2, 1
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = alloca i8, i64 %4
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %32, label %9
9: ; preds = %1
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %30, label %12
12: ; preds = %9, %27
%13 = phi %struct.dirent* [ %28, %27 ], [ %10, %9 ]
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 @strcpy(i8* %5, i8* %15)
%17 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp sgt i64 %17, 0
br i1 %18, label %19, label %27
19: ; preds = %12
%20 = call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %19
%23 = call i32 @strcpy(i8* %6, i8* %0)
%24 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @strcat(i8* %6, i8* %5)
%26 = call i32 @process_file(i8* %6)
br label %27
27: ; preds = %22, %19, %12
%28 = call %struct.dirent* @readdir(i32* %7)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %12
30: ; preds = %27, %9
%31 = call i32 @closedir(i32* %7)
br label %35
32: ; preds = %1
%33 = load i32, i32* @stderr
%34 = tail call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i8* %0)
br label %35
35: ; preds = %30, %32
%36 = phi i32 [ 0, %30 ], [ 1, %32 ]
ret i32 %36
}