#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 *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char const *);
int /*<<< orphan*/ rmdir(char *);
void delete_file(const char *path) {
  DIR *dir;
  struct dirent *dir_info;
  char file_path[PATH_MAX];
  if (is_file(path)) {
    remove(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_file(file_path);
      rmdir(file_path);
    }
  }
}


x86 assembly (clang, -O0):
<delete_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e4d(%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   10a0 <is_file@plt>
cmp    $0x0,%rax
je     11f0 <delete_file+0x60>
mov    -0x8(%rbp),%rdi
call   1030 <remove@plt>
movl   $0x1,-0x2c(%rbp)
jmp    1292 <delete_file+0x102>
mov    -0x8(%rbp),%rdi
call   1080 <is_dir@plt>
cmp    $0x0,%rax
je     128b <delete_file+0xfb>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1226 <delete_file+0x96>
movl   $0x1,-0x2c(%rbp)
jmp    1292 <delete_file+0x102>
jmp    122b <delete_file+0x9b>
mov    -0x10(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1286 <delete_file+0xf6>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   10b0 <get_file_path@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1070 <is_special_dir@plt>
cmp    $0x0,%rax
je     126f <delete_file+0xdf>
jmp    122b <delete_file+0x9b>
mov    -0x38(%rbp),%rdi
call   1040 <delete_file@plt>
mov    -0x38(%rbp),%rdi
call   1060 <rmdir@plt>
jmp    122b <delete_file+0x9b>
jmp    128b <delete_file+0xfb>
movl   $0x0,-0x2c(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_file>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r14
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
call   10a0 <is_file@plt>
test   %rax,%rax
je     11d6 <delete_file+0x46>
mov    %r14,%rdi
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <remove@plt>
mov    %r14,%rdi
call   1080 <is_dir@plt>
test   %rax,%rax
je     124b <delete_file+0xbb>
mov    %r14,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     124b <delete_file+0xbb>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     124b <delete_file+0xbb>
mov    %rax,%rbx
jmp    1220 <delete_file+0x90>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     124b <delete_file+0xbb>
mov    (%rbx),%esi
mov    %r14,%rdi
mov    %r12,%rdx
call   10b0 <get_file_path@plt>
mov    (%rbx),%edi
call   1070 <is_special_dir@plt>
test   %rax,%rax
jne    1210 <delete_file+0x80>
mov    %r12,%rdi
call   1040 <delete_file@plt>
mov    %r12,%rdi
call   1060 <rmdir@plt>
jmp    1210 <delete_file+0x80>
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
define void @delete_file(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 %18
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 @remove(i8* %16)
store i32 1, i32* %7
br label %48
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i64 @is_dir(i8* %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %47
22: ; preds = %18
%23 = load i8*, i8** %2
%24 = call i32* @opendir(i8* %23)
store i32* %24, i32** %3
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %22
store i32 1, i32* %7
br label %48
27: ; preds = %22
br label %28
28: ; preds = %44, %43, %27
%29 = load i32*, i32** %3
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %4
%31 = icmp ne %struct.dirent* %30, null
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = load i8*, i8** %2
%34 = load %struct.dirent*, %struct.dirent** %4
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @get_file_path(i8* %33, i32 %36, i8* %11)
%38 = load %struct.dirent*, %struct.dirent** %4
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @is_special_dir(i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %32
br label %28
44: ; preds = %32
%45 = call i32 @rmdir(i8* %11)
br label %28
46: ; preds = %28
br label %47
47: ; preds = %46, %18
store i32 0, i32* %7
br label %48
48: ; preds = %47, %26, %15
%49 = load i8*, i8** %5
%50 = load i32, i32* %7
switch i32 %50, label %52 [
i32 0, label %51
i32 1, label %51
]
51: ; preds = %48, %48
ret void
52: ; preds = %48
unreachable
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@PATH_MAX = global i32 0
define void @delete_file(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 %9, label %7
7: ; preds = %1
%8 = tail call i32 @remove(i8* %0)
br label %31
9: ; preds = %1
%10 = tail call i64 @is_dir(i8* %0)
%11 = icmp eq i64 %10, 0
br i1 %11, label %31, label %12
12: ; preds = %9
%13 = tail call i32* @opendir(i8* %0)
%14 = icmp eq i32* %13, null
br i1 %14, label %31, label %15
15: ; preds = %12
%16 = call %struct.dirent* @readdir(i32* %13)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %31, label %18
18: ; preds = %15, %28
%19 = phi %struct.dirent* [ %29, %28 ], [ %16, %15 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @get_file_path(i8* %0, i32 %21, i8* %4)
%23 = load i32, i32* %20
%24 = call i64 @is_special_dir(i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %18
%27 = call i32 @rmdir(i8* %4)
br label %28
28: ; preds = %26, %18
%29 = call %struct.dirent* @readdir(i32* %13)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %31, label %18
31: ; preds = %28, %15, %9, %12, %7
ret void
}