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

/* Variables and functions */
int get_dump_status(int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
void remove_dir(char *path, char *dir_name) {
  struct dirent *next_file;
  DIR *theFolder;
  char filepath[256];
  char out_dir[256];
  sprintf(out_dir, "%s/%s", path, dir_name);
  if (get_dump_status(2) == 1) {
    theFolder = opendir(out_dir);
    if (theFolder != NULL) {
      while ((next_file = readdir(theFolder)) != NULL) {
        sprintf(filepath, "%s/%s", out_dir, next_file->d_name);
        remove(filepath);
      }
      remove(out_dir);
    }
  }
}


x86 assembly (clang, -O0):
<remove_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xe87(%rip),%rsi
call   1070 <sprintf@plt>
mov    $0x2,%edi
call   1050 <get_dump_status@plt>
cmp    $0x1,%eax
jne    120b <remove_dir+0xbb>
lea    -0x220(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1206 <remove_dir+0xb6>
jmp    11b1 <remove_dir+0x61>
mov    -0x20(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11fa <remove_dir+0xaa>
lea    -0x120(%rbp),%rdi
lea    -0x220(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xe1c(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x120(%rbp),%rdi
call   1030 <remove@plt>
jmp    11b1 <remove_dir+0x61>
lea    -0x220(%rbp),%rdi
call   1030 <remove@plt>
jmp    120b <remove_dir+0xbb>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_dir>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0xe95(%rip),%rsi
mov    %rsp,%rdi
call   1070 <sprintf@plt>
mov    $0x2,%edi
call   1050 <get_dump_status@plt>
cmp    $0x1,%eax
jne    11ee <remove_dir+0x9e>
mov    %rsp,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11ee <remove_dir+0x9e>
mov    %rax,%r15
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11e6 <remove_dir+0x96>
lea    0xe5a(%rip),%r14
lea    0x100(%rsp),%rbx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rax),%rcx
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1070 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <remove@plt>
mov    %r15,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    11c0 <remove_dir+0x70>
mov    %rsp,%rdi
call   1030 <remove@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"%s/%s\00"
define void @remove_dir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.dirent*
%6 = alloca i32*
%7 = alloca [256 x i8]
%8 = alloca [256 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%10 = load i8*, i8** %3
%11 = load i8*, i8** %4
%12 = call i32 @sprintf(i8* %9, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
%13 = call i32 @get_dump_status(i32 2)
%14 = icmp eq i32 %13, 1
br i1 %14, label %15, label %38
15: ; preds = %2
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %6
%18 = load i32*, i32** %6
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %37
20: ; preds = %15
br label %21
21: ; preds = %25, %20
%22 = load i32*, i32** %6
%23 = call %struct.dirent* @readdir(i32* %22)
store %struct.dirent* %23, %struct.dirent** %5
%24 = icmp ne %struct.dirent* %23, null
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%28 = load %struct.dirent*, %struct.dirent** %5
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %27, i8* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %7, i64 0, i64 0
%33 = call i32 @remove(i8* %32)
br label %21
34: ; preds = %21
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%36 = call i32 @remove(i8* %35)
br label %37
37: ; preds = %34, %15
br label %38
38: ; preds = %37, %2
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"%s/%s\00"
define void @remove_dir(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = tail call i32 @get_dump_status(i32 2)
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %26
10: ; preds = %2
%11 = call i32* @opendir(i8* %6)
%12 = icmp eq i32* %11, null
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = call %struct.dirent* @readdir(i32* %11)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %24, label %16
16: ; preds = %13, %16
%17 = phi %struct.dirent* [ %22, %16 ], [ %14, %13 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %6, i8* %19)
%21 = call i32 @remove(i8* %5)
%22 = call %struct.dirent* @readdir(i32* %11)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %24, label %16
24: ; preds = %16, %13
%25 = call i32 @remove(i8* %6)
br label %26
26: ; preds = %10, %24, %2
ret void
}