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


x86 assembly (clang, -O0):
<clean_dump>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ef <clean_dump+0x6f>
lea    0xe29(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    1292 <clean_dump+0x112>
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1284 <clean_dump+0x104>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xdf3(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    123e <clean_dump+0xbe>
jmp    1206 <clean_dump+0x86>
mov    -0x40(%rbp),%rdx
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%esi
call   1080 <get_file_path@plt>
mov    -0x40(%rbp),%rsi
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rdi
call   1070 <is_file@plt>
cmp    $0x0,%rax
je     127f <clean_dump+0xff>
mov    -0x40(%rbp),%rdi
call   1030 <remove@plt>
jmp    1206 <clean_dump+0x86>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_dump>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e48(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
call   1050 <opendir@plt>
test   %rax,%rax
je     1262 <clean_dump+0xd2>
mov    %rax,%r12
mov    (%r15),%esi
lea    0xe39(%rip),%rdi
xor    %r13d,%r13d
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1250 <clean_dump+0xc0>
mov    %rax,%r15
lea    0xe25(%rip),%r13
jmp    1210 <clean_dump+0x80>
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1070 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     124d <clean_dump+0xbd>
mov    (%r15),%edi
mov    %r13,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     1200 <clean_dump+0x70>
mov    (%r15),%esi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1090 <get_file_path@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1080 <is_file@plt>
test   %rax,%rax
je     1200 <clean_dump+0x70>
mov    %rbx,%rdi
call   1030 <remove@plt>
jmp    1200 <clean_dump+0x70>
xor    %r13d,%r13d
mov    %r13d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd97(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%r13d
jmp    1250 <clean_dump+0xc0>

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

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