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

/* Variables and functions */
scalar_t__ asprintf(char **, char *, char *, ...);
int /*<<< orphan*/ getcwd(char *, int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
const char *getDir() {
  char path[1024];
  getcwd(path, 1024);
  printf("Dir :: %s\n", path);
  struct dirent *ent;
  DIR *directory;
  directory = opendir(path);
  int fileCnt = 0;
  char *dirListPtr;
  char *temp;
  int flag = 0;
  while ((ent = readdir(directory)) != NULL) {
    if (strcmp(ent->d_name, ".") == 0) {
    } else if (strcmp(ent->d_name, "..") == 0) {
    } else {
      fileCnt++;
      if (flag == 0) {
        if (asprintf(&dirListPtr, "%s\n", ent->d_name))
          ;
        flag = 1;
      } else {
        if (asprintf(&temp, "%s", dirListPtr))
          ;
        if (asprintf(&dirListPtr, "%s%s\n", temp, ent->d_name))
          ;
      }
    }
  }
  return dirListPtr;
}


x86 assembly (clang, -O0):
<getDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
lea    -0x400(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    -0x400(%rbp),%rsi
lea    0xe76(%rip),%rdi
call   1040 <printf@plt>
lea    -0x400(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x410(%rbp)
movl   $0x0,-0x414(%rbp)
movl   $0x0,-0x42c(%rbp)
mov    -0x410(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x408(%rbp)
cmp    $0x0,%rax
je     12e7 <getDir+0x187>
mov    -0x408(%rbp),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11f7 <getDir+0x97>
jmp    12e2 <getDir+0x182>
mov    -0x408(%rbp),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    121b <getDir+0xbb>
jmp    12dd <getDir+0x17d>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x42c(%rbp)
jne    1274 <getDir+0x114>
mov    -0x408(%rbp),%rax
movslq (%rax),%rdx
lea    -0x420(%rbp),%rdi
lea    0xdb8(%rip),%rsi
mov    $0x0,%al
call   1080 <asprintf@plt>
cmp    $0x0,%rax
je     1265 <getDir+0x105>
jmp    1265 <getDir+0x105>
movl   $0x1,-0x42c(%rbp)
jmp    12d8 <getDir+0x178>
mov    -0x420(%rbp),%rdx
lea    -0x428(%rbp),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1080 <asprintf@plt>
cmp    $0x0,%rax
je     129f <getDir+0x13f>
jmp    129f <getDir+0x13f>
mov    -0x428(%rbp),%rdx
mov    -0x408(%rbp),%rax
mov    (%rax),%ecx
lea    -0x420(%rbp),%rdi
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1080 <asprintf@plt>
cmp    $0x0,%rax
je     12d3 <getDir+0x173>
jmp    12d3 <getDir+0x173>
jmp    12d8 <getDir+0x178>
jmp    12dd <getDir+0x17d>
jmp    12e2 <getDir+0x182>
jmp    11b6 <getDir+0x56>
mov    -0x420(%rbp),%rax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
lea    0xe76(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1259 <getDir+0xf9>
mov    %rax,%r12
lea    0xe54(%rip),%r14
lea    0xe4c(%rip),%r15
mov    %rsp,%r13
xor    %ebp,%ebp
jmp    1216 <getDir+0xb6>
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp),%rdx
lea    0x8(%rsp),%rdi
lea    0xe2e(%rip),%rsi
xor    %eax,%eax
call   1080 <asprintf@plt>
mov    0x8(%rsp),%rdx
mov    (%r12),%ecx
mov    %r13,%rdi
lea    0xe17(%rip),%rsi
xor    %eax,%eax
call   1080 <asprintf@plt>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1253 <getDir+0xf3>
mov    (%r12),%edi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1206 <getDir+0xa6>
mov    (%r12),%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     1206 <getDir+0xa6>
test   %ebp,%ebp
jne    11d0 <getDir+0x70>
movslq (%r12),%rdx
mov    %r13,%rdi
lea    0xdbd(%rip),%rsi
xor    %eax,%eax
call   1080 <asprintf@plt>
jmp    1201 <getDir+0xa1>
mov    (%rsp),%rax
jmp    1259 <getDir+0xf9>
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [11 x i8] c"Dir :: %s\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"%s%s\0A\00"
define i8* @getDir() {
%1 = alloca [1024 x i8]
%2 = alloca %struct.dirent*
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%9 = call i32 @getcwd(i8* %8, i32 1024)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%13 = call i32* @opendir(i8* %12)
store i32* %13, i32** %3
store i32 0, i32* %4
store i32 0, i32* %7
br label %14
14: ; preds = %63, %0
%15 = load i32*, i32** %3
%16 = call %struct.dirent* @readdir(i32* %15)
store %struct.dirent* %16, %struct.dirent** %2
%17 = icmp ne %struct.dirent* %16, null
br i1 %17, label %18, label %64
18: ; preds = %14
%19 = load %struct.dirent*, %struct.dirent** %2
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @strcmp(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18
br label %63
25: ; preds = %18
%26 = load %struct.dirent*, %struct.dirent** %2
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i64 @strcmp(i32 %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
br i1 %30, label %31, label %32
31: ; preds = %25
br label %62
32: ; preds = %25
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
%35 = load i32, i32* %7
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %47
37: ; preds = %32
%38 = load %struct.dirent*, %struct.dirent** %2
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i8*
%43 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37
br label %46
46: ; preds = %45, %37
store i32 1, i32* %7
br label %61
47: ; preds = %32
%48 = load i8*, i8** %5
%49 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %47
br label %52
52: ; preds = %51, %47
%53 = load i8*, i8** %6
%54 = load %struct.dirent*, %struct.dirent** %2
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i32, i32* %55
%57 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %53, i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %52
br label %60
60: ; preds = %59, %52
br label %61
61: ; preds = %60, %46
br label %62
62: ; preds = %61, %31
br label %63
63: ; preds = %62, %24
br label %14
64: ; preds = %14
%65 = load i8*, i8** %5
ret i8* %65
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [11 x i8] c"Dir :: %s\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [6 x i8] c"%s%s\0A\00"
define i8* @getDir() {
%1 = alloca [1024 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = call i32 @getcwd(i8* %4, i32 1024)
%6 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %4)
%7 = call i32* @opendir(i8* %4)
%8 = bitcast i8** %2 to i8*
%9 = bitcast i8** %3 to i8*
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %42, label %12
12: ; preds = %0, %36
%13 = phi %struct.dirent* [ %38, %36 ], [ %10, %0 ]
%14 = phi i32 [ %37, %36 ], [ 0, %0 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i64 @strcmp(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %36, label %19
19: ; preds = %12
%20 = load i32, i32* %15
%21 = call i64 @strcmp(i32 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %36, label %23
23: ; preds = %19
%24 = icmp eq i32 %14, 0
br i1 %24, label %25, label %30
25: ; preds = %23
%26 = load i32, i32* %15
%27 = sext i32 %26 to i64
%28 = inttoptr i64 %27 to i8*
%29 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %28)
br label %36
30: ; preds = %23
%31 = load i8*, i8** %2
%32 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %31)
%33 = load i8*, i8** %3
%34 = load i32, i32* %15
%35 = call i64 (i8**, i8*, i8*, ...) @asprintf(i8** %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %33, i32 %34)
br label %36
36: ; preds = %19, %30, %25, %12
%37 = phi i32 [ %14, %12 ], [ %14, %19 ], [ 1, %25 ], [ 1, %30 ]
%38 = call %struct.dirent* @readdir(i32* %7)
%39 = icmp eq %struct.dirent* %38, null
br i1 %39, label %40, label %12
40: ; preds = %36
%41 = load i8*, i8** %2
br label %42
42: ; preds = %40, %0
%43 = phi i8* [ %41, %40 ], [ undef, %0 ]
ret i8* %43
}