#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;
};

/* Variables and functions */
int /*<<< orphan*/ alphasort;
int /*<<< orphan*/ getcwd(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int scandir(char *, struct dirent ***, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  struct dirent **namelist;
  int n, i;
  char pathname[100];
  getcwd(pathname);
  n = scandir(pathname, &namelist, 0, alphasort);
  if (n < 0) {
    perror("scandir");
  } else {
    for (i = 0; i < n; i++) {
      if (namelist[i]->d_name[0] != '.') {
        printf("%s \n", namelist[i]->d_name);
      }
    }
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <getcwd@plt>
lea    -0x80(%rbp),%rdi
mov    0x2e7a(%rip),%rax
mov    (%rax),%ecx
lea    -0x10(%rbp),%rsi
xor    %edx,%edx
call   1040 <scandir@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1191 <main+0x51>
lea    0xe79(%rip),%rdi
call   1060 <perror@plt>
jmp    11f4 <main+0xb4>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ef <main+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11dc <main+0x9c>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%rsi
lea    0xe33(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11e1 <main+0xa1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <main+0x58>
jmp    11f4 <main+0xb4>
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <getcwd@plt>
mov    0x2e70(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <scandir@plt>
test   %eax,%eax
js     11c6 <main+0x76>
je     11d2 <main+0x82>
mov    %eax,%r15d
lea    0xe77(%rip),%r14
xor    %ebx,%ebx
jmp    11a9 <main+0x59>
cs nopw 0x0(%rax,%rax,1)
nop
add    $0x1,%rbx
cmp    %rbx,%r15
je     11d2 <main+0x82>
mov    0x8(%rsp),%rax
mov    (%rax,%rbx,8),%rax
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11a0 <main+0x50>
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11a0 <main+0x50>
lea    0xe33(%rip),%rdi
call   1070 <perror@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@alphasort = global i32 0
@.str = [8 x i8] c"scandir\00"
@.str.1 = [5 x i8] c"%s \0A\00"
@.str.2 = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.dirent**
%3 = alloca i32
%4 = alloca i32
%5 = alloca [100 x i8]
store i32 0, i32* %1
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%7 = call i32 @getcwd(i8* %6)
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @alphasort
%10 = call i32 @scandir(i8* %8, %struct.dirent*** %2, i32 0, i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %46
15: ; preds = %0
store i32 0, i32* %4
br label %16
16: ; preds = %42, %15
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = load %struct.dirent**, %struct.dirent*** %2
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds %struct.dirent*, %struct.dirent** %21, i64 %23
%25 = load %struct.dirent*, %struct.dirent** %24
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i32 0, i32 0
%27 = load i8*, i8** %26
%28 = getelementptr inbounds i8, i8* %27, i64 0
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 46
br i1 %31, label %32, label %41
32: ; preds = %20
%33 = load %struct.dirent**, %struct.dirent*** %2
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds %struct.dirent*, %struct.dirent** %33, i64 %35
%37 = load %struct.dirent*, %struct.dirent** %36
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %32, %20
br label %42
42: ; preds = %41
%43 = load i32, i32* %4
%44 = add nsw i32 %43, 1
store i32 %44, i32* %4
br label %16
45: ; preds = %16
br label %46
46: ; preds = %45, %13
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@alphasort = global i32 0
@.str = [8 x i8] c"scandir\00"
@.str.1 = [5 x i8] c"%s \0A\00"
define i32 @main() {
%1 = alloca %struct.dirent**
%2 = alloca [100 x i8]
%3 = bitcast %struct.dirent*** %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = call i32 @getcwd(i8* %4)
%6 = load i32, i32* @alphasort
%7 = call i32 @scandir(i8* %4, %struct.dirent*** %1, i32 0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %0
%10 = icmp eq i32 %7, 0
br i1 %10, label %29, label %11
11: ; preds = %9
%12 = zext i32 %7 to i64
br label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
br label %29
15: ; preds = %11, %26
%16 = phi i64 [ 0, %11 ], [ %27, %26 ]
%17 = load %struct.dirent**, %struct.dirent*** %1
%18 = getelementptr inbounds %struct.dirent*, %struct.dirent** %17, i64 %16
%19 = load %struct.dirent*, %struct.dirent** %18
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 46
br i1 %23, label %26, label %24
24: ; preds = %15
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* %21)
br label %26
26: ; preds = %15, %24
%27 = add nuw nsw i64 %16, 1
%28 = icmp eq i64 %27, %12
br i1 %28, label %29, label %15
29: ; preds = %26, %9, %13
%30 = call i32 @putchar(i32 10)
ret i32 0
}