#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*/ clean_file(char *, int, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
void clean_boot_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);
        clean_file(boot_history_path, 0x20, 1);
      }
    }
    closedir(d);
  } else {
  }
}


x86 assembly (clang, -O0):
<clean_boot_history>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
lea    0xe9e(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1201 <clean_boot_history+0xb1>
jmp    117b <clean_boot_history+0x2b>
mov    -0x8(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f3 <clean_boot_history+0xa3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jne    11ee <clean_boot_history+0x9e>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11ee <clean_boot_history+0x9e>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
lea    0xe3d(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x110(%rbp),%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   1050 <clean_file@plt>
jmp    117b <clean_boot_history+0x2b>
mov    -0x8(%rbp),%rdi
call   1040 <closedir@plt>
jmp    1206 <clean_boot_history+0xb6>
jmp    1206 <clean_boot_history+0xb6>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clean_boot_history>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x108,%rsp
lea    0xe9b(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11e6 <clean_boot_history+0x96>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11de <clean_boot_history+0x8e>
mov    0x2e5a(%rip),%r12
lea    0xe83(%rip),%r14
mov    %rsp,%r15
jmp    11ad <clean_boot_history+0x5d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11de <clean_boot_history+0x8e>
mov    (%rax),%rcx
cmp    (%r12),%rcx
jne    11a0 <clean_boot_history+0x50>
mov    0x8(%rax),%rdx
cmpb   $0x2e,(%rdx)
je     11a0 <clean_boot_history+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <sprintf@plt>
mov    %r15,%rdi
mov    $0x20,%esi
mov    $0x1,%edx
call   1050 <clean_file@plt>
jmp    11a0 <clean_boot_history+0x50>
mov    %rbx,%rdi
call   1040 <closedir@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"
define void @clean_boot_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 %38
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 @clean_file(i8* %32, i32 32, i32 1)
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)
br label %39
38: ; preds = %0
br label %39
39: ; preds = %38, %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"
define void @clean_boot_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 %27, label %5
5: ; preds = %0
%6 = 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 @clean_file(i8* %3, i32 32, i32 1)
br label %22
22: ; preds = %19, %14, %8
%23 = 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 = call i32 @closedir(i32* %2)
br label %27
27: ; preds = %0, %25
ret void
}