#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 */
typedef int /*<<< orphan*/ timeoutpath;
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int PATH_MAX;
scalar_t__ _is_valid_session(char *);
int /*<<< orphan*/ _q_unlink(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
int /*<<< orphan*/ strcat(char *, char *);
size_t strlen(char *);
scalar_t__ strstr(char *, char *);
bool _clear_repo(const char *session_repository_path) {
  DIR *dp;
  if ((dp = opendir(session_repository_path)) == NULL) {
    ;
    return false;
  }
  struct dirent *dirp;
  while ((dirp = readdir(dp)) != NULL) {
    if (strstr(dirp->d_name, "qsession-") && strstr(dirp->d_name, ".expire")) {
      char timeoutpath[PATH_MAX];
      snprintf(timeoutpath, sizeof(timeoutpath), "%s/%s",
               session_repository_path, dirp->d_name);
      if (_is_valid_session(timeoutpath) <= 0) {
        _q_unlink(timeoutpath);
        timeoutpath[strlen(timeoutpath) - strlen(".expire")] = '\0';
        strcat(timeoutpath, ".properties");
        _q_unlink(timeoutpath);
      }
    }
  }
  closedir(dp);
  return true;
}


x86 assembly (clang, -O0):
<_clear_repo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11bf <_clear_repo+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    12d2 <_clear_repo+0x142>
jmp    11c4 <_clear_repo+0x34>
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12c2 <_clear_repo+0x132>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe17(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     12bd <_clear_repo+0x12d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe04(%rip),%rsi
call   10b0 <strstr@plt>
cmp    $0x0,%rax
je     12bd <_clear_repo+0x12d>
mov    0x2dd4(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%r8
lea    0xdbd(%rip),%rdx
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
call   1090 <_is_valid_session@plt>
cmp    $0x0,%rax
jg     12b6 <_clear_repo+0x126>
mov    -0x38(%rbp),%rdi
call   1080 <_q_unlink@plt>
mov    -0x38(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x40(%rbp)
lea    0xd80(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    %rcx,%rax
movb   $0x0,(%rdi,%rax,1)
lea    0xd70(%rip),%rsi
call   10a0 <strcat@plt>
mov    -0x38(%rbp),%rdi
call   1080 <_q_unlink@plt>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
jmp    11c4 <_clear_repo+0x34>
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_clear_repo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,-0x30(%rbp)
call   1030 <opendir@plt>
test   %rax,%rax
je     1296 <_clear_repo+0x106>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1287 <_clear_repo+0xf7>
mov    %rax,%r13
lea    0xe32(%rip),%r15
jmp    11e7 <_clear_repo+0x57>
mov    %r14,%rsp
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1287 <_clear_repo+0xf7>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     11d3 <_clear_repo+0x43>
mov    0x0(%r13),%rdi
lea    0xe07(%rip),%rsi
call   10b0 <strstr@plt>
test   %rax,%rax
je     11d3 <_clear_repo+0x43>
mov    %rsp,%r14
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r12
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x0(%r13),%r8
mov    %r12,%rdi
lea    0xdd7(%rip),%rdx
mov    -0x30(%rbp),%rcx
call   1050 <snprintf@plt>
mov    %r12,%rdi
call   1090 <_is_valid_session@plt>
test   %rax,%rax
jg     11d0 <_clear_repo+0x40>
mov    %r12,%rdi
call   1080 <_q_unlink@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
movb   $0x0,-0x7(%rax,%r12,1)
mov    %r12,%rdi
lea    0xda3(%rip),%rsi
call   10a0 <strcat@plt>
mov    %r12,%rdi
call   1080 <_q_unlink@plt>
jmp    11d0 <_clear_repo+0x40>
mov    %rbx,%rdi
call   1060 <closedir@plt>
mov    $0x1,%eax
jmp    1298 <_clear_repo+0x108>
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [10 x i8] c"qsession-\00"
@.str.1 = [8 x i8] c".expire\00"
@PATH_MAX = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [12 x i8] c".properties\00"
define i32 @_clear_repo(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.dirent*
%6 = alloca i8*
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %4
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %1
store i32 0, i32* %2
br label %56
12: ; preds = %1
br label %13
13: ; preds = %52, %12
%14 = load i32*, i32** %4
%15 = call %struct.dirent* @readdir(i32* %14)
store %struct.dirent* %15, %struct.dirent** %5
%16 = icmp ne %struct.dirent* %15, null
br i1 %16, label %17, label %53
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %5
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i64 @strstr(i8* %20, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %52
23: ; preds = %17
%24 = load %struct.dirent*, %struct.dirent** %5
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @strstr(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %52
29: ; preds = %23
%30 = load i32, i32* @PATH_MAX
%31 = zext i32 %30 to i64
%32 = call i8* @llvm.stacksave()
store i8* %32, i8** %6
%33 = alloca i8, i64 %31
store i64 %31, i64* %7
%34 = trunc i64 %31 to i32
%35 = load i8*, i8** %3
%36 = load %struct.dirent*, %struct.dirent** %5
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @snprintf(i8* %33, i32 %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %38)
%40 = call i64 @_is_valid_session(i8* %33)
%41 = icmp sle i64 %40, 0
br i1 %41, label %42, label %50
42: ; preds = %29
%43 = call i32 @_q_unlink(i8* %33)
%44 = call i64 @strlen(i8* %33)
%45 = call i64 @strlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%46 = sub i64 %44, %45
%47 = getelementptr inbounds i8, i8* %33, i64 %46
store i8 0, i8* %47
%48 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%49 = call i32 @_q_unlink(i8* %33)
br label %50
50: ; preds = %42, %29
%51 = load i8*, i8** %6
br label %52
52: ; preds = %50, %23, %17
br label %13
53: ; preds = %13
%54 = load i32*, i32** %4
%55 = call i32 @closedir(i32* %54)
store i32 1, i32* %2
br label %56
56: ; preds = %53, %11
%57 = load i32, i32* %2
ret i32 %57
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [10 x i8] c"qsession-\00"
@.str.1 = [8 x i8] c".expire\00"
@PATH_MAX = global i32 0
@.str.2 = [6 x i8] c"%s/%s\00"
@.str.3 = [12 x i8] c".properties\00"
define i32 @_clear_repo(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %39, label %4
4: ; preds = %1
%5 = call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %37, label %7
7: ; preds = %4, %34
%8 = phi %struct.dirent* [ %35, %34 ], [ %5, %4 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = call i64 @strstr(i8* %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %34, label %13
13: ; preds = %7
%14 = load i8*, i8** %9
%15 = call i64 @strstr(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %34, label %17
17: ; preds = %13
%18 = load i32, i32* @PATH_MAX
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
%21 = alloca i8, i64 %19
%22 = load i8*, i8** %9
%23 = call i32 @snprintf(i8* %21, i32 %18, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %22)
%24 = call i64 @_is_valid_session(i8* %21)
%25 = icmp slt i64 %24, 1
br i1 %25, label %26, label %33
26: ; preds = %17
%27 = call i32 @_q_unlink(i8* %21)
%28 = call i64 @strlen(i8* %21)
%29 = add i64 %28, -7
%30 = getelementptr inbounds i8, i8* %21, i64 %29
store i8 0, i8* %30
%31 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @_q_unlink(i8* %21)
br label %33
33: ; preds = %26, %17
br label %34
34: ; preds = %33, %13, %7
%35 = call %struct.dirent* @readdir(i32* %2)
%36 = icmp eq %struct.dirent* %35, null
br i1 %36, label %37, label %7
37: ; preds = %34, %4
%38 = call i32 @closedir(i32* %2)
br label %39
39: ; preds = %1, %37
%40 = phi i32 [ 1, %37 ], [ 0, %1 ]
ret i32 %40
}