#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;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, ...);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
char *strrchr(char const *, char);
char *strstr(char *, char *);
char *strtok_r(char *, char *, char **);
scalar_t__ tolower(int);
int /*<<< orphan*/ trace(int, char *, char const *, ...);
extern int expath(const char *path, char *paths[], int nmax) {
  int i, j, n = 0;
  char tmp[1024];
  struct dirent *d;
  DIR *dp;
  const char *file = path;
  char dir[1024] = "", s1[1024], s2[1024], *p, *q, *r;
  trace(3, "expath  : path=%s nmax=%d\n", path, nmax);
  if ((p = strrchr(path, '/')) || (p = strrchr(path, '\\'))) {
    file = p + 1;
    strncpy(dir, path, p - path + 1);
    dir[p - path + 1] = '\0';
  }
  if (!(dp = opendir(*dir ? dir : ".")))
    return 0;
  while ((d = readdir(dp))) {
    if (*(d->d_name) == '.')
      continue;
    sprintf(s1, "^%s$", d->d_name);
    sprintf(s2, "^%s$", file);
    for (p = s1; *p; p++)
      *p = (char)tolower((int)*p);
    for (p = s2; *p; p++)
      *p = (char)tolower((int)*p);
    for (p = s1, q = strtok_r(s2, "*", &r); q; q = strtok_r(NULL, "*", &r)) {
      if ((p = strstr(p, q)))
        p += strlen(q);
      else
        break;
    }
    if (p && n < nmax)
      sprintf(paths[n++], "%s%s", dir, d->d_name);
  }
  closedir(dp);
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (strcmp(paths[i], paths[j]) > 0) {
        strcpy(tmp, paths[i]);
        strcpy(paths[i], paths[j]);
        strcpy(paths[j], tmp);
      }
    }
  }
  for (i = 0; i < n; i++)
    trace(3, "expath  : file=%s\n", paths[i]);
  return n;
}


x86 assembly (clang, -O0):
<expath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x850(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
mov    -0x10(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
mov    $0x3,%edi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   10e0 <trace@plt>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x1058(%rbp)
cmp    $0x0,%rax
jne    1273 <expath+0x93>
mov    -0x10(%rbp),%rdi
mov    $0x5c,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x1058(%rbp)
cmp    $0x0,%rax
je     12bf <expath+0xdf>
mov    -0x1058(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x448(%rbp)
lea    -0x850(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1058(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
add    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x1058(%rbp),%rax
mov    -0x10(%rbp),%rcx
sub    %rcx,%rax
movb   $0x0,-0x84f(%rbp,%rax,1)
movsbl -0x850(%rbp),%eax
cmp    $0x0,%eax
je     12e2 <expath+0x102>
lea    -0x850(%rbp),%rax
mov    %rax,-0x1070(%rbp)
jmp    12f5 <expath+0x115>
lea    0xd32(%rip),%rax
mov    %rax,-0x1070(%rbp)
jmp    12f5 <expath+0x115>
mov    -0x1070(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
jne    131e <expath+0x13e>
movl   $0x0,-0x4(%rbp)
jmp    1656 <expath+0x476>
jmp    1323 <expath+0x143>
mov    -0x440(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
je     153d <expath+0x35d>
mov    -0x438(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    135b <expath+0x17b>
jmp    1323 <expath+0x143>
lea    -0xc50(%rbp),%rdi
mov    -0x438(%rbp),%rax
mov    (%rax),%rdx
lea    0xcaa(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0x1050(%rbp),%rdi
mov    -0x448(%rbp),%rdx
lea    0xc8e(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
lea    -0xc50(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x1058(%rbp),%rax
cmpb   $0x0,(%rax)
je     13e5 <expath+0x205>
mov    -0x1058(%rbp),%rax
movsbl (%rax),%edi
call   10d0 <tolower@plt>
mov    %al,%cl
mov    -0x1058(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1058(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1058(%rbp)
jmp    13a4 <expath+0x1c4>
lea    -0x1050(%rbp),%rax
mov    %rax,-0x1058(%rbp)
mov    -0x1058(%rbp),%rax
cmpb   $0x0,(%rax)
je     1434 <expath+0x254>
mov    -0x1058(%rbp),%rax
movsbl (%rax),%edi
call   10d0 <tolower@plt>
mov    %al,%cl
mov    -0x1058(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1058(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1058(%rbp)
jmp    13f3 <expath+0x213>
lea    -0xc50(%rbp),%rax
mov    %rax,-0x1058(%rbp)
lea    -0x1050(%rbp),%rdi
lea    0xbd2(%rip),%rsi
lea    -0x1068(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x1060(%rbp)
cmpq   $0x0,-0x1060(%rbp)
je     14e9 <expath+0x309>
mov    -0x1058(%rbp),%rdi
mov    -0x1060(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x1058(%rbp)
cmp    $0x0,%rax
je     14bc <expath+0x2dc>
mov    -0x1060(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x1058(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x1058(%rbp)
jmp    14c1 <expath+0x2e1>
jmp    14e9 <expath+0x309>
jmp    14c6 <expath+0x2e6>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb51(%rip),%rsi
lea    -0x1068(%rbp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,-0x1060(%rbp)
jmp    1463 <expath+0x283>
cmpq   $0x0,-0x1058(%rbp)
je     1538 <expath+0x358>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1538 <expath+0x358>
mov    -0x18(%rbp),%rax
mov    -0x28(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x28(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x850(%rbp),%rdx
mov    -0x438(%rbp),%rax
mov    (%rax),%rcx
lea    0xaf3(%rip),%rsi
mov    $0x0,%al
call   10f0 <sprintf@plt>
jmp    1323 <expath+0x143>
mov    -0x440(%rbp),%rdi
call   1090 <closedir@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    -0x28(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    1610 <expath+0x430>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    15fd <expath+0x41d>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   10b0 <strcmp@plt>
cmp    $0x0,%rax
jle    15ea <expath+0x40a>
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    -0x430(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    15ef <expath+0x40f>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    156a <expath+0x38a>
jmp    1602 <expath+0x422>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1550 <expath+0x370>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1650 <expath+0x470>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x3,%edi
lea    0x9ee(%rip),%rsi
mov    $0x0,%al
call   10e0 <trace@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1617 <expath+0x437>
mov    -0x28(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<expath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    %edx,%ebx
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x830(%rsp),%r15
mov    $0x400,%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xde9(%rip),%rsi
mov    $0x3,%edi
mov    %r12,%rdx
mov    %ebx,0x18(%rsp)
mov    %ebx,%ecx
xor    %eax,%eax
call   10e0 <trace@plt>
mov    %r12,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    125a <expath+0x7a>
mov    %r12,%rdi
mov    $0x5c,%esi
call   1070 <strrchr@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1506 <expath+0x326>
lea    0x1(%rbp),%rbx
sub    %r12,%rbp
lea    0x1(%rbp),%rdx
mov    %r15,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
movb   $0x0,0x831(%rsp,%rbp,1)
cmpb   $0x0,0x830(%rsp)
lea    0xd94(%rip),%rdi
cmovne %r15,%rdi
mov    %rbx,0x10(%rsp)
call   1050 <opendir@plt>
test   %rax,%rax
je     14ee <expath+0x30e>
mov    %rax,%r12
lea    0x30(%rsp),%rbp
xor    %eax,%eax
mov    %rax,0x8(%rsp)
nopl   (%rax)
mov    %r12,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     1407 <expath+0x227>
mov    %rax,%rbx
mov    (%rax),%rdx
cmpb   $0x2e,(%rdx)
je     12b0 <expath+0xd0>
mov    %rbp,%rdi
lea    0xd47(%rip),%rbp
mov    %rbp,%rsi
xor    %eax,%eax
call   10f0 <sprintf@plt>
lea    0x430(%rsp),%rdi
mov    %rbp,%rsi
mov    0x10(%rsp),%rdx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x30(%rsp),%al
test   %al,%al
je     1327 <expath+0x147>
lea    0x31(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   10d0 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1310 <expath+0x130>
mov    0x430(%rsp),%al
test   %al,%al
je     1357 <expath+0x177>
lea    0x431(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   10d0 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1340 <expath+0x160>
lea    0x430(%rsp),%rdi
lea    0xcbc(%rip),%rsi
lea    0x28(%rsp),%rdx
call   10a0 <strtok_r@plt>
test   %rax,%rax
lea    0x30(%rsp),%rbp
je     13bf <expath+0x1df>
mov    %rax,%r15
mov    %rbp,%r13
mov    %r13,%rdi
mov    %r15,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
je     12b0 <expath+0xd0>
mov    %rax,%r13
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
add    %rax,%r13
xor    %edi,%edi
lea    0xc75(%rip),%rsi
lea    0x28(%rsp),%rdx
call   10a0 <strtok_r@plt>
mov    %rax,%r15
test   %rax,%rax
jne    1380 <expath+0x1a0>
mov    0x18(%rsp),%eax
cmp    %eax,0x8(%rsp)
jge    12b0 <expath+0xd0>
mov    0x8(%rsp),%rax
mov    %rax,%rbp
add    $0x1,%rbp
mov    %eax,%eax
mov    (%r14,%rax,8),%rdi
mov    (%rbx),%rcx
lea    0xc3b(%rip),%rsi
lea    0x830(%rsp),%rdx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %rbp,0x8(%rsp)
lea    0x30(%rsp),%rbp
jmp    12b0 <expath+0xd0>
mov    %r12,%rdi
call   1090 <closedir@plt>
cmpl   $0x2,0x8(%rsp)
jb     14b2 <expath+0x2d2>
mov    0x8(%rsp),%rbp
lea    -0x1(%rbp),%eax
mov    %rax,0x18(%rsp)
mov    %ebp,%eax
mov    %rax,0x20(%rsp)
xor    %r13d,%r13d
lea    0xc30(%rsp),%r12
mov    %r14,%rbx
jmp    1454 <expath+0x274>
xchg   %ax,%ax
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
mov    0x10(%rsp),%r13
cmp    0x18(%rsp),%r13
je     14b2 <expath+0x2d2>
lea    0x1(%r13),%rax
mov    %rax,0x10(%rsp)
cmp    0x20(%rsp),%rax
jae    1440 <expath+0x260>
mov    $0x1,%r15d
jmp    1479 <expath+0x299>
nopl   0x0(%rax)
add    $0x1,%r15
cmp    %r15,%rbp
je     1440 <expath+0x260>
mov    (%r14,%r13,8),%rdi
mov    (%rbx,%r15,8),%rsi
call   10b0 <strcmp@plt>
test   %rax,%rax
jle    1470 <expath+0x290>
mov    (%r14,%r13,8),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    (%r14,%r13,8),%rdi
mov    (%rbx,%r15,8),%rsi
call   1040 <strcpy@plt>
mov    (%rbx,%r15,8),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    1470 <expath+0x290>
mov    0x8(%rsp),%r15
test   %r15d,%r15d
je     14f1 <expath+0x311>
lea    0xb66(%rip),%rbp
mov    %r15,%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%r14),%rdx
mov    $0x3,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   10e0 <trace@plt>
add    $0x8,%r14
add    $0xffffffffffffffff,%rbx
jne    14d0 <expath+0x2f0>
jmp    14f1 <expath+0x311>
xor    %r15d,%r15d
mov    %r15d,%eax
add    $0x1038,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,0x10(%rsp)
lea    0xb09(%rip),%rdi
jmp    1290 <expath+0xb0>

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [27 x i8] c"expath : path=%s nmax=%d\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [5 x i8] c"^%s$\00"
@.str.3 = [2 x i8] c"*\00"
@.str.4 = [5 x i8] c"%s%s\00"
@.str.5 = [19 x i8] c"expath : file=%s\0A\00"
define i32 @expath(i8* %0, i8** nocapture %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i8*
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%13 = bitcast i8** %8 to i8*
%14 = tail call i32 (i32, i8*, i8*, ...) @trace(i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %2)
%15 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 92)
%19 = icmp eq i8* %18, null
br i1 %19, label %33, label %20
20: ; preds = %17, %3
%21 = phi i8* [ %15, %3 ], [ %18, %17 ]
%22 = getelementptr inbounds i8, i8* %21, i64 1
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %0 to i64
%25 = sub i64 %23, %24
%26 = add nsw i64 %25, 1
%27 = trunc i64 %26 to i32
%28 = call i32 @strncpy(i8* %10, i8* %0, i32 %27)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %26
store i8 0, i8* %29
%30 = load i8, i8* %10
%31 = icmp eq i8 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* %10
br label %33
33: ; preds = %20, %17
%34 = phi i8* [ %32, %20 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %17 ]
%35 = phi i8* [ %22, %20 ], [ %0, %17 ]
%36 = call i32* @opendir(i8* %34)
%37 = icmp eq i32* %36, null
br i1 %37, label %147, label %38
38: ; preds = %33, %92
%39 = phi i32 [ %94, %92 ], [ 0, %33 ]
%40 = icmp slt i32 %39, %2
br label %41
41: ; preds = %91, %38
br label %42
42: ; preds = %41, %45
%43 = call %struct.dirent* @readdir(i32* %36)
%44 = icmp eq %struct.dirent* %43, null
br i1 %44, label %100, label %45
45: ; preds = %42
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i64 0, i32 0
%47 = load i8*, i8** %46
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 46
br i1 %49, label %42, label %50
50: ; preds = %45
%51 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %47)
%52 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %12, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%53 = load i8, i8* %11
%54 = icmp eq i8 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %58, %50
%56 = load i8, i8* %12
%57 = icmp eq i8 %56, 0
br i1 %57, label %76, label %67
58: ; preds = %50, %58
%59 = phi i8 [ %65, %58 ], [ %53, %50 ]
%60 = phi i8* [ %64, %58 ], [ %11, %50 ]
%61 = sext i8 %59 to i32
%62 = call i64 @tolower(i32 %61)
%63 = trunc i64 %62 to i8
store i8 %63, i8* %60
%64 = getelementptr inbounds i8, i8* %60, i64 1
%65 = load i8, i8* %64
%66 = icmp eq i8 %65, 0
br i1 %66, label %55, label %58
67: ; preds = %55, %67
%68 = phi i8 [ %74, %67 ], [ %56, %55 ]
%69 = phi i8* [ %73, %67 ], [ %12, %55 ]
%70 = sext i8 %68 to i32
%71 = call i64 @tolower(i32 %70)
%72 = trunc i64 %71 to i8
store i8 %72, i8* %69
%73 = getelementptr inbounds i8, i8* %69, i64 1
%74 = load i8, i8* %73
%75 = icmp eq i8 %74, 0
br i1 %75, label %76, label %67
76: ; preds = %67, %55
%77 = call i8* @strtok_r(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %8)
%78 = icmp eq i8* %77, null
br i1 %78, label %90, label %79
79: ; preds = %76, %84
%80 = phi i8* [ %88, %84 ], [ %77, %76 ]
%81 = phi i8* [ %87, %84 ], [ %11, %76 ]
%82 = call i8* @strstr(i8* dereferenceable(1) %81, i8* %80)
%83 = icmp eq i8* %82, null
br i1 %83, label %91, label %84
84: ; preds = %79
%85 = call i32 @strlen(i8* %80)
%86 = sext i32 %85 to i64
%87 = getelementptr inbounds i8, i8* %82, i64 %86
%88 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %8)
%89 = icmp eq i8* %88, null
br i1 %89, label %90, label %79
90: ; preds = %84, %76
br i1 %40, label %92, label %91
91: ; preds = %79, %90
br label %41
92: ; preds = %90
%93 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i64 0, i32 0
%94 = add nuw nsw i32 %39, 1
%95 = zext i32 %39 to i64
%96 = getelementptr inbounds i8*, i8** %1, i64 %95
%97 = load i8*, i8** %96
%98 = load i8*, i8** %93
%99 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %97, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %98)
br label %38
100: ; preds = %42
%101 = call i32 @closedir(i32* %36)
%102 = icmp ugt i32 %39, 1
br i1 %102, label %103, label %111
103: ; preds = %100
%104 = add nsw i32 %39, -1
%105 = zext i32 %39 to i64
%106 = zext i32 %104 to i64
%107 = zext i32 %39 to i64
br label %115
108: ; preds = %137, %115
%109 = add nuw nsw i64 %117, 1
%110 = icmp eq i64 %118, %106
br i1 %110, label %111, label %115
111: ; preds = %108, %100
%112 = icmp eq i32 %39, 0
br i1 %112, label %147, label %113
113: ; preds = %111
%114 = zext i32 %39 to i64
br label %140
115: ; preds = %103, %108
%116 = phi i64 [ 0, %103 ], [ %118, %108 ]
%117 = phi i64 [ 1, %103 ], [ %109, %108 ]
%118 = add nuw nsw i64 %116, 1
%119 = icmp ult i64 %118, %105
br i1 %119, label %120, label %108
120: ; preds = %115
%121 = getelementptr inbounds i8*, i8** %1, i64 %116
br label %122
122: ; preds = %120, %137
%123 = phi i64 [ %117, %120 ], [ %138, %137 ]
%124 = load i8*, i8** %121
%125 = getelementptr inbounds i8*, i8** %1, i64 %123
%126 = load i8*, i8** %125
%127 = call i64 @strcmp(i8* %124, i8* %126)
%128 = icmp sgt i64 %127, 0
br i1 %128, label %129, label %137
129: ; preds = %122
%130 = load i8*, i8** %121
%131 = call i32 @strcpy(i8* %9, i8* %130)
%132 = load i8*, i8** %121
%133 = load i8*, i8** %125
%134 = call i32 @strcpy(i8* %132, i8* %133)
%135 = load i8*, i8** %125
%136 = call i32 @strcpy(i8* %135, i8* %9)
br label %137
137: ; preds = %122, %129
%138 = add nuw nsw i64 %123, 1
%139 = icmp eq i64 %138, %107
br i1 %139, label %108, label %122
140: ; preds = %113, %140
%141 = phi i64 [ 0, %113 ], [ %145, %140 ]
%142 = getelementptr inbounds i8*, i8** %1, i64 %141
%143 = load i8*, i8** %142
%144 = call i32 (i32, i8*, i8*, ...) @trace(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %143)
%145 = add nuw nsw i64 %141, 1
%146 = icmp eq i64 %145, %114
br i1 %146, label %147, label %140
147: ; preds = %140, %111, %33
%148 = phi i32 [ 0, %33 ], [ %39, %111 ], [ %39, %140 ]
ret i32 %148
}