#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*/ EXIT_FAILURE;
int asprintf(char **, char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int recursive_delete(char *, int /*<<< orphan*/);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int remove_files_from_dir(const char *path) {
  DIR *dir;
  struct dirent *entry;
  dir = opendir(path);
  if (dir) {
    int exit_code = 0;
    while ((entry = readdir(dir)) != NULL) {
      if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
        continue;
      }
      char *newpath;
      int bytesPrinted = asprintf(&newpath, "%s/%s", path, entry->d_name);
      if (bytesPrinted == -1) {
        exit(EXIT_FAILURE);
      }
      if (newpath) {
        int new_exit = recursive_delete(newpath, 0);
        if (!exit_code) {
          exit_code = new_exit;
        }
      }
      free(newpath);
    }
    closedir(dir);
    return exit_code;
  }
  return -1;
}


x86 assembly (clang, -O0):
<remove_files_from_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1284 <remove_files_from_dir+0x104>
movl   $0x0,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1270 <remove_files_from_dir+0xf0>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     11fa <remove_files_from_dir+0x7a>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    11ff <remove_files_from_dir+0x7f>
jmp    11ab <remove_files_from_dir+0x2b>
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
lea    -0x30(%rbp),%rdi
lea    0xdef(%rip),%rsi
call   1090 <asprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0xffffffff,-0x34(%rbp)
jne    1234 <remove_files_from_dir+0xb4>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x30(%rbp)
je     1262 <remove_files_from_dir+0xe2>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
call   1040 <recursive_delete@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    125d <remove_files_from_dir+0xdd>
mov    -0x38(%rbp),%eax
mov    %eax,-0x24(%rbp)
jmp    1262 <remove_files_from_dir+0xe2>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
jmp    11ab <remove_files_from_dir+0x2b>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    128b <remove_files_from_dir+0x10b>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_files_from_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1050 <opendir@plt>
test   %rax,%rax
je     11be <remove_files_from_dir+0x3e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11c6 <remove_files_from_dir+0x46>
mov    %rax,%rbp
xor    %r15d,%r15d
lea    0xe4c(%rip),%r12
lea    0xe44(%rip),%r13
jmp    1210 <remove_files_from_dir+0x90>
mov    $0xffffffff,%r15d
jmp    11d1 <remove_files_from_dir+0x51>
xor    %r15d,%r15d
mov    %rbx,%rdi
call   1060 <closedir@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %esi,%esi
call   1040 <recursive_delete@plt>
test   %r15d,%r15d
cmove  %eax,%r15d
mov    (%rsp),%rdi
call   1030 <free@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11c9 <remove_files_from_dir+0x49>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <remove_files_from_dir+0x80>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1200 <remove_files_from_dir+0x80>
mov    0x0(%rbp),%ecx
mov    %rsp,%rdi
lea    0xdc6(%rip),%rsi
mov    %r14,%rdx
call   1090 <asprintf@plt>
cmp    $0xffffffff,%eax
je     1257 <remove_files_from_dir+0xd7>
mov    (%rsp),%rdi
test   %rdi,%rdi
jne    11e3 <remove_files_from_dir+0x63>
xor    %edi,%edi
jmp    11f5 <remove_files_from_dir+0x75>
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@EXIT_FAILURE = global i32 0
define i32 @remove_files_from_dir(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
%10 = load i8*, i8** %3
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %61
14: ; preds = %1
store i32 0, i32* %6
br label %15
15: ; preds = %54, %31, %14
%16 = load i32*, i32** %4
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %5
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %57
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %5
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @strcmp(i32 %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %31, label %25
25: ; preds = %19
%26 = load %struct.dirent*, %struct.dirent** %5
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @strcmp(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25, %19
br label %15
32: ; preds = %25
%33 = load i8*, i8** %3
%34 = load %struct.dirent*, %struct.dirent** %5
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %36)
store i32 %37, i32* %8
%38 = load i32, i32* %8
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %32
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %32
%44 = load i8*, i8** %7
%45 = icmp ne i8* %44, null
br i1 %45, label %46, label %54
46: ; preds = %43
%47 = load i8*, i8** %7
%48 = call i32 @recursive_delete(i8* %47, i32 0)
store i32 %48, i32* %9
%49 = load i32, i32* %6
%50 = icmp ne i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %46
%52 = load i32, i32* %9
store i32 %52, i32* %6
br label %53
53: ; preds = %51, %46
br label %54
54: ; preds = %53, %43
%55 = load i8*, i8** %7
%56 = call i32 @free(i8* %55)
br label %15
57: ; preds = %15
%58 = load i32*, i32** %4
%59 = call i32 @closedir(i32* %58)
%60 = load i32, i32* %6
store i32 %60, i32* %2
br label %62
61: ; preds = %1
store i32 -1, i32* %2
br label %62
62: ; preds = %61, %57
%63 = load i32, i32* %2
ret i32 %63
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"..\00"
@.str.2 = [6 x i8] c"%s/%s\00"
@EXIT_FAILURE = global i32 0
define i32 @remove_files_from_dir(i8* %0) {
%2 = alloca i8*
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %50, label %5
5: ; preds = %1
%6 = call %struct.dirent* @readdir(i32* %3)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %47, label %8
8: ; preds = %5
%9 = bitcast i8** %2 to i8*
br label %10
10: ; preds = %8, %41
%11 = phi %struct.dirent* [ %6, %8 ], [ %45, %41 ]
%12 = phi i32 [ 0, %8 ], [ %43, %41 ]
br label %13
13: ; preds = %10, %23
%14 = phi %struct.dirent* [ %11, %10 ], [ %24, %23 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @strcmp(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %23, label %19
19: ; preds = %13
%20 = load i32, i32* %15
%21 = call i64 @strcmp(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %19, %13
%24 = call %struct.dirent* @readdir(i32* %3)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %47, label %13
26: ; preds = %19
%27 = load i32, i32* %15
%28 = call i32 @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %27)
%29 = icmp eq i32 %28, -1
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %26
%34 = load i8*, i8** %2
%35 = icmp eq i8* %34, null
br i1 %35, label %41, label %36
36: ; preds = %33
%37 = call i32 @recursive_delete(i8* %34, i32 0)
%38 = icmp eq i32 %12, 0
%39 = select i1 %38, i32 %37, i32 %12
%40 = load i8*, i8** %2
br label %41
41: ; preds = %36, %33
%42 = phi i8* [ %40, %36 ], [ null, %33 ]
%43 = phi i32 [ %39, %36 ], [ %12, %33 ]
%44 = call i32 @free(i8* %42)
%45 = call %struct.dirent* @readdir(i32* %3)
%46 = icmp eq %struct.dirent* %45, null
br i1 %46, label %47, label %10
47: ; preds = %41, %23, %5
%48 = phi i32 [ 0, %5 ], [ %12, %23 ], [ %43, %41 ]
%49 = call i32 @closedir(i32* %3)
br label %50
50: ; preds = %1, %47
%51 = phi i32 [ %48, %47 ], [ -1, %1 ]
ret i32 %51
}