#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 */

/* Variables and functions */
int allFilesInDir(char *, char ***);
char **createStringArray(int, int);
int filterStringArray(char **, int, char **, int, int, char ***);
int /*<<< orphan*/ free(char **);
int /*<<< orphan*/ freeStringArray(char **, int);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int getFileNamesWith(char *dir, char *subStr, char ***ans) {
  char **allFiles;
  int numAllFiles = allFilesInDir(dir, &allFiles);
  if (!numAllFiles) {
    freeStringArray(allFiles, numAllFiles);
    return 0;
  }
  char *subStrs[1];
  subStrs[0] = subStr;
  char **goodFiles;
  int numGoodFiles =
      filterStringArray(allFiles, numAllFiles, subStrs, 1, 1, &goodFiles);
  if (!numGoodFiles) {
    freeStringArray(allFiles, numAllFiles);
    free(goodFiles);
    return 0;
  }
  *ans = createStringArray(numGoodFiles, 1024);
  int i;
  for (i = 0; i < numGoodFiles; i++) {
    sprintf((*ans)[i], "%s/%s", dir, goodFiles[i]);
  }
  freeStringArray(allFiles, numAllFiles);
  free(goodFiles);
  return numGoodFiles;
}


x86 assembly (clang, -O0):
<getFileNamesWith>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1070 <allFilesInDir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    11a6 <getFileNamesWith+0x46>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <freeStringArray@plt>
movl   $0x0,-0x4(%rbp)
jmp    1277 <getFileNamesWith+0x117>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
lea    -0x38(%rbp),%rdx
mov    $0x1,%r8d
lea    -0x40(%rbp),%r9
mov    %r8d,%ecx
call   1040 <filterStringArray@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jne    11f9 <getFileNamesWith+0x99>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <freeStringArray@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1277 <getFileNamesWith+0x117>
mov    -0x44(%rbp),%edi
mov    $0x400,%esi
call   1060 <createStringArray@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x48(%rbp)
mov    -0x48(%rbp),%eax
cmp    -0x44(%rbp),%eax
jge    125c <getFileNamesWith+0xfc>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x40(%rbp),%rax
movslq -0x48(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xdb7(%rip),%rsi
call   1080 <sprintf@plt>
mov    -0x48(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x48(%rbp)
jmp    1217 <getFileNamesWith+0xb7>
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%esi
call   1050 <freeStringArray@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFileNamesWith>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0x10(%rsp),%rsi
call   1070 <allFilesInDir@plt>
test   %eax,%eax
je     123e <getFileNamesWith+0xde>
mov    %rbp,0x20(%rsp)
mov    0x10(%rsp),%rdi
lea    0x20(%rsp),%rdx
lea    0x8(%rsp),%r9
mov    %eax,0x1c(%rsp)
mov    %eax,%esi
mov    $0x1,%ecx
mov    $0x1,%r8d
call   1040 <filterStringArray@plt>
mov    %eax,%r12d
test   %eax,%eax
je     1224 <getFileNamesWith+0xc4>
mov    %r12d,%edi
mov    $0x400,%esi
call   1060 <createStringArray@plt>
mov    %rax,(%r14)
test   %r12d,%r12d
jle    1224 <getFileNamesWith+0xc4>
mov    (%rax),%rdi
mov    0x8(%rsp),%rax
mov    (%rax),%rcx
lea    0xe1f(%rip),%rsi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
cmp    $0x1,%r12d
je     1224 <getFileNamesWith+0xc4>
mov    %r12d,%ebp
mov    $0x1,%r15d
lea    0xe01(%rip),%r13
nop
mov    (%r14),%rax
mov    (%rax,%r15,8),%rdi
mov    0x8(%rsp),%rax
mov    (%rax,%r15,8),%rcx
mov    %r13,%rsi
mov    %rbx,%rdx
call   1080 <sprintf@plt>
add    $0x1,%r15
cmp    %r15,%rbp
jne    1200 <getFileNamesWith+0xa0>
mov    0x10(%rsp),%rdi
mov    0x1c(%rsp),%esi
call   1050 <freeStringArray@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
jmp    124d <getFileNamesWith+0xed>
mov    0x10(%rsp),%rdi
xor    %r12d,%r12d
xor    %esi,%esi
call   1050 <freeStringArray@plt>
mov    %r12d,%eax
add    $0x28,%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"
define i32 @getFileNamesWith(i8* %0, i8* %1, i8*** %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8***
%8 = alloca i8**
%9 = alloca i32
%10 = alloca [1 x i8*]
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8*** %2, i8**** %7
%14 = load i8*, i8** %5
%15 = call i32 @allFilesInDir(i8* %14, i8*** %8)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp ne i32 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i8**, i8*** %8
%20 = load i32, i32* %9
%21 = call i32 @freeStringArray(i8** %19, i32 %20)
store i32 0, i32* %4
br label %69
22: ; preds = %3
%23 = load i8*, i8** %6
%24 = getelementptr inbounds [1 x i8*], [1 x i8*]* %10, i64 0, i64 0
store i8* %23, i8** %24
%25 = load i8**, i8*** %8
%26 = load i32, i32* %9
%27 = getelementptr inbounds [1 x i8*], [1 x i8*]* %10, i64 0, i64 0
%28 = call i32 @filterStringArray(i8** %25, i32 %26, i8** %27, i32 1, i32 1, i8*** %11)
store i32 %28, i32* %12
%29 = load i32, i32* %12
%30 = icmp ne i32 %29, 0
br i1 %30, label %37, label %31
31: ; preds = %22
%32 = load i8**, i8*** %8
%33 = load i32, i32* %9
%34 = call i32 @freeStringArray(i8** %32, i32 %33)
%35 = load i8**, i8*** %11
%36 = call i32 @free(i8** %35)
store i32 0, i32* %4
br label %69
37: ; preds = %22
%38 = load i32, i32* %12
%39 = call i8** @createStringArray(i32 %38, i32 1024)
%40 = load i8***, i8**** %7
store i8** %39, i8*** %40
store i32 0, i32* %13
br label %41
41: ; preds = %59, %37
%42 = load i32, i32* %13
%43 = load i32, i32* %12
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %62
45: ; preds = %41
%46 = load i8***, i8**** %7
%47 = load i8**, i8*** %46
%48 = load i32, i32* %13
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = load i8*, i8** %5
%53 = load i8**, i8*** %11
%54 = load i32, i32* %13
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = call i32 @sprintf(i8* %51, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %52, i8* %57)
br label %59
59: ; preds = %45
%60 = load i32, i32* %13
%61 = add nsw i32 %60, 1
store i32 %61, i32* %13
br label %41
62: ; preds = %41
%63 = load i8**, i8*** %8
%64 = load i32, i32* %9
%65 = call i32 @freeStringArray(i8** %63, i32 %64)
%66 = load i8**, i8*** %11
%67 = call i32 @free(i8** %66)
%68 = load i32, i32* %12
store i32 %68, i32* %4
br label %69
69: ; preds = %62, %31, %18
%70 = load i32, i32* %4
ret i32 %70
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
define i32 @getFileNamesWith(i8* %0, i8* %1, i8*** nocapture %2) {
%4 = alloca i8**
%5 = alloca [1 x i8*]
%6 = alloca i8**
%7 = bitcast i8*** %4 to i8*
%8 = call i32 @allFilesInDir(i8* %0, i8*** %4)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %3
%11 = load i8**, i8*** %4
%12 = call i32 @freeStringArray(i8** %11, i32 0)
br label %46
13: ; preds = %3
%14 = bitcast [1 x i8*]* %5 to i8*
%15 = getelementptr inbounds [1 x i8*], [1 x i8*]* %5, i64 0, i64 0
store i8* %1, i8** %15
%16 = bitcast i8*** %6 to i8*
%17 = load i8**, i8*** %4
%18 = call i32 @filterStringArray(i8** %17, i32 %8, i8** %15, i32 1, i32 1, i8*** %6)
%19 = icmp eq i32 %18, 0
br i1 %19, label %41, label %20
20: ; preds = %13
%21 = call i8** @createStringArray(i32 %18, i32 1024)
store i8** %21, i8*** %2
%22 = icmp sgt i32 %18, 0
br i1 %22, label %23, label %41
23: ; preds = %20
%24 = zext i32 %18 to i64
%25 = load i8*, i8** %21
%26 = load i8**, i8*** %6
%27 = load i8*, i8** %26
%28 = call i32 @sprintf(i8* dereferenceable(1) %25, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %27)
%29 = icmp eq i32 %18, 1
br i1 %29, label %41, label %30
30: ; preds = %23, %30
%31 = phi i64 [ %39, %30 ], [ 1, %23 ]
%32 = load i8**, i8*** %2
%33 = getelementptr inbounds i8*, i8** %32, i64 %31
%34 = load i8*, i8** %33
%35 = load i8**, i8*** %6
%36 = getelementptr inbounds i8*, i8** %35, i64 %31
%37 = load i8*, i8** %36
%38 = call i32 @sprintf(i8* dereferenceable(1) %34, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %37)
%39 = add nuw nsw i64 %31, 1
%40 = icmp eq i64 %39, %24
br i1 %40, label %41, label %30
41: ; preds = %20, %23, %30, %13
%42 = load i8**, i8*** %4
%43 = call i32 @freeStringArray(i8** %42, i32 %8)
%44 = load i8**, i8*** %6
%45 = call i32 @free(i8** %44)
br label %46
46: ; preds = %41, %10
%47 = phi i32 [ %18, %41 ], [ 0, %10 ]
ret i32 %47
}