void FS_Dir_f(void) {
  char *path = ((void *)0);
  char findname[1024];
  char wildcard[1024] = "*.*";
  char **dirnames;
  int ndirs;
  if (Cmd_Argc() != 1) {
    strcpy(wildcard, Cmd_Argv(1));
  }
  while ((path = FS_NextPath(path)) != ((void *)0)) {
    char *tmp = findname;
    Com_sprintf(findname, sizeof(findname), "%s/%s", path, wildcard);
    while (*tmp != 0) {
      if (*tmp == '\\') {
        *tmp = '/';
      }
      tmp++;
    }
    Com_Printf("Directory of %s\n", findname);
    Com_Printf("----\n");
    if ((dirnames = FS_ListFiles(findname, &ndirs, 0, 0)) != 0) {
      int i;
      for (i = 0; i < ndirs - 1; i++) {
        if (strrchr(dirnames[i], '/')) {
          Com_Printf("%s\n", strrchr(dirnames[i], '/') + 1);
        } else {
          Com_Printf("%s\n", dirnames[i]);
        }
        Z_Free(dirnames[i]);
      }
      Z_Free(dirnames);
    }
    Com_Printf("\n");
  }
}


x86 assembly (clang, -O0):
<FS_Dir_f>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
movq   $0x0,-0x8(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
movb   $0x2a,-0x810(%rbp)
movb   $0x2e,-0x80f(%rbp)
movb   $0x2a,-0x80e(%rbp)
mov    $0x0,%al
call   1050 <Cmd_Argc@plt>
cmp    $0x1,%eax
je     1214 <FS_Dir_f+0x74>
lea    -0x810(%rbp),%rax
mov    %rax,-0x838(%rbp)
mov    $0x1,%edi
mov    $0x0,%al
call   10c0 <Cmd_Argv@plt>
mov    -0x838(%rbp),%rdi
movslq %eax,%rsi
call   1040 <strcpy@plt>
jmp    1219 <FS_Dir_f+0x79>
mov    -0x8(%rbp),%rdi
mov    $0x0,%al
call   1090 <FS_NextPath@plt>
cltq
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
je     13e8 <FS_Dir_f+0x248>
lea    -0x410(%rbp),%rax
mov    %rax,-0x828(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rcx
lea    -0x810(%rbp),%r8
mov    $0x400,%esi
lea    0xda0(%rip),%rdx
mov    $0x0,%al
call   10a0 <Com_sprintf@plt>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     12ae <FS_Dir_f+0x10e>
mov    -0x828(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    1297 <FS_Dir_f+0xf7>
mov    -0x828(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x828(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
jmp    1267 <FS_Dir_f+0xc7>
lea    -0x410(%rbp),%rsi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   10b0 <Com_Printf@plt>
lea    0xd4d(%rip),%rdi
mov    $0x0,%al
call   10b0 <Com_Printf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x81c(%rbp),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
mov    $0x0,%al
call   1060 <FS_ListFiles@plt>
cltq
mov    %rax,-0x818(%rbp)
cmp    $0x0,%rax
je     13d5 <FS_Dir_f+0x235>
movl   $0x0,-0x82c(%rbp)
mov    -0x82c(%rbp),%eax
mov    -0x81c(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    13c7 <FS_Dir_f+0x227>
mov    -0x818(%rbp),%rax
movslq -0x82c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
cmp    $0x0,%rax
je     137a <FS_Dir_f+0x1da>
mov    -0x818(%rbp),%rax
movslq -0x82c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,%rsi
add    $0x1,%rsi
lea    0xca5(%rip),%rdi
mov    $0x0,%al
call   10b0 <Com_Printf@plt>
jmp    139a <FS_Dir_f+0x1fa>
mov    -0x818(%rbp),%rax
movslq -0x82c(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xc80(%rip),%rdi
mov    $0x0,%al
call   10b0 <Com_Printf@plt>
mov    -0x818(%rbp),%rax
movslq -0x82c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x0,%al
call   1030 <Z_Free@plt>
mov    -0x82c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x82c(%rbp)
jmp    1307 <FS_Dir_f+0x167>
mov    -0x818(%rbp),%rdi
mov    $0x0,%al
call   1030 <Z_Free@plt>
lea    0xc3f(%rip),%rdi
mov    $0x0,%al
call   10b0 <Com_Printf@plt>
jmp    1219 <FS_Dir_f+0x79>
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS_Dir_f>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
movw   $0x2e2a,0x10(%rsp)
movb   $0x2a,0x12(%rsp)
xor    %eax,%eax
call   1050 <Cmd_Argc@plt>
cmp    $0x1,%eax
je     11f3 <FS_Dir_f+0x53>
mov    $0x1,%edi
xor    %eax,%eax
call   10c0 <Cmd_Argv@plt>
movslq %eax,%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
xor    %edi,%edi
xor    %eax,%eax
call   1090 <FS_NextPath@plt>
test   %eax,%eax
je     1322 <FS_Dir_f+0x182>
lea    0x410(%rsp),%rbx
lea    0xe00(%rip),%r15
jmp    124a <FS_Dir_f+0xaa>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
xor    %eax,%eax
call   1030 <Z_Free@plt>
lea    0xdea(%rip),%rdi
xor    %eax,%eax
call   10b0 <Com_Printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1090 <FS_NextPath@plt>
test   %eax,%eax
je     1322 <FS_Dir_f+0x182>
movslq %eax,%r12
mov    $0x400,%esi
mov    %rbx,%rdi
lea    0xda4(%rip),%rdx
mov    %r12,%rcx
lea    0x10(%rsp),%r8
xor    %eax,%eax
call   10a0 <Com_sprintf@plt>
mov    %rbx,%rax
jmp    1277 <FS_Dir_f+0xd7>
movb   $0x2f,(%rax)
add    $0x1,%rax
movzbl (%rax),%ecx
cmp    $0x5c,%cl
je     1270 <FS_Dir_f+0xd0>
test   %cl,%cl
jne    1273 <FS_Dir_f+0xd3>
lea    0xd7c(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10b0 <Com_Printf@plt>
lea    0xd7c(%rip),%rdi
xor    %eax,%eax
call   10b0 <Com_Printf@plt>
mov    %rbx,%rdi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <FS_ListFiles@plt>
test   %eax,%eax
je     122a <FS_Dir_f+0x8a>
movslq %eax,%r13
cmpl   $0x2,0xc(%rsp)
jl     1220 <FS_Dir_f+0x80>
xor    %r14d,%r14d
jmp    12ff <FS_Dir_f+0x15f>
mov    %r15,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   10b0 <Com_Printf@plt>
mov    0x0(%r13,%r14,8),%rdi
xor    %eax,%eax
call   1030 <Z_Free@plt>
add    $0x1,%r14
movslq 0xc(%rsp),%rax
add    $0xffffffffffffffff,%rax
cmp    %rax,%r14
jge    1220 <FS_Dir_f+0x80>
mov    0x0(%r13,%r14,8),%rbp
mov    %rbp,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     12d0 <FS_Dir_f+0x130>
add    $0x1,%rax
mov    %r15,%rdi
mov    %rax,%rsi
jmp    12d6 <FS_Dir_f+0x136>
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [17 x i8] c"Directory of %s\0A\00"
@.str.2 = [6 x i8] c"----\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @FS_Dir_f() {
%1 = alloca i8*
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i8* null, i8** %1
%8 = bitcast [1024 x i8]* %3 to i8*
%9 = bitcast i8* %8 to [1024 x i8]*
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i32 0, i32 0
store i8 42, i8* %10
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i32 0, i32 1
store i8 46, i8* %11
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i32 0, i32 2
store i8 42, i8* %12
%13 = call i32 (...) @Cmd_Argc()
%14 = icmp ne i32 %13, 1
br i1 %14, label %15, label %21
15: ; preds = %0
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = call i32 (i32, ...) bitcast (i32 (...)* @Cmd_Argv to i32 (i32, ...)*)(i32 1)
%18 = sext i32 %17 to i64
%19 = inttoptr i64 %18 to i8*
%20 = call i8* @strcpy(i8* %16, i8* %19)
br label %21
21: ; preds = %15, %0
br label %22
22: ; preds = %101, %21
%23 = load i8*, i8** %1
%24 = call i32 (i8*, ...) bitcast (i32 (...)* @FS_NextPath to i32 (i8*, ...)*)(i8* %23)
%25 = sext i32 %24 to i64
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %1
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %103
28: ; preds = %22
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
store i8* %29, i8** %6
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%31 = load i8*, i8** %1
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%33 = call i32 (i8*, i64, i8*, i8*, i8*, ...) bitcast (i32 (...)* @Com_sprintf to i32 (i8*, i64, i8*, i8*, i8*, ...)*)(i8* %30, i64 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %31, i8* %32)
br label %34
34: ; preds = %46, %28
%35 = load i8*, i8** %6
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %49
39: ; preds = %34
%40 = load i8*, i8** %6
%41 = load i8, i8* %40
%42 = sext i8 %41 to i32
%43 = icmp eq i32 %42, 92
br i1 %43, label %44, label %46
44: ; preds = %39
%45 = load i8*, i8** %6
store i8 47, i8* %45
br label %46
46: ; preds = %44, %39
%47 = load i8*, i8** %6
%48 = getelementptr inbounds i8, i8* %47, i32 1
store i8* %48, i8** %6
br label %34
49: ; preds = %34
%50 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%51 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %50)
%52 = call i32 (i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%54 = call i32 (i8*, i32*, i32, i32, ...) bitcast (i32 (...)* @FS_ListFiles to i32 (i8*, i32*, i32, i32, ...)*)(i8* %53, i32* %5, i32 0, i32 0)
%55 = sext i32 %54 to i64
%56 = inttoptr i64 %55 to i8**
store i8** %56, i8*** %4
%57 = icmp ne i8** %56, null
br i1 %57, label %58, label %101
58: ; preds = %49
store i32 0, i32* %7
br label %59
59: ; preds = %95, %58
%60 = load i32, i32* %7
%61 = load i32, i32* %5
%62 = sub nsw i32 %61, 1
%63 = icmp slt i32 %60, %62
br i1 %63, label %64, label %98
64: ; preds = %59
%65 = load i8**, i8*** %4
%66 = load i32, i32* %7
%67 = sext i32 %66 to i64
%68 = getelementptr inbounds i8*, i8** %65, i64 %67
%69 = load i8*, i8** %68
%70 = call i8* @strrchr(i8* %69, i32 47)
%71 = icmp ne i8* %70, null
br i1 %71, label %72, label %81
72: ; preds = %64
%73 = load i8**, i8*** %4
%74 = load i32, i32* %7
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8*, i8** %73, i64 %75
%77 = load i8*, i8** %76
%78 = call i8* @strrchr(i8* %77, i32 47)
%79 = getelementptr inbounds i8, i8* %78, i64 1
%80 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %79)
br label %88
81: ; preds = %64
%82 = load i8**, i8*** %4
%83 = load i32, i32* %7
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %86)
br label %88
88: ; preds = %81, %72
%89 = load i8**, i8*** %4
%90 = load i32, i32* %7
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8*, i8** %89, i64 %91
%93 = load i8*, i8** %92
%94 = call i32 (i8*, ...) bitcast (i32 (...)* @Z_Free to i32 (i8*, ...)*)(i8* %93)
br label %95
95: ; preds = %88
%96 = load i32, i32* %7
%97 = add nsw i32 %96, 1
store i32 %97, i32* %7
br label %59
98: ; preds = %59
%99 = load i8**, i8*** %4
%100 = call i32 (i8**, ...) bitcast (i32 (...)* @Z_Free to i32 (i8**, ...)*)(i8** %99)
br label %101
101: ; preds = %98, %49
%102 = call i32 (i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %22
103: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [17 x i8] c"Directory of %s\0A\00"
@.str.2 = [6 x i8] c"----\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [2 x i8] c"\0A\00"
define void @FS_Dir_f() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca i32
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
store i8 42, i8* %5
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 1
store i8 46, i8* %6
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 2
store i8 42, i8* %7
%8 = bitcast i32* %3 to i8*
%9 = tail call i32 (...) @Cmd_Argc()
%10 = icmp eq i32 %9, 1
br i1 %10, label %16, label %11
11: ; preds = %0
%12 = tail call i32 (i32, ...) bitcast (i32 (...)* @Cmd_Argv to i32 (i32, ...)*)(i32 1)
%13 = sext i32 %12 to i64
%14 = inttoptr i64 %13 to i8*
%15 = call i8* @strcpy(i8* %5, i8* dereferenceable(1) %14)
br label %16
16: ; preds = %11, %0
%17 = call i32 (i8*, ...) bitcast (i32 (...)* @FS_NextPath to i32 (i8*, ...)*)(i8* null)
%18 = icmp eq i32 %17, 0
br i1 %18, label %65, label %19
19: ; preds = %16, %61
%20 = phi i32 [ %63, %61 ], [ %17, %16 ]
%21 = sext i32 %20 to i64
%22 = inttoptr i64 %21 to i8*
%23 = call i32 (i8*, i64, i8*, i8*, i8*, ...) bitcast (i32 (...)* @Com_sprintf to i32 (i8*, i64, i8*, i8*, i8*, ...)*)(i8* %4, i64 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %22, i8* %5)
br label %24
24: ; preds = %28, %19
%25 = phi i8* [ %4, %19 ], [ %29, %28 ]
%26 = load i8, i8* %25
switch i8 %26, label %28 [
i8 0, label %30
i8 92, label %27
]
27: ; preds = %24
store i8 47, i8* %25
br label %28
28: ; preds = %24, %27
%29 = getelementptr inbounds i8, i8* %25, i64 1
br label %24
30: ; preds = %24
%31 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%32 = call i32 (i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 (i8*, i32*, i32, i32, ...) bitcast (i32 (...)* @FS_ListFiles to i32 (i8*, i32*, i32, i32, ...)*)(i8* %4, i32* %3, i32 0, i32 0)
%34 = sext i32 %33 to i64
%35 = inttoptr i64 %34 to i8**
%36 = icmp eq i32 %33, 0
br i1 %36, label %61, label %37
37: ; preds = %30
%38 = load i32, i32* %3
%39 = icmp sgt i32 %38, 1
br i1 %39, label %40, label %59
40: ; preds = %37, %51
%41 = phi i64 [ %54, %51 ], [ 0, %37 ]
%42 = getelementptr inbounds i8*, i8** %35, i64 %41
%43 = load i8*, i8** %42
%44 = call i8* @strrchr(i8* dereferenceable(1) %43, i32 47)
%45 = icmp eq i8* %44, null
br i1 %45, label %49, label %46
46: ; preds = %40
%47 = getelementptr inbounds i8, i8* %44, i64 1
%48 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %51
49: ; preds = %40
%50 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %51
51: ; preds = %49, %46
%52 = load i8*, i8** %42
%53 = call i32 (i8*, ...) bitcast (i32 (...)* @Z_Free to i32 (i8*, ...)*)(i8* %52)
%54 = add nuw nsw i64 %41, 1
%55 = load i32, i32* %3
%56 = add nsw i32 %55, -1
%57 = sext i32 %56 to i64
%58 = icmp slt i64 %54, %57
br i1 %58, label %40, label %59
59: ; preds = %51, %37
%60 = call i32 (i8**, ...) bitcast (i32 (...)* @Z_Free to i32 (i8**, ...)*)(i8** %35)
br label %61
61: ; preds = %59, %30
%62 = call i32 (i8*, ...) bitcast (i32 (...)* @Com_Printf to i32 (i8*, ...)*)(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%63 = call i32 (i8*, ...) bitcast (i32 (...)* @FS_NextPath to i32 (i8*, ...)*)(i8* %22)
%64 = icmp eq i32 %63, 0
br i1 %64, label %65, label %19
65: ; preds = %61, %16
ret void
}