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

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
void remove_pattern(char *path) {
  DIR *dir;
  struct dirent *dentry;
  char spath[10000];
  char cache[10000];
  size_t len = strlen(path);
  if (path[len - 1] == '/' && len > 1)
    path[len - 1] = '\0';
  if ((dir = opendir(path))) {
    dentry = readdir(dir);
    while (dentry) {
      if (len > 1)
        sprintf(spath, "%s/%s", path, dentry->d_name);
      else
        sprintf(spath, "%s%s", path, dentry->d_name);
      if ((strcmp(".", dentry->d_name) != 0) &&
          (strcmp("..", dentry->d_name) != 0)) {
        if (dentry->d_type == DT_DIR)
          strcpy(cache, spath);
        remove(spath);
      }
      remove(cache);
      if (dentry->d_type == DT_DIR && (strcmp(".", dentry->d_name)) &&
          (strcmp("..", dentry->d_name))) {
        remove_pattern(spath);
      }
      dentry = readdir(dir);
    }
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<remove_pattern>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4e50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0x4e48(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x4e48(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    11ec <remove_pattern+0x5c>
cmpq   $0x1,-0x4e48(%rbp)
01
jbe    11ec <remove_pattern+0x5c>
mov    -0x8(%rbp),%rax
mov    -0x4e48(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     135c <remove_pattern+0x1cc>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1357 <remove_pattern+0x1c7>
cmpq   $0x1,-0x4e48(%rbp)
01
jbe    124c <remove_pattern+0xbc>
lea    -0x2730(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xdbe(%rip),%rsi
call   10b0 <sprintf@plt>
jmp    126a <remove_pattern+0xda>
lea    -0x2730(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    0xda1(%rip),%rsi
call   10b0 <sprintf@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd94(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12db <remove_pattern+0x14b>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd76(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12db <remove_pattern+0x14b>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2d2d(%rip),%rcx
cmp    (%rcx),%rax
jne    12cf <remove_pattern+0x13f>
lea    -0x4e40(%rbp),%rdi
lea    -0x2730(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x2730(%rbp),%rdi
call   1030 <remove@plt>
lea    -0x4e40(%rbp),%rdi
call   1030 <remove@plt>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2cea(%rip),%rcx
cmp    (%rcx),%rax
jne    1345 <remove_pattern+0x1b5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xcff(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1345 <remove_pattern+0x1b5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xce1(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1345 <remove_pattern+0x1b5>
lea    -0x2730(%rbp),%rdi
call   1050 <remove_pattern@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
jmp    1210 <remove_pattern+0x80>
jmp    135c <remove_pattern+0x1cc>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
add    $0x4e50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_pattern>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4e28,%rsp
mov    %rdi,%r14
call   1070 <strlen@plt>
mov    %rax,%r15
cmpb   $0x2f,-0x1(%rax,%r14,1)
jne    11c0 <remove_pattern+0x30>
cmp    $0x2,%r15
jb     11c0 <remove_pattern+0x30>
movb   $0x0,-0x1(%r14,%r15,1)
mov    %r14,%rdi
call   1060 <opendir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12d6 <remove_pattern+0x146>
mov    %rbx,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12d6 <remove_pattern+0x146>
mov    %rax,%rbp
cmp    $0x2,%r15
lea    0xe0d(%rip),%rax
lea    0xe0c(%rip),%r15
cmovae %rax,%r15
lea    0x2710(%rsp),%r12
lea    0xdff(%rip),%r13
jmp    1224 <remove_pattern+0x94>
nop
mov    %rbx,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12d6 <remove_pattern+0x146>
mov    0x0(%rbp),%rcx
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   10b0 <sprintf@plt>
mov    0x0(%rbp),%rsi
mov    %r13,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     127f <remove_pattern+0xef>
mov    0x0(%rbp),%rsi
lea    0xdb9(%rip),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     127f <remove_pattern+0xef>
mov    0x8(%rbp),%rax
mov    0x2d79(%rip),%rcx
cmp    (%rcx),%rax
jne    1277 <remove_pattern+0xe7>
mov    %rsp,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rdi
call   1030 <remove@plt>
mov    %rsp,%rdi
call   1030 <remove@plt>
mov    0x8(%rbp),%rax
mov    0x2d4e(%rip),%rcx
cmp    (%rcx),%rax
jne    1210 <remove_pattern+0x80>
mov    0x0(%rbp),%rsi
mov    %r13,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1210 <remove_pattern+0x80>
mov    0x0(%rbp),%rsi
lea    0xd50(%rip),%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     1210 <remove_pattern+0x80>
mov    %r12,%rdi
call   1050 <remove_pattern@plt>
jmp    1210 <remove_pattern+0x80>
mov    %rbx,%rdi
call   1080 <closedir@plt>
add    $0x4e28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [5 x i8] c"%s%s\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@DT_DIR = global i64 0
define void @remove_pattern(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca [10000 x i8]
%6 = alloca [10000 x i8]
%7 = alloca i64
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i64 @strlen(i8* %8)
store i64 %9, i64* %7
%10 = load i8*, i8** %2
%11 = load i64, i64* %7
%12 = sub i64 %11, 1
%13 = getelementptr inbounds i8, i8* %10, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 47
br i1 %16, label %17, label %25
17: ; preds = %1
%18 = load i64, i64* %7
%19 = icmp ugt i64 %18, 1
br i1 %19, label %20, label %25
20: ; preds = %17
%21 = load i8*, i8** %2
%22 = load i64, i64* %7
%23 = sub i64 %22, 1
%24 = getelementptr inbounds i8, i8* %21, i64 %23
store i8 0, i8* %24
br label %25
25: ; preds = %20, %17, %1
%26 = load i8*, i8** %2
%27 = call i32* @opendir(i8* %26)
store i32* %27, i32** %3
%28 = icmp ne i32* %27, null
br i1 %28, label %29, label %103
29: ; preds = %25
%30 = load i32*, i32** %3
%31 = call %struct.dirent* @readdir(i32* %30)
store %struct.dirent* %31, %struct.dirent** %4
br label %32
32: ; preds = %99, %29
%33 = load %struct.dirent*, %struct.dirent** %4
%34 = icmp ne %struct.dirent* %33, null
br i1 %34, label %35, label %102
35: ; preds = %32
%36 = load i64, i64* %7
%37 = icmp ugt i64 %36, 1
br i1 %37, label %38, label %45
38: ; preds = %35
%39 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%40 = load i8*, i8** %2
%41 = load %struct.dirent*, %struct.dirent** %4
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = call i32 @sprintf(i8* %39, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %40, i8* %43)
br label %52
45: ; preds = %35
%46 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%47 = load i8*, i8** %2
%48 = load %struct.dirent*, %struct.dirent** %4
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %47, i8* %50)
br label %52
52: ; preds = %45, %38
%53 = load %struct.dirent*, %struct.dirent** %4
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %77
58: ; preds = %52
%59 = load %struct.dirent*, %struct.dirent** %4
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %61)
%63 = icmp ne i64 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %58
%65 = load %struct.dirent*, %struct.dirent** %4
%66 = getelementptr inbounds %struct.dirent, %struct.dirent* %65, i32 0, i32 1
%67 = load i64, i64* %66
%68 = load i64, i64* @DT_DIR
%69 = icmp eq i64 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %64
%71 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%72 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%73 = call i32 @strcpy(i8* %71, i8* %72)
br label %74
74: ; preds = %70, %64
%75 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
%76 = call i32 @remove(i8* %75)
br label %77
77: ; preds = %74, %58, %52
%78 = getelementptr inbounds [10000 x i8], [10000 x i8]* %6, i64 0, i64 0
%79 = call i32 @remove(i8* %78)
%80 = load %struct.dirent*, %struct.dirent** %4
%81 = getelementptr inbounds %struct.dirent, %struct.dirent* %80, i32 0, i32 1
%82 = load i64, i64* %81
%83 = load i64, i64* @DT_DIR
%84 = icmp eq i64 %82, %83
br i1 %84, label %85, label %99
85: ; preds = %77
%86 = load %struct.dirent*, %struct.dirent** %4
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %86, i32 0, i32 0
%88 = load i8*, i8** %87
%89 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %99
91: ; preds = %85
%92 = load %struct.dirent*, %struct.dirent** %4
%93 = getelementptr inbounds %struct.dirent, %struct.dirent* %92, i32 0, i32 0
%94 = load i8*, i8** %93
%95 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %94)
%96 = icmp ne i64 %95, 0
br i1 %96, label %97, label %99
97: ; preds = %91
%98 = getelementptr inbounds [10000 x i8], [10000 x i8]* %5, i64 0, i64 0
br label %99
99: ; preds = %97, %91, %85, %77
%100 = load i32*, i32** %3
%101 = call %struct.dirent* @readdir(i32* %100)
store %struct.dirent* %101, %struct.dirent** %4
br label %32
102: ; preds = %32
br label %103
103: ; preds = %102, %25
%104 = load i32*, i32** %3
%105 = call i32 @closedir(i32* %104)
ret void
}

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