#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*/ HandleFile(char *);
int /*<<< orphan*/ PATH_MAX;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
void HandleDirectory(const char *DirName) {
  DIR *theDir;
  struct dirent *dentp;
  fprintf(stderr, "HandleDirectory on %s\n", DirName);
  if ((theDir = opendir(DirName)) != NULL) {
    while ((dentp = readdir(theDir))) {
      struct stat sbuf;
      char pathName[PATH_MAX + 1];
      if (!strcmp(dentp->d_name, ".") || !strcmp(dentp->d_name, ".."))
        continue;
      sprintf(pathName, "%s/%s", DirName, dentp->d_name);
      if (stat(pathName, &sbuf) < 0) {
        fprintf(stderr, "Unable to open %s: %s\n", pathName, strerror(errno));
        continue;
      }
      if (S_ISDIR(sbuf.st_mode))
        HandleDirectory(pathName);
      else
        HandleFile(pathName);
    }
    closedir(theDir);
  } else {
    fprintf(stderr, "Unable to open %s: %s\n", DirName, strerror(errno));
  }
}


x86 assembly (clang, -O0):
<HandleDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe30(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     134c <HandleDirectory+0x19c>
jmp    11f3 <HandleDirectory+0x43>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     133e <HandleDirectory+0x18e>
mov    0x2ddf(%rip),%rax
mov    (%rax),%eax
add    $0x1,%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    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd1(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1271 <HandleDirectory+0xc1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xdb4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    127d <HandleDirectory+0xcd>
movl   $0x2,-0x34(%rbp)
jmp    131d <HandleDirectory+0x16d>
mov    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xd87(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x40(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    12ed <HandleDirectory+0x13d>
mov    0x2d22(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d0e(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xd46(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
movl   $0x2,-0x34(%rbp)
jmp    131d <HandleDirectory+0x16d>
mov    -0x20(%rbp),%edi
call   1050 <S_ISDIR@plt>
cmp    $0x0,%rax
je     130d <HandleDirectory+0x15d>
mov    -0x40(%rbp),%rdi
call   1030 <HandleDirectory@plt>
jmp    1316 <HandleDirectory+0x166>
mov    -0x40(%rbp),%rdi
call   10b0 <HandleFile@plt>
movl   $0x0,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x34(%rbp),%eax
test   %eax,%eax
je     1339 <HandleDirectory+0x189>
jmp    1334 <HandleDirectory+0x184>
jmp    11f3 <HandleDirectory+0x43>
jmp    11f3 <HandleDirectory+0x43>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
jmp    1386 <HandleDirectory+0x1d6>
mov    0x2c85(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c69(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x50(%rbp),%rdx
mov    %rax,%rcx
lea    0xca1(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HandleDirectory>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e10(%rip),%r15
mov    (%r15),%edi
lea    0xe2e(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12f6 <HandleDirectory+0x146>
mov    %rax,%r14
jmp    1203 <HandleDirectory+0x53>
call   10b0 <HandleFile@plt>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rsp
mov    %r14,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12df <HandleDirectory+0x12f>
mov    %rsp,%r15
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%ecx
add    $0x1,%ecx
mov    %rsp,%r13
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r13
mov    %r13,%rsp
mov    (%rax),%r12
mov    %r12,%rdi
lea    0xdd7(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1200 <HandleDirectory+0x50>
mov    %r12,%rdi
lea    0xdc3(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1200 <HandleDirectory+0x50>
mov    %r13,%rdi
lea    0xdb3(%rip),%rsi
mov    %rbx,%rdx
mov    %r12,%rcx
call   10c0 <sprintf@plt>
mov    %r13,%rdi
lea    -0x30(%rbp),%rsi
call   1090 <stat@plt>
test   %rax,%rax
js     12a4 <HandleDirectory+0xf4>
mov    -0x30(%rbp),%edi
call   1050 <S_ISDIR@plt>
mov    %r13,%rdi
test   %rax,%rax
je     11f2 <HandleDirectory+0x42>
call   1030 <HandleDirectory@plt>
mov    %r15,%rsp
jmp    1203 <HandleDirectory+0x53>
mov    %rbx,%r12
mov    0x2d2a(%rip),%rax
mov    (%rax),%ebx
mov    0x2d19(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %ebx,%edi
mov    %r12,%rbx
lea    0xd56(%rip),%rsi
mov    %r13,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    %r15,%rsp
jmp    1203 <HandleDirectory+0x53>
mov    %r14,%rdi
call   1060 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%r14
mov    (%r15),%ebx
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
lea    0xd0f(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <fprintf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [23 x i8] c"HandleDirectory on %s\0A\00"
@PATH_MAX = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@.str.4 = [23 x i8] c"Unable to open %s: %s\0A\00"
@errno = global i32 0
define void @HandleDirectory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %2
%11 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i8*, i8** %2
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %3
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %67
15: ; preds = %1
br label %16
16: ; preds = %63, %60, %15
%17 = load i32*, i32** %3
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %4
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %64
20: ; preds = %16
%21 = load i32, i32* @PATH_MAX
%22 = add nsw i32 %21, 1
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %6
%25 = alloca i8, i64 %23
store i64 %23, i64* %7
%26 = load %struct.dirent*, %struct.dirent** %4
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %20
%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 = call i32 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp ne i32 %35, 0
br i1 %36, label %38, label %37
37: ; preds = %31, %20
store i32 2, i32* %8
br label %60
38: ; preds = %31
%39 = load i8*, i8** %2
%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 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %42)
%44 = call i64 @stat(i8* %25, %struct.stat* %5)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %51
46: ; preds = %38
%47 = load i32, i32* @stderr
%48 = load i32, i32* @errno
%49 = call i8* @strerror(i32 %48)
%50 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %25, i8* %49)
store i32 2, i32* %8
br label %60
51: ; preds = %38
%52 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @S_ISDIR(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %57
56: ; preds = %51
br label %59
57: ; preds = %51
%58 = call i32 @HandleFile(i8* %25)
br label %59
59: ; preds = %57, %56
store i32 0, i32* %8
br label %60
60: ; preds = %59, %46, %37
%61 = load i8*, i8** %6
%62 = load i32, i32* %8
switch i32 %62, label %74 [
i32 0, label %63
i32 2, label %16
]
63: ; preds = %60
br label %16
64: ; preds = %16
%65 = load i32*, i32** %3
%66 = call i32 @closedir(i32* %65)
br label %73
67: ; preds = %1
%68 = load i32, i32* @stderr
%69 = load i8*, i8** %2
%70 = load i32, i32* @errno
%71 = call i8* @strerror(i32 %70)
%72 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i8* %69, i8* %71)
br label %73
73: ; preds = %67, %64
ret void
74: ; preds = %60
unreachable
}

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