#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*/ die(char *);
int /*<<< orphan*/ free(struct dirent **);
int /*<<< orphan*/ get_dir(char *);
int /*<<< orphan*/ printf(char *, char *);
int scandir(char *, struct dirent ***, int /*<<< orphan*/, int /*<<< orphan*/);
void list_notes() {
  int n;
  char file[50];
  struct dirent **d;
  get_dir(file);
  n = scandir(file, &d, 0, alphasort);
  if (n < 0)
    die("Couldn't open ~/notes directory.");
  while (n--) {
    if ((*d)->d_name[0] != '.')
      printf("%s\n", (*d)->d_name);
    ++d;
  }
  free(d);
}


x86 assembly (clang, -O0):
<list_notes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x40(%rbp),%rdi
call   1040 <get_dir@plt>
lea    -0x40(%rbp),%rdi
mov    0x2e74(%rip),%rax
mov    (%rax),%ecx
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1060 <scandir@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    1192 <list_notes+0x42>
lea    0xe73(%rip),%rdi
call   1070 <die@plt>
jmp    1197 <list_notes+0x47>
mov    -0x4(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x4(%rbp)
cmp    $0x0,%eax
je     11e8 <list_notes+0x98>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11d7 <list_notes+0x87>
mov    -0x48(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
call   1050 <printf@plt>
mov    -0x48(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x48(%rbp)
jmp    1197 <list_notes+0x47>
mov    -0x48(%rbp),%rdi
call   1030 <free@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_notes>:
push   %r14
push   %rbx
sub    $0x48,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <get_dir@plt>
mov    0x2e75(%rip),%rax
mov    (%rax),%ecx
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1060 <scandir@plt>
mov    %eax,%ebx
test   %eax,%eax
js     1196 <list_notes+0x46>
jne    11a2 <list_notes+0x52>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe63(%rip),%rdi
call   1070 <die@plt>
mov    0x8(%rsp),%rdi
lea    0xe73(%rip),%r14
jmp    11bd <list_notes+0x6d>
add    $0x8,%rdi
mov    %rdi,0x8(%rsp)
test   %ebx,%ebx
je     1189 <list_notes+0x39>
add    $0xffffffff,%ebx
mov    (%rdi),%rax
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     11b0 <list_notes+0x60>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    0x8(%rsp),%rdi
jmp    11b0 <list_notes+0x60>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@alphasort = global i32 0
@.str = [33 x i8] c"Couldn't open ~/notes directory.\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @list_notes() {
%1 = alloca i32
%2 = alloca [50 x i8]
%3 = alloca %struct.dirent**
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = call i32 @get_dir(i8* %4)
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%7 = load i32, i32* @alphasort
%8 = call i32 @scandir(i8* %6, %struct.dirent*** %3, i32 0, i32 %7)
store i32 %8, i32* %1
%9 = load i32, i32* %1
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %0
br label %14
14: ; preds = %33, %13
%15 = load i32, i32* %1
%16 = add nsw i32 %15, -1
store i32 %16, i32* %1
%17 = icmp ne i32 %15, 0
br i1 %17, label %18, label %36
18: ; preds = %14
%19 = load %struct.dirent**, %struct.dirent*** %3
%20 = load %struct.dirent*, %struct.dirent** %19
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i8*, i8** %21
%23 = getelementptr inbounds i8, i8* %22, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp ne i32 %25, 46
br i1 %26, label %27, label %33
27: ; preds = %18
%28 = load %struct.dirent**, %struct.dirent*** %3
%29 = load %struct.dirent*, %struct.dirent** %28
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %27, %18
%34 = load %struct.dirent**, %struct.dirent*** %3
%35 = getelementptr inbounds %struct.dirent*, %struct.dirent** %34, i32 1
store %struct.dirent** %35, %struct.dirent*** %3
br label %14
36: ; preds = %14
%37 = load %struct.dirent**, %struct.dirent*** %3
%38 = call i32 @free(%struct.dirent** %37)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@alphasort = global i32 0
@.str = [33 x i8] c"Couldn't open ~/notes directory.\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define void @list_notes() {
%1 = alloca [50 x i8]
%2 = alloca %struct.dirent**
%3 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.dirent*** %2 to i8*
%5 = call i32 @get_dir(i8* %3)
%6 = load i32, i32* @alphasort
%7 = call i32 @scandir(i8* %3, %struct.dirent*** %2, i32 0, i32 %6)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @die(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %15
11: ; preds = %0
%12 = icmp eq i32 %7, 0
br i1 %12, label %13, label %15
13: ; preds = %11
%14 = load %struct.dirent**, %struct.dirent*** %2
br label %33
15: ; preds = %9, %11
%16 = load %struct.dirent**, %struct.dirent*** %2
br label %17
17: ; preds = %15, %29
%18 = phi %struct.dirent** [ %31, %29 ], [ %16, %15 ]
%19 = phi i32 [ %20, %29 ], [ %7, %15 ]
%20 = add nsw i32 %19, -1
%21 = load %struct.dirent*, %struct.dirent** %18
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = load i8, i8* %23
%25 = icmp eq i8 %24, 46
br i1 %25, label %29, label %26
26: ; preds = %17
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%28 = load %struct.dirent**, %struct.dirent*** %2
br label %29
29: ; preds = %26, %17
%30 = phi %struct.dirent** [ %28, %26 ], [ %18, %17 ]
%31 = getelementptr inbounds %struct.dirent*, %struct.dirent** %30, i64 1
store %struct.dirent** %31, %struct.dirent*** %2
%32 = icmp eq i32 %20, 0
br i1 %32, label %33, label %17
33: ; preds = %29, %13
%34 = phi %struct.dirent** [ %14, %13 ], [ %31, %29 ]
%35 = call i32 @free(%struct.dirent** %34)
ret void
}