#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 *, ...);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ scanf(char *, char **);
int /*<<< orphan*/ system(char *);
int main(void) {
  system("clear");
  DIR *d;
  struct dirent *dir;
  char path[400];
  puts("Enter full path name of directory you want to view:");
  scanf("%s", &path);
  d = opendir(path);
  if (d) {
    printf("The Directory Contents are .\n/******************************/ \n");
    while ((dir = readdir(d)) != NULL) {
      printf("%s\n", dir->d_name);
    }
    closedir(d);
  } else
    printf("Directory doesnt exist");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe77(%rip),%rdi
call   1050 <system@plt>
lea    0xe71(%rip),%rdi
call   1030 <puts@plt>
lea    -0x1b0(%rbp),%rsi
lea    0xe92(%rip),%rdi
call   1090 <scanf@plt>
lea    -0x1b0(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1215 <main+0xa5>
lea    0xe6e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1207 <main+0x97>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    11d6 <main+0x66>
mov    -0x10(%rbp),%rdi
call   1070 <closedir@plt>
jmp    1223 <main+0xb3>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x190,%rsp
lea    0xe81(%rip),%rdi
call   1050 <system@plt>
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
lea    0xea3(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1090 <scanf@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11e1 <main+0x71>
mov    %rax,%rbx
lea    0xe9b(%rip),%rdi
nopl   0x0(%rax)
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11d7 <main+0x67>
mov    (%rax),%rdi
jmp    11c0 <main+0x50>
mov    %rbx,%rdi
call   1070 <closedir@plt>
jmp    11ef <main+0x7f>
lea    0xe55(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %eax,%eax
add    $0x190,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"clear\00"
@.str.1 = [52 x i8] c"Enter full path name of directory you want to view:\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [64 x i8] c"The Directory Contents are .\0A/******************************/ \0A\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [23 x i8] c"Directory doesnt exist\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca %struct.dirent*
%4 = alloca [400 x i8]
store i32 0, i32* %1
%5 = call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @puts(i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%7 = bitcast [400 x i8]* %4 to i8**
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %7)
%9 = getelementptr inbounds [400 x i8], [400 x i8]* %4, i64 0, i64 0
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %2
%11 = load i32*, i32** %2
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %27
13: ; preds = %0
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %19, %13
%16 = load i32*, i32** %2
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %3
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %24
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %3
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %22)
br label %15
24: ; preds = %15
%25 = load i32*, i32** %2
%26 = call i32 @closedir(i32* %25)
br label %29
27: ; preds = %0
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %29
29: ; preds = %27, %24
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"clear\00"
@.str.1 = [52 x i8] c"Enter full path name of directory you want to view:\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.5 = [23 x i8] c"Directory doesnt exist\00"
@str = [63 x i8] c"The Directory Contents are .\0A/******************************/ \00"
define i32 @main() {
%1 = alloca [400 x i8]
%2 = tail call i32 @system(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%3 = getelementptr inbounds [400 x i8], [400 x i8]* %1, i64 0, i64 0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%5 = bitcast [400 x i8]* %1 to i8**
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8** %5)
%7 = call i32* @opendir(i8* %3)
%8 = icmp eq i32* %7, null
br i1 %8, label %22, label %9
9: ; preds = %0
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([63 x i8], [63 x i8]* @str, i64 0, i64 0))
%11 = call %struct.dirent* @readdir(i32* %7)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %20, label %13
13: ; preds = %9, %13
%14 = phi %struct.dirent* [ %18, %13 ], [ %11, %9 ]
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i64 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @puts(i8* dereferenceable(1) %16)
%18 = call %struct.dirent* @readdir(i32* %7)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %20, label %13
20: ; preds = %13, %9
%21 = call i32 @closedir(i32* %7)
br label %24
22: ; preds = %0
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %24
24: ; preds = %22, %20
ret i32 0
}