#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 */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ putchange(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char *, char *);
scalar_t__ strlen(char *);
void putchange_recursive(char *dir) {
  DIR *dp;
  struct dirent *ep;
  struct stat stat_struct;
  dp = opendir(dir);
  if (dp == NULL)
    return;
  while (ep = readdir(dp)) {
    if (strcmp(".", ep->d_name) == 0)
      continue;
    if (strcmp("..", ep->d_name) == 0)
      continue;
    if (stat(dir, &stat_struct))
      continue;
    char *npath = malloc(strlen(dir) + strlen(ep->d_name) + 2);
    npath[0] = 0;
    strcat(npath, dir);
    strcat(npath, "/");
    strcat(npath, ep->d_name);
    putchange(npath);
    if (S_ISDIR(stat_struct.st_mode)) {
      putchange_recursive(npath);
    }
    free(npath);
  }
  closedir(dp);
}


x86 assembly (clang, -O0):
<putchange_recursive>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e9 <putchange_recursive+0x29>
jmp    1301 <putchange_recursive+0x141>
jmp    11ee <putchange_recursive+0x2e>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12f8 <putchange_recursive+0x138>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xdee(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1227 <putchange_recursive+0x67>
jmp    11ee <putchange_recursive+0x2e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xdcb(%rip),%rdi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1249 <putchange_recursive+0x89>
jmp    11ee <putchange_recursive+0x2e>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
je     1265 <putchange_recursive+0xa5>
jmp    11ee <putchange_recursive+0x2e>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    -0x30(%rbp),%rdi
add    %rax,%rdi
add    $0x2,%rdi
call   10b0 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x28(%rbp),%rdi
lea    0xd52(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   10d0 <strcat@plt>
mov    -0x28(%rbp),%rdi
call   10e0 <putchange@plt>
mov    -0x20(%rbp),%edi
call   1060 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12ea <putchange_recursive+0x12a>
mov    -0x28(%rbp),%rdi
call   10c0 <putchange_recursive@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
jmp    11ee <putchange_recursive+0x2e>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<putchange_recursive>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     12e1 <putchange_recursive+0x121>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12d9 <putchange_recursive+0x119>
mov    %rax,%rbp
lea    0xe07(%rip),%r15
lea    0xdff(%rip),%rbx
mov    %rsp,%r13
jmp    1234 <putchange_recursive+0x74>
mov    %r13,%rdi
call   1030 <free@plt>
lea    0xdeb(%rip),%rbx
mov    %rsp,%r13
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12d9 <putchange_recursive+0x119>
mov    0x0(%rbp),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1220 <putchange_recursive+0x60>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1220 <putchange_recursive+0x60>
mov    %r14,%rdi
mov    %r13,%rsi
call   1090 <stat@plt>
test   %rax,%rax
jne    1220 <putchange_recursive+0x60>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
mov    0x0(%rbp),%rdi
call   1050 <strlen@plt>
lea    (%rbx,%rax,1),%rdi
add    $0x2,%rdi
call   10b0 <malloc@plt>
mov    %rax,%r13
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %r14,%rsi
call   10d0 <strcat@plt>
mov    %r13,%rdi
lea    0xd61(%rip),%rsi
call   10d0 <strcat@plt>
mov    0x0(%rbp),%rsi
mov    %r13,%rdi
call   10d0 <strcat@plt>
mov    %r13,%rdi
call   10e0 <putchange@plt>
mov    (%rsp),%edi
call   1060 <S_ISDIR@plt>
test   %rax,%rax
je     1206 <putchange_recursive+0x46>
mov    %r13,%rdi
call   10c0 <putchange_recursive@plt>
jmp    1206 <putchange_recursive+0x46>
mov    %r12,%rdi
call   1070 <closedir@plt>
add    $0x8,%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 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @putchange_recursive(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i8*
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
br label %72
12: ; preds = %1
br label %13
13: ; preds = %66, %35, %30, %23, %12
%14 = load i32*, i32** %3
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %4
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %69
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %4
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %13
24: ; preds = %17
%25 = load %struct.dirent*, %struct.dirent** %4
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %13
31: ; preds = %24
%32 = load i8*, i8** %2
%33 = call i64 @stat(i8* %32, %struct.stat* %5)
%34 = icmp ne i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %31
br label %13
36: ; preds = %31
%37 = load i8*, i8** %2
%38 = call i64 @strlen(i8* %37)
%39 = load %struct.dirent*, %struct.dirent** %4
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i8*, i8** %40
%42 = call i64 @strlen(i8* %41)
%43 = add nsw i64 %38, %42
%44 = add nsw i64 %43, 2
%45 = call i8* @malloc(i64 %44)
store i8* %45, i8** %6
%46 = load i8*, i8** %6
%47 = getelementptr inbounds i8, i8* %46, i64 0
store i8 0, i8* %47
%48 = load i8*, i8** %6
%49 = load i8*, i8** %2
%50 = call i32 @strcat(i8* %48, i8* %49)
%51 = load i8*, i8** %6
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%53 = load i8*, i8** %6
%54 = load %struct.dirent*, %struct.dirent** %4
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @strcat(i8* %53, i8* %56)
%58 = load i8*, i8** %6
%59 = call i32 @putchange(i8* %58)
%60 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%61 = load i32, i32* %60
%62 = call i64 @S_ISDIR(i32 %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %66
64: ; preds = %36
%65 = load i8*, i8** %6
br label %66
66: ; preds = %64, %36
%67 = load i8*, i8** %6
%68 = call i32 @free(i8* %67)
br label %13
69: ; preds = %13
%70 = load i32*, i32** %3
%71 = call i32 @closedir(i32* %70)
br label %72
72: ; preds = %69, %11
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [2 x i8] c"/\00"
define void @putchange_recursive(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 %47, label %6
6: ; preds = %1
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %45, label %9
9: ; preds = %6
%10 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %11
11: ; preds = %9, %42
%12 = phi %struct.dirent* [ %7, %9 ], [ %43, %42 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %42, label %17
17: ; preds = %11
%18 = load i8*, i8** %13
%19 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %42, label %21
21: ; preds = %17
%22 = call i64 @stat(i8* %0, %struct.stat* %2)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %42
24: ; preds = %21
%25 = call i64 @strlen(i8* dereferenceable(1) %0)
%26 = load i8*, i8** %13
%27 = call i64 @strlen(i8* dereferenceable(1) %26)
%28 = add i64 %25, 2
%29 = add i64 %28, %27
%30 = call i8* @malloc(i64 %29)
store i8 0, i8* %30
%31 = call i32 @strcat(i8* %30, i8* %0)
%32 = call i32 @strcat(i8* %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = load i8*, i8** %13
%34 = call i32 @strcat(i8* %30, i8* %33)
%35 = call i32 @putchange(i8* %30)
%36 = load i32, i32* %10
%37 = call i64 @S_ISDIR(i32 %36)
%38 = icmp eq i64 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %24
br label %40
40: ; preds = %39, %24
%41 = call i32 @free(i8* %30)
br label %42
42: ; preds = %40, %11, %17, %21
%43 = call %struct.dirent* @readdir(i32* %4)
%44 = icmp eq %struct.dirent* %43, null
br i1 %44, label %45, label %11
45: ; preds = %42, %6
%46 = call i32 @closedir(i32* %4)
br label %47
47: ; preds = %1, %45
ret void
}