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

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
char getch();
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main() {
  system("setterm -cursor off");
  char *path = calloc(4096, sizeof(char));
  char *name = calloc(255, sizeof(char));
  uint64_t cursor = 0;
  strcpy(path, ".");
  char act;
  do {
    fputs("\e[1;1H\e[2J", stdout);
    DIR *this = opendir(path);
    struct dirent *file;
    readdir(this);
    uint8_t is_dir;
    uint64_t max;
    for (max = 0; file = readdir(this); ++max) {
      if (max == cursor) {
        is_dir = (file->d_type == 0x04);
        strcpy(name, file->d_name);
        fputs("\e[1;32m", stdout);
      }
      fputs((file->d_type == 0x04 ? " + " : " − "), stdout);
      fputs(file->d_name, stdout);
      puts("\e[1;37m");
    }
    --max;
    if ((act = getch()) == '\e') {
      getch();
      if ((act = getch()) == 'A' && cursor > 0)
        --cursor;
      else if (act == 'B' && cursor < max)
        ++cursor;
    } else if (act == '\n') {
      if (is_dir) {
        char *c = path + strlen(path);
        c[0] = '/';
        c[1] = '\0';
        strcat(path, name);
        cursor = 0;
      } else {
        char *command = calloc(4096, sizeof(char));
        strcpy(command, "xdg-open ");
        strcat(command, path);
        char *c = command + strlen(command);
        c[0] = '/', c[1] = '\0';
        strcat(command, name);
        strcat(command, " 1> /dev/null 2> /dev/null");
        system(command);
      }
    }
    closedir(this);
  } while (act != 'q' && act != 'Q');
  fputs("\e[0m", stdout);
  fputs("\e[1;1H\e[2J", stdout);
  system("setterm -cursor on");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe37(%rip),%rdi
call   1070 <system@plt>
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x10(%rbp)
mov    $0xff,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1030 <strcpy@plt>
mov    0x2dcd(%rip),%rax
mov    (%rax),%esi
lea    0xdfa(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <readdir@plt>
movq   $0x0,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     12f8 <main+0x148>
mov    -0x48(%rbp),%rax
cmp    -0x20(%rbp),%rax
jne    129c <main+0xec>
mov    -0x38(%rbp),%rax
cmpl   $0x4,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
lea    0xd8a(%rip),%rdi
call   1080 <fputs@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
lea    0xd84(%rip),%rdi
lea    0xd79(%rip),%rax
cmp    $0x4,%ecx
cmove  %rax,%rdi
mov    0x2d22(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d0c(%rip),%rax
mov    (%rax),%esi
call   1080 <fputs@plt>
lea    0xd51(%rip),%rdi
call   1040 <puts@plt>
mov    -0x48(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
jmp    123f <main+0x8f>
mov    -0x48(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x48(%rbp)
mov    $0x0,%al
call   10c0 <getch@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0x1b,%eax
jne    1384 <main+0x1d4>
mov    $0x0,%al
call   10c0 <getch@plt>
mov    $0x0,%al
call   10c0 <getch@plt>
mov    %al,-0x21(%rbp)
movsbl %al,%eax
cmp    $0x41,%eax
jne    1353 <main+0x1a3>
cmpq   $0x0,-0x20(%rbp)
jle    1353 <main+0x1a3>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    137f <main+0x1cf>
movsbl -0x21(%rbp),%eax
cmp    $0x42,%eax
jne    137a <main+0x1ca>
mov    -0x20(%rbp),%rax
cmp    -0x48(%rbp),%rax
jge    137a <main+0x1ca>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    137f <main+0x1cf>
jmp    1475 <main+0x2c5>
movsbl -0x21(%rbp),%eax
cmp    $0xa,%eax
jne    1470 <main+0x2c0>
cmpl   $0x0,-0x3c(%rbp)
je     13e5 <main+0x235>
mov    -0x10(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x50(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <strcat@plt>
movq   $0x0,-0x20(%rbp)
jmp    146b <main+0x2bb>
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
lea    0xc38(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x58(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x60(%rbp),%rax
movb   $0x0,0x1(%rax)
mov    -0x58(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x58(%rbp),%rdi
lea    0xbe8(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x58(%rbp),%rdi
call   1070 <system@plt>
jmp    1470 <main+0x2c0>
jmp    1475 <main+0x2c5>
mov    -0x30(%rbp),%rdi
call   1090 <closedir@plt>
movsbl -0x21(%rbp),%ecx
xor    %eax,%eax
cmp    $0x71,%ecx
mov    %al,-0x71(%rbp)
je     149d <main+0x2ed>
movsbl -0x21(%rbp),%eax
cmp    $0x51,%eax
setne  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    120c <main+0x5c>
mov    0x2b31(%rip),%rax
mov    (%rax),%esi
lea    0xba8(%rip),%rdi
call   1080 <fputs@plt>
mov    0x2b1c(%rip),%rax
mov    (%rax),%esi
lea    0xb49(%rip),%rdi
call   1080 <fputs@plt>
lea    0xb8c(%rip),%rdi
call   1070 <system@plt>
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe3b(%rip),%rdi
call   1070 <system@plt>
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbx
mov    $0xff,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%r14
lea    0xe1f(%rip),%rsi
mov    %rbx,0x10(%rsp)
mov    %rbx,%rdi
call   1030 <strcpy@plt>
xor    %eax,%eax
mov    %rax,(%rsp)
mov    %r14,0x8(%rsp)
jmp    124b <main+0x9b>
add    $0xffffffffffffffff,%r12
cmp    $0x42,%r15b
sete   %al
cmp    %r12,%rdx
setl   %cl
and    %al,%cl
movzbl %cl,%eax
add    %rax,%rdx
mov    %rdx,(%rsp)
nopl   0x0(%rax)
mov    %r13,%rdi
call   1090 <closedir@plt>
and    $0xdf,%r15b
cmp    $0x51,%r15b
mov    0x8(%rsp),%r14
je     1410 <main+0x260>
mov    0x2d8e(%rip),%rax
mov    (%rax),%esi
lea    0xdbb(%rip),%rdi
call   1080 <fputs@plt>
mov    0x10(%rsp),%rdi
call   1050 <opendir@plt>
mov    %rax,%r13
mov    %rax,%rdi
call   10b0 <readdir@plt>
mov    %r13,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1320 <main+0x170>
mov    %rax,%rbp
xor    %r12d,%r12d
jmp    12e1 <main+0x131>
xchg   %ax,%ax
cmpl   $0x4,0x0(%rbp)
lea    0xd92(%rip),%rdi
lea    0xd87(%rip),%rax
cmove  %rax,%rdi
mov    0x2d33(%rip),%r15
mov    (%r15),%esi
call   1080 <fputs@plt>
mov    0x8(%rbp),%rdi
mov    (%r15),%esi
call   1080 <fputs@plt>
lea    0xd6b(%rip),%rdi
call   1040 <puts@plt>
add    $0x1,%r12
mov    %r13,%rdi
call   10b0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1323 <main+0x173>
cmp    %r12,(%rsp)
jne    1290 <main+0xe0>
xor    %ebx,%ebx
cmpl   $0x4,0x0(%rbp)
sete   %bl
mov    0x8(%rbp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
lea    0xd15(%rip),%rdi
call   1080 <fputs@plt>
jmp    1290 <main+0xe0>
cs nopw 0x0(%rax,%rax,1)
xor    %r12d,%r12d
xor    %eax,%eax
call   10c0 <getch@plt>
cmp    $0xa,%al
je     1370 <main+0x1c0>
mov    %eax,%r15d
cmp    $0x1b,%al
jne    1230 <main+0x80>
xor    %eax,%eax
call   10c0 <getch@plt>
xor    %eax,%eax
call   10c0 <getch@plt>
mov    %eax,%r15d
cmp    $0x41,%al
mov    (%rsp),%rdx
jne    120f <main+0x5f>
test   %rdx,%rdx
jle    120f <main+0x5f>
add    $0xffffffffffffffff,%rdx
mov    %rdx,(%rsp)
mov    $0x41,%r15b
jmp    1230 <main+0x80>
nop
test   %ebx,%ebx
je     13a5 <main+0x1f5>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
movw   $0x2f,0x0(%rbp,%rax,1)
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
call   10d0 <strcat@plt>
mov    $0xa,%r15b
xor    %eax,%eax
mov    %rax,(%rsp)
jmp    1230 <main+0x80>
mov    $0x1000,%edi
mov    $0x1,%esi
call   10a0 <calloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
lea    0xc7a(%rip),%rsi
call   1030 <strcpy@plt>
mov    %rbp,%rdi
mov    0x10(%rsp),%rsi
call   10d0 <strcat@plt>
mov    %rbp,%rdi
call   1060 <strlen@plt>
cltq
movw   $0x2f,0x0(%rbp,%rax,1)
mov    %rbp,%rdi
mov    0x8(%rsp),%rsi
call   10d0 <strcat@plt>
mov    %rbp,%rdi
lea    0xc4a(%rip),%rsi
call   10d0 <strcat@plt>
mov    %rbp,%rdi
call   1070 <system@plt>
mov    $0xa,%r15b
jmp    1230 <main+0x80>
mov    0x2bc9(%rip),%rbx
mov    (%rbx),%esi
lea    0xc40(%rip),%rdi
call   1080 <fputs@plt>
mov    (%rbx),%esi
lea    0xbe8(%rip),%rdi
call   1080 <fputs@plt>
lea    0xc2b(%rip),%rdi
call   1070 <system@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32, i8* }
@.str = [20 x i8] c"setterm -cursor off\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [11 x i8] c"\1B[1;1H\1B[2J\00"
@stdout = global i32 0
@.str.3 = [8 x i8] c"\1B[1;32m\00"
@.str.4 = [4 x i8] c" + \00"
@.str.5 = [6 x i8] c" \E2\88\92 \00"
@.str.6 = [8 x i8] c"\1B[1;37m\00"
@.str.7 = [10 x i8] c"xdg-open \00"
@.str.8 = [27 x i8] c" 1> /dev/null 2> /dev/null\00"
@.str.9 = [5 x i8] c"\1B[0m\00"
@.str.10 = [19 x i8] c"setterm -cursor on\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i8
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
store i32 0, i32* %1
%13 = call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%14 = call i8* @calloc(i32 4096, i32 1)
store i8* %14, i8** %2
%15 = call i8* @calloc(i32 255, i32 1)
store i8* %15, i8** %3
store i64 0, i64* %4
%16 = load i8*, i8** %2
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %150, %0
%19 = load i32, i32* @stdout
%20 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %2
%22 = call i32* @opendir(i8* %21)
store i32* %22, i32** %6
%23 = load i32*, i32** %6
%24 = call %struct.dirent* @readdir(i32* %23)
store i64 0, i64* %9
br label %25
25: ; preds = %61, %18
%26 = load i32*, i32** %6
%27 = call %struct.dirent* @readdir(i32* %26)
store %struct.dirent* %27, %struct.dirent** %7
%28 = icmp ne %struct.dirent* %27, null
br i1 %28, label %29, label %64
29: ; preds = %25
%30 = load i64, i64* %9
%31 = load i64, i64* %4
%32 = icmp eq i64 %30, %31
br i1 %32, label %33, label %46
33: ; preds = %29
%34 = load %struct.dirent*, %struct.dirent** %7
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i32, i32* %35
%37 = icmp eq i32 %36, 4
%38 = zext i1 %37 to i32
store i32 %38, i32* %8
%39 = load i8*, i8** %3
%40 = load %struct.dirent*, %struct.dirent** %7
%41 = getelementptr inbounds %struct.dirent, %struct.dirent* %40, i32 0, i32 1
%42 = load i8*, i8** %41
%43 = call i32 @strcpy(i8* %39, i8* %42)
%44 = load i32, i32* @stdout
%45 = call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %44)
br label %46
46: ; preds = %33, %29
%47 = load %struct.dirent*, %struct.dirent** %7
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = icmp eq i32 %49, 4
%51 = zext i1 %50 to i64
%52 = select i1 %50, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%53 = load i32, i32* @stdout
%54 = call i32 @fputs(i8* %52, i32 %53)
%55 = load %struct.dirent*, %struct.dirent** %7
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 1
%57 = load i8*, i8** %56
%58 = load i32, i32* @stdout
%59 = call i32 @fputs(i8* %57, i32 %58)
%60 = call i32 @puts(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %61
61: ; preds = %46
%62 = load i64, i64* %9
%63 = add nsw i64 %62, 1
store i64 %63, i64* %9
br label %25
64: ; preds = %25
%65 = load i64, i64* %9
%66 = add nsw i64 %65, -1
store i64 %66, i64* %9
%67 = call signext i8 (...) @getch()
store i8 %67, i8* %5
%68 = sext i8 %67 to i32
%69 = icmp eq i32 %68, 27
br i1 %69, label %70, label %94
70: ; preds = %64
%71 = call signext i8 (...) @getch()
%72 = call signext i8 (...) @getch()
store i8 %72, i8* %5
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 65
br i1 %74, label %75, label %81
75: ; preds = %70
%76 = load i64, i64* %4
%77 = icmp sgt i64 %76, 0
br i1 %77, label %78, label %81
78: ; preds = %75
%79 = load i64, i64* %4
%80 = add nsw i64 %79, -1
store i64 %80, i64* %4
br label %93
81: ; preds = %75, %70
%82 = load i8, i8* %5
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 66
br i1 %84, label %85, label %92
85: ; preds = %81
%86 = load i64, i64* %4
%87 = load i64, i64* %9
%88 = icmp slt i64 %86, %87
br i1 %88, label %89, label %92
89: ; preds = %85
%90 = load i64, i64* %4
%91 = add nsw i64 %90, 1
store i64 %91, i64* %4
br label %92
92: ; preds = %89, %85, %81
br label %93
93: ; preds = %92, %78
br label %139
94: ; preds = %64
%95 = load i8, i8* %5
%96 = sext i8 %95 to i32
%97 = icmp eq i32 %96, 10
br i1 %97, label %98, label %138
98: ; preds = %94
%99 = load i32, i32* %8
%100 = icmp ne i32 %99, 0
br i1 %100, label %101, label %114
101: ; preds = %98
%102 = load i8*, i8** %2
%103 = load i8*, i8** %2
%104 = call i32 @strlen(i8* %103)
%105 = sext i32 %104 to i64
%106 = getelementptr inbounds i8, i8* %102, i64 %105
store i8* %106, i8** %10
%107 = load i8*, i8** %10
%108 = getelementptr inbounds i8, i8* %107, i64 0
store i8 47, i8* %108
%109 = load i8*, i8** %10
%110 = getelementptr inbounds i8, i8* %109, i64 1
store i8 0, i8* %110
%111 = load i8*, i8** %2
%112 = load i8*, i8** %3
%113 = call i32 @strcat(i8* %111, i8* %112)
store i64 0, i64* %4
br label %137
114: ; preds = %98
%115 = call i8* @calloc(i32 4096, i32 1)
store i8* %115, i8** %11
%116 = load i8*, i8** %11
%117 = call i32 @strcpy(i8* %116, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%118 = load i8*, i8** %11
%119 = load i8*, i8** %2
%120 = call i32 @strcat(i8* %118, i8* %119)
%121 = load i8*, i8** %11
%122 = load i8*, i8** %11
%123 = call i32 @strlen(i8* %122)
%124 = sext i32 %123 to i64
%125 = getelementptr inbounds i8, i8* %121, i64 %124
store i8* %125, i8** %12
%126 = load i8*, i8** %12
%127 = getelementptr inbounds i8, i8* %126, i64 0
store i8 47, i8* %127
%128 = load i8*, i8** %12
%129 = getelementptr inbounds i8, i8* %128, i64 1
store i8 0, i8* %129
%130 = load i8*, i8** %11
%131 = load i8*, i8** %3
%132 = call i32 @strcat(i8* %130, i8* %131)
%133 = load i8*, i8** %11
%134 = call i32 @strcat(i8* %133, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%135 = load i8*, i8** %11
%136 = call i32 @system(i8* %135)
br label %137
137: ; preds = %114, %101
br label %138
138: ; preds = %137, %94
br label %139
139: ; preds = %138, %93
%140 = load i32*, i32** %6
%141 = call i32 @closedir(i32* %140)
br label %142
142: ; preds = %139
%143 = load i8, i8* %5
%144 = sext i8 %143 to i32
%145 = icmp ne i32 %144, 113
br i1 %145, label %146, label %150
146: ; preds = %142
%147 = load i8, i8* %5
%148 = sext i8 %147 to i32
%149 = icmp ne i32 %148, 81
br label %150
150: ; preds = %146, %142
%151 = phi i1 [ false, %142 ], [ %149, %146 ]
br i1 %151, label %18, label %152
152: ; preds = %150
%153 = load i32, i32* @stdout
%154 = call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %153)
%155 = load i32, i32* @stdout
%156 = call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %155)
%157 = call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
%158 = load i32, i32* %1
ret i32 %158
}

LLVM IR (-O2):
%struct.dirent = type { i32, i8* }
@.str = [20 x i8] c"setterm -cursor off\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [11 x i8] c"\1B[1;1H\1B[2J\00"
@stdout = global i32 0
@.str.3 = [8 x i8] c"\1B[1;32m\00"
@.str.4 = [4 x i8] c" + \00"
@.str.5 = [6 x i8] c" \E2\88\92 \00"
@.str.6 = [8 x i8] c"\1B[1;37m\00"
@.str.7 = [10 x i8] c"xdg-open \00"
@.str.8 = [27 x i8] c" 1> /dev/null 2> /dev/null\00"
@.str.9 = [5 x i8] c"\1B[0m\00"
@.str.10 = [19 x i8] c"setterm -cursor on\00"
define i32 @main() {
%1 = tail call i32 @system(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(4096) i8* @calloc(i32 4096, i32 1)
%3 = tail call dereferenceable_or_null(255) i8* @calloc(i32 255, i32 1)
%4 = tail call i32 @strcpy(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %5
5: ; preds = %83, %0
%6 = phi i32 [ undef, %0 ], [ %47, %83 ]
%7 = phi i64 [ 0, %0 ], [ %85, %83 ]
%8 = load i32, i32* @stdout
%9 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32* @opendir(i8* %2)
%11 = tail call %struct.dirent* @readdir(i32* %10)
%12 = tail call %struct.dirent* @readdir(i32* %10)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %45, label %14
14: ; preds = %5, %29
%15 = phi %struct.dirent* [ %43, %29 ], [ %12, %5 ]
%16 = phi i32 [ %30, %29 ], [ %6, %5 ]
%17 = phi i64 [ %42, %29 ], [ 0, %5 ]
%18 = icmp eq i64 %17, %7
br i1 %18, label %19, label %29
19: ; preds = %14
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, 4
%23 = zext i1 %22 to i32
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 1
%25 = load i8*, i8** %24
%26 = tail call i32 @strcpy(i8* %3, i8* %25)
%27 = load i32, i32* @stdout
%28 = tail call i32 @fputs(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %19, %14
%30 = phi i32 [ %23, %19 ], [ %16, %14 ]
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 0
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 4
%34 = select i1 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0)
%35 = load i32, i32* @stdout
%36 = tail call i32 @fputs(i8* %34, i32 %35)
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i64 0, i32 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @stdout
%40 = tail call i32 @fputs(i8* %38, i32 %39)
%41 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%42 = add nuw nsw i64 %17, 1
%43 = tail call %struct.dirent* @readdir(i32* %10)
%44 = icmp eq %struct.dirent* %43, null
br i1 %44, label %45, label %14
45: ; preds = %29, %5
%46 = phi i64 [ 0, %5 ], [ %42, %29 ]
%47 = phi i32 [ %6, %5 ], [ %30, %29 ]
%48 = add nsw i64 %46, -1
%49 = tail call signext i8 (...) @getch()
switch i8 %49, label %83 [
i8 27, label %50
i8 10, label %64
]
50: ; preds = %45
%51 = tail call signext i8 (...) @getch()
%52 = tail call signext i8 (...) @getch()
%53 = icmp eq i8 %52, 65
%54 = icmp sgt i64 %7, 0
%55 = select i1 %53, i1 %54, i1 false
br i1 %55, label %56, label %58
56: ; preds = %50
%57 = add nsw i64 %7, -1
br label %83
58: ; preds = %50
%59 = icmp eq i8 %52, 66
%60 = icmp slt i64 %7, %48
%61 = select i1 %59, i1 %60, i1 false
%62 = zext i1 %61 to i64
%63 = add nsw i64 %7, %62
br label %83
64: ; preds = %45
%65 = icmp eq i32 %47, 0
br i1 %65, label %72, label %66
66: ; preds = %64
%67 = tail call i32 @strlen(i8* %2)
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8, i8* %2, i64 %68
store i8 47, i8* %69
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8 0, i8* %70
%71 = tail call i32 @strcat(i8* %2, i8* %3)
br label %83
72: ; preds = %64
%73 = tail call dereferenceable_or_null(4096) i8* @calloc(i32 4096, i32 1)
%74 = tail call i32 @strcpy(i8* %73, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.7, i64 0, i64 0))
%75 = tail call i32 @strcat(i8* %73, i8* %2)
%76 = tail call i32 @strlen(i8* %73)
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %73, i64 %77
store i8 47, i8* %78
%79 = getelementptr inbounds i8, i8* %78, i64 1
store i8 0, i8* %79
%80 = tail call i32 @strcat(i8* %73, i8* %3)
%81 = tail call i32 @strcat(i8* %73, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%82 = tail call i32 @system(i8* %73)
br label %83
83: ; preds = %58, %45, %72, %66, %56
%84 = phi i8 [ 65, %56 ], [ 10, %66 ], [ 10, %72 ], [ %49, %45 ], [ %52, %58 ]
%85 = phi i64 [ %57, %56 ], [ 0, %66 ], [ %7, %72 ], [ %7, %45 ], [ %63, %58 ]
%86 = tail call i32 @closedir(i32* %10)
%87 = and i8 %84, -33
%88 = icmp eq i8 %87, 81
br i1 %88, label %89, label %5
89: ; preds = %83
%90 = load i32, i32* @stdout
%91 = tail call i32 @fputs(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0), i32 %90)
%92 = load i32, i32* @stdout
%93 = tail call i32 @fputs(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i32 %92)
%94 = tail call i32 @system(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}