char **FS_ListFiles(char *findname, int *numfiles, unsigned musthave,
                    unsigned canthave) {
  char *s;
  int nfiles = 0;
  char **list = 0;
  s = FS_FindFirst(findname, musthave, canthave);
  while (s) {
    if (s[strlen(s) - 1] != '.')
      nfiles++;
    s = FS_FindNext(musthave, canthave);
  }
  FS_FindClose();
  if (!nfiles)
    return ((void *)0);
  nfiles++;
  *numfiles = nfiles;
  list = (char **)Memory_malloc((sizeof(char *) * nfiles));
  if (list == ((void *)0)) {
    Memory_outofmem(
        ("list"),
        "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
        "2022-01-22/02-19-57/repos/MichaelLiedirher/Wolfenstein3D_Redux/refs/"
        "heads/master/wolf3dredux/env/files.c",
        339);
  }
  memset(list, 0, sizeof(char *) * nfiles);
  s = FS_FindFirst(findname, musthave, canthave);
  nfiles = 0;
  while (s) {
    if (s[strlen(s) - 1] != '.') {
      list[nfiles] = strdup(s);
      (void)com_strlwr(list[nfiles]);
      nfiles++;
    }
    s = FS_FindNext(musthave, canthave);
  }
  FS_FindClose();
  return list;
}


x86 assembly (clang, -O0):
<FS_ListFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %ecx,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1050 <FS_FindFirst@plt>
cltq
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1221 <FS_ListFiles+0x91>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x40(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1209 <FS_ListFiles+0x79>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x0,%al
call   1080 <FS_FindNext@plt>
cltq
mov    %rax,-0x28(%rbp)
jmp    11cc <FS_ListFiles+0x3c>
mov    $0x0,%al
call   1090 <FS_FindClose@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    123f <FS_ListFiles+0xaf>
movq   $0x0,-0x8(%rbp)
jmp    134b <FS_ListFiles+0x1bb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
movslq -0x2c(%rbp),%rdi
shl    $0x3,%rdi
mov    $0x0,%al
call   1030 <Memory_malloc@plt>
cltq
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    128b <FS_ListFiles+0xfb>
lea    0xd88(%rip),%rdi
lea    0xd86(%rip),%rsi
mov    $0x153,%edx
mov    $0x0,%al
call   1040 <Memory_outofmem@plt>
mov    -0x38(%rbp),%rdi
movslq -0x2c(%rbp),%rdx
shl    $0x3,%rdx
xor    %esi,%esi
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x20(%rbp),%edx
mov    $0x0,%al
call   1050 <FS_FindFirst@plt>
cltq
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     133c <FS_ListFiles+0x1ac>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2e,%eax
je     1324 <FS_ListFiles+0x194>
mov    -0x28(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,%rdx
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    $0x0,%al
call   10b0 <com_strlwr@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    $0x0,%al
call   1080 <FS_FindNext@plt>
cltq
mov    %rax,-0x28(%rbp)
jmp    12bc <FS_ListFiles+0x12c>
mov    $0x0,%al
call   1090 <FS_FindClose@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FS_ListFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r13d
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %rdi,%rbp
xor    %r14d,%r14d
mov    %edx,%esi
mov    %ecx,%edx
xor    %eax,%eax
call   1050 <FS_FindFirst@plt>
test   %eax,%eax
je     12c1 <FS_ListFiles+0x131>
mov    %rbx,(%rsp)
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movslq %eax,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
xor    %ecx,%ecx
cmpb   $0x2e,-0x1(%rax,%rbx,1)
setne  %cl
add    %ecx,%r12d
mov    %r15d,%edi
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <FS_FindNext@plt>
test   %eax,%eax
jne    11d0 <FS_ListFiles+0x40>
xor    %r14d,%r14d
xor    %eax,%eax
call   1090 <FS_FindClose@plt>
test   %r12d,%r12d
je     12c8 <FS_ListFiles+0x138>
lea    0x1(%r12),%eax
mov    (%rsp),%rcx
mov    %eax,(%rcx)
mov    %r12d,%eax
lea    0x8(,%rax,8),%r12
mov    %r12,%rdi
xor    %eax,%eax
call   1030 <Memory_malloc@plt>
movslq %eax,%r14
test   %r14d,%r14d
jne    124e <FS_ListFiles+0xbe>
lea    0xdc5(%rip),%rdi
lea    0xdc3(%rip),%rsi
mov    $0x153,%edx
xor    %eax,%eax
call   1040 <Memory_outofmem@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %r12,%rdx
call   1070 <memset@plt>
mov    %rbp,%rdi
mov    %r15d,%esi
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <FS_FindFirst@plt>
test   %eax,%eax
je     12c1 <FS_ListFiles+0x131>
xor    %ebp,%ebp
jmp    1291 <FS_ListFiles+0x101>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <FS_FindNext@plt>
test   %eax,%eax
je     12c1 <FS_ListFiles+0x131>
movslq %eax,%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
cmpb   $0x2e,-0x1(%rax,%rbx,1)
je     1280 <FS_ListFiles+0xf0>
mov    %rbx,%rdi
call   10a0 <strdup@plt>
movslq %ebp,%rbp
mov    %rax,(%r14,%rbp,8)
mov    %rax,%rdi
xor    %eax,%eax
call   10b0 <com_strlwr@plt>
add    $0x1,%ebp
jmp    1280 <FS_ListFiles+0xf0>
xor    %eax,%eax
call   1090 <FS_FindClose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"list\00"
@.str.1 = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MichaelLiedirher/Wolfenstein3D_Redux/refs/heads/master/wolf3dredux/env/files.c\00"
define i8** @FS_ListFiles(i8* %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i8**
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 0, i32* %11
store i8** null, i8*** %12
%13 = load i8*, i8** %6
%14 = load i32, i32* %8
%15 = load i32, i32* %9
%16 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @FS_FindFirst to i32 (i8*, i32, i32, ...)*)(i8* %13, i32 %14, i32 %15)
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
store i8* %18, i8** %10
br label %19
19: ; preds = %34, %4
%20 = load i8*, i8** %10
%21 = icmp ne i8* %20, null
br i1 %21, label %22, label %40
22: ; preds = %19
%23 = load i8*, i8** %10
%24 = load i8*, i8** %10
%25 = call i64 @strlen(i8* %24)
%26 = sub i64 %25, 1
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = icmp ne i32 %29, 46
br i1 %30, label %31, label %34
31: ; preds = %22
%32 = load i32, i32* %11
%33 = add nsw i32 %32, 1
store i32 %33, i32* %11
br label %34
34: ; preds = %31, %22
%35 = load i32, i32* %8
%36 = load i32, i32* %9
%37 = call i32 (i32, i32, ...) bitcast (i32 (...)* @FS_FindNext to i32 (i32, i32, ...)*)(i32 %35, i32 %36)
%38 = sext i32 %37 to i64
%39 = inttoptr i64 %38 to i8*
store i8* %39, i8** %10
br label %19
40: ; preds = %19
%41 = call i32 (...) @FS_FindClose()
%42 = load i32, i32* %11
%43 = icmp ne i32 %42, 0
br i1 %43, label %45, label %44
44: ; preds = %40
store i8** null, i8*** %5
br label %108
45: ; preds = %40
%46 = load i32, i32* %11
%47 = add nsw i32 %46, 1
store i32 %47, i32* %11
%48 = load i32, i32* %11
%49 = load i32*, i32** %7
store i32 %48, i32* %49
%50 = load i32, i32* %11
%51 = sext i32 %50 to i64
%52 = mul i64 8, %51
%53 = call i32 (i64, ...) bitcast (i32 (...)* @Memory_malloc to i32 (i64, ...)*)(i64 %52)
%54 = sext i32 %53 to i64
%55 = inttoptr i64 %54 to i8**
store i8** %55, i8*** %12
%56 = load i8**, i8*** %12
%57 = icmp eq i8** %56, null
br i1 %57, label %58, label %60
58: ; preds = %45
%59 = call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @Memory_outofmem to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.1, i64 0, i64 0), i32 339)
br label %60
60: ; preds = %58, %45
%61 = load i8**, i8*** %12
%62 = bitcast i8** %61 to i8*
%63 = load i32, i32* %11
%64 = sext i32 %63 to i64
%65 = mul i64 8, %64
%66 = load i8*, i8** %6
%67 = load i32, i32* %8
%68 = load i32, i32* %9
%69 = call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @FS_FindFirst to i32 (i8*, i32, i32, ...)*)(i8* %66, i32 %67, i32 %68)
%70 = sext i32 %69 to i64
%71 = inttoptr i64 %70 to i8*
store i8* %71, i8** %10
store i32 0, i32* %11
br label %72
72: ; preds = %99, %60
%73 = load i8*, i8** %10
%74 = icmp ne i8* %73, null
br i1 %74, label %75, label %105
75: ; preds = %72
%76 = load i8*, i8** %10
%77 = load i8*, i8** %10
%78 = call i64 @strlen(i8* %77)
%79 = sub i64 %78, 1
%80 = getelementptr inbounds i8, i8* %76, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp ne i32 %82, 46
br i1 %83, label %84, label %99
84: ; preds = %75
%85 = load i8*, i8** %10
%86 = call i8* @strdup(i8* %85)
%87 = load i8**, i8*** %12
%88 = load i32, i32* %11
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds i8*, i8** %87, i64 %89
store i8* %86, i8** %90
%91 = load i8**, i8*** %12
%92 = load i32, i32* %11
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = load i8*, i8** %94
%96 = call i32 (i8*, ...) bitcast (i32 (...)* @com_strlwr to i32 (i8*, ...)*)(i8* %95)
%97 = load i32, i32* %11
%98 = add nsw i32 %97, 1
store i32 %98, i32* %11
br label %99
99: ; preds = %84, %75
%100 = load i32, i32* %8
%101 = load i32, i32* %9
%102 = call i32 (i32, i32, ...) bitcast (i32 (...)* @FS_FindNext to i32 (i32, i32, ...)*)(i32 %100, i32 %101)
%103 = sext i32 %102 to i64
%104 = inttoptr i64 %103 to i8*
store i8* %104, i8** %10
br label %72
105: ; preds = %72
%106 = call i32 (...) @FS_FindClose()
%107 = load i8**, i8*** %12
store i8** %107, i8*** %5
br label %108
108: ; preds = %105, %44
%109 = load i8**, i8*** %5
ret i8** %109
}

LLVM IR (-O2):
@.str = [5 x i8] c"list\00"
@.str.1 = [169 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/MichaelLiedirher/Wolfenstein3D_Redux/refs/heads/master/wolf3dredux/env/files.c\00"
define i8** @FS_ListFiles(i8* %0, i32* nocapture writeonly %1, i32 %2, i32 %3) {
%5 = tail call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @FS_FindFirst to i32 (i8*, i32, i32, ...)*)(i8* %0, i32 %2, i32 %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %58, label %7
7: ; preds = %4, %7
%8 = phi i32 [ %19, %7 ], [ %5, %4 ]
%9 = phi i32 [ %18, %7 ], [ 0, %4 ]
%10 = sext i32 %8 to i64
%11 = inttoptr i64 %10 to i8*
%12 = tail call i64 @strlen(i8* %11)
%13 = add i64 %12, -1
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = icmp ne i8 %15, 46
%17 = zext i1 %16 to i32
%18 = add nuw nsw i32 %9, %17
%19 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @FS_FindNext to i32 (i32, i32, ...)*)(i32 %2, i32 %3)
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %7
21: ; preds = %7
%22 = tail call i32 (...) @FS_FindClose()
%23 = icmp eq i32 %18, 0
br i1 %23, label %61, label %24
24: ; preds = %21
%25 = add nuw nsw i32 %18, 1
store i32 %25, i32* %1
%26 = zext i32 %25 to i64
%27 = shl nuw nsw i64 %26, 3
%28 = tail call i32 (i64, ...) bitcast (i32 (...)* @Memory_malloc to i32 (i64, ...)*)(i64 %27)
%29 = sext i32 %28 to i64
%30 = inttoptr i64 %29 to i8**
%31 = icmp eq i32 %28, 0
br i1 %31, label %32, label %34
32: ; preds = %24
%33 = tail call i32 (i8*, i8*, i32, ...) bitcast (i32 (...)* @Memory_outofmem to i32 (i8*, i8*, i32, ...)*)(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.1, i64 0, i64 0), i32 339)
br label %34
34: ; preds = %32, %24
%35 = inttoptr i64 %29 to i8*
tail call void @llvm.memset.p0i8.i64(i8* align 8 dereferenceable(1) %35, i8 0, i64 %27, i1 false)
%36 = tail call i32 (i8*, i32, i32, ...) bitcast (i32 (...)* @FS_FindFirst to i32 (i8*, i32, i32, ...)*)(i8* %0, i32 %2, i32 %3)
%37 = icmp eq i32 %36, 0
br i1 %37, label %58, label %38
38: ; preds = %34, %54
%39 = phi i32 [ %56, %54 ], [ %36, %34 ]
%40 = phi i32 [ %55, %54 ], [ 0, %34 ]
%41 = sext i32 %39 to i64
%42 = inttoptr i64 %41 to i8*
%43 = tail call i64 @strlen(i8* %42)
%44 = add i64 %43, -1
%45 = getelementptr inbounds i8, i8* %42, i64 %44
%46 = load i8, i8* %45
%47 = icmp eq i8 %46, 46
br i1 %47, label %54, label %48
48: ; preds = %38
%49 = tail call i8* @strdup(i8* %42)
%50 = sext i32 %40 to i64
%51 = getelementptr inbounds i8*, i8** %30, i64 %50
store i8* %49, i8** %51
%52 = tail call i32 (i8*, ...) bitcast (i32 (...)* @com_strlwr to i32 (i8*, ...)*)(i8* %49)
%53 = add nsw i32 %40, 1
br label %54
54: ; preds = %48, %38
%55 = phi i32 [ %53, %48 ], [ %40, %38 ]
%56 = tail call i32 (i32, i32, ...) bitcast (i32 (...)* @FS_FindNext to i32 (i32, i32, ...)*)(i32 %2, i32 %3)
%57 = icmp eq i32 %56, 0
br i1 %57, label %58, label %38
58: ; preds = %54, %34, %4
%59 = phi i8** [ null, %4 ], [ %30, %34 ], [ %30, %54 ]
%60 = tail call i32 (...) @FS_FindClose()
br label %61
61: ; preds = %58, %21
%62 = phi i8** [ null, %21 ], [ %59, %58 ]
ret i8** %62
}