#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 {
  int d_type;
  char *d_name;
  int d_reclen;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IFDIR;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *internal_sub_strdup(char *);
char *malloc(int);
scalar_t__ memcmp(char *, char *, scalar_t__);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ realloc(char *, scalar_t__);
scalar_t__ strcasecmp(char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
scalar_t__ strncasecmp(char *, char *, int);
char *strrchr(char *, char);
char *internal_sub_filenames(char *filename, unsigned perfect_match) {
  char *dir;
  char *sub_exts[] = {"utf", "sub", "srt", "smi", "rt",  "txt",
                      "ssa", "aqt", "jss", "js",  "ass", NULL};
  char *p = NULL, *p2 = NULL;
  char *ext, *fn, *long_fn;
  DIR *pDir;
  int i, looking;
  struct dirent *pDirEntry;
  char *subname = NULL;
  unsigned videofile_lnamlen = 0;
  fn = p;
  p = strrchr(filename, '/');
  p2 = strrchr(filename, '\\');
  if (p2 > p) {
    p = p2;
  }
  if (p) {
    dir = (char *)malloc(p - filename + 2);
    if (!dir) {
      return NULL;
    }
    memcpy(dir, filename, p - filename + 1);
    dir[p - filename + 1] = '\0';
    fn = p + 1;
  } else {
    dir = (char *)malloc(3);
    if (!dir) {
      return NULL;
    }
    strcpy(dir, "./");
  }
  pDir = opendir(dir);
  if (!pDir) {
    free(dir);
    return NULL;
  }
  looking = 1;
  while (looking) {
    pDirEntry = readdir(pDir);
    if (!pDirEntry) {
      break;
    }
    if (pDirEntry->d_type & S_IFDIR) {
      continue;
    }
    if (strncasecmp(fn, pDirEntry->d_name, pDirEntry->d_reclen) == 0) {
      looking = 0;
    }
  }
  if (looking == 1) {
    closedir(pDir);
    free(dir);
    return NULL;
  } else {
    long_fn = malloc(pDirEntry->d_reclen);
    if (!long_fn) {
      closedir(pDir);
      free(dir);
      return NULL;
    }
    memcpy(long_fn, pDirEntry->d_name, pDirEntry->d_reclen);
    if (pDirEntry->d_reclen)
      videofile_lnamlen = pDirEntry->d_reclen;
  }
  closedir(pDir);
  pDir = opendir(dir);
  if (!pDir) {
    free(long_fn);
    free(dir);
    return NULL;
  }
  looking = 1;
  while (looking) {
    pDirEntry = readdir(pDir);
    if (!pDirEntry) {
      break;
    }
    if (pDirEntry->d_type & S_IFDIR) {
      continue;
    }
    ext = strrchr(pDirEntry->d_name, '.');
    if (!ext) {
      continue;
    }
    ext++;
    i = 0;
    while (sub_exts[i]) {
      if (strcasecmp(ext, sub_exts[i]) == 0) {
        if (subname) {
          free(subname);
        }
        subname = internal_sub_strdup(pDirEntry->d_name);
        if (memcmp(long_fn, pDirEntry->d_name, (strlen(long_fn) - 4)) == 0) {
          looking = 0;
        }
        break;
      }
      i++;
    }
  }
  closedir(pDir);
  free(long_fn);
  if ((subname) && (looking == 0)) {
    p = (char *)realloc(dir, strlen(dir) + strlen(subname) + 1);
    if (p) {
      strcat(p, subname);
    }
    free(subname);
    return p;
  } else {
    free(dir);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<internal_sub_filenames>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
lea    0x2ba3(%rip),%rsi
mov    $0x60,%edx
call   10b0 <memcpy@plt>
movq   $0x0,-0x88(%rbp)
movq   $0x0,-0x90(%rbp)
movq   $0x0,-0xc8(%rbp)
movl   $0x0,-0xcc(%rbp)
mov    -0x88(%rbp),%rax
mov    %rax,-0xa0(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x88(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x90(%rbp)
mov    -0x90(%rbp),%rax
cmp    -0x88(%rbp),%rax
jbe    129c <internal_sub_filenames+0xac>
mov    -0x90(%rbp),%rax
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     132e <internal_sub_filenames+0x13e>
mov    -0x88(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x2,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12df <internal_sub_filenames+0xef>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x88(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   10b0 <memcpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x88(%rbp),%rcx
mov    -0x10(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,0x1(%rax,%rcx,1)
mov    -0x88(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0xa0(%rbp)
jmp    1364 <internal_sub_filenames+0x174>
mov    $0x3,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1354 <internal_sub_filenames+0x164>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
mov    -0x20(%rbp),%rdi
lea    0xcc8(%rip),%rsi
call   1050 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    1398 <internal_sub_filenames+0x1a8>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
movl   $0x1,-0xb8(%rbp)
cmpl   $0x0,-0xb8(%rbp)
je     142f <internal_sub_filenames+0x23f>
mov    -0xb0(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jne    13d5 <internal_sub_filenames+0x1e5>
jmp    142f <internal_sub_filenames+0x23f>
mov    -0xc0(%rbp),%rax
mov    (%rax),%eax
mov    0x2beb(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     13f5 <internal_sub_filenames+0x205>
jmp    13a2 <internal_sub_filenames+0x1b2>
mov    -0xa0(%rbp),%rdi
mov    -0xc0(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0xc0(%rbp),%rax
mov    0x10(%rax),%edx
call   10e0 <strncasecmp@plt>
cmp    $0x0,%rax
jne    142a <internal_sub_filenames+0x23a>
movl   $0x0,-0xb8(%rbp)
jmp    13a2 <internal_sub_filenames+0x1b2>
cmpl   $0x1,-0xb8(%rbp)
jne    145e <internal_sub_filenames+0x26e>
mov    -0xb0(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
mov    -0xc0(%rbp),%rax
mov    0x10(%rax),%edi
call   10d0 <malloc@plt>
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0xa8(%rbp)
jne    14a4 <internal_sub_filenames+0x2b4>
mov    -0xb0(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
mov    -0xa8(%rbp),%rdi
mov    -0xc0(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0xc0(%rbp),%rax
mov    0x10(%rax),%edx
call   10b0 <memcpy@plt>
mov    -0xc0(%rbp),%rax
cmpl   $0x0,0x10(%rax)
je     14e6 <internal_sub_filenames+0x2f6>
mov    -0xc0(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0xcc(%rbp)
jmp    14eb <internal_sub_filenames+0x2fb>
mov    -0xb0(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0x20(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0xb0(%rbp)
cmpq   $0x0,-0xb0(%rbp)
jne    1537 <internal_sub_filenames+0x347>
mov    -0xa8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
movl   $0x1,-0xb8(%rbp)
cmpl   $0x0,-0xb8(%rbp)
je     16bd <internal_sub_filenames+0x4cd>
mov    -0xb0(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0xc0(%rbp)
cmpq   $0x0,-0xc0(%rbp)
jne    1574 <internal_sub_filenames+0x384>
jmp    16bd <internal_sub_filenames+0x4cd>
mov    -0xc0(%rbp),%rax
mov    (%rax),%eax
mov    0x2a4c(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1594 <internal_sub_filenames+0x3a4>
jmp    1541 <internal_sub_filenames+0x351>
mov    -0xc0(%rbp),%rax
mov    0x8(%rax),%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
jne    15c3 <internal_sub_filenames+0x3d3>
jmp    1541 <internal_sub_filenames+0x351>
mov    -0x98(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x98(%rbp)
movl   $0x0,-0xb4(%rbp)
movslq -0xb4(%rbp),%rax
cmpq   $0x0,-0x80(%rbp,%rax,8)
je     16b8 <internal_sub_filenames+0x4c8>
mov    -0x98(%rbp),%rdi
movslq -0xb4(%rbp),%rax
mov    -0x80(%rbp,%rax,8),%rsi
call   1040 <strcasecmp@plt>
cmp    $0x0,%rax
jne    16a4 <internal_sub_filenames+0x4b4>
cmpq   $0x0,-0xc8(%rbp)
je     162e <internal_sub_filenames+0x43e>
mov    -0xc8(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc0(%rbp),%rax
mov    0x8(%rax),%rdi
call   1110 <internal_sub_strdup@plt>
mov    %rax,-0xc8(%rbp)
mov    -0xa8(%rbp),%rax
mov    %rax,-0xe0(%rbp)
mov    -0xc0(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xd8(%rbp)
mov    -0xa8(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xe0(%rbp),%rdi
mov    -0xd8(%rbp),%rsi
mov    %rax,%rdx
sub    $0x4,%rdx
call   10a0 <memcmp@plt>
cmp    $0x0,%rax
jne    169f <internal_sub_filenames+0x4af>
movl   $0x0,-0xb8(%rbp)
jmp    16b8 <internal_sub_filenames+0x4c8>
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    15df <internal_sub_filenames+0x3ef>
jmp    1541 <internal_sub_filenames+0x351>
mov    -0xb0(%rbp),%rdi
call   1090 <closedir@plt>
mov    -0xa8(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0xc8(%rbp)
je     1775 <internal_sub_filenames+0x585>
cmpl   $0x0,-0xb8(%rbp)
jne    1775 <internal_sub_filenames+0x585>
mov    -0x20(%rbp),%rax
mov    %rax,-0xe8(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,-0xf0(%rbp)
mov    -0xc8(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0xf0(%rbp),%rsi
mov    -0xe8(%rbp),%rdi
add    %rax,%rsi
add    $0x1,%rsi
call   10f0 <realloc@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
je     1759 <internal_sub_filenames+0x569>
mov    -0x88(%rbp),%rdi
mov    -0xc8(%rbp),%rsi
call   1100 <strcat@plt>
mov    -0xc8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x88(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1786 <internal_sub_filenames+0x596>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internal_sub_filenames>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1080 <strrchr@plt>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x5c,%esi
call   1080 <strrchr@plt>
cmp    %r14,%rax
cmova  %rax,%r14
test   %r14,%r14
je     125c <internal_sub_filenames+0x6c>
mov    %r14,%rbp
sub    %rbx,%rbp
lea    0x2(%rbp),%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     12de <internal_sub_filenames+0xee>
mov    %rax,%r13
lea    0x1(%rbp),%rdx
mov    %rax,%rdi
mov    %rbx,%rsi
call   10b0 <memcpy@plt>
movb   $0x0,0x1(%r13,%rbp,1)
add    $0x1,%r14
jmp    1280 <internal_sub_filenames+0x90>
mov    $0x3,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     12de <internal_sub_filenames+0xee>
mov    %rax,%r13
lea    0xdb2(%rip),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
xor    %r14d,%r14d
mov    %r13,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     1528 <internal_sub_filenames+0x338>
mov    %rax,%rbp
mov    0x2d3d(%rip),%r12
jmp    12a4 <internal_sub_filenames+0xb4>
nopl   (%rax)
test   %ecx,%ecx
je     12e5 <internal_sub_filenames+0xf5>
mov    %rbp,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     1520 <internal_sub_filenames+0x330>
mov    %rax,%rbx
mov    (%r12),%eax
mov    $0x1,%ecx
test   %eax,(%rbx)
jne    12a0 <internal_sub_filenames+0xb0>
mov    0x8(%rbx),%rsi
mov    0x10(%rbx),%edx
mov    %r14,%rdi
call   10e0 <strncasecmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
jmp    12a0 <internal_sub_filenames+0xb0>
xor    %ebx,%ebx
jmp    1532 <internal_sub_filenames+0x342>
mov    0x10(%rbx),%r15d
mov    %r15d,%edi
call   10d0 <malloc@plt>
test   %rax,%rax
je     1520 <internal_sub_filenames+0x330>
mov    %rax,%r14
mov    0x8(%rbx),%rsi
mov    %rax,%rdi
mov    %r15d,%edx
call   10b0 <memcpy@plt>
mov    %rbp,%rdi
call   1090 <closedir@plt>
mov    %r13,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     1544 <internal_sub_filenames+0x354>
mov    %rax,%rbx
mov    %r14,0x10(%rsp)
mov    %r13,0x8(%rsp)
xor    %eax,%eax
mov    %rax,(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10c0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
sete   %r14b
je     14bd <internal_sub_filenames+0x2cd>
mov    (%r12),%eax
test   %eax,0x0(%rbp)
jne    1340 <internal_sub_filenames+0x150>
mov    0x8(%rbp),%r13
mov    %r13,%rdi
mov    $0x2e,%esi
call   1080 <strrchr@plt>
test   %rax,%rax
je     1340 <internal_sub_filenames+0x150>
mov    %rax,%r15
add    $0x1,%r15
mov    %r15,%rdi
lea    0xc78(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc64(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc50(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc3c(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc21(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc14(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xc04(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xbf4(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xbe4(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xbd4(%rip),%rsi
call   1040 <strcasecmp@plt>
test   %rax,%rax
je     146f <internal_sub_filenames+0x27f>
mov    %r15,%rdi
lea    0xbc3(%rip),%rsi
call   1040 <strcasecmp@plt>
mov    $0x1,%ecx
test   %rax,%rax
jne    14b5 <internal_sub_filenames+0x2c5>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1481 <internal_sub_filenames+0x291>
call   1030 <free@plt>
mov    0x8(%rbp),%r13
mov    %r13,%rdi
call   1110 <internal_sub_strdup@plt>
mov    %rax,(%rsp)
mov    0x8(%rbp),%r15
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    -0x4(%rax),%rdx
mov    %rbp,%rdi
mov    %r15,%rsi
call   10a0 <memcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
test   %ecx,%ecx
jne    1340 <internal_sub_filenames+0x150>
mov    %rbx,%rdi
call   1090 <closedir@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
test   $0x1,%r14b
jne    154e <internal_sub_filenames+0x35e>
mov    (%rsp),%rbp
test   %rbp,%rbp
mov    0x8(%rsp),%r13
je     152a <internal_sub_filenames+0x33a>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1070 <strlen@plt>
lea    (%rbx,%rax,1),%rsi
add    $0x1,%rsi
mov    %r13,%rdi
call   10f0 <realloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     151b <internal_sub_filenames+0x32b>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1100 <strcat@plt>
mov    %rbp,%r13
jmp    152a <internal_sub_filenames+0x33a>
mov    %rbp,%rdi
call   1090 <closedir@plt>
xor    %ebx,%ebx
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
jmp    1528 <internal_sub_filenames+0x338>
mov    0x8(%rsp),%r13
jmp    152a <internal_sub_filenames+0x33a>

LLVM IR (-O0):
%struct.dirent = type { i32, i8*, i32 }
@.str = [4 x i8] c"utf\00"
@.str.1 = [4 x i8] c"sub\00"
@.str.2 = [4 x i8] c"srt\00"
@.str.3 = [4 x i8] c"smi\00"
@.str.4 = [3 x i8] c"rt\00"
@.str.5 = [4 x i8] c"txt\00"
@.str.6 = [4 x i8] c"ssa\00"
@.str.7 = [4 x i8] c"aqt\00"
@.str.8 = [4 x i8] c"jss\00"
@.str.9 = [3 x i8] c"js\00"
@.str.10 = [4 x i8] c"ass\00"
@__const.internal_sub_filenames.sub_exts = [12 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* null]
@.str.11 = [3 x i8] c"./\00"
@S_IFDIR = global i32 0
define i8* @internal_sub_filenames(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca [12 x i8*]
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32
%15 = alloca i32
%16 = alloca %struct.dirent*
%17 = alloca i8*
%18 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%19 = bitcast [12 x i8*]* %7 to i8*
store i8* null, i8** %8
store i8* null, i8** %9
store i8* null, i8** %17
store i32 0, i32* %18
%20 = load i8*, i8** %8
store i8* %20, i8** %11
%21 = load i8*, i8** %4
%22 = call i8* @strrchr(i8* %21, i8 signext 47)
store i8* %22, i8** %8
%23 = load i8*, i8** %4
%24 = call i8* @strrchr(i8* %23, i8 signext 92)
store i8* %24, i8** %9
%25 = load i8*, i8** %9
%26 = load i8*, i8** %8
%27 = icmp ugt i8* %25, %26
br i1 %27, label %28, label %30
28: ; preds = %2
%29 = load i8*, i8** %9
store i8* %29, i8** %8
br label %30
30: ; preds = %28, %2
%31 = load i8*, i8** %8
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %66
33: ; preds = %30
%34 = load i8*, i8** %8
%35 = load i8*, i8** %4
%36 = ptrtoint i8* %34 to i64
%37 = ptrtoint i8* %35 to i64
%38 = sub i64 %36, %37
%39 = add nsw i64 %38, 2
%40 = trunc i64 %39 to i32
%41 = call i8* @malloc(i32 %40)
store i8* %41, i8** %6
%42 = load i8*, i8** %6
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %33
store i8* null, i8** %3
br label %264
45: ; preds = %33
%46 = load i8*, i8** %6
%47 = load i8*, i8** %4
%48 = load i8*, i8** %8
%49 = load i8*, i8** %4
%50 = ptrtoint i8* %48 to i64
%51 = ptrtoint i8* %49 to i64
%52 = sub i64 %50, %51
%53 = add nsw i64 %52, 1
%54 = trunc i64 %53 to i32
%55 = call i32 @memcpy(i8* %46, i8* %47, i32 %54)
%56 = load i8*, i8** %6
%57 = load i8*, i8** %8
%58 = load i8*, i8** %4
%59 = ptrtoint i8* %57 to i64
%60 = ptrtoint i8* %58 to i64
%61 = sub i64 %59, %60
%62 = add nsw i64 %61, 1
%63 = getelementptr inbounds i8, i8* %56, i64 %62
store i8 0, i8* %63
%64 = load i8*, i8** %8
%65 = getelementptr inbounds i8, i8* %64, i64 1
store i8* %65, i8** %11
br label %74
66: ; preds = %30
%67 = call i8* @malloc(i32 3)
store i8* %67, i8** %6
%68 = load i8*, i8** %6
%69 = icmp ne i8* %68, null
br i1 %69, label %71, label %70
70: ; preds = %66
store i8* null, i8** %3
br label %264
71: ; preds = %66
%72 = load i8*, i8** %6
%73 = call i32 @strcpy(i8* %72, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %74
74: ; preds = %71, %45
%75 = load i8*, i8** %6
%76 = call i32* @opendir(i8* %75)
store i32* %76, i32** %13
%77 = load i32*, i32** %13
%78 = icmp ne i32* %77, null
br i1 %78, label %82, label %79
79: ; preds = %74
%80 = load i8*, i8** %6
%81 = call i32 @free(i8* %80)
store i8* null, i8** %3
br label %264
82: ; preds = %74
store i32 1, i32* %15
br label %83
83: ; preds = %111, %99, %82
%84 = load i32, i32* %15
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %112
86: ; preds = %83
%87 = load i32*, i32** %13
%88 = call %struct.dirent* @readdir(i32* %87)
store %struct.dirent* %88, %struct.dirent** %16
%89 = load %struct.dirent*, %struct.dirent** %16
%90 = icmp ne %struct.dirent* %89, null
br i1 %90, label %92, label %91
91: ; preds = %86
br label %112
92: ; preds = %86
%93 = load %struct.dirent*, %struct.dirent** %16
%94 = getelementptr inbounds %struct.dirent, %struct.dirent* %93, i32 0, i32 0
%95 = load i32, i32* %94
%96 = load i32, i32* @S_IFDIR
%97 = and i32 %95, %96
%98 = icmp ne i32 %97, 0
br i1 %98, label %99, label %100
99: ; preds = %92
br label %83
100: ; preds = %92
%101 = load i8*, i8** %11
%102 = load %struct.dirent*, %struct.dirent** %16
%103 = getelementptr inbounds %struct.dirent, %struct.dirent* %102, i32 0, i32 1
%104 = load i8*, i8** %103
%105 = load %struct.dirent*, %struct.dirent** %16
%106 = getelementptr inbounds %struct.dirent, %struct.dirent* %105, i32 0, i32 2
%107 = load i32, i32* %106
%108 = call i64 @strncasecmp(i8* %101, i8* %104, i32 %107)
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %111
110: ; preds = %100
store i32 0, i32* %15
br label %111
111: ; preds = %110, %100
br label %83
112: ; preds = %91, %83
%113 = load i32, i32* %15
%114 = icmp eq i32 %113, 1
br i1 %114, label %115, label %120
115: ; preds = %112
%116 = load i32*, i32** %13
%117 = call i32 @closedir(i32* %116)
%118 = load i8*, i8** %6
%119 = call i32 @free(i8* %118)
store i8* null, i8** %3
br label %264
120: ; preds = %112
%121 = load %struct.dirent*, %struct.dirent** %16
%122 = getelementptr inbounds %struct.dirent, %struct.dirent* %121, i32 0, i32 2
%123 = load i32, i32* %122
%124 = call i8* @malloc(i32 %123)
store i8* %124, i8** %12
%125 = load i8*, i8** %12
%126 = icmp ne i8* %125, null
br i1 %126, label %132, label %127
127: ; preds = %120
%128 = load i32*, i32** %13
%129 = call i32 @closedir(i32* %128)
%130 = load i8*, i8** %6
%131 = call i32 @free(i8* %130)
store i8* null, i8** %3
br label %264
132: ; preds = %120
%133 = load i8*, i8** %12
%134 = load %struct.dirent*, %struct.dirent** %16
%135 = getelementptr inbounds %struct.dirent, %struct.dirent* %134, i32 0, i32 1
%136 = load i8*, i8** %135
%137 = load %struct.dirent*, %struct.dirent** %16
%138 = getelementptr inbounds %struct.dirent, %struct.dirent* %137, i32 0, i32 2
%139 = load i32, i32* %138
%140 = call i32 @memcpy(i8* %133, i8* %136, i32 %139)
%141 = load %struct.dirent*, %struct.dirent** %16
%142 = getelementptr inbounds %struct.dirent, %struct.dirent* %141, i32 0, i32 2
%143 = load i32, i32* %142
%144 = icmp ne i32 %143, 0
br i1 %144, label %145, label %149
145: ; preds = %132
%146 = load %struct.dirent*, %struct.dirent** %16
%147 = getelementptr inbounds %struct.dirent, %struct.dirent* %146, i32 0, i32 2
%148 = load i32, i32* %147
store i32 %148, i32* %18
br label %149
149: ; preds = %145, %132
br label %150
150: ; preds = %149
%151 = load i32*, i32** %13
%152 = call i32 @closedir(i32* %151)
%153 = load i8*, i8** %6
%154 = call i32* @opendir(i8* %153)
store i32* %154, i32** %13
%155 = load i32*, i32** %13
%156 = icmp ne i32* %155, null
br i1 %156, label %162, label %157
157: ; preds = %150
%158 = load i8*, i8** %12
%159 = call i32 @free(i8* %158)
%160 = load i8*, i8** %6
%161 = call i32 @free(i8* %160)
store i8* null, i8** %3
br label %264
162: ; preds = %150
store i32 1, i32* %15
br label %163
163: ; preds = %230, %187, %179, %162
%164 = load i32, i32* %15
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %231
166: ; preds = %163
%167 = load i32*, i32** %13
%168 = call %struct.dirent* @readdir(i32* %167)
store %struct.dirent* %168, %struct.dirent** %16
%169 = load %struct.dirent*, %struct.dirent** %16
%170 = icmp ne %struct.dirent* %169, null
br i1 %170, label %172, label %171
171: ; preds = %166
br label %231
172: ; preds = %166
%173 = load %struct.dirent*, %struct.dirent** %16
%174 = getelementptr inbounds %struct.dirent, %struct.dirent* %173, i32 0, i32 0
%175 = load i32, i32* %174
%176 = load i32, i32* @S_IFDIR
%177 = and i32 %175, %176
%178 = icmp ne i32 %177, 0
br i1 %178, label %179, label %180
179: ; preds = %172
br label %163
180: ; preds = %172
%181 = load %struct.dirent*, %struct.dirent** %16
%182 = getelementptr inbounds %struct.dirent, %struct.dirent* %181, i32 0, i32 1
%183 = load i8*, i8** %182
%184 = call i8* @strrchr(i8* %183, i8 signext 46)
store i8* %184, i8** %10
%185 = load i8*, i8** %10
%186 = icmp ne i8* %185, null
br i1 %186, label %188, label %187
187: ; preds = %180
br label %163
188: ; preds = %180
%189 = load i8*, i8** %10
%190 = getelementptr inbounds i8, i8* %189, i32 1
store i8* %190, i8** %10
store i32 0, i32* %14
br label %191
191: ; preds = %227, %188
%192 = load i32, i32* %14
%193 = sext i32 %192 to i64
%194 = getelementptr inbounds [12 x i8*], [12 x i8*]* %7, i64 0, i64 %193
%195 = load i8*, i8** %194
%196 = icmp ne i8* %195, null
br i1 %196, label %197, label %230
197: ; preds = %191
%198 = load i8*, i8** %10
%199 = load i32, i32* %14
%200 = sext i32 %199 to i64
%201 = getelementptr inbounds [12 x i8*], [12 x i8*]* %7, i64 0, i64 %200
%202 = load i8*, i8** %201
%203 = call i64 @strcasecmp(i8* %198, i8* %202)
%204 = icmp eq i64 %203, 0
br i1 %204, label %205, label %227
205: ; preds = %197
%206 = load i8*, i8** %17
%207 = icmp ne i8* %206, null
br i1 %207, label %208, label %211
208: ; preds = %205
%209 = load i8*, i8** %17
%210 = call i32 @free(i8* %209)
br label %211
211: ; preds = %208, %205
%212 = load %struct.dirent*, %struct.dirent** %16
%213 = getelementptr inbounds %struct.dirent, %struct.dirent* %212, i32 0, i32 1
%214 = load i8*, i8** %213
%215 = call i8* @internal_sub_strdup(i8* %214)
store i8* %215, i8** %17
%216 = load i8*, i8** %12
%217 = load %struct.dirent*, %struct.dirent** %16
%218 = getelementptr inbounds %struct.dirent, %struct.dirent* %217, i32 0, i32 1
%219 = load i8*, i8** %218
%220 = load i8*, i8** %12
%221 = call i64 @strlen(i8* %220)
%222 = sub nsw i64 %221, 4
%223 = call i64 @memcmp(i8* %216, i8* %219, i64 %222)
%224 = icmp eq i64 %223, 0
br i1 %224, label %225, label %226
225: ; preds = %211
store i32 0, i32* %15
br label %226
226: ; preds = %225, %211
br label %230
227: ; preds = %197
%228 = load i32, i32* %14
%229 = add nsw i32 %228, 1
store i32 %229, i32* %14
br label %191
230: ; preds = %226, %191
br label %163
231: ; preds = %171, %163
%232 = load i32*, i32** %13
%233 = call i32 @closedir(i32* %232)
%234 = load i8*, i8** %12
%235 = call i32 @free(i8* %234)
%236 = load i8*, i8** %17
%237 = icmp ne i8* %236, null
br i1 %237, label %238, label %261
238: ; preds = %231
%239 = load i32, i32* %15
%240 = icmp eq i32 %239, 0
br i1 %240, label %241, label %261
241: ; preds = %238
%242 = load i8*, i8** %6
%243 = load i8*, i8** %6
%244 = call i64 @strlen(i8* %243)
%245 = load i8*, i8** %17
%246 = call i64 @strlen(i8* %245)
%247 = add nsw i64 %244, %246
%248 = add nsw i64 %247, 1
%249 = call i64 @realloc(i8* %242, i64 %248)
%250 = inttoptr i64 %249 to i8*
store i8* %250, i8** %8
%251 = load i8*, i8** %8
%252 = icmp ne i8* %251, null
br i1 %252, label %253, label %257
253: ; preds = %241
%254 = load i8*, i8** %8
%255 = load i8*, i8** %17
%256 = call i32 @strcat(i8* %254, i8* %255)
br label %257
257: ; preds = %253, %241
%258 = load i8*, i8** %17
%259 = call i32 @free(i8* %258)
%260 = load i8*, i8** %8
store i8* %260, i8** %3
br label %264
261: ; preds = %238, %231
%262 = load i8*, i8** %6
%263 = call i32 @free(i8* %262)
store i8* null, i8** %3
br label %264
264: ; preds = %261, %257, %157, %127, %115, %79, %70, %44
%265 = load i8*, i8** %3
ret i8* %265
}

LLVM IR (-O2):
%struct.dirent = type { i32, i8*, i32 }
@.str = [4 x i8] c"utf\00"
@.str.1 = [4 x i8] c"sub\00"
@.str.2 = [4 x i8] c"srt\00"
@.str.3 = [4 x i8] c"smi\00"
@.str.4 = [3 x i8] c"rt\00"
@.str.5 = [4 x i8] c"txt\00"
@.str.6 = [4 x i8] c"ssa\00"
@.str.7 = [4 x i8] c"aqt\00"
@.str.8 = [4 x i8] c"jss\00"
@.str.9 = [3 x i8] c"js\00"
@.str.10 = [4 x i8] c"ass\00"
@.str.11 = [3 x i8] c"./\00"
@S_IFDIR = global i32 0
define i8* @internal_sub_filenames(i8* %0, i32 %1) {
%3 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%4 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%5 = icmp ugt i8* %4, %3
%6 = select i1 %5, i8* %4, i8* %3
%7 = icmp eq i8* %6, null
br i1 %7, label %22, label %8
8: ; preds = %2
%9 = ptrtoint i8* %6 to i64
%10 = ptrtoint i8* %0 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = add i32 %12, 2
%14 = tail call i8* @malloc(i32 %13)
%15 = icmp eq i8* %14, null
br i1 %15, label %164, label %16
16: ; preds = %8
%17 = add nsw i64 %11, 1
%18 = trunc i64 %17 to i32
%19 = tail call i32 @memcpy(i8* %14, i8* %0, i32 %18)
%20 = getelementptr inbounds i8, i8* %14, i64 %17
store i8 0, i8* %20
%21 = getelementptr inbounds i8, i8* %6, i64 1
br label %27
22: ; preds = %2
%23 = tail call dereferenceable_or_null(3) i8* @malloc(i32 3)
%24 = icmp eq i8* %23, null
br i1 %24, label %164, label %25
25: ; preds = %22
%26 = tail call i32 @strcpy(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
br label %27
27: ; preds = %25, %16
%28 = phi i8* [ %14, %16 ], [ %23, %25 ]
%29 = phi i8* [ %21, %16 ], [ null, %25 ]
%30 = tail call i32* @opendir(i8* %28)
%31 = icmp eq i32* %30, null
br i1 %31, label %160, label %32
32: ; preds = %27, %41
%33 = tail call %struct.dirent* @readdir(i32* %30)
%34 = icmp eq %struct.dirent* %33, null
br i1 %34, label %52, label %35
35: ; preds = %32
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 0
%37 = load i32, i32* %36
%38 = load i32, i32* @S_IFDIR
%39 = and i32 %38, %37
%40 = icmp eq i32 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %35, %44
%42 = phi i32 [ 1, %35 ], [ %51, %44 ]
%43 = icmp eq i32 %42, 0
br i1 %43, label %54, label %32
44: ; preds = %35
%45 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 1
%46 = load i8*, i8** %45
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 2
%48 = load i32, i32* %47
%49 = tail call i64 @strncasecmp(i8* %29, i8* %46, i32 %48)
%50 = icmp ne i64 %49, 0
%51 = zext i1 %50 to i32
br label %41
52: ; preds = %32
%53 = tail call i32 @closedir(i32* %30)
br label %160
54: ; preds = %41
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 2
%56 = load i32, i32* %55
%57 = tail call i8* @malloc(i32 %56)
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %61
59: ; preds = %54
%60 = tail call i32 @closedir(i32* %30)
br label %160
61: ; preds = %54
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i64 0, i32 1
%63 = load i8*, i8** %62
%64 = tail call i32 @memcpy(i8* %57, i8* %63, i32 %56)
%65 = tail call i32 @closedir(i32* %30)
%66 = tail call i32* @opendir(i8* %28)
%67 = icmp eq i32* %66, null
br i1 %67, label %68, label %139
68: ; preds = %61
%69 = tail call i32 @free(i8* %57)
br label %160
70: ; preds = %139, %78
%71 = phi i1 [ %80, %78 ], [ %142, %139 ]
%72 = phi %struct.dirent* [ %79, %78 ], [ %141, %139 ]
%73 = getelementptr inbounds %struct.dirent, %struct.dirent* %72, i64 0, i32 0
%74 = load i32, i32* %73
%75 = load i32, i32* @S_IFDIR
%76 = and i32 %75, %74
%77 = icmp eq i32 %76, 0
br i1 %77, label %81, label %78
78: ; preds = %70, %81
%79 = tail call %struct.dirent* @readdir(i32* %66)
%80 = icmp eq %struct.dirent* %79, null
br i1 %80, label %143, label %70
81: ; preds = %70
%82 = getelementptr inbounds %struct.dirent, %struct.dirent* %72, i64 0, i32 1
%83 = load i8*, i8** %82
%84 = tail call i8* @strrchr(i8* dereferenceable(1) %83, i8 signext 46)
%85 = icmp eq i8* %84, null
br i1 %85, label %78, label %86
86: ; preds = %81
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %72, i64 0, i32 1
%88 = getelementptr inbounds i8, i8* %84, i64 1
%89 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%90 = icmp eq i64 %89, 0
br i1 %90, label %121, label %91
91: ; preds = %86
%92 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%93 = icmp eq i64 %92, 0
br i1 %93, label %121, label %94
94: ; preds = %91
%95 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%96 = icmp eq i64 %95, 0
br i1 %96, label %121, label %97
97: ; preds = %94
%98 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%99 = icmp eq i64 %98, 0
br i1 %99, label %121, label %100
100: ; preds = %97
%101 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%102 = icmp eq i64 %101, 0
br i1 %102, label %121, label %103
103: ; preds = %100
%104 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%105 = icmp eq i64 %104, 0
br i1 %105, label %121, label %106
106: ; preds = %103
%107 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%108 = icmp eq i64 %107, 0
br i1 %108, label %121, label %109
109: ; preds = %106
%110 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%111 = icmp eq i64 %110, 0
br i1 %111, label %121, label %112
112: ; preds = %109
%113 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%114 = icmp eq i64 %113, 0
br i1 %114, label %121, label %115
115: ; preds = %112
%116 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0))
%117 = icmp eq i64 %116, 0
br i1 %117, label %121, label %118
118: ; preds = %115
%119 = tail call i64 @strcasecmp(i8* %88, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%120 = icmp eq i64 %119, 0
br i1 %120, label %121, label %135
121: ; preds = %118, %115, %112, %109, %106, %103, %100, %97, %94, %91, %86
%122 = icmp eq i8* %140, null
br i1 %122, label %126, label %123
123: ; preds = %121
%124 = tail call i32 @free(i8* %140)
%125 = load i8*, i8** %87
br label %126
126: ; preds = %123, %121
%127 = phi i8* [ %125, %123 ], [ %83, %121 ]
%128 = tail call i8* @internal_sub_strdup(i8* %127)
%129 = load i8*, i8** %87
%130 = tail call i64 @strlen(i8* %57)
%131 = add nsw i64 %130, -4
%132 = tail call i64 @memcmp(i8* %57, i8* %129, i64 %131)
%133 = icmp ne i64 %132, 0
%134 = zext i1 %133 to i32
br label %135
135: ; preds = %118, %126
%136 = phi i32 [ %134, %126 ], [ 1, %118 ]
%137 = phi i8* [ %128, %126 ], [ %140, %118 ]
%138 = icmp eq i32 %136, 0
br i1 %138, label %143, label %139
139: ; preds = %61, %135
%140 = phi i8* [ %137, %135 ], [ null, %61 ]
%141 = tail call %struct.dirent* @readdir(i32* %66)
%142 = icmp eq %struct.dirent* %141, null
br i1 %142, label %143, label %70
143: ; preds = %135, %139, %78
%144 = phi i1 [ %80, %78 ], [ %71, %135 ], [ %142, %139 ]
%145 = phi i8* [ %140, %78 ], [ %137, %135 ], [ %140, %139 ]
%146 = tail call i32 @closedir(i32* %66)
%147 = tail call i32 @free(i8* %57)
%148 = icmp eq i8* %145, null
%149 = or i1 %144, %148
br i1 %149, label %160, label %150
150: ; preds = %143
%151 = tail call i64 @strlen(i8* %28)
%152 = tail call i64 @strlen(i8* %145)
%153 = add i64 %151, 1
%154 = add i64 %153, %152
%155 = tail call i64 @realloc(i8* %28, i64 %154)
%156 = inttoptr i64 %155 to i8*
%157 = icmp eq i64 %155, 0
br i1 %157, label %160, label %158
158: ; preds = %150
%159 = tail call i32 @strcat(i8* %156, i8* %145)
br label %160
160: ; preds = %143, %150, %158, %27, %52, %59, %68
%161 = phi i8* [ %28, %68 ], [ %28, %59 ], [ %28, %52 ], [ %28, %27 ], [ %145, %158 ], [ %145, %150 ], [ %28, %143 ]
%162 = phi i8* [ null, %68 ], [ null, %59 ], [ null, %52 ], [ null, %27 ], [ %156, %158 ], [ %156, %150 ], [ null, %143 ]
%163 = tail call i32 @free(i8* %161)
br label %164
164: ; preds = %160, %22, %8
%165 = phi i8* [ null, %8 ], [ null, %22 ], [ %162, %160 ]
ret i8* %165
}