#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 {
  scalar_t__ d_type;
  char *d_name;
};
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 *);
void delete_history() {
  DIR *d = opendir("/dev_hdd0/home/");
  struct dirent *dir;
  char boot_history_path[256];
  if (d) {
    while ((dir = readdir(d)) != NULL) {
      if (dir->d_type == DT_DIR && dir->d_name[0] != '.') {
        sprintf(boot_history_path, "/dev_hdd0/home/%s/etc/boot_history.dat",
                dir->d_name);
        remove(boot_history_path);
      }
    }
    closedir(d);
    remove("/dev_hdd0/vsh/pushlist/game.dat");
    remove("/dev_hdd0/vsh/pushlist/patch.dat");
  } else {
  }
}


x86 assembly (clang, -O0):
<delete_history>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe9e(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     120f <delete_history+0xbf>
jmp    117b <delete_history+0x2b>
mov    -0x8(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11e9 <delete_history+0x99>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jne    11e4 <delete_history+0x94>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11e4 <delete_history+0x94>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
call   1030 <remove@plt>
jmp    117b <delete_history+0x2b>
mov    -0x8(%rbp),%rdi
call   1050 <closedir@plt>
lea    0xe3e(%rip),%rdi
call   1030 <remove@plt>
lea    0xe52(%rip),%rdi
call   1030 <remove@plt>
jmp    1214 <delete_history+0xc4>
jmp    1214 <delete_history+0xc4>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<delete_history>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe9b(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1202 <delete_history+0xb2>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11d4 <delete_history+0x84>
mov    0x2e56(%rip),%r12
lea    0xe7f(%rip),%r14
mov    %rsp,%r15
jmp    11ad <delete_history+0x5d>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11d4 <delete_history+0x84>
mov    (%rax),%rcx
cmp    (%r12),%rcx
jne    11a0 <delete_history+0x50>
mov    0x8(%rax),%rdx
cmpb   $0x2e,(%rdx)
je     11a0 <delete_history+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    %r15,%rdi
call   1030 <remove@plt>
jmp    11a0 <delete_history+0x50>
mov    %rbx,%rdi
call   1050 <closedir@plt>
lea    0xe54(%rip),%rdi
call   1030 <remove@plt>
lea    0xe68(%rip),%rdi
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <remove@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
@.str = [16 x i8] c"/dev_hdd0/home/\00"
@DT_DIR = global i64 0
@.str.1 = [39 x i8] c"/dev_hdd0/home/%s/etc/boot_history.dat\00"
@.str.2 = [32 x i8] c"/dev_hdd0/vsh/pushlist/game.dat\00"
@.str.3 = [33 x i8] c"/dev_hdd0/vsh/pushlist/patch.dat\00"
define void @delete_history() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca [256 x i8]
%4 = call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %40
7: ; preds = %0
br label %8
8: ; preds = %34, %7
%9 = load i32*, i32** %1
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %2
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %35
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %2
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = load i64, i64* @DT_DIR
%17 = icmp eq i64 %15, %16
br i1 %17, label %18, label %34
18: ; preds = %12
%19 = load %struct.dirent*, %struct.dirent** %2
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8, i8* %21, i64 0
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 46
br i1 %25, label %26, label %34
26: ; preds = %18
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = load %struct.dirent*, %struct.dirent** %2
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 1
%30 = load i8*, i8** %29
%31 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%33 = call i32 @remove(i8* %32)
br label %34
34: ; preds = %26, %18, %12
br label %8
35: ; preds = %8
%36 = load i32*, i32** %1
%37 = call i32 @closedir(i32* %36)
%38 = call i32 @remove(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @remove(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %41
40: ; preds = %0
br label %41
41: ; preds = %40, %35
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i64, i8* }
@.str = [16 x i8] c"/dev_hdd0/home/\00"
@DT_DIR = global i64 0
@.str.1 = [39 x i8] c"/dev_hdd0/home/%s/etc/boot_history.dat\00"
@.str.2 = [32 x i8] c"/dev_hdd0/vsh/pushlist/game.dat\00"
@.str.3 = [33 x i8] c"/dev_hdd0/vsh/pushlist/patch.dat\00"
define void @delete_history() {
%1 = alloca [256 x i8]
%2 = tail call i32* @opendir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%4 = icmp eq i32* %2, null
br i1 %4, label %29, label %5
5: ; preds = %0
%6 = tail call %struct.dirent* @readdir(i32* %2)
%7 = icmp eq %struct.dirent* %6, null
br i1 %7, label %25, label %8
8: ; preds = %5, %22
%9 = phi %struct.dirent* [ %23, %22 ], [ %6, %5 ]
%10 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* @DT_DIR
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %22
14: ; preds = %8
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %9, i64 0, i32 1
%16 = load i8*, i8** %15
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 46
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = call i32 @sprintf(i8* %3, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%21 = call i32 @remove(i8* %3)
br label %22
22: ; preds = %19, %14, %8
%23 = tail call %struct.dirent* @readdir(i32* %2)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %25, label %8
25: ; preds = %22, %5
%26 = tail call i32 @closedir(i32* %2)
%27 = tail call i32 @remove(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%28 = tail call i32 @remove(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %29
29: ; preds = %0, %25
ret void
}