#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 PATH_MAX;
int /*<<< orphan*/ get_file_path(char const *, int /*<<< orphan*/, char *);
scalar_t__ is_dir(char const *);
scalar_t__ is_file(char const *);
scalar_t__ is_special_dir(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char const *);
int /*<<< orphan*/ rmdir(char *);
void delete_files(const char *path) {
  DIR *dir;
  struct dirent *dir_info;
  char file_path[PATH_MAX];
  if (is_file(path)) {
    remove(path);
    printf("delete file %s\n", path);
    return;
  }
  if (is_dir(path)) {
    if ((dir = opendir(path)) == NULL)
      return;
    while ((dir_info = readdir(dir)) != NULL) {
      get_file_path(path, dir_info->d_name, file_path);
      if (is_special_dir(dir_info->d_name))
        continue;
      delete_files(file_path);
      rmdir(file_path);
    }
  }
  printf("delete dir %s\n", path);
}


x86 assembly (clang, -O0):
<delete_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e3d(%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,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   10b0 <is_file@plt>
cmp    $0x0,%rax
je     1210 <delete_files+0x70>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x8(%rbp),%rsi
lea    0xe01(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x2c(%rbp)
jmp    12c2 <delete_files+0x122>
mov    -0x8(%rbp),%rdi
call   1090 <is_dir@plt>
cmp    $0x0,%rax
je     12ab <delete_files+0x10b>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1246 <delete_files+0xa6>
movl   $0x1,-0x2c(%rbp)
jmp    12c2 <delete_files+0x122>
jmp    124b <delete_files+0xab>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12a6 <delete_files+0x106>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   10c0 <get_file_path@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <is_special_dir@plt>
cmp    $0x0,%rax
je     128f <delete_files+0xef>
jmp    124b <delete_files+0xab>
mov    -0x38(%rbp),%rdi
call   1040 <delete_files@plt>
mov    -0x38(%rbp),%rdi
call   1060 <rmdir@plt>
jmp    124b <delete_files+0xab>
jmp    12ab <delete_files+0x10b>
mov    -0x8(%rbp),%rsi
lea    0xd5a(%rip),%rdi
call   1080 <printf@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_files>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e3b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
call   10b0 <is_file@plt>
mov    %r14,%rdi
test   %rax,%rax
je     11f5 <delete_files+0x55>
call   1030 <remove@plt>
lea    0xe1f(%rip),%rdi
mov    %r14,%rsi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1080 <printf@plt>
call   1090 <is_dir@plt>
test   %rax,%rax
je     126b <delete_files+0xcb>
mov    %r14,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     127a <delete_files+0xda>
mov    %rax,%r15
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     126b <delete_files+0xcb>
mov    %rax,%rbx
jmp    1240 <delete_files+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     126b <delete_files+0xcb>
mov    (%rbx),%esi
mov    %r14,%rdi
mov    %r12,%rdx
call   10c0 <get_file_path@plt>
mov    (%rbx),%edi
call   1070 <is_special_dir@plt>
test   %rax,%rax
jne    1230 <delete_files+0x90>
mov    %r12,%rdi
call   1040 <delete_files@plt>
mov    %r12,%rdi
call   1060 <rmdir@plt>
jmp    1230 <delete_files+0x90>
lea    0xd9e(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@PATH_MAX = global i32 0
@.str = [16 x i8] c"delete file %s\0A\00"
@.str.1 = [15 x i8] c"delete dir %s\0A\00"
define void @delete_files(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i32, i32* @PATH_MAX
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %5
%11 = alloca i8, i64 %9
store i64 %9, i64* %6
%12 = load i8*, i8** %2
%13 = call i64 @is_file(i8* %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @remove(i8* %16)
%18 = load i8*, i8** %2
%19 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 1, i32* %7
br label %52
20: ; preds = %1
%21 = load i8*, i8** %2
%22 = call i64 @is_dir(i8* %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %49
24: ; preds = %20
%25 = load i8*, i8** %2
%26 = call i32* @opendir(i8* %25)
store i32* %26, i32** %3
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 1, i32* %7
br label %52
29: ; preds = %24
br label %30
30: ; preds = %46, %45, %29
%31 = load i32*, i32** %3
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %4
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %48
34: ; preds = %30
%35 = load i8*, i8** %2
%36 = load %struct.dirent*, %struct.dirent** %4
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i32 @get_file_path(i8* %35, i32 %38, i8* %11)
%40 = load %struct.dirent*, %struct.dirent** %4
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @is_special_dir(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %34
br label %30
46: ; preds = %34
%47 = call i32 @rmdir(i8* %11)
br label %30
48: ; preds = %30
br label %49
49: ; preds = %48, %20
%50 = load i8*, i8** %2
%51 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %50)
store i32 0, i32* %7
br label %52
52: ; preds = %49, %28, %15
%53 = load i8*, i8** %5
%54 = load i32, i32* %7
switch i32 %54, label %56 [
i32 0, label %55
i32 1, label %55
]
55: ; preds = %52, %52
ret void
56: ; preds = %52
unreachable
}

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