#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*/ EXIT_FAILURE;
int PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void recurseprint(char *topdir) {
  DIR *dp;
  struct dirent *de;
  char newdir[PATH_MAX];
  if (!(dp = opendir(topdir))) {
    perror(topdir);
    exit(EXIT_FAILURE);
  }
  printf("Dir is:%s\n", topdir);
  while ((de = readdir(dp))) {
    if (strcmp(".", de->d_name) == 0)
      continue;
    if (strcmp("..", de->d_name) == 0)
      continue;
    if (de->d_type == DT_DIR) {
      strcpy(newdir, topdir);
      if (newdir[strlen(newdir) - 1] != '/')
        strcat(newdir, "/");
      strcat(newdir, de->d_name);
      recurseprint(newdir);
    }
  }
  closedir(dp);
}


x86 assembly (clang, -O0):
<recurseprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1216 <recurseprint+0x66>
mov    -0x8(%rbp),%rdi
call   10b0 <perror@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xddf(%rip),%rdi
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12f6 <recurseprint+0x146>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xdc1(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    125f <recurseprint+0xaf>
jmp    1226 <recurseprint+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd9e(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1281 <recurseprint+0xd1>
jmp    1226 <recurseprint+0x76>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%rax
jne    12f1 <recurseprint+0x141>
mov    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     12d8 <recurseprint+0x128>
mov    -0x30(%rbp),%rdi
lea    0xd3b(%rip),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
call   1030 <recurseprint@plt>
jmp    1226 <recurseprint+0x76>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recurseprint>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1050 <opendir@plt>
test   %rax,%rax
je     12c8 <recurseprint+0x118>
mov    %rax,%r15
lea    0xe0d(%rip),%rdi
mov    %r14,-0x30(%rbp)
mov    %r14,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12b1 <recurseprint+0x101>
mov    %rax,%r14
lea    0xdf2(%rip),%r12
lea    0xdea(%rip),%r13
jmp    1250 <recurseprint+0xa0>
mov    (%r14),%rsi
mov    %rbx,%rdi
call   10c0 <strcat@plt>
mov    %rbx,%rdi
call   1030 <recurseprint@plt>
cs nopw 0x0(%rax,%rax,1)
mov    %r15,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     12b1 <recurseprint+0x101>
mov    (%r14),%rsi
mov    %r12,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1240 <recurseprint+0x90>
mov    (%r14),%rsi
mov    %r13,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1240 <recurseprint+0x90>
mov    0x8(%r14),%rax
mov    0x2d5d(%rip),%rcx
cmp    (%rcx),%rax
jne    1240 <recurseprint+0x90>
mov    %rbx,%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1223 <recurseprint+0x73>
mov    %rbx,%rdi
lea    0xd67(%rip),%rsi
call   10c0 <strcat@plt>
jmp    1223 <recurseprint+0x73>
mov    %r15,%rdi
call   1080 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   10b0 <perror@plt>
mov    0x2cf9(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
%struct.dirent = type { i8*, i64 }
@PATH_MAX = global i32 0
@EXIT_FAILURE = global i32 0
@.str = [11 x i8] c"Dir is:%s\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
@.str.3 = [2 x i8] c"/\00"
define void @recurseprint(i8* %0) {
%2 = load i32, i32* @PATH_MAX
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = tail call i32* @opendir(i8* %0)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %11
7: ; preds = %1
%8 = tail call i32 @perror(i8* %0)
%9 = load i32, i32* @EXIT_FAILURE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %0)
%13 = call %struct.dirent* @readdir(i32* %5)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %46, label %15
15: ; preds = %11, %43
%16 = phi %struct.dirent* [ %44, %43 ], [ %13, %11 ]
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 0
%18 = load i8*, i8** %17
%19 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %43, label %21
21: ; preds = %15
%22 = load i8*, i8** %17
%23 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %22)
%24 = icmp eq i64 %23, 0
br i1 %24, label %43, label %25
25: ; preds = %21
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i64 0, i32 1
%27 = load i64, i64* %26
%28 = load i64, i64* @DT_DIR
%29 = icmp eq i64 %27, %28
br i1 %29, label %30, label %43
30: ; preds = %25
%31 = call i32 @strcpy(i8* %4, i8* %0)
%32 = call i32 @strlen(i8* %4)
%33 = add nsw i32 %32, -1
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds i8, i8* %4, i64 %34
%36 = load i8, i8* %35
%37 = icmp eq i8 %36, 47
br i1 %37, label %40, label %38
38: ; preds = %30
%39 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %38, %30
%41 = load i8*, i8** %17
%42 = call i32 @strcat(i8* %4, i8* %41)
br label %43
43: ; preds = %25, %40, %15, %21
%44 = call %struct.dirent* @readdir(i32* %5)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %46, label %15
46: ; preds = %43, %11
%47 = call i32 @closedir(i32* %5)
ret void
}