#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(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;
  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(s2, "*"); q; q = strtok(NULL, "*")) {
      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   10d0 <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,-0x1068(%rbp)
jmp    12f5 <expath+0x115>
lea    0xd32(%rip),%rax
mov    %rax,-0x1068(%rbp)
jmp    12f5 <expath+0x115>
mov    -0x1068(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x440(%rbp)
cmp    $0x0,%rax
jne    131e <expath+0x13e>
movl   $0x0,-0x4(%rbp)
jmp    1648 <expath+0x468>
jmp    1323 <expath+0x143>
mov    -0x440(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x438(%rbp)
cmp    $0x0,%rax
je     152f <expath+0x34f>
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   10c0 <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   10c0 <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
call   10e0 <strtok@plt>
mov    %rax,-0x1060(%rbp)
cmpq   $0x0,-0x1060(%rbp)
je     14db <expath+0x2fb>
mov    -0x1058(%rbp),%rdi
mov    -0x1060(%rbp),%rsi
call   1100 <strstr@plt>
mov    %rax,-0x1058(%rbp)
cmp    $0x0,%rax
je     14b5 <expath+0x2d5>
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    14ba <expath+0x2da>
jmp    14db <expath+0x2fb>
jmp    14bf <expath+0x2df>
xor    %eax,%eax
mov    %eax,%edi
lea    0xb58(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x1060(%rbp)
jmp    145c <expath+0x27c>
cmpq   $0x0,-0x1058(%rbp)
je     152a <expath+0x34a>
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    152a <expath+0x34a>
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    0xb01(%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    1602 <expath+0x422>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    15ef <expath+0x40f>
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   10a0 <strcmp@plt>
cmp    $0x0,%rax
jle    15dc <expath+0x3fc>
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    15e1 <expath+0x401>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    155c <expath+0x37c>
jmp    15f4 <expath+0x414>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1542 <expath+0x362>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1642 <expath+0x462>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    $0x3,%edi
lea    0x9fc(%rip),%rsi
mov    $0x0,%al
call   10d0 <trace@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1609 <expath+0x429>
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    $0x1028,%rsp
mov    %edx,%ebx
mov    %rsi,%r15
mov    %rdi,%r12
lea    0x820(%rsp),%r14
mov    $0x400,%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xde9(%rip),%rsi
mov    $0x3,%edi
mov    %r12,%rdx
mov    %ebx,0x10(%rsp)
mov    %ebx,%ecx
xor    %eax,%eax
call   10d0 <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    %r14,%rdi
mov    %r12,%rsi
call   1030 <strncpy@plt>
movb   $0x0,0x821(%rsp,%rbp,1)
cmpb   $0x0,0x820(%rsp)
lea    0xd94(%rip),%rdi
cmovne %r14,%rdi
mov    %rbx,0x8(%rsp)
call   1050 <opendir@plt>
test   %rax,%rax
je     14ee <expath+0x30e>
mov    %rax,%r12
lea    0x20(%rsp),%rbp
xor    %eax,%eax
mov    %rax,(%rsp)
nopl   0x0(%rax)
mov    %r12,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     13ff <expath+0x21f>
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    0x420(%rsp),%rdi
mov    %rbp,%rsi
mov    0x8(%rsp),%rdx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    0x20(%rsp),%al
test   %al,%al
je     1327 <expath+0x147>
lea    0x21(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl %al,%edi
call   10c0 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1310 <expath+0x130>
mov    0x420(%rsp),%al
test   %al,%al
je     1357 <expath+0x177>
lea    0x421(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
movsbl %al,%edi
call   10c0 <tolower@plt>
mov    %al,-0x1(%rbp)
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1340 <expath+0x160>
lea    0x420(%rsp),%rdi
lea    0xcbc(%rip),%rsi
call   10e0 <strtok@plt>
test   %rax,%rax
lea    0x20(%rsp),%rbp
je     13ba <expath+0x1da>
mov    %rax,%r13
mov    %rbp,%r14
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r13,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
je     12b0 <expath+0xd0>
mov    %rax,%r14
mov    %r13,%rdi
call   1060 <strlen@plt>
cltq
add    %rax,%r14
xor    %edi,%edi
lea    0xc75(%rip),%rsi
call   10e0 <strtok@plt>
mov    %rax,%r13
test   %rax,%rax
jne    1380 <expath+0x1a0>
mov    0x10(%rsp),%eax
cmp    %eax,(%rsp)
jge    12b0 <expath+0xd0>
mov    (%rsp),%rax
mov    %rax,%rbp
add    $0x1,%rbp
mov    %eax,%eax
mov    (%r15,%rax,8),%rdi
mov    (%rbx),%rcx
lea    0xc42(%rip),%rsi
lea    0x820(%rsp),%rdx
xor    %eax,%eax
call   10f0 <sprintf@plt>
mov    %rbp,(%rsp)
lea    0x20(%rsp),%rbp
jmp    12b0 <expath+0xd0>
mov    %r12,%rdi
call   1090 <closedir@plt>
cmpl   $0x2,(%rsp)
jb     14b2 <expath+0x2d2>
mov    (%rsp),%rbp
lea    -0x1(%rbp),%eax
mov    %rax,0x10(%rsp)
mov    %ebp,%eax
mov    %rax,0x18(%rsp)
xor    %r13d,%r13d
lea    0xc20(%rsp),%r12
mov    %r15,%rbx
jmp    1454 <expath+0x274>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x8,%rbx
add    $0xffffffffffffffff,%rbp
mov    0x8(%rsp),%r13
cmp    0x10(%rsp),%r13
je     14b2 <expath+0x2d2>
lea    0x1(%r13),%rax
mov    %rax,0x8(%rsp)
cmp    0x18(%rsp),%rax
jae    1440 <expath+0x260>
mov    $0x1,%r14d
jmp    1479 <expath+0x299>
nopl   0x0(%rax)
add    $0x1,%r14
cmp    %r14,%rbp
je     1440 <expath+0x260>
mov    (%r15,%r13,8),%rdi
mov    (%rbx,%r14,8),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jle    1470 <expath+0x290>
mov    (%r15,%r13,8),%rsi
mov    %r12,%rdi
call   1040 <strcpy@plt>
mov    (%r15,%r13,8),%rdi
mov    (%rbx,%r14,8),%rsi
call   1040 <strcpy@plt>
mov    (%rbx,%r14,8),%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
jmp    1470 <expath+0x290>
mov    (%rsp),%r14
test   %r14d,%r14d
je     14f1 <expath+0x311>
lea    0xb67(%rip),%rbp
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%r15),%rdx
mov    $0x3,%edi
mov    %rbp,%rsi
xor    %eax,%eax
call   10d0 <trace@plt>
add    $0x8,%r15
add    $0xffffffffffffffff,%rbx
jne    14d0 <expath+0x2f0>
jmp    14f1 <expath+0x311>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x1028,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12,0x8(%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*
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i32 %2, i32* %7
store i32 0, i32* %10
%20 = load i8*, i8** %5
store i8* %20, i8** %14
%21 = bitcast [1024 x i8]* %15 to i8*
%22 = load i8*, i8** %5
%23 = load i32, i32* %7
%24 = call i32 (i32, i8*, i8*, ...) @trace(i32 3, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %22, i32 %23)
%25 = load i8*, i8** %5
%26 = call i8* @strrchr(i8* %25, i8 signext 47)
store i8* %26, i8** %18
%27 = icmp ne i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %3
%29 = load i8*, i8** %5
%30 = call i8* @strrchr(i8* %29, i8 signext 92)
store i8* %30, i8** %18
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %52
32: ; preds = %28, %3
%33 = load i8*, i8** %18
%34 = getelementptr inbounds i8, i8* %33, i64 1
store i8* %34, i8** %14
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%36 = load i8*, i8** %5
%37 = load i8*, i8** %18
%38 = load i8*, i8** %5
%39 = ptrtoint i8* %37 to i64
%40 = ptrtoint i8* %38 to i64
%41 = sub i64 %39, %40
%42 = add nsw i64 %41, 1
%43 = trunc i64 %42 to i32
%44 = call i32 @strncpy(i8* %35, i8* %36, i32 %43)
%45 = load i8*, i8** %18
%46 = load i8*, i8** %5
%47 = ptrtoint i8* %45 to i64
%48 = ptrtoint i8* %46 to i64
%49 = sub i64 %47, %48
%50 = add nsw i64 %49, 1
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 %50
store i8 0, i8* %51
br label %52
52: ; preds = %32, %28
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp ne i32 %55, 0
br i1 %56, label %57, label %59
57: ; preds = %52
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
br label %60
59: ; preds = %52
br label %60
60: ; preds = %59, %57
%61 = phi i8* [ %58, %57 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %59 ]
%62 = call i32* @opendir(i8* %61)
store i32* %62, i32** %13
%63 = icmp ne i32* %62, null
br i1 %63, label %65, label %64
64: ; preds = %60
store i32 0, i32* %4
br label %239
65: ; preds = %60
br label %66
66: ; preds = %159, %77, %65
%67 = load i32*, i32** %13
%68 = call %struct.dirent* @readdir(i32* %67)
store %struct.dirent* %68, %struct.dirent** %12
%69 = icmp ne %struct.dirent* %68, null
br i1 %69, label %70, label %160
70: ; preds = %66
%71 = load %struct.dirent*, %struct.dirent** %12
%72 = getelementptr inbounds %struct.dirent, %struct.dirent* %71, i32 0, i32 0
%73 = load i8*, i8** %72
%74 = load i8, i8* %73
%75 = sext i8 %74 to i32
%76 = icmp eq i32 %75, 46
br i1 %76, label %77, label %78
77: ; preds = %70
br label %66
78: ; preds = %70
%79 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%80 = load %struct.dirent*, %struct.dirent** %12
%81 = getelementptr inbounds %struct.dirent, %struct.dirent* %80, i32 0, i32 0
%82 = load i8*, i8** %81
%83 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %79, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %82)
%84 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%85 = load i8*, i8** %14
%86 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %84, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %85)
%87 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
store i8* %87, i8** %18
br label %88
88: ; preds = %99, %78
%89 = load i8*, i8** %18
%90 = load i8, i8* %89
%91 = icmp ne i8 %90, 0
br i1 %91, label %92, label %102
92: ; preds = %88
%93 = load i8*, i8** %18
%94 = load i8, i8* %93
%95 = sext i8 %94 to i32
%96 = call i64 @tolower(i32 %95)
%97 = trunc i64 %96 to i8
%98 = load i8*, i8** %18
store i8 %97, i8* %98
br label %99
99: ; preds = %92
%100 = load i8*, i8** %18
%101 = getelementptr inbounds i8, i8* %100, i32 1
store i8* %101, i8** %18
br label %88
102: ; preds = %88
%103 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
store i8* %103, i8** %18
br label %104
104: ; preds = %115, %102
%105 = load i8*, i8** %18
%106 = load i8, i8* %105
%107 = icmp ne i8 %106, 0
br i1 %107, label %108, label %118
108: ; preds = %104
%109 = load i8*, i8** %18
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = call i64 @tolower(i32 %111)
%113 = trunc i64 %112 to i8
%114 = load i8*, i8** %18
store i8 %113, i8* %114
br label %115
115: ; preds = %108
%116 = load i8*, i8** %18
%117 = getelementptr inbounds i8, i8* %116, i32 1
store i8* %117, i8** %18
br label %104
118: ; preds = %104
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
store i8* %119, i8** %18
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %17, i64 0, i64 0
%121 = call i8* @strtok(i8* %120, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %121, i8** %19
br label %122
122: ; preds = %138, %118
%123 = load i8*, i8** %19
%124 = icmp ne i8* %123, null
br i1 %124, label %125, label %140
125: ; preds = %122
%126 = load i8*, i8** %18
%127 = load i8*, i8** %19
%128 = call i8* @strstr(i8* %126, i8* %127)
store i8* %128, i8** %18
%129 = icmp ne i8* %128, null
br i1 %129, label %130, label %136
130: ; preds = %125
%131 = load i8*, i8** %19
%132 = call i32 @strlen(i8* %131)
%133 = load i8*, i8** %18
%134 = sext i32 %132 to i64
%135 = getelementptr inbounds i8, i8* %133, i64 %134
store i8* %135, i8** %18
br label %137
136: ; preds = %125
br label %140
137: ; preds = %130
br label %138
138: ; preds = %137
%139 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i8* %139, i8** %19
br label %122
140: ; preds = %136, %122
%141 = load i8*, i8** %18
%142 = icmp ne i8* %141, null
br i1 %142, label %143, label %159
143: ; preds = %140
%144 = load i32, i32* %10
%145 = load i32, i32* %7
%146 = icmp slt i32 %144, %145
br i1 %146, label %147, label %159
147: ; preds = %143
%148 = load i8**, i8*** %6
%149 = load i32, i32* %10
%150 = add nsw i32 %149, 1
store i32 %150, i32* %10
%151 = sext i32 %149 to i64
%152 = getelementptr inbounds i8*, i8** %148, i64 %151
%153 = load i8*, i8** %152
%154 = getelementptr inbounds [1024 x i8], [1024 x i8]* %15, i64 0, i64 0
%155 = load %struct.dirent*, %struct.dirent** %12
%156 = getelementptr inbounds %struct.dirent, %struct.dirent* %155, i32 0, i32 0
%157 = load i8*, i8** %156
%158 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %153, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %154, i8* %157)
br label %159
159: ; preds = %147, %143, %140
br label %66
160: ; preds = %66
%161 = load i32*, i32** %13
%162 = call i32 @closedir(i32* %161)
store i32 0, i32* %8
br label %163
163: ; preds = %219, %160
%164 = load i32, i32* %8
%165 = load i32, i32* %10
%166 = sub nsw i32 %165, 1
%167 = icmp slt i32 %164, %166
br i1 %167, label %168, label %222
168: ; preds = %163
%169 = load i32, i32* %8
%170 = add nsw i32 %169, 1
store i32 %170, i32* %9
br label %171
171: ; preds = %215, %168
%172 = load i32, i32* %9
%173 = load i32, i32* %10
%174 = icmp slt i32 %172, %173
br i1 %174, label %175, label %218
175: ; preds = %171
%176 = load i8**, i8*** %6
%177 = load i32, i32* %8
%178 = sext i32 %177 to i64
%179 = getelementptr inbounds i8*, i8** %176, i64 %178
%180 = load i8*, i8** %179
%181 = load i8**, i8*** %6
%182 = load i32, i32* %9
%183 = sext i32 %182 to i64
%184 = getelementptr inbounds i8*, i8** %181, i64 %183
%185 = load i8*, i8** %184
%186 = call i64 @strcmp(i8* %180, i8* %185)
%187 = icmp sgt i64 %186, 0
br i1 %187, label %188, label %214
188: ; preds = %175
%189 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%190 = load i8**, i8*** %6
%191 = load i32, i32* %8
%192 = sext i32 %191 to i64
%193 = getelementptr inbounds i8*, i8** %190, i64 %192
%194 = load i8*, i8** %193
%195 = call i32 @strcpy(i8* %189, i8* %194)
%196 = load i8**, i8*** %6
%197 = load i32, i32* %8
%198 = sext i32 %197 to i64
%199 = getelementptr inbounds i8*, i8** %196, i64 %198
%200 = load i8*, i8** %199
%201 = load i8**, i8*** %6
%202 = load i32, i32* %9
%203 = sext i32 %202 to i64
%204 = getelementptr inbounds i8*, i8** %201, i64 %203
%205 = load i8*, i8** %204
%206 = call i32 @strcpy(i8* %200, i8* %205)
%207 = load i8**, i8*** %6
%208 = load i32, i32* %9
%209 = sext i32 %208 to i64
%210 = getelementptr inbounds i8*, i8** %207, i64 %209
%211 = load i8*, i8** %210
%212 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%213 = call i32 @strcpy(i8* %211, i8* %212)
br label %214
214: ; preds = %188, %175
br label %215
215: ; preds = %214
%216 = load i32, i32* %9
%217 = add nsw i32 %216, 1
store i32 %217, i32* %9
br label %171
218: ; preds = %171
br label %219
219: ; preds = %218
%220 = load i32, i32* %8
%221 = add nsw i32 %220, 1
store i32 %221, i32* %8
br label %163
222: ; preds = %163
store i32 0, i32* %8
br label %223
223: ; preds = %234, %222
%224 = load i32, i32* %8
%225 = load i32, i32* %10
%226 = icmp slt i32 %224, %225
br i1 %226, label %227, label %237
227: ; preds = %223
%228 = load i8**, i8*** %6
%229 = load i32, i32* %8
%230 = sext i32 %229 to i64
%231 = getelementptr inbounds i8*, i8** %228, i64 %230
%232 = load i8*, i8** %231
%233 = call i32 (i32, i8*, i8*, ...) @trace(i32 3, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %232)
br label %234
234: ; preds = %227
%235 = load i32, i32* %8
%236 = add nsw i32 %235, 1
store i32 %236, i32* %8
br label %223
237: ; preds = %223
%238 = load i32, i32* %10
store i32 %238, i32* %4
br label %239
239: ; preds = %237, %64
%240 = load i32, i32* %4
ret i32 %240
}

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