#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 stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  int /*<<< orphan*/ d_name;
};
typedef int /*<<< orphan*/ prefix;
typedef int /*<<< orphan*/ pathcopy;
typedef int /*<<< orphan*/ newpath;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int MAXPATHLEN;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
char *basename(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *dirname(char *);
char next_prefix_char(int /*<<< orphan*/ *, char *, unsigned int);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(int /*<<< orphan*/, char const *, size_t);
int /*<<< orphan*/ strncpy(char *, char const *, unsigned int);
unsigned complete(const char *path, char *suggest, unsigned suggest_length) {
  const char *dir, *base;
  char pathcopy[MAXPATHLEN];
  *suggest = 0;
  if (path[strlen(path) - 1] == '/')
    return 0;
  strncpy(pathcopy, path, sizeof(pathcopy));
  pathcopy[sizeof(pathcopy) - 1] = '\0';
  dir = dirname(pathcopy);
  base = basename(pathcopy);
  if (dir && base) {
    size_t len = strlen(base);
    DIR *dd = opendir(dir);
    if (dd != NULL) {
      struct dirent *entry;
      for (entry = readdir(dd); entry; entry = readdir(dd)) {
        if (!strncmp(entry->d_name, base, len)) {
          char prefix[MAXPATHLEN];
          unsigned prefix_len = len;
          strncpy(prefix, base, sizeof(prefix) - 1);
          prefix[sizeof(prefix) - 1] = '\0';
          while (prefix_len < sizeof(prefix)) {
            prefix[prefix_len] = next_prefix_char(dd, prefix, prefix_len);
            if (prefix[prefix_len] == '\0') {
              if (prefix_len > 0 && prefix[prefix_len - 1] != '/') {
                struct stat f;
                char newpath[MAXPATHLEN];
                snprintf(newpath, sizeof(newpath), "%s%s", path, prefix + len);
                if (!stat(newpath, &f) && S_ISDIR(f.st_mode)) {
                  prefix[prefix_len] = '/';
                  prefix[++prefix_len] = '\0';
                }
              }
              break;
            }
            prefix[++prefix_len] = '\0';
          }
          strncpy(suggest, prefix + len, suggest_length - 1);
          suggest[suggest_length - 1] = '\0';
          closedir(dd);
          return prefix_len - len;
        }
      }
      closedir(dd);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<complete>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    0x2e0b(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xa0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x98(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x90(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x90(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    1256 <complete+0x96>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
jmp    151d <complete+0x35d>
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0x98(%rbp),%rdi
mov    -0xa0(%rbp),%rax
sub    $0x1,%rax
movb   $0x0,(%rdi,%rax,1)
call   10a0 <dirname@plt>
mov    -0x98(%rbp),%rdi
mov    %rax,-0x28(%rbp)
call   10c0 <basename@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     150f <complete+0x34f>
cmpq   $0x0,-0x30(%rbp)
je     150f <complete+0x34f>
mov    -0x30(%rbp),%rdi
call   1070 <strlen@plt>
cltq
mov    %rax,-0x50(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
je     150a <complete+0x34a>
mov    -0x58(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x60(%rbp)
cmpq   $0x0,-0x60(%rbp)
je     1501 <complete+0x341>
mov    -0x60(%rbp),%rax
mov    (%rax),%edi
mov    -0x30(%rbp),%rsi
mov    -0x50(%rbp),%rdx
call   1040 <strncmp@plt>
cmp    $0x0,%eax
jne    14ea <complete+0x32a>
mov    0x2cd2(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0xb0(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xa8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x50(%rbp),%rcx
mov    %ecx,-0x74(%rbp)
mov    -0x30(%rbp),%rsi
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <strncpy@plt>
mov    -0xb0(%rbp),%rcx
mov    -0xa8(%rbp),%rax
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0xb0(%rbp),%rcx
mov    -0x74(%rbp),%eax
cmp    %rcx,%rax
jae    149a <complete+0x2da>
mov    -0xa8(%rbp),%rsi
mov    -0x58(%rbp),%rdi
mov    -0x74(%rbp),%edx
call   1050 <next_prefix_char@plt>
mov    %al,%dl
mov    -0xa8(%rbp),%rax
mov    -0x74(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x74(%rbp),%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
jne    147f <complete+0x2bf>
cmpl   $0x0,-0x74(%rbp)
jbe    147a <complete+0x2ba>
mov    -0xa8(%rbp),%rax
mov    -0x74(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     147a <complete+0x2ba>
mov    -0xa8(%rbp),%r8
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0xb8(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x88(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%rcx
add    -0x50(%rbp),%r8
lea    0xbda(%rip),%rdx
call   1090 <snprintf@plt>
mov    -0xb8(%rbp),%rdi
lea    -0x78(%rbp),%rsi
call   10d0 <stat@plt>
cmp    $0x0,%eax
jne    1473 <complete+0x2b3>
mov    -0x78(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1473 <complete+0x2b3>
mov    -0xa8(%rbp),%rax
mov    -0x74(%rbp),%ecx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x74(%rbp)
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x80(%rbp),%rax
mov    %rax,%rsp
jmp    149a <complete+0x2da>
mov    -0xa8(%rbp),%rax
mov    -0x74(%rbp),%ecx
add    $0x1,%ecx
mov    %ecx,-0x74(%rbp)
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
jmp    1371 <complete+0x1b1>
mov    -0xa8(%rbp),%rsi
mov    -0x18(%rbp),%rdi
add    -0x50(%rbp),%rsi
mov    -0x1c(%rbp),%edx
sub    $0x1,%edx
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x58(%rbp),%rdi
call   10b0 <closedir@plt>
mov    -0x74(%rbp),%eax
sub    -0x50(%rbp),%rax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x68(%rbp),%rax
mov    %rax,%rsp
jmp    151d <complete+0x35d>
jmp    14ef <complete+0x32f>
mov    -0x58(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x60(%rbp)
jmp    12e8 <complete+0x128>
mov    -0x58(%rbp),%rdi
call   10b0 <closedir@plt>
jmp    150f <complete+0x34f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complete>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %edx,%r13d
mov    %rdi,%r15
mov    0x2e0a(%rip),%rax
mov    (%rax),%r14d
mov    %rsp,%rbx
lea    0xf(%r14),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsi,-0x60(%rbp)
movb   $0x0,(%rsi)
call   1070 <strlen@plt>
cltq
xor    %r12d,%r12d
cmpb   $0x2f,-0x1(%rax,%r15,1)
jne    121d <complete+0x5d>
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r13,-0x58(%rbp)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x1(%r14,%rbx,1)
mov    %rbx,%rdi
call   10a0 <dirname@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   10c0 <basename@plt>
test   %r13,%r13
je     120b <complete+0x4b>
mov    %rax,%r14
test   %rax,%rax
je     120b <complete+0x4b>
mov    %r14,%rdi
call   1070 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    %r13,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     120b <complete+0x4b>
mov    %rax,%r13
mov    %rax,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     12af <complete+0xef>
mov    -0x2c(%rbp),%ecx
mov    %ecx,%ebx
movslq %ecx,%rcx
mov    %rcx,-0x40(%rbp)
nopl   0x0(%rax)
mov    (%rax),%edi
mov    %r14,%rsi
mov    -0x40(%rbp),%rdx
call   1040 <strncmp@plt>
test   %eax,%eax
je     12bc <complete+0xfc>
mov    %r13,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
jne    1290 <complete+0xd0>
mov    %r13,%rdi
call   10b0 <closedir@plt>
jmp    120b <complete+0x4b>
mov    %rsp,-0x50(%rbp)
mov    0x2d21(%rip),%rax
mov    (%rax),%ecx
mov    %rcx,-0x38(%rbp)
mov    %rsp,%r12
lea    0xf(%rcx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x1(%rcx),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rcx
movb   $0x0,-0x1(%rcx,%r12,1)
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jae    13c5 <complete+0x205>
mov    %rcx,%r14
mov    %eax,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1050 <next_prefix_char@plt>
mov    %al,(%r12,%rbx,1)
test   %al,%al
je     133c <complete+0x17c>
movb   $0x0,0x1(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1310 <complete+0x150>
mov    %r14d,%ebx
jmp    13c5 <complete+0x205>
test   %ebx,%ebx
je     139b <complete+0x1db>
lea    -0x1(%rbx),%eax
cmpb   $0x2f,(%r12,%rax,1)
je     13c5 <complete+0x205>
mov    %rsp,-0x38(%rbp)
mov    0x2c93(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    -0x40(%rbp),%rax
lea    (%r12,%rax,1),%r8
lea    0xc86(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
call   1090 <snprintf@plt>
lea    -0x48(%rbp),%rsi
mov    %r14,%rdi
call   10d0 <stat@plt>
test   %eax,%eax
je     139f <complete+0x1df>
mov    -0x38(%rbp),%rsp
jmp    13c5 <complete+0x205>
xor    %ebx,%ebx
jmp    13c5 <complete+0x205>
mov    -0x38(%rbp),%r15
mov    -0x48(%rbp),%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     13c2 <complete+0x202>
mov    %ebx,%eax
movb   $0x2f,(%r12,%rax,1)
add    $0x1,%rbx
mov    %ebx,%eax
movb   $0x0,(%r12,%rax,1)
mov    %r15,%rsp
add    -0x40(%rbp),%r12
mov    -0x58(%rbp),%r14
add    $0xffffffff,%r14d
mov    -0x60(%rbp),%r15
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1030 <strncpy@plt>
movb   $0x0,(%r15,%r14,1)
mov    %r13,%rdi
call   10b0 <closedir@plt>
sub    -0x2c(%rbp),%ebx
mov    -0x50(%rbp),%rsp
mov    %ebx,%r12d
jmp    120b <complete+0x4b>

LLVM IR (-O0):
%struct.dirent = type { i32 }
%struct.stat = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
define i32 @complete(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32*
%15 = alloca %struct.dirent*
%16 = alloca i8*
%17 = alloca i64
%18 = alloca i32
%19 = alloca %struct.stat
%20 = alloca i8*
%21 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
%22 = load i32, i32* @MAXPATHLEN
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %10
%25 = alloca i8, i64 %23
store i64 %23, i64* %11
%26 = load i8*, i8** %6
store i8 0, i8* %26
%27 = load i8*, i8** %5
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %27, i64 %31
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 47
br i1 %35, label %36, label %37
36: ; preds = %3
store i32 0, i32* %4
store i32 1, i32* %12
br label %175
37: ; preds = %3
%38 = load i8*, i8** %5
%39 = trunc i64 %23 to i32
%40 = call i32 @strncpy(i8* %25, i8* %38, i32 %39)
%41 = sub i64 %23, 1
%42 = getelementptr inbounds i8, i8* %25, i64 %41
store i8 0, i8* %42
%43 = call i8* @dirname(i8* %25)
store i8* %43, i8** %8
%44 = call i8* @basename(i8* %25)
store i8* %44, i8** %9
%45 = load i8*, i8** %8
%46 = icmp ne i8* %45, null
br i1 %46, label %47, label %174
47: ; preds = %37
%48 = load i8*, i8** %9
%49 = icmp ne i8* %48, null
br i1 %49, label %50, label %174
50: ; preds = %47
%51 = load i8*, i8** %9
%52 = call i32 @strlen(i8* %51)
%53 = sext i32 %52 to i64
store i64 %53, i64* %13
%54 = load i8*, i8** %8
%55 = call i32* @opendir(i8* %54)
store i32* %55, i32** %14
%56 = load i32*, i32** %14
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %173
58: ; preds = %50
%59 = load i32*, i32** %14
%60 = call %struct.dirent* @readdir(i32* %59)
store %struct.dirent* %60, %struct.dirent** %15
br label %61
61: ; preds = %167, %58
%62 = load %struct.dirent*, %struct.dirent** %15
%63 = icmp ne %struct.dirent* %62, null
br i1 %63, label %64, label %170
64: ; preds = %61
%65 = load %struct.dirent*, %struct.dirent** %15
%66 = getelementptr inbounds %struct.dirent, %struct.dirent* %65, i32 0, i32 0
%67 = load i32, i32* %66
%68 = load i8*, i8** %9
%69 = load i64, i64* %13
%70 = call i32 @strncmp(i32 %67, i8* %68, i64 %69)
%71 = icmp ne i32 %70, 0
br i1 %71, label %166, label %72
72: ; preds = %64
%73 = load i32, i32* @MAXPATHLEN
%74 = zext i32 %73 to i64
%75 = call i8* @llvm.stacksave()
store i8* %75, i8** %16
%76 = alloca i8, i64 %74
store i64 %74, i64* %17
%77 = load i64, i64* %13
%78 = trunc i64 %77 to i32
store i32 %78, i32* %18
%79 = load i8*, i8** %9
%80 = sub i64 %74, 1
%81 = trunc i64 %80 to i32
%82 = call i32 @strncpy(i8* %76, i8* %79, i32 %81)
%83 = sub i64 %74, 1
%84 = getelementptr inbounds i8, i8* %76, i64 %83
store i8 0, i8* %84
br label %85
85: ; preds = %141, %72
%86 = load i32, i32* %18
%87 = zext i32 %86 to i64
%88 = icmp ult i64 %87, %74
br i1 %88, label %89, label %146
89: ; preds = %85
%90 = load i32*, i32** %14
%91 = load i32, i32* %18
%92 = call signext i8 @next_prefix_char(i32* %90, i8* %76, i32 %91)
%93 = load i32, i32* %18
%94 = zext i32 %93 to i64
%95 = getelementptr inbounds i8, i8* %76, i64 %94
store i8 %92, i8* %95
%96 = load i32, i32* %18
%97 = zext i32 %96 to i64
%98 = getelementptr inbounds i8, i8* %76, i64 %97
%99 = load i8, i8* %98
%100 = sext i8 %99 to i32
%101 = icmp eq i32 %100, 0
br i1 %101, label %102, label %141
102: ; preds = %89
%103 = load i32, i32* %18
%104 = icmp ugt i32 %103, 0
br i1 %104, label %105, label %140
105: ; preds = %102
%106 = load i32, i32* %18
%107 = sub i32 %106, 1
%108 = zext i32 %107 to i64
%109 = getelementptr inbounds i8, i8* %76, i64 %108
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp ne i32 %111, 47
br i1 %112, label %113, label %140
113: ; preds = %105
%114 = load i32, i32* @MAXPATHLEN
%115 = zext i32 %114 to i64
%116 = call i8* @llvm.stacksave()
store i8* %116, i8** %20
%117 = alloca i8, i64 %115
store i64 %115, i64* %21
%118 = trunc i64 %115 to i32
%119 = load i8*, i8** %5
%120 = load i64, i64* %13
%121 = getelementptr inbounds i8, i8* %76, i64 %120
%122 = call i32 @snprintf(i8* %117, i32 %118, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %119, i8* %121)
%123 = call i32 @stat(i8* %117, %struct.stat* %19)
%124 = icmp ne i32 %123, 0
br i1 %124, label %138, label %125
125: ; preds = %113
%126 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 0
%127 = load i32, i32* %126
%128 = call i64 @S_ISDIR(i32 %127)
%129 = icmp ne i64 %128, 0
br i1 %129, label %130, label %138
130: ; preds = %125
%131 = load i32, i32* %18
%132 = zext i32 %131 to i64
%133 = getelementptr inbounds i8, i8* %76, i64 %132
store i8 47, i8* %133
%134 = load i32, i32* %18
%135 = add i32 %134, 1
store i32 %135, i32* %18
%136 = zext i32 %135 to i64
%137 = getelementptr inbounds i8, i8* %76, i64 %136
store i8 0, i8* %137
br label %138
138: ; preds = %130, %125, %113
%139 = load i8*, i8** %20
br label %140
140: ; preds = %138, %105, %102
br label %146
141: ; preds = %89
%142 = load i32, i32* %18
%143 = add i32 %142, 1
store i32 %143, i32* %18
%144 = zext i32 %143 to i64
%145 = getelementptr inbounds i8, i8* %76, i64 %144
store i8 0, i8* %145
br label %85
146: ; preds = %140, %85
%147 = load i8*, i8** %6
%148 = load i64, i64* %13
%149 = getelementptr inbounds i8, i8* %76, i64 %148
%150 = load i32, i32* %7
%151 = sub i32 %150, 1
%152 = call i32 @strncpy(i8* %147, i8* %149, i32 %151)
%153 = load i8*, i8** %6
%154 = load i32, i32* %7
%155 = sub i32 %154, 1
%156 = zext i32 %155 to i64
%157 = getelementptr inbounds i8, i8* %153, i64 %156
store i8 0, i8* %157
%158 = load i32*, i32** %14
%159 = call i32 @closedir(i32* %158)
%160 = load i32, i32* %18
%161 = zext i32 %160 to i64
%162 = load i64, i64* %13
%163 = sub i64 %161, %162
%164 = trunc i64 %163 to i32
store i32 %164, i32* %4
store i32 1, i32* %12
%165 = load i8*, i8** %16
br label %175
166: ; preds = %64
br label %167
167: ; preds = %166
%168 = load i32*, i32** %14
%169 = call %struct.dirent* @readdir(i32* %168)
store %struct.dirent* %169, %struct.dirent** %15
br label %61
170: ; preds = %61
%171 = load i32*, i32** %14
%172 = call i32 @closedir(i32* %171)
br label %173
173: ; preds = %170, %50
br label %174
174: ; preds = %173, %47, %37
store i32 0, i32* %4
store i32 1, i32* %12
br label %175
175: ; preds = %174, %146, %36
%176 = load i8*, i8** %10
%177 = load i32, i32* %4
ret i32 %177
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i32 }
@MAXPATHLEN = global i32 0
@.str = [5 x i8] c"%s%s\00"
define i32 @complete(i8* %0, i8* %1, i32 %2) {
%4 = alloca %struct.stat
%5 = load i32, i32* @MAXPATHLEN
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
store i8 0, i8* %1
%8 = tail call i32 @strlen(i8* %0)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %105, label %14
14: ; preds = %3
%15 = call i32 @strncpy(i8* %7, i8* %0, i32 %5)
%16 = add nsw i64 %6, -1
%17 = getelementptr inbounds i8, i8* %7, i64 %16
store i8 0, i8* %17
%18 = call i8* @dirname(i8* %7)
%19 = call i8* @basename(i8* %7)
%20 = icmp ne i8* %18, null
%21 = icmp ne i8* %19, null
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %23, label %105
23: ; preds = %14
%24 = call i32 @strlen(i8* %19)
%25 = sext i32 %24 to i64
%26 = call i32* @opendir(i8* %18)
%27 = icmp eq i32* %26, null
br i1 %27, label %105, label %28
28: ; preds = %23
%29 = call %struct.dirent* @readdir(i32* %26)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %94, label %31
31: ; preds = %28, %91
%32 = phi %struct.dirent* [ %92, %91 ], [ %29, %28 ]
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i64 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @strncmp(i32 %34, i8* %19, i64 %25)
%36 = icmp eq i32 %35, 0
br i1 %36, label %37, label %91
37: ; preds = %31
%38 = load i32, i32* @MAXPATHLEN
%39 = zext i32 %38 to i64
%40 = call i8* @llvm.stacksave()
%41 = alloca i8, i64 %39
%42 = add nsw i64 %39, -1
%43 = trunc i64 %42 to i32
%44 = call i32 @strncpy(i8* %41, i8* %19, i32 %43)
%45 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 0, i8* %45
%46 = icmp ult i32 %24, %38
br i1 %46, label %47, label %96
47: ; preds = %37
%48 = zext i32 %24 to i64
br label %49
49: ; preds = %47, %87
%50 = phi i64 [ %48, %47 ], [ %88, %87 ]
%51 = trunc i64 %50 to i32
%52 = call signext i8 @next_prefix_char(i32* %26, i8* %41, i32 %51)
%53 = getelementptr inbounds i8, i8* %41, i64 %50
store i8 %52, i8* %53
%54 = icmp eq i8 %52, 0
br i1 %54, label %55, label %87
55: ; preds = %49
%56 = trunc i64 %50 to i32
%57 = and i64 %50, 4294967295
%58 = getelementptr inbounds i8, i8* %41, i64 %57
%59 = icmp eq i32 %56, 0
br i1 %59, label %96, label %60
60: ; preds = %55
%61 = add nuw i64 %50, 4294967295
%62 = and i64 %61, 4294967295
%63 = getelementptr inbounds i8, i8* %41, i64 %62
%64 = load i8, i8* %63
%65 = icmp eq i8 %64, 47
br i1 %65, label %96, label %66
66: ; preds = %60
%67 = bitcast %struct.stat* %4 to i8*
%68 = load i32, i32* @MAXPATHLEN
%69 = zext i32 %68 to i64
%70 = call i8* @llvm.stacksave()
%71 = alloca i8, i64 %69
%72 = getelementptr inbounds i8, i8* %41, i64 %25
%73 = call i32 @snprintf(i8* %71, i32 %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %72)
%74 = call i32 @stat(i8* %71, %struct.stat* %4)
%75 = icmp eq i32 %74, 0
br i1 %75, label %76, label %85
76: ; preds = %66
%77 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%78 = load i32, i32* %77
%79 = call i64 @S_ISDIR(i32 %78)
%80 = icmp eq i64 %79, 0
br i1 %80, label %85, label %81
81: ; preds = %76
store i8 47, i8* %58
%82 = add nuw i32 %56, 1
%83 = zext i32 %82 to i64
%84 = getelementptr inbounds i8, i8* %41, i64 %83
store i8 0, i8* %84
br label %85
85: ; preds = %81, %76, %66
%86 = phi i32 [ %56, %66 ], [ %82, %81 ], [ %56, %76 ]
br label %96
87: ; preds = %49
%88 = add nuw nsw i64 %50, 1
%89 = getelementptr inbounds i8, i8* %41, i64 %88
store i8 0, i8* %89
%90 = icmp eq i64 %88, %39
br i1 %90, label %96, label %49
91: ; preds = %31
%92 = call %struct.dirent* @readdir(i32* %26)
%93 = icmp eq %struct.dirent* %92, null
br i1 %93, label %94, label %31
94: ; preds = %91, %28
%95 = call i32 @closedir(i32* %26)
br label %105
96: ; preds = %87, %37, %85, %60, %55
%97 = phi i32 [ %86, %85 ], [ %56, %60 ], [ 0, %55 ], [ %24, %37 ], [ %38, %87 ]
%98 = getelementptr inbounds i8, i8* %41, i64 %25
%99 = add i32 %2, -1
%100 = call i32 @strncpy(i8* %1, i8* %98, i32 %99)
%101 = zext i32 %99 to i64
%102 = getelementptr inbounds i8, i8* %1, i64 %101
store i8 0, i8* %102
%103 = call i32 @closedir(i32* %26)
%104 = sub i32 %97, %24
br label %105
105: ; preds = %94, %23, %96, %14, %3
%106 = phi i32 [ 0, %3 ], [ %104, %96 ], [ 0, %14 ], [ 0, %23 ], [ 0, %94 ]
ret i32 %106
}