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

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ time(int *);
void ref_now(const char *dirname) {
  DIR *dirp;
  struct dirent *dir;
  struct stat buf;
  time_t latest;
  time_t diff;
  char cwd[PATH_MAX];
  if ((dirp = opendir(dirname)) == NULL) {
    perror("opendir");
    return;
  }
  time(&latest);
  getcwd(cwd, sizeof cwd);
  chdir(dirname);
  while ((dir = readdir(dirp)) != NULL) {
    if (stat(dir->d_name, &buf) == -1) {
      continue;
    }
    if (strcmp(dir->d_name, ".") == 0 || strcmp(dir->d_name, "..") == 0) {
      continue;
    }
    diff = latest - buf.st_mtime;
    if (diff < (24 * 60 * 60)) {
      printf("\e[31m%s\e[39m\n", dir->d_name);
    } else if (diff < 3 * (24 * 60 * 60))
      printf("\e[91m%s\e[39m\n", dir->d_name);
    else if (diff < (7 * (24 * 60 * 60))) {
      printf("\e[35m%s\e[39m\n", dir->d_name);
    } else if (diff < (30 * (24 * 60 * 60))) {
      printf("\e[95m%s\e[39m\n", dir->d_name);
    } else if (diff < (365 * (24 * 60 * 60))) {
      printf("\e[34m%s\e[39m\n", dir->d_name);
    } else {
      printf("\e[94m%s\e[39m\n", dir->d_name);
    }
  }
  chdir(cwd);
  closedir(dirp);
}


x86 assembly (clang, -O0):
<ref_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x50(%rbp)
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    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    120b <ref_now+0x6b>
lea    0xe06(%rip),%rdi
call   10c0 <perror@plt>
movl   $0x1,-0x3c(%rbp)
jmp    13a7 <ref_now+0x207>
lea    -0x24(%rbp),%rdi
call   10a0 <time@plt>
mov    -0x48(%rbp),%rdi
mov    -0x50(%rbp),%rax
mov    %eax,%esi
call   1060 <getcwd@plt>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     138e <ref_now+0x1ee>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    -0x20(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    1261 <ref_now+0xc1>
jmp    122c <ref_now+0x8c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd9a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     129b <ref_now+0xfb>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xd7c(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12a0 <ref_now+0x100>
jmp    122c <ref_now+0x8c>
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpl   $0x15180,-0x28(%rbp)
jge    12ce <ref_now+0x12e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd47(%rip),%rdi
call   1050 <printf@plt>
jmp    1389 <ref_now+0x1e9>
cmpl   $0x3f480,-0x28(%rbp)
jge    12f3 <ref_now+0x153>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd30(%rip),%rdi
call   1050 <printf@plt>
jmp    1384 <ref_now+0x1e4>
cmpl   $0x93a80,-0x28(%rbp)
jge    1318 <ref_now+0x178>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd19(%rip),%rdi
call   1050 <printf@plt>
jmp    137f <ref_now+0x1df>
cmpl   $0x278d00,-0x28(%rbp)
jge    133d <ref_now+0x19d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xd02(%rip),%rdi
call   1050 <printf@plt>
jmp    137a <ref_now+0x1da>
cmpl   $0x1e13380,-0x28(%rbp)
jge    1362 <ref_now+0x1c2>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xceb(%rip),%rdi
call   1050 <printf@plt>
jmp    1375 <ref_now+0x1d5>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xce1(%rip),%rdi
call   1050 <printf@plt>
jmp    137a <ref_now+0x1da>
jmp    137f <ref_now+0x1df>
jmp    1384 <ref_now+0x1e4>
jmp    1389 <ref_now+0x1e9>
jmp    122c <ref_now+0x8c>
mov    -0x48(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ref_now>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%r15
mov    %rsp,%r13
mov    0x2e32(%rip),%rax
mov    (%rax),%r12d
mov    %rsp,%r14
lea    0xf(%r12),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
call   1030 <opendir@plt>
test   %rax,%rax
je     130c <ref_now+0x16c>
mov    %rax,%rbx
mov    %r13,-0x40(%rbp)
lea    -0x34(%rbp),%rdi
call   10a0 <time@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1060 <getcwd@plt>
mov    %r15,%rdi
call   1040 <chdir@plt>
mov    %rbx,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     12e6 <ref_now+0x146>
mov    %rax,%r13
lea    -0x30(%rbp),%r15
lea    0xde6(%rip),%r12
jmp    124d <ref_now+0xad>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13),%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     12e6 <ref_now+0x146>
mov    0x0(%r13),%rdi
mov    %r15,%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     1239 <ref_now+0x99>
mov    0x0(%r13),%rdi
mov    %r12,%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1239 <ref_now+0x99>
mov    0x0(%r13),%rdi
lea    0xd8e(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1239 <ref_now+0x99>
mov    -0x34(%rbp),%eax
sub    -0x30(%rbp),%eax
lea    0xd7a(%rip),%rdi
cmp    $0x15180,%eax
jl     1230 <ref_now+0x90>
lea    0xd7a(%rip),%rdi
cmp    $0x3f480,%eax
jb     1230 <ref_now+0x90>
lea    0xd7a(%rip),%rdi
cmp    $0x93a80,%eax
jb     1230 <ref_now+0x90>
lea    0xd76(%rip),%rdi
cmp    $0x278d00,%eax
jb     1230 <ref_now+0x90>
cmp    $0x1e13380,%eax
lea    0xd7b(%rip),%rdi
lea    0xd66(%rip),%rax
cmovb  %rax,%rdi
jmp    1230 <ref_now+0x90>
mov    %r14,%rdi
call   1040 <chdir@plt>
mov    %rbx,%rdi
call   1070 <closedir@plt>
mov    -0x40(%rbp),%r13
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xced(%rip),%rdi
call   10c0 <perror@plt>
jmp    12fa <ref_now+0x15a>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@PATH_MAX = global i32 0
@.str = [8 x i8] c"opendir\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [14 x i8] c"\1B[31m%s\1B[39m\0A\00"
@.str.4 = [14 x i8] c"\1B[91m%s\1B[39m\0A\00"
@.str.5 = [14 x i8] c"\1B[35m%s\1B[39m\0A\00"
@.str.6 = [14 x i8] c"\1B[95m%s\1B[39m\0A\00"
@.str.7 = [14 x i8] c"\1B[34m%s\1B[39m\0A\00"
@.str.8 = [14 x i8] c"\1B[94m%s\1B[39m\0A\00"
define void @ref_now(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
store i8* %0, i8** %2
%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** %2
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %3
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %10
br label %108
20: ; preds = %1
%21 = call i32 @time(i32* %6)
%22 = trunc i64 %12 to i32
%23 = call i32 @getcwd(i8* %14, i32 %22)
%24 = load i8*, i8** %2
%25 = call i32 @chdir(i8* %24)
br label %26
26: ; preds = %103, %49, %36, %20
%27 = load i32*, i32** %3
%28 = call %struct.dirent* @readdir(i32* %27)
store %struct.dirent* %28, %struct.dirent** %4
%29 = icmp ne %struct.dirent* %28, null
br i1 %29, label %30, label %104
30: ; preds = %26
%31 = load %struct.dirent*, %struct.dirent** %4
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @stat(i8* %33, %struct.stat* %5)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %37
36: ; preds = %30
br label %26
37: ; preds = %30
%38 = load %struct.dirent*, %struct.dirent** %4
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %49, label %43
43: ; preds = %37
%44 = load %struct.dirent*, %struct.dirent** %4
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %44, i32 0, i32 0
%46 = load i8*, i8** %45
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %43, %37
br label %26
50: ; preds = %43
%51 = load i32, i32* %6
%52 = getelementptr inbounds %struct.stat, %struct.stat* %5, i32 0, i32 0
%53 = load i32, i32* %52
%54 = sub nsw i32 %51, %53
store i32 %54, i32* %7
%55 = load i32, i32* %7
%56 = icmp slt i32 %55, 86400
br i1 %56, label %57, label %62
57: ; preds = %50
%58 = load %struct.dirent*, %struct.dirent** %4
%59 = getelementptr inbounds %struct.dirent, %struct.dirent* %58, i32 0, i32 0
%60 = load i8*, i8** %59
%61 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8* %60)
br label %103
62: ; preds = %50
%63 = load i32, i32* %7
%64 = icmp slt i32 %63, 259200
br i1 %64, label %65, label %70
65: ; preds = %62
%66 = load %struct.dirent*, %struct.dirent** %4
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* %68)
br label %102
70: ; preds = %62
%71 = load i32, i32* %7
%72 = icmp slt i32 %71, 604800
br i1 %72, label %73, label %78
73: ; preds = %70
%74 = load %struct.dirent*, %struct.dirent** %4
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 0
%76 = load i8*, i8** %75
%77 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %76)
br label %101
78: ; preds = %70
%79 = load i32, i32* %7
%80 = icmp slt i32 %79, 2592000
br i1 %80, label %81, label %86
81: ; preds = %78
%82 = load %struct.dirent*, %struct.dirent** %4
%83 = getelementptr inbounds %struct.dirent, %struct.dirent* %82, i32 0, i32 0
%84 = load i8*, i8** %83
%85 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), i8* %84)
br label %100
86: ; preds = %78
%87 = load i32, i32* %7
%88 = icmp slt i32 %87, 31536000
br i1 %88, label %89, label %94
89: ; preds = %86
%90 = load %struct.dirent*, %struct.dirent** %4
%91 = getelementptr inbounds %struct.dirent, %struct.dirent* %90, i32 0, i32 0
%92 = load i8*, i8** %91
%93 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* %92)
br label %99
94: ; preds = %86
%95 = load %struct.dirent*, %struct.dirent** %4
%96 = getelementptr inbounds %struct.dirent, %struct.dirent* %95, i32 0, i32 0
%97 = load i8*, i8** %96
%98 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i8* %97)
br label %99
99: ; preds = %94, %89
br label %100
100: ; preds = %99, %81
br label %101
101: ; preds = %100, %73
br label %102
102: ; preds = %101, %65
br label %103
103: ; preds = %102, %57
br label %26
104: ; preds = %26
%105 = call i32 @chdir(i8* %14)
%106 = load i32*, i32** %3
%107 = call i32 @closedir(i32* %106)
store i32 0, i32* %10
br label %108
108: ; preds = %104, %18
%109 = load i8*, i8** %8
%110 = load i32, i32* %10
switch i32 %110, label %112 [
i32 0, label %111
i32 1, label %111
]
111: ; preds = %108, %108
ret void
112: ; preds = %108
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@PATH_MAX = global i32 0
@.str = [8 x i8] c"opendir\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [14 x i8] c"\1B[31m%s\1B[39m\0A\00"
@.str.4 = [14 x i8] c"\1B[91m%s\1B[39m\0A\00"
@.str.5 = [14 x i8] c"\1B[35m%s\1B[39m\0A\00"
@.str.6 = [14 x i8] c"\1B[95m%s\1B[39m\0A\00"
@.str.7 = [14 x i8] c"\1B[34m%s\1B[39m\0A\00"
@.str.8 = [14 x i8] c"\1B[94m%s\1B[39m\0A\00"
define void @ref_now(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i32
%4 = bitcast %struct.stat* %2 to i8*
%5 = bitcast i32* %3 to i8*
%6 = load i32, i32* @PATH_MAX
%7 = zext i32 %6 to i64
%8 = tail call i8* @llvm.stacksave()
%9 = alloca i8, i64 %7
%10 = tail call i32* @opendir(i8* %0)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %1
%13 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %60
14: ; preds = %1
%15 = call i32 @time(i32* %3)
%16 = call i32 @getcwd(i8* %9, i32 %6)
%17 = call i32 @chdir(i8* %0)
%18 = call %struct.dirent* @readdir(i32* %10)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %57, label %20
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %22
22: ; preds = %20, %40
%23 = phi %struct.dirent* [ %18, %20 ], [ %41, %40 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @stat(i8* %25, %struct.stat* %2)
%27 = icmp eq i32 %26, -1
br i1 %27, label %40, label %28
28: ; preds = %22
%29 = load i8*, i8** %24
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %28
%33 = load i8*, i8** %24
%34 = call i64 @strcmp(i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%35 = icmp eq i64 %34, 0
br i1 %35, label %40, label %43
36: ; preds = %54, %52, %50, %48, %43
%37 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), %43 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), %48 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), %50 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0), %52 ], [ %56, %54 ]
%38 = load i8*, i8** %24
%39 = call i32 @printf(i8* %37, i8* %38)
br label %40
40: ; preds = %36, %28, %32, %22
%41 = call %struct.dirent* @readdir(i32* %10)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %57, label %22
43: ; preds = %32
%44 = load i32, i32* %3
%45 = load i32, i32* %21
%46 = sub nsw i32 %44, %45
%47 = icmp slt i32 %46, 86400
br i1 %47, label %36, label %48
48: ; preds = %43
%49 = icmp ult i32 %46, 259200
br i1 %49, label %36, label %50
50: ; preds = %48
%51 = icmp ult i32 %46, 604800
br i1 %51, label %36, label %52
52: ; preds = %50
%53 = icmp ult i32 %46, 2592000
br i1 %53, label %36, label %54
54: ; preds = %52
%55 = icmp ult i32 %46, 31536000
%56 = select i1 %55, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0)
br label %36
57: ; preds = %40, %14
%58 = call i32 @chdir(i8* %9)
%59 = call i32 @closedir(i32* %10)
br label %60
60: ; preds = %57, %12
ret void
}