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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ gettext(char *);
scalar_t__ isdir(char *);
int /*<<< orphan*/ join_path(int, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf_log(int /*<<< orphan*/, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
void remove_dir(char *dir_name) {
  struct dirent *next_file;
  DIR *theFolder;
  char filepath[256];
  theFolder = opendir(dir_name);
  if (theFolder != NULL) {
    while ((next_file = readdir(theFolder)) != NULL) {
      if ((strcmp(next_file->d_name, ".") != 0) &&
          (strcmp(next_file->d_name, "..") != 0)) {
        join_path(2, filepath, dir_name, next_file->d_name);
        if (isdir(filepath) == 0) {
          remove_dir(filepath);
          printf_log(gettext("Deleting dir =%s\n"), filepath);
          remove(filepath);
        } else {
          remove(filepath);
        }
      }
    }
    closedir(theFolder);
  }
}


x86 assembly (clang, -O0):
<remove_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     12a2 <remove_dir+0x102>
jmp    11cc <remove_dir+0x2c>
mov    -0x18(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1299 <remove_dir+0xf9>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xe11(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1294 <remove_dir+0xf4>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xdf4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1294 <remove_dir+0xf4>
lea    -0x120(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    $0x2,%edi
call   1060 <join_path@plt>
lea    -0x120(%rbp),%rdi
call   1090 <isdir@plt>
cmp    $0x0,%rax
jne    1283 <remove_dir+0xe3>
lea    -0x120(%rbp),%rdi
call   10b0 <remove_dir@plt>
lea    0xda4(%rip),%rdi
call   1050 <gettext@plt>
mov    %eax,%edi
lea    -0x120(%rbp),%rsi
call   10c0 <printf_log@plt>
lea    -0x120(%rbp),%rdi
call   1030 <remove@plt>
jmp    128f <remove_dir+0xef>
lea    -0x120(%rbp),%rdi
call   1030 <remove@plt>
jmp    1294 <remove_dir+0xf4>
jmp    11cc <remove_dir+0x2c>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     1270 <remove_dir+0xd0>
mov    %rax,%rbx
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     1268 <remove_dir+0xc8>
mov    %rax,%rbp
lea    0xe21(%rip),%r15
lea    0xe19(%rip),%r12
mov    %rsp,%r13
jmp    1208 <remove_dir+0x68>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <remove@plt>
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1268 <remove_dir+0xc8>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11f8 <remove_dir+0x58>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11f8 <remove_dir+0x58>
mov    0x0(%rbp),%ecx
mov    $0x2,%edi
mov    %r13,%rsi
mov    %r14,%rdx
call   1060 <join_path@plt>
mov    %r13,%rdi
call   1090 <isdir@plt>
test   %rax,%rax
jne    11f0 <remove_dir+0x50>
mov    %r13,%rdi
call   10b0 <remove_dir@plt>
lea    0xdac(%rip),%rdi
call   1050 <gettext@plt>
mov    %eax,%edi
mov    %r13,%rsi
call   10c0 <printf_log@plt>
jmp    11f0 <remove_dir+0x50>
mov    %rbx,%rdi
call   1070 <closedir@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [18 x i8] c"Deleting dir =%s\0A\00"
define void @remove_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.dirent*
%4 = alloca i32*
%5 = alloca [256 x i8]
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %4
%8 = load i32*, i32** %4
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %52
10: ; preds = %1
br label %11
11: ; preds = %48, %10
%12 = load i32*, i32** %4
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %3
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %49
15: ; preds = %11
%16 = load %struct.dirent*, %struct.dirent** %3
%17 = getelementptr inbounds %struct.dirent, %struct.dirent* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @strcmp(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %48
21: ; preds = %15
%22 = load %struct.dirent*, %struct.dirent** %3
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @strcmp(i32 %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %48
27: ; preds = %21
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%29 = load i8*, i8** %2
%30 = load %struct.dirent*, %struct.dirent** %3
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @join_path(i32 2, i8* %28, i8* %29, i32 %32)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = call i64 @isdir(i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %44
37: ; preds = %27
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%39 = call i32 @gettext(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%41 = call i32 @printf_log(i32 %39, i8* %40)
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%43 = call i32 @remove(i8* %42)
br label %47
44: ; preds = %27
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%46 = call i32 @remove(i8* %45)
br label %47
47: ; preds = %44, %37
br label %48
48: ; preds = %47, %21, %15
br label %11
49: ; preds = %11
%50 = load i32*, i32** %4
%51 = call i32 @closedir(i32* %50)
br label %52
52: ; preds = %49, %1
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [18 x i8] c"Deleting dir =%s\0A\00"
define void @remove_dir(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %34, label %6
6: ; preds = %1
%7 = call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %32, label %9
9: ; preds = %6, %29
%10 = phi %struct.dirent* [ %30, %29 ], [ %7, %6 ]
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = call i64 @strcmp(i32 %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %9
%16 = load i32, i32* %11
%17 = call i64 @strcmp(i32 %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %29, label %19
19: ; preds = %15
%20 = load i32, i32* %11
%21 = call i32 @join_path(i32 2, i8* %3, i8* %0, i32 %20)
%22 = call i64 @isdir(i8* %3)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 @gettext(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @printf_log(i32 %25, i8* %3)
br label %27
27: ; preds = %19, %24
%28 = call i32 @remove(i8* %3)
br label %29
29: ; preds = %27, %15, %9
%30 = call %struct.dirent* @readdir(i32* %4)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %32, label %9
32: ; preds = %29, %6
%33 = call i32 @closedir(i32* %4)
br label %34
34: ; preds = %32, %1
ret void
}