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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void get_file(char *file) {
  DIR *cur_dir;
  cur_dir;
  struct dirent *next;
  char to_open[60];
  cur_dir = opendir(".//hortfiles/");
  printf("These are the files available:");
  while (next != NULL) {
    printf("\n -- %s", next->d_name);
    next = readdir(cur_dir);
  }
  strcpy(file, ".//hortfiles/");
  printf("\nWhat file do you want?");
  scanf(" %s", to_open);
  strcat(file, to_open);
  closedir(cur_dir);
}


x86 assembly (clang, -O0):
<get_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe7d(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
lea    0xe7b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpq   $0x0,-0x18(%rbp)
je     11cc <get_file+0x5c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
jmp    119a <get_file+0x2a>
mov    -0x8(%rbp),%rdi
lea    0xe29(%rip),%rsi
call   1030 <strcpy@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x60(%rbp),%rsi
lea    0xe3c(%rip),%rdi
call   1080 <scanf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file>:
push   %rax
lea    0xed8(%rip),%rdi
call   1030 <opendir@plt>
lea    0xeda(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [14 x i8] c".//hortfiles/\00"
@.str.1 = [31 x i8] c"These are the files available:\00"
@.str.2 = [8 x i8] c"\0A -- %s\00"
@.str.3 = [24 x i8] c"\0AWhat file do you want?\00"
@.str.4 = [4 x i8] c" %s\00"
define void @get_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca [60 x i8]
store i8* %0, i8** %2
%6 = load i32*, i32** %3
%7 = call i32* @opendir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %12, %1
%10 = load %struct.dirent*, %struct.dirent** %4
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = load %struct.dirent*, %struct.dirent** %4
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %3
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %4
br label %9
19: ; preds = %9
%20 = load i8*, i8** %2
%21 = call i32 @strcpy(i8* %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds [60 x i8], [60 x i8]* %5, i64 0, i64 0
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %2
%26 = getelementptr inbounds [60 x i8], [60 x i8]* %5, i64 0, i64 0
%27 = call i32 @strcat(i8* %25, i8* %26)
%28 = load i32*, i32** %3
%29 = call i32 @closedir(i32* %28)
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c".//hortfiles/\00"
@.str.1 = [31 x i8] c"These are the files available:\00"
define void @get_file(i8* %0) {
%2 = tail call i32* @opendir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%3 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
unreachable
}