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

/* Variables and functions */
scalar_t__ DT_REG;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, long, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strstr(int /*<<< orphan*/, char *);
char **get_file_list(const char *path, int count) {
  DIR *dp = NULL;
  struct dirent *ep = NULL;
  int i = 0;
  if ((dp = opendir(path)) == NULL) {
    perror("opendir");
    exit(1);
  }
  char **list = (char **)calloc(count, 255);
  if (list == NULL) {
    perror("calloc");
    exit(1);
  }
  while ((ep = readdir(dp))) {
    if (ep->d_type == DT_REG && !strstr(ep->d_name, ".")) {
      list[i] = (char *)malloc(sizeof(char) * strlen(ep->d_name) + 1);
      memset(list[i], 0L, strlen(ep->d_name));
      strncpy(list[i], ep->d_name, strlen(ep->d_name));
      i++;
    }
  }
  closedir(dp);
  return list;
}


x86 assembly (clang, -O0):
<get_file_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1203 <get_file_list+0x53>
lea    0xe0c(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0xc(%rbp),%edi
mov    $0xff,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1235 <get_file_list+0x85>
lea    0xde2(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    123a <get_file_list+0x8a>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     131d <get_file_list+0x16d>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    0x2d81(%rip),%rcx
cmp    (%rcx),%rax
jne    1318 <get_file_list+0x168>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
lea    0xd99(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%eax
jne    1318 <get_file_list+0x168>
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <strlen@plt>
cltq
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,%rdx
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <strlen@plt>
mov    -0x48(%rbp),%rdi
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%esi
call   1060 <memset@plt>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%edi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123a <get_file_list+0x8a>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x30(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%ebx
call   1040 <opendir@plt>
test   %rax,%rax
je     12ba <get_file_list+0x10a>
mov    %rax,%r12
mov    %ebx,%edi
mov    $0xff,%esi
call   1080 <calloc@plt>
mov    %rax,(%rsp)
test   %rax,%rax
je     12c3 <get_file_list+0x113>
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     129f <get_file_list+0xef>
mov    %rax,%rbx
xor    %r14d,%r14d
mov    0x2ddb(%rip),%r15
lea    0xe03(%rip),%rbp
jmp    1220 <get_file_list+0x70>
xchg   %ax,%ax
mov    %r12,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     129f <get_file_list+0xef>
mov    (%rbx),%rax
cmp    (%r15),%rax
jne    1210 <get_file_list+0x60>
mov    0x8(%rbx),%edi
mov    %rbp,%rsi
call   10d0 <strstr@plt>
test   %eax,%eax
jne    1210 <get_file_list+0x60>
mov    0x8(%rbx),%edi
call   1050 <strlen@plt>
lea    0x1(%rax),%edi
call   10a0 <malloc@plt>
mov    %rax,%r13
movslq %r14d,%r14
mov    %r12,%rbp
mov    %r15,%r12
mov    (%rsp),%r15
mov    %rax,(%r15,%r14,8)
mov    0x8(%rbx),%edi
call   1050 <strlen@plt>
mov    %r13,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1060 <memset@plt>
mov    (%r15,%r14,8),%r13
mov    %r12,%r15
mov    %rbp,%r12
mov    0x8(%rbx),%ebx
mov    %ebx,%edi
call   1050 <strlen@plt>
mov    %r13,%rdi
lea    0xd82(%rip),%rbp
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <strncpy@plt>
add    $0x1,%r14d
jmp    1210 <get_file_list+0x60>
mov    %r12,%rdi
call   1070 <closedir@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd3f(%rip),%rdi
jmp    12ca <get_file_list+0x11a>
lea    0xd3e(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i64, i32 }
@.str = [8 x i8] c"opendir\00"
@.str.1 = [7 x i8] c"calloc\00"
@DT_REG = global i64 0
@.str.2 = [2 x i8] c".\00"
define i8** @get_file_list(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca i32
%8 = alloca i8**
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32* null, i32** %5
store %struct.dirent* null, %struct.dirent** %6
store i32 0, i32* %7
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i32, i32* %4
%17 = call i64 @calloc(i32 %16, i32 255)
%18 = inttoptr i64 %17 to i8**
store i8** %18, i8*** %8
%19 = load i8**, i8*** %8
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
br label %25
25: ; preds = %81, %24
%26 = load i32*, i32** %5
%27 = call %struct.dirent* @readdir(i32* %26)
store %struct.dirent* %27, %struct.dirent** %6
%28 = icmp ne %struct.dirent* %27, null
br i1 %28, label %29, label %82
29: ; preds = %25
%30 = load %struct.dirent*, %struct.dirent** %6
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = load i64, i64* @DT_REG
%34 = icmp eq i64 %32, %33
br i1 %34, label %35, label %81
35: ; preds = %29
%36 = load %struct.dirent*, %struct.dirent** %6
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = call i32 @strstr(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = icmp ne i32 %39, 0
br i1 %40, label %81, label %41
41: ; preds = %35
%42 = load %struct.dirent*, %struct.dirent** %6
%43 = getelementptr inbounds %struct.dirent, %struct.dirent* %42, i32 0, i32 1
%44 = load i32, i32* %43
%45 = call i32 @strlen(i32 %44)
%46 = sext i32 %45 to i64
%47 = mul i64 1, %46
%48 = add i64 %47, 1
%49 = trunc i64 %48 to i32
%50 = call i64 @malloc(i32 %49)
%51 = inttoptr i64 %50 to i8*
%52 = load i8**, i8*** %8
%53 = load i32, i32* %7
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8*, i8** %52, i64 %54
store i8* %51, i8** %55
%56 = load i8**, i8*** %8
%57 = load i32, i32* %7
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
%61 = load %struct.dirent*, %struct.dirent** %6
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %61, i32 0, i32 1
%63 = load i32, i32* %62
%64 = call i32 @strlen(i32 %63)
%65 = call i32 @memset(i8* %60, i64 0, i32 %64)
%66 = load i8**, i8*** %8
%67 = load i32, i32* %7
%68 = sext i32 %67 to i64
%69 = getelementptr inbounds i8*, i8** %66, i64 %68
%70 = load i8*, i8** %69
%71 = load %struct.dirent*, %struct.dirent** %6
%72 = getelementptr inbounds %struct.dirent, %struct.dirent* %71, i32 0, i32 1
%73 = load i32, i32* %72
%74 = load %struct.dirent*, %struct.dirent** %6
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 1
%76 = load i32, i32* %75
%77 = call i32 @strlen(i32 %76)
%78 = call i32 @strncpy(i8* %70, i32 %73, i32 %77)
%79 = load i32, i32* %7
%80 = add nsw i32 %79, 1
store i32 %80, i32* %7
br label %81
81: ; preds = %41, %35, %29
br label %25
82: ; preds = %25
%83 = load i32*, i32** %5
%84 = call i32 @closedir(i32* %83)
%85 = load i8**, i8*** %8
ret i8** %85
}

LLVM IR (-O2):
%struct.dirent = type { i64, i32 }
@.str = [8 x i8] c"opendir\00"
@.str.1 = [7 x i8] c"calloc\00"
@DT_REG = global i64 0
@.str.2 = [2 x i8] c".\00"
define i8** @get_file_list(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i64 @calloc(i32 %1, i32 255)
%10 = inttoptr i64 %9 to i8**
%11 = icmp eq i64 %9, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = tail call %struct.dirent* @readdir(i32* %3)
%14 = icmp eq %struct.dirent* %13, null
br i1 %14, label %50, label %18
15: ; preds = %8
%16 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %46
%19 = phi %struct.dirent* [ %48, %46 ], [ %13, %12 ]
%20 = phi i32 [ %47, %46 ], [ 0, %12 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%22 = load i64, i64* %21
%23 = load i64, i64* @DT_REG
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %46
25: ; preds = %18
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 1
%27 = load i32, i32* %26
%28 = tail call i32 @strstr(i32 %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %46
30: ; preds = %25
%31 = load i32, i32* %26
%32 = tail call i32 @strlen(i32 %31)
%33 = add i32 %32, 1
%34 = tail call i64 @malloc(i32 %33)
%35 = inttoptr i64 %34 to i8*
%36 = sext i32 %20 to i64
%37 = getelementptr inbounds i8*, i8** %10, i64 %36
store i8* %35, i8** %37
%38 = load i32, i32* %26
%39 = tail call i32 @strlen(i32 %38)
%40 = tail call i32 @memset(i8* %35, i64 0, i32 %39)
%41 = load i8*, i8** %37
%42 = load i32, i32* %26
%43 = tail call i32 @strlen(i32 %42)
%44 = tail call i32 @strncpy(i8* %41, i32 %42, i32 %43)
%45 = add nsw i32 %20, 1
br label %46
46: ; preds = %30, %25, %18
%47 = phi i32 [ %20, %25 ], [ %45, %30 ], [ %20, %18 ]
%48 = tail call %struct.dirent* @readdir(i32* %3)
%49 = icmp eq %struct.dirent* %48, null
br i1 %49, label %50, label %18
50: ; preds = %46, %12
%51 = tail call i32 @closedir(i32* %3)
ret i8** %10
}