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

/* Variables and functions */
int LINES;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *getenv(char *);
int /*<<< orphan*/ mvwprintw(int /*<<< orphan*/ *, int, int, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int strcmp(int /*<<< orphan*/, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
void print_archive(WINDOW *win) {
  DIR *d;
  struct dirent *dir;
  int i = 0, j = 1, n = 0;
  char tdir[80];
  snprintf(tdir, sizeof(tdir), "%s/Timesheets", getenv("HOME"));
  d = opendir(tdir);
  if (d) {
    while ((dir = readdir(d)) != NULL)
      if (strcmp(dir->d_name, "timesheet") > 8)
        n++;
    char files[n][25];
    rewinddir(d);
    while ((dir = readdir(d)) != NULL)
      if (strcmp(dir->d_name, "timesheet") > 8) {
        strcpy(files[i], dir->d_name);
        i++;
      }
    while (j < LINES - 5) {
      mvwprintw(win, j + 3, 1, "%s", files[n - 1]);
      j++;
      n--;
    }
    closedir(d);
  }
}


x86 assembly (clang, -O0):
<print_archive>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x98(%rbp)
lea    0xe48(%rip),%rdi
call   1030 <getenv@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,%rcx
mov    $0x50,%esi
lea    0xe1f(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x80(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     135a <print_archive+0x1ca>
jmp    1203 <print_archive+0x73>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1243 <print_archive+0xb3>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x8,%eax
jle    123e <print_archive+0xae>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1203 <print_archive+0x73>
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x88(%rbp)
lea    (%rax,%rax,4),%rcx
lea    0xf(%rcx,%rcx,4),%rdx
movabs $0x3ffffffff0,%rcx
and    %rcx,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xa0(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <rewinddir@plt>
mov    -0x10(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     12e3 <print_archive+0x153>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xd69(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x8,%eax
jle    12de <print_archive+0x14e>
mov    -0xa0(%rbp),%rdi
movslq -0x1c(%rbp),%rax
imul   $0x19,%rax,%rax
add    %rax,%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
call   1040 <strcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1286 <print_archive+0xf6>
jmp    12e8 <print_archive+0x158>
mov    -0x20(%rbp),%eax
mov    0x2cf6(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x5,%ecx
cmp    %ecx,%eax
jge    1347 <print_archive+0x1b7>
mov    -0xa0(%rbp),%r8
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    $0x3,%esi
mov    -0x24(%rbp),%eax
sub    $0x1,%eax
cltq
imul   $0x19,%rax,%rax
add    %rax,%r8
mov    $0x1,%edx
lea    0xcf2(%rip),%rcx
call   10b0 <mvwprintw@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    12e8 <print_archive+0x158>
mov    -0x10(%rbp),%rdi
call   1080 <closedir@plt>
mov    -0x88(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_archive>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%r14
lea    0xe63(%rip),%rdi
call   1030 <getenv@plt>
lea    0xe49(%rip),%rdx
lea    -0x90(%rbp),%rbx
mov    %rbx,%rdi
mov    $0x50,%esi
mov    %rax,%rcx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     132b <print_archive+0x19b>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
mov    %r14,-0x40(%rbp)
je     1224 <print_archive+0x94>
xor    %r13d,%r13d
lea    0xe16(%rip),%rbx
nopl   (%rax)
mov    (%rax),%edi
mov    %rbx,%rsi
call   1090 <strcmp@plt>
xor    %ecx,%ecx
cmp    $0x9,%eax
setge  %cl
add    %ecx,%r13d
mov    %r12,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
jne    1200 <print_archive+0x70>
jmp    1227 <print_archive+0x97>
xor    %r13d,%r13d
mov    %rsp,-0x38(%rbp)
mov    %r13d,%eax
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,4),%rax
add    $0xf,%rax
movabs $0x3ffffffff0,%rcx
and    %rax,%rcx
mov    %rsp,%rax
sub    %rcx,%rax
mov    %rax,-0x30(%rbp)
mov    %rax,%rsp
mov    %r12,%rdi
call   1070 <rewinddir@plt>
mov    %r12,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12bb <print_archive+0x12b>
mov    %rax,%rbx
xor    %r14d,%r14d
lea    0xd9d(%rip),%r15
jmp    1290 <print_archive+0x100>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     12bb <print_archive+0x12b>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1090 <strcmp@plt>
cmp    $0x9,%eax
jl     1280 <print_archive+0xf0>
movslq %r14d,%r14
lea    (%r14,%r14,4),%rax
lea    (%rax,%rax,4),%rdi
add    -0x30(%rbp),%rdi
mov    (%rbx),%esi
call   1040 <strcpy@plt>
add    $0x1,%r14d
jmp    1280 <print_archive+0xf0>
mov    0x2d26(%rip),%r15
cmpl   $0x7,(%r15)
mov    -0x40(%rbp),%r14
jl     131f <print_archive+0x18f>
movslq %r13d,%rax
lea    (%rax,%rax,4),%rax
lea    (%rax,%rax,4),%rax
mov    -0x30(%rbp),%rcx
lea    (%rcx,%rax,1),%r13
add    $0xffffffffffffffe7,%r13
mov    $0x4,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
lea    0xd1c(%rip),%rcx
mov    %r13,%r8
call   10b0 <mvwprintw@plt>
mov    (%r15),%eax
add    $0xfffffffb,%eax
add    $0xffffffffffffffe7,%r13
lea    0x1(%rbx),%ecx
add    $0xfffffffe,%ebx
cmp    %eax,%ebx
mov    %ecx,%ebx
jl     12f0 <print_archive+0x160>
mov    %r12,%rdi
call   1080 <closedir@plt>
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [14 x i8] c"%s/Timesheets\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [10 x i8] c"timesheet\00"
@LINES = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define void @print_archive(i32* %0) {
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [80 x i8]
%9 = alloca i8*
%10 = alloca i64
store i32* %0, i32** %2
store i32 0, i32* %5
store i32 1, i32* %6
store i32 0, i32* %7
%11 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%12 = call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 @snprintf(i8* %11, i32 80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [80 x i8], [80 x i8]* %8, i64 0, i64 0
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %3
%16 = load i32*, i32** %3
%17 = icmp ne i32* %16, null
br i1 %17, label %18, label %86
18: ; preds = %1
br label %19
19: ; preds = %32, %18
%20 = load i32*, i32** %3
%21 = call %struct.dirent* @readdir(i32* %20)
store %struct.dirent* %21, %struct.dirent** %4
%22 = icmp ne %struct.dirent* %21, null
br i1 %22, label %23, label %33
23: ; preds = %19
%24 = load %struct.dirent*, %struct.dirent** %4
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i32, i32* %25
%27 = call i32 @strcmp(i32 %26, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%28 = icmp sgt i32 %27, 8
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %32
32: ; preds = %29, %23
br label %19
33: ; preds = %19
%34 = load i32, i32* %7
%35 = zext i32 %34 to i64
%36 = call i8* @llvm.stacksave()
store i8* %36, i8** %9
%37 = alloca [25 x i8], i64 %35
store i64 %35, i64* %10
%38 = load i32*, i32** %3
%39 = call i32 @rewinddir(i32* %38)
br label %40
40: ; preds = %61, %33
%41 = load i32*, i32** %3
%42 = call %struct.dirent* @readdir(i32* %41)
store %struct.dirent* %42, %struct.dirent** %4
%43 = icmp ne %struct.dirent* %42, null
br i1 %43, label %44, label %62
44: ; preds = %40
%45 = load %struct.dirent*, %struct.dirent** %4
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i32 @strcmp(i32 %47, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%49 = icmp sgt i32 %48, 8
br i1 %49, label %50, label %61
50: ; preds = %44
%51 = load i32, i32* %5
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [25 x i8], [25 x i8]* %37, i64 %52
%54 = getelementptr inbounds [25 x i8], [25 x i8]* %53, i64 0, i64 0
%55 = load %struct.dirent*, %struct.dirent** %4
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i32, i32* %56
%58 = call i32 @strcpy(i8* %54, i32 %57)
%59 = load i32, i32* %5
%60 = add nsw i32 %59, 1
store i32 %60, i32* %5
br label %61
61: ; preds = %50, %44
br label %40
62: ; preds = %40
br label %63
63: ; preds = %68, %62
%64 = load i32, i32* %6
%65 = load i32, i32* @LINES
%66 = sub nsw i32 %65, 5
%67 = icmp slt i32 %64, %66
br i1 %67, label %68, label %82
68: ; preds = %63
%69 = load i32*, i32** %2
%70 = load i32, i32* %6
%71 = add nsw i32 %70, 3
%72 = load i32, i32* %7
%73 = sub nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [25 x i8], [25 x i8]* %37, i64 %74
%76 = getelementptr inbounds [25 x i8], [25 x i8]* %75, i64 0, i64 0
%77 = call i32 @mvwprintw(i32* %69, i32 %71, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %76)
%78 = load i32, i32* %6
%79 = add nsw i32 %78, 1
store i32 %79, i32* %6
%80 = load i32, i32* %7
%81 = add nsw i32 %80, -1
store i32 %81, i32* %7
br label %63
82: ; preds = %63
%83 = load i32*, i32** %3
%84 = call i32 @closedir(i32* %83)
%85 = load i8*, i8** %9
br label %86
86: ; preds = %82, %1
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [14 x i8] c"%s/Timesheets\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [10 x i8] c"timesheet\00"
@LINES = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define void @print_archive(i32* %0) {
%2 = alloca [80 x i8]
%3 = getelementptr inbounds [80 x i8], [80 x i8]* %2, i64 0, i64 0
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%5 = call i32 @snprintf(i8* %3, i32 80, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %4)
%6 = call i32* @opendir(i8* %3)
%7 = icmp eq i32* %6, null
br i1 %7, label %65, label %8
8: ; preds = %1
%9 = call %struct.dirent* @readdir(i32* %6)
%10 = icmp eq %struct.dirent* %9, null
br i1 %10, label %22, label %11
11: ; preds = %8, %11
%12 = phi %struct.dirent* [ %20, %11 ], [ %9, %8 ]
%13 = phi i32 [ %19, %11 ], [ 0, %8 ]
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @strcmp(i32 %15, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp sgt i32 %16, 8
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %13, %18
%20 = call %struct.dirent* @readdir(i32* %6)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %11
22: ; preds = %11, %8
%23 = phi i32 [ 0, %8 ], [ %19, %11 ]
%24 = zext i32 %23 to i64
%25 = call i8* @llvm.stacksave()
%26 = alloca [25 x i8], i64 %24
%27 = call i32 @rewinddir(i32* %6)
%28 = call %struct.dirent* @readdir(i32* %6)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %30, label %35
30: ; preds = %48, %22
%31 = load i32, i32* @LINES
%32 = icmp sgt i32 %31, 6
br i1 %32, label %33, label %63
33: ; preds = %30
%34 = sext i32 %23 to i64
br label %52
35: ; preds = %22, %48
%36 = phi %struct.dirent* [ %50, %48 ], [ %28, %22 ]
%37 = phi i32 [ %49, %48 ], [ 0, %22 ]
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @strcmp(i32 %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp sgt i32 %40, 8
br i1 %41, label %42, label %48
42: ; preds = %35
%43 = sext i32 %37 to i64
%44 = getelementptr inbounds [25 x i8], [25 x i8]* %26, i64 %43, i64 0
%45 = load i32, i32* %38
%46 = call i32 @strcpy(i8* %44, i32 %45)
%47 = add nsw i32 %37, 1
br label %48
48: ; preds = %42, %35
%49 = phi i32 [ %47, %42 ], [ %37, %35 ]
%50 = call %struct.dirent* @readdir(i32* %6)
%51 = icmp eq %struct.dirent* %50, null
br i1 %51, label %30, label %35
52: ; preds = %33, %52
%53 = phi i64 [ %34, %33 ], [ %56, %52 ]
%54 = phi i32 [ 1, %33 ], [ %59, %52 ]
%55 = add nuw nsw i32 %54, 3
%56 = add nsw i64 %53, -1
%57 = getelementptr inbounds [25 x i8], [25 x i8]* %26, i64 %56, i64 0
%58 = call i32 @mvwprintw(i32* %0, i32 %55, i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %57)
%59 = add nuw nsw i32 %54, 1
%60 = load i32, i32* @LINES
%61 = add nsw i32 %60, -5
%62 = icmp slt i32 %59, %61
br i1 %62, label %52, label %63
63: ; preds = %52, %30
%64 = call i32 @closedir(i32* %6)
br label %65
65: ; preds = %63, %1
ret void
}