#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 *, int /*<<< orphan*/, char *);
scalar_t__ is_file(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ remove(char *);
int /*<<< orphan*/ *strstr(int /*<<< orphan*/, char *);
int delete_appendix(char *path, char *appendix) {
  DIR *dir;
  struct dirent *dir_info;
  char file_path[PATH_MAX];
  dir = opendir(path);
  if (dir == NULL) {
    perror("open dir failed");
    return 1;
  }
  while ((dir_info = readdir(dir)) != NULL) {
    if (strstr(dir_info->d_name, appendix) == NULL)
      continue;
    get_file_path(path, dir_info->d_name, file_path);
    printf("delete %s\n", file_path);
    if (is_file(file_path))
      remove(file_path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<delete_appendix>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <delete_appendix+0x73>
lea    0xe25(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    127f <delete_appendix+0xff>
jmp    11f8 <delete_appendix+0x78>
mov    -0x20(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     1271 <delete_appendix+0xf1>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    122d <delete_appendix+0xad>
jmp    11f8 <delete_appendix+0x78>
mov    -0x48(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%esi
call   1080 <get_file_path@plt>
mov    -0x48(%rbp),%rsi
lea    0xdc5(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%rdi
call   1070 <is_file@plt>
cmp    $0x0,%rax
je     126c <delete_appendix+0xec>
mov    -0x48(%rbp),%rdi
call   1030 <remove@plt>
jmp    11f8 <delete_appendix+0x78>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_appendix>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    0x2e55(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1040 <opendir@plt>
test   %rax,%rax
je     1237 <delete_appendix+0xb7>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <readdir@plt>
mov    %rax,%r13
xor    %eax,%eax
test   %r13,%r13
jne    11e0 <delete_appendix+0x60>
jmp    1228 <delete_appendix+0xa8>
nop
mov    %r12,%rdi
call   1060 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1226 <delete_appendix+0xa6>
mov    0x0(%r13),%edi
mov    %r15,%rsi
call   10a0 <strstr@plt>
test   %rax,%rax
je     11d0 <delete_appendix+0x50>
mov    0x0(%r13),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1080 <get_file_path@plt>
lea    0xe09(%rip),%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <is_file@plt>
test   %rax,%rax
je     11d0 <delete_appendix+0x50>
mov    %rbx,%rdi
call   1030 <remove@plt>
jmp    11d0 <delete_appendix+0x50>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdc2(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%eax
jmp    1228 <delete_appendix+0xa8>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@PATH_MAX = global i32 0
@.str = [16 x i8] c"open dir failed\00"
@.str.1 = [11 x i8] c"delete %s\0A\00"
define i32 @delete_appendix(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%11 = load i32, i32* @PATH_MAX
%12 = zext i32 %11 to i64
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %8
%14 = alloca i8, i64 %12
store i64 %12, i64* %9
%15 = load i8*, i8** %4
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %2
%20 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %10
br label %47
21: ; preds = %2
br label %22
22: ; preds = %45, %33, %21
%23 = load i32*, i32** %6
%24 = call %struct.dirent* @readdir(i32* %23)
store %struct.dirent* %24, %struct.dirent** %7
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %26, label %46
26: ; preds = %22
%27 = load %struct.dirent*, %struct.dirent** %7
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = load i8*, i8** %5
%31 = call i32* @strstr(i32 %29, i8* %30)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %34
33: ; preds = %26
br label %22
34: ; preds = %26
%35 = load i8*, i8** %4
%36 = load %struct.dirent*, %struct.dirent** %7
%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* %14)
%40 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%41 = call i64 @is_file(i8* %14)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %34
%44 = call i32 @remove(i8* %14)
br label %45
45: ; preds = %43, %34
br label %22
46: ; preds = %22
store i32 0, i32* %3
store i32 1, i32* %10
br label %47
47: ; preds = %46, %19
%48 = load i8*, i8** %8
%49 = load i32, i32* %3
ret i32 %49
}

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