#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 */
typedef struct TYPE_5__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ subdirs;
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct TYPE_5__ {
  size_t gl_pathc;
  char **gl_pathv;
};
typedef TYPE_1__ glob_t;

/* Variables and functions */
int /*<<< orphan*/ GLOB_NOSORT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ glob(char *, int /*<<< orphan*/, int /*<<< orphan*/ *,
                        TYPE_1__ *);
int /*<<< orphan*/ globfree(TYPE_1__ *);
int /*<<< orphan*/ memset(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ rmdir(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ unlink(char *);
void recursive_remove(char *path) {
  glob_t subdirs;
  size_t i;
  char pattern[256];
  struct stat info;
  if (path == NULL)
    return;
  if (*path == '\0')
    return;
  if (stat(path, &info) < 0)
    return;
  if (!S_ISDIR(info.st_mode)) {
    unlink(path);
    return;
  }
  sprintf(pattern, "%s/*", path);
  memset(&subdirs, 0, sizeof(subdirs));
  glob(pattern, GLOB_NOSORT, NULL, &subdirs);
  for (i = 0; i < subdirs.gl_pathc; i++) {
    if (stat(subdirs.gl_pathv[i], &info) < 0)
      continue;
    if (S_ISDIR(info.st_mode)) {
      recursive_remove(subdirs.gl_pathv[i]);
    } else {
      unlink(subdirs.gl_pathv[i]);
    }
  }
  globfree(&subdirs);
  rmdir(path);
}


x86 assembly (clang, -O0):
<recursive_remove>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11af <recursive_remove+0x1f>
jmp    12eb <recursive_remove+0x15b>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11c4 <recursive_remove+0x34>
jmp    12eb <recursive_remove+0x15b>
mov    -0x8(%rbp),%rdi
lea    -0x128(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    11e3 <recursive_remove+0x53>
jmp    12eb <recursive_remove+0x15b>
mov    -0x128(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
jne    1206 <recursive_remove+0x76>
mov    -0x8(%rbp),%rdi
call   1050 <unlink@plt>
jmp    12eb <recursive_remove+0x15b>
lea    -0x120(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xde8(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
lea    -0x120(%rbp),%rdi
mov    0x2da5(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
lea    -0x18(%rbp),%rcx
call   10a0 <glob@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    12d9 <recursive_remove+0x149>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x128(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0x0,%rax
jge    1287 <recursive_remove+0xf7>
jmp    12c8 <recursive_remove+0x138>
mov    -0x128(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12b2 <recursive_remove+0x122>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1030 <recursive_remove@plt>
jmp    12c3 <recursive_remove+0x133>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
call   1050 <unlink@plt>
jmp    12c8 <recursive_remove+0x138>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1252 <recursive_remove+0xc2>
lea    -0x18(%rbp),%rdi
call   1040 <globfree@plt>
mov    -0x8(%rbp),%rdi
call   1060 <rmdir@plt>
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recursive_remove>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x128,%rsp
test   %rdi,%rdi
je     1290 <recursive_remove+0x100>
mov    %rdi,%r12
cmpb   $0x0,(%rdi)
je     1290 <recursive_remove+0x100>
lea    0x8(%rsp),%rsi
mov    %r12,%rdi
call   1090 <stat@plt>
test   %rax,%rax
js     1290 <recursive_remove+0x100>
mov    0x8(%rsp),%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     1288 <recursive_remove+0xf8>
lea    0xe1e(%rip),%rsi
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rdx
call   10b0 <sprintf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %edx,%edx
mov    %r15,%rcx
call   10a0 <glob@plt>
cmpq   $0x0,0x10(%rsp)
je     1274 <recursive_remove+0xe4>
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
jmp    1240 <recursive_remove+0xb0>
nopl   (%rax)
call   1030 <recursive_remove@plt>
add    $0x1,%rbx
cmp    0x10(%rsp),%rbx
jae    1274 <recursive_remove+0xe4>
mov    0x18(%rsp),%rax
mov    (%rax,%rbx,8),%rdi
mov    %r14,%rsi
call   1090 <stat@plt>
test   %rax,%rax
js     1235 <recursive_remove+0xa5>
mov    0x8(%rsp),%edi
call   1070 <S_ISDIR@plt>
mov    0x18(%rsp),%rcx
mov    (%rcx,%rbx,8),%rdi
test   %rax,%rax
jne    1230 <recursive_remove+0xa0>
call   1050 <unlink@plt>
jmp    1235 <recursive_remove+0xa5>
lea    0x10(%rsp),%rdi
call   1040 <globfree@plt>
mov    %r12,%rdi
call   1060 <rmdir@plt>
jmp    1290 <recursive_remove+0x100>
mov    %r12,%rdi
call   1050 <unlink@plt>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TYPE_5__ = type { i64, i8** }
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s/*\00"
@GLOB_NOSORT = global i32 0
define void @recursive_remove(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.TYPE_5__
%4 = alloca i64
%5 = alloca [256 x i8]
%6 = alloca %struct.stat
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
br label %77
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %10
br label %77
16: ; preds = %10
%17 = load i8*, i8** %2
%18 = call i64 @stat(i8* %17, %struct.stat* %6)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %16
br label %77
21: ; preds = %16
%22 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i64 @S_ISDIR(i32 %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i8*, i8** %2
%28 = call i32 @unlink(i8* %27)
br label %77
29: ; preds = %21
%30 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%31 = load i8*, i8** %2
%32 = call i32 @sprintf(i8* %30, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %31)
%33 = call i32 @memset(%struct.TYPE_5__* %3, i32 0, i32 16)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = load i32, i32* @GLOB_NOSORT
%36 = call i32 @glob(i8* %34, i32 %35, i32* null, %struct.TYPE_5__* %3)
store i64 0, i64* %4
br label %37
37: ; preds = %70, %29
%38 = load i64, i64* %4
%39 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i32 0, i32 0
%40 = load i64, i64* %39
%41 = icmp ult i64 %38, %40
br i1 %41, label %42, label %73
42: ; preds = %37
%43 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i32 0, i32 1
%44 = load i8**, i8*** %43
%45 = load i64, i64* %4
%46 = getelementptr inbounds i8*, i8** %44, i64 %45
%47 = load i8*, i8** %46
%48 = call i64 @stat(i8* %47, %struct.stat* %6)
%49 = icmp slt i64 %48, 0
br i1 %49, label %50, label %51
50: ; preds = %42
br label %70
51: ; preds = %42
%52 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = call i64 @S_ISDIR(i32 %53)
%55 = icmp ne i64 %54, 0
br i1 %55, label %56, label %62
56: ; preds = %51
%57 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i32 0, i32 1
%58 = load i8**, i8*** %57
%59 = load i64, i64* %4
%60 = getelementptr inbounds i8*, i8** %58, i64 %59
%61 = load i8*, i8** %60
br label %69
62: ; preds = %51
%63 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %3, i32 0, i32 1
%64 = load i8**, i8*** %63
%65 = load i64, i64* %4
%66 = getelementptr inbounds i8*, i8** %64, i64 %65
%67 = load i8*, i8** %66
%68 = call i32 @unlink(i8* %67)
br label %69
69: ; preds = %62, %56
br label %70
70: ; preds = %69, %50
%71 = load i64, i64* %4
%72 = add i64 %71, 1
store i64 %72, i64* %4
br label %37
73: ; preds = %37
%74 = call i32 @globfree(%struct.TYPE_5__* %3)
%75 = load i8*, i8** %2
%76 = call i32 @rmdir(i8* %75)
br label %77
77: ; preds = %73, %26, %20, %15, %9
ret void
}

LLVM IR (-O2):
%struct.TYPE_5__ = type { i64, i8** }
%struct.stat = type { i32 }
@.str = [5 x i8] c"%s/*\00"
@GLOB_NOSORT = global i32 0
define void @recursive_remove(i8* %0) {
%2 = alloca %struct.TYPE_5__
%3 = alloca [256 x i8]
%4 = alloca %struct.stat
%5 = bitcast %struct.TYPE_5__* %2 to i8*
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.stat* %4 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %56, label %9
9: ; preds = %1
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %56, label %12
12: ; preds = %9
%13 = call i64 @stat(i8* %0, %struct.stat* %4)
%14 = icmp slt i64 %13, 0
br i1 %14, label %56, label %15
15: ; preds = %12
%16 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @S_ISDIR(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = call i32 @unlink(i8* %0)
br label %56
22: ; preds = %15
%23 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0)
%24 = call i32 @memset(%struct.TYPE_5__* %2, i32 0, i32 16)
%25 = load i32, i32* @GLOB_NOSORT
%26 = call i32 @glob(i8* %6, i32 %25, i32* null, %struct.TYPE_5__* %2)
%27 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %2, i64 0, i32 0
%28 = load i64, i64* %27
%29 = icmp eq i64 %28, 0
br i1 %29, label %53, label %30
30: ; preds = %22
%31 = getelementptr inbounds %struct.TYPE_5__, %struct.TYPE_5__* %2, i64 0, i32 1
br label %32
32: ; preds = %30, %49
%33 = phi i64 [ 0, %30 ], [ %50, %49 ]
%34 = load i8**, i8*** %31
%35 = getelementptr inbounds i8*, i8** %34, i64 %33
%36 = load i8*, i8** %35
%37 = call i64 @stat(i8* %36, %struct.stat* %4)
%38 = icmp slt i64 %37, 0
br i1 %38, label %49, label %39
39: ; preds = %32
%40 = load i32, i32* %16
%41 = call i64 @S_ISDIR(i32 %40)
%42 = icmp eq i64 %41, 0
%43 = load i8**, i8*** %31
%44 = getelementptr inbounds i8*, i8** %43, i64 %33
%45 = load i8*, i8** %44
br i1 %42, label %47, label %46
46: ; preds = %39
br label %49
47: ; preds = %39
%48 = call i32 @unlink(i8* %45)
br label %49
49: ; preds = %46, %47, %32
%50 = add nuw i64 %33, 1
%51 = load i64, i64* %27
%52 = icmp ult i64 %50, %51
br i1 %52, label %32, label %53
53: ; preds = %49, %22
%54 = call i32 @globfree(%struct.TYPE_5__* %2)
%55 = call i32 @rmdir(i8* %0)
br label %56
56: ; preds = %12, %9, %1, %53, %20
ret void
}