#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*/ ZSortDirStrings(char **);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char **YDirRead(void) {
  int i;
  static char *buffer[200];
  static char fnames[200][20];
  DIR *dirp, *dirtemp;
  struct dirent *direntp;
  dirp = opendir(".");
  i = 0;
  while ((direntp = readdir(dirp)) != NULL) {
    if (!strcmp(direntp->d_name, "."))
      continue;
    if ((dirtemp = opendir(direntp->d_name))) {
      fnames[i][0] = '\\';
      closedir(dirtemp);
    } else
      fnames[i][0] = ' ';
    if (strlen(direntp->d_name) > 20 - 2 || i > 200 - 1) {
      fprintf(stderr, "ERROR: %s \n", ("YDirRead"));
      exit(0);
    };
    strcpy(&(fnames[i][1]), direntp->d_name);
    buffer[i] = &(fnames[i][0]);
    i++;
  }
  closedir(dirp);
  buffer[i] = NULL;
  ZSortDirStrings(buffer);
  return (buffer);
}


x86 assembly (clang, -O0):
<YDirRead>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe61(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x4(%rbp)
mov    -0x10(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12cf <YDirRead+0x13f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe2c(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    11e7 <YDirRead+0x57>
jmp    11af <YDirRead+0x1f>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1224 <YDirRead+0x94>
movslq -0x4(%rbp),%rcx
lea    0x34b4(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movb   $0x5c,(%rax)
mov    -0x18(%rbp),%rdi
call   1060 <closedir@plt>
jmp    1239 <YDirRead+0xa9>
movslq -0x4(%rbp),%rcx
lea    0x3491(%rip),%rax
imul   $0x14,%rcx,%rcx
add    %rcx,%rax
movb   $0x20,(%rax)
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
cmp    $0x12,%eax
jg     125b <YDirRead+0xcb>
cmpl   $0xc7,-0x4(%rbp)
jle    127e <YDirRead+0xee>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xd97(%rip),%rsi
lea    0xd9c(%rip),%rdx
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
movslq -0x4(%rbp),%rax
lea    0x3437(%rip),%rdi
imul   $0x14,%rax,%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   1030 <strcpy@plt>
movslq -0x4(%rbp),%rax
lea    0x3415(%rip),%rdx
imul   $0x14,%rax,%rax
add    %rax,%rdx
movslq -0x4(%rbp),%rcx
lea    0x2dc3(%rip),%rax
mov    %rdx,(%rax,%rcx,8)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    11af <YDirRead+0x1f>
mov    -0x10(%rbp),%rdi
call   1060 <closedir@plt>
movslq -0x4(%rbp),%rcx
lea    0x2d9d(%rip),%rax
movq   $0x0,(%rax,%rcx,8)
lea    0x2d8e(%rip),%rdi
call   10b0 <ZSortDirStrings@plt>
lea    0x2d82(%rip),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<YDirRead>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe5e(%rip),%r15
mov    %r15,%rdi
call   1040 <opendir@plt>
mov    %rax,%r12
xor    %r14d,%r14d
lea    0x2ec9(%rip),%rbp
nopw   0x0(%rax,%rax,1)
mov    %r12,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1257 <YDirRead+0xc7>
mov    %rax,%r13
mov    (%rax),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11c0 <YDirRead+0x30>
mov    %rbx,%rdi
call   1040 <opendir@plt>
lea    (%r14,%r14,4),%rbx
lea    0x34c7(%rip),%rcx
lea    (%rcx,%rbx,4),%rcx
test   %rax,%rax
mov    %rcx,(%rsp)
je     1213 <YDirRead+0x83>
movb   $0x5c,(%rcx)
mov    %rax,%rdi
call   1060 <closedir@plt>
jmp    1216 <YDirRead+0x86>
movb   $0x20,(%rcx)
mov    0x0(%r13),%rdi
call   1050 <strlen@plt>
cmp    $0x12,%eax
jg     1285 <YDirRead+0xf5>
cmp    $0xc8,%r14
jae    1285 <YDirRead+0xf5>
lea    0x348c(%rip),%rax
lea    (%rax,%rbx,4),%rdi
add    $0x1,%rdi
mov    0x0(%r13),%rsi
call   1030 <strcpy@plt>
mov    (%rsp),%rax
mov    %rax,0x0(%rbp,%r14,8)
add    $0x1,%r14
jmp    11c0 <YDirRead+0x30>
mov    %r12,%rdi
call   1060 <closedir@plt>
mov    %r14d,%eax
movq   $0x0,0x0(%rbp,%rax,8)
mov    %rbp,%rdi
call   10b0 <ZSortDirStrings@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d54(%rip),%rax
mov    (%rax),%edi
lea    0xd6d(%rip),%rsi
lea    0xd72(%rip),%rdx
call   1080 <fprintf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@YDirRead.buffer = internal global [200 x i8*] zeroinitializer
@YDirRead.fnames = internal global [200 x [20 x i8]] zeroinitializer
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"ERROR: %s \0A\00"
@.str.2 = [9 x i8] c"YDirRead\00"
define i8** @YDirRead() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %2
store i32 0, i32* %1
br label %6
6: ; preds = %48, %16, %0
%7 = load i32*, i32** %2
%8 = call %struct.dirent* @readdir(i32* %7)
store %struct.dirent* %8, %struct.dirent** %4
%9 = icmp ne %struct.dirent* %8, null
br i1 %9, label %10, label %66
10: ; preds = %6
%11 = load %struct.dirent*, %struct.dirent** %4
%12 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i32 0, i32 0
%13 = load i8*, i8** %12
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %10
br label %6
17: ; preds = %10
%18 = load %struct.dirent*, %struct.dirent** %4
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i8*, i8** %19
%21 = call i32* @opendir(i8* %20)
store i32* %21, i32** %3
%22 = icmp ne i32* %21, null
br i1 %22, label %23, label %30
23: ; preds = %17
%24 = load i32, i32* %1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %25
%27 = getelementptr inbounds [20 x i8], [20 x i8]* %26, i64 0, i64 0
store i8 92, i8* %27
%28 = load i32*, i32** %3
%29 = call i32 @closedir(i32* %28)
br label %35
30: ; preds = %17
%31 = load i32, i32* %1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %32
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %33, i64 0, i64 0
store i8 32, i8* %34
br label %35
35: ; preds = %30, %23
%36 = load %struct.dirent*, %struct.dirent** %4
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
%39 = call i32 @strlen(i8* %38)
%40 = icmp sgt i32 %39, 18
br i1 %40, label %44, label %41
41: ; preds = %35
%42 = load i32, i32* %1
%43 = icmp sgt i32 %42, 199
br i1 %43, label %44, label %48
44: ; preds = %41, %35
%45 = load i32, i32* @stderr
%46 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%47 = call i32 @exit(i32 0)
unreachable
48: ; preds = %41
%49 = load i32, i32* %1
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %50
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %51, i64 0, i64 1
%53 = load %struct.dirent*, %struct.dirent** %4
%54 = getelementptr inbounds %struct.dirent, %struct.dirent* %53, i32 0, i32 0
%55 = load i8*, i8** %54
%56 = call i32 @strcpy(i8* %52, i8* %55)
%57 = load i32, i32* %1
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %58
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %59, i64 0, i64 0
%61 = load i32, i32* %1
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds [200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 %62
store i8* %60, i8** %63
%64 = load i32, i32* %1
%65 = add nsw i32 %64, 1
store i32 %65, i32* %1
br label %6
66: ; preds = %6
%67 = load i32*, i32** %2
%68 = call i32 @closedir(i32* %67)
%69 = load i32, i32* %1
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 %70
store i8* null, i8** %71
%72 = call i32 @ZSortDirStrings(i8** getelementptr inbounds ([200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 0))
ret i8** getelementptr inbounds ([200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@YDirRead.buffer = internal global [200 x i8*] zeroinitializer
@YDirRead.fnames = internal global [200 x [20 x i8]] zeroinitializer
@.str = [2 x i8] c".\00"
@stderr = global i32 0
@.str.1 = [12 x i8] c"ERROR: %s \0A\00"
@.str.2 = [9 x i8] c"YDirRead\00"
define i8** @YDirRead() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %2
2: ; preds = %30, %0
%3 = phi i64 [ %36, %30 ], [ 0, %0 ]
br label %4
4: ; preds = %2, %7
%5 = tail call %struct.dirent* @readdir(i32* %1)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %37, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %9, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %4, label %12
12: ; preds = %7
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %5, i64 0, i32 0
%14 = tail call i32* @opendir(i8* %9)
%15 = icmp eq i32* %14, null
%16 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %3, i64 0
br i1 %15, label %19, label %17
17: ; preds = %12
store i8 92, i8* %16
%18 = tail call i32 @closedir(i32* %14)
br label %20
19: ; preds = %12
store i8 32, i8* %16
br label %20
20: ; preds = %19, %17
%21 = load i8*, i8** %13
%22 = tail call i32 @strlen(i8* %21)
%23 = icmp sgt i32 %22, 18
%24 = icmp ugt i64 %3, 199
%25 = select i1 %23, i1 true, i1 %24
br i1 %25, label %26, label %30
26: ; preds = %20
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%29 = tail call i32 @exit(i32 0)
unreachable
30: ; preds = %20
%31 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %3, i64 1
%32 = load i8*, i8** %13
%33 = tail call i32 @strcpy(i8* %31, i8* %32)
%34 = getelementptr inbounds [200 x [20 x i8]], [200 x [20 x i8]]* @YDirRead.fnames, i64 0, i64 %3, i64 0
%35 = getelementptr inbounds [200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 %3
store i8* %34, i8** %35
%36 = add nuw nsw i64 %3, 1
br label %2
37: ; preds = %4
%38 = tail call i32 @closedir(i32* %1)
%39 = and i64 %3, 4294967295
%40 = getelementptr inbounds [200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 %39
store i8* null, i8** %40
%41 = tail call i32 @ZSortDirStrings(i8** getelementptr inbounds ([200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 0))
ret i8** getelementptr inbounds ([200 x i8*], [200 x i8*]* @YDirRead.buffer, i64 0, i64 0)
}