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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *strrchr(char *, char);
int /*<<< orphan*/ warnl(char *, char *);
int /*<<< orphan*/ xasprintf(char **, char *, char *, ...);
char **xrealloc(char **, int, int);
char *xstrdup(char *);
char **complete_on_files(char *start) {
  struct dirent *content = NULL;
  struct stat st;
  DIR *dir;
  char *home, *path, *dirname = NULL;
  char **namelist = NULL, *filepath, *p = start;
  int count = 0;
  if (*p == '\0' || !strrchr(p, '/'))
    path = xstrdup(".");
  else {
    if (!(home = getenv("HOME")))
      return NULL;
    if (!strncmp(p, "~/", 2) && home)
      xasprintf(&dirname, "%s%s", home, p + 1);
    else
      dirname = xstrdup(p);
    p = strrchr(dirname, '/');
    if (p != dirname) {
      *(p++) = '\0';
      path = xstrdup(dirname);
    } else {
      path = xstrdup("/");
      p++;
    }
  }
  if ((dir = opendir(path))) {
    while ((content = readdir(dir))) {
      if (!strcmp(content->d_name, ".") || !strcmp(content->d_name, "..") ||
          strncmp(content->d_name, p, strlen(p)))
        continue;
      xasprintf(&filepath, "%s/%s", path, content->d_name);
      if (filepath && stat(filepath, &st) != -1) {
        namelist = xrealloc(namelist, ++count, sizeof(*namelist));
        if (S_ISDIR(st.st_mode))
          xasprintf(&namelist[count - 1], "%s/", content->d_name + strlen(p));
        else
          namelist[count - 1] = xstrdup(content->d_name + strlen(p));
      } else
        warnl("%s", filepath);
      free(filepath);
    }
    closedir(dir);
  }
  if (count) {
    namelist = xrealloc(namelist, ++count, sizeof(*namelist));
    namelist[count - 1] = NULL;
  }
  free(dirname);
  free(path);
  return namelist;
}


x86 assembly (clang, -O0):
<complete_on_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     124e <complete_on_files+0x5e>
mov    -0x58(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
cmp    $0x0,%rax
jne    1263 <complete_on_files+0x73>
lea    0xdb9(%rip),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,-0x38(%rbp)
jmp    1349 <complete_on_files+0x159>
lea    0xd96(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    128a <complete_on_files+0x9a>
movq   $0x0,-0x8(%rbp)
jmp    1561 <complete_on_files+0x371>
mov    -0x58(%rbp),%rdi
lea    0xd70(%rip),%rsi
mov    $0x2,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
jne    12d7 <complete_on_files+0xe7>
cmpq   $0x0,-0x30(%rbp)
je     12d7 <complete_on_files+0xe7>
mov    -0x30(%rbp),%rdx
mov    -0x58(%rbp),%rcx
add    $0x1,%rcx
lea    -0x40(%rbp),%rdi
lea    0xd3d(%rip),%rsi
mov    $0x0,%al
call   1110 <xasprintf@plt>
jmp    12e4 <complete_on_files+0xf4>
mov    -0x58(%rbp),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x40(%rbp),%rax
je     1328 <complete_on_files+0x138>
mov    -0x58(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x58(%rbp)
movb   $0x0,(%rax)
mov    -0x40(%rbp),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,-0x38(%rbp)
jmp    1344 <complete_on_files+0x154>
lea    0xce9(%rip),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,-0x38(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1349 <complete_on_files+0x159>
mov    -0x38(%rbp),%rdi
call   1060 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     150d <complete_on_files+0x31d>
jmp    1365 <complete_on_files+0x175>
mov    -0x28(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1504 <complete_on_files+0x314>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xc84(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
je     13e9 <complete_on_files+0x1f9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xc67(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
je     13e9 <complete_on_files+0x1f9>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x70(%rbp)
mov    -0x58(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
cmp    $0x0,%rax
je     13ee <complete_on_files+0x1fe>
jmp    1365 <complete_on_files+0x175>
mov    -0x38(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%rcx
lea    -0x50(%rbp),%rdi
lea    0xc0c(%rip),%rsi
mov    $0x0,%al
call   1110 <xasprintf@plt>
cmpq   $0x0,-0x50(%rbp)
je     14e6 <complete_on_files+0x2f6>
mov    -0x50(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     14e6 <complete_on_files+0x2f6>
mov    -0x48(%rbp),%rdi
mov    -0x5c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x5c(%rbp)
mov    $0x8,%edx
call   1090 <xrealloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x20(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
je     14a5 <complete_on_files+0x2b5>
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
shl    $0x3,%rcx
add    %rcx,%rax
mov    %rax,-0x78(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x80(%rbp),%rdx
mov    -0x78(%rbp),%rdi
cltq
add    %rax,%rdx
lea    0xb7d(%rip),%rsi
mov    $0x0,%al
call   1110 <xasprintf@plt>
jmp    14e1 <complete_on_files+0x2f1>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x88(%rbp)
mov    -0x58(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x88(%rbp),%rdi
cltq
add    %rax,%rdi
call   10b0 <xstrdup@plt>
mov    %rax,%rdx
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %rdx,(%rax,%rcx,8)
jmp    14f6 <complete_on_files+0x306>
mov    -0x50(%rbp),%rsi
lea    0xb22(%rip),%rdi
call   10f0 <warnl@plt>
mov    -0x50(%rbp),%rdi
call   1040 <free@plt>
jmp    1365 <complete_on_files+0x175>
mov    -0x28(%rbp),%rdi
call   10c0 <closedir@plt>
cmpl   $0x0,-0x5c(%rbp)
je     1547 <complete_on_files+0x357>
mov    -0x48(%rbp),%rdi
mov    -0x5c(%rbp),%esi
add    $0x1,%esi
mov    %esi,-0x5c(%rbp)
mov    $0x8,%edx
call   1090 <xrealloc@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
mov    -0x5c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movq   $0x0,(%rax,%rcx,8)
mov    -0x40(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
mov    -0x48(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<complete_on_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%r12
movq   $0x0,0x8(%rsp)
cmpb   $0x0,(%rdi)
je     1260 <complete_on_files+0x70>
mov    %r12,%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
test   %rax,%rax
je     1260 <complete_on_files+0x70>
lea    0xdd8(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     1269 <complete_on_files+0x79>
mov    %rax,%rbx
lea    0xdc9(%rip),%rsi
mov    %r12,%rdi
mov    $0x2,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
je     1270 <complete_on_files+0x80>
mov    %r12,%rdi
call   10b0 <xstrdup@plt>
mov    %rax,%r12
mov    %rax,0x8(%rsp)
jmp    1292 <complete_on_files+0xa2>
lea    0xda7(%rip),%rdi
jmp    12b3 <complete_on_files+0xc3>
xor    %ebx,%ebx
jmp    14a8 <complete_on_files+0x2b8>
add    $0x1,%r12
lea    0xd8d(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %rbx,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1110 <xasprintf@plt>
mov    0x8(%rsp),%r12
mov    %r12,%rdi
mov    $0x2f,%esi
call   10a0 <strrchr@plt>
cmp    %r12,%rax
je     1313 <complete_on_files+0x123>
mov    %rax,%r12
add    $0x1,%r12
movb   $0x0,(%rax)
mov    0x8(%rsp),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,%rbp
mov    %rbp,%rdi
call   1060 <opendir@plt>
test   %rax,%rax
je     12fd <complete_on_files+0x10d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     1304 <complete_on_files+0x114>
mov    %rax,%r14
mov    %rbp,0x30(%rsp)
lea    0xd27(%rip),%r13
lea    0xd1f(%rip),%rbp
xor    %eax,%eax
mov    %rax,0x18(%rsp)
xor    %eax,%eax
mov    %rax,(%rsp)
jmp    1354 <complete_on_files+0x164>
xor    %ebx,%ebx
jmp    1496 <complete_on_files+0x2a6>
mov    %rbx,%rdi
call   10c0 <closedir@plt>
xor    %ebx,%ebx
jmp    1496 <complete_on_files+0x2a6>
lea    0xcfe(%rip),%rdi
call   10b0 <xstrdup@plt>
mov    %rax,%rbp
add    $0x1,%r12
jmp    12bb <complete_on_files+0xcb>
xor    %esi,%esi
lea    0xce2(%rip),%rdi
call   10f0 <warnl@plt>
mov    0x20(%rsp),%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
call   1100 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     1459 <complete_on_files+0x269>
mov    (%r14),%r15
mov    %r15,%rdi
mov    %r13,%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     1340 <complete_on_files+0x150>
mov    %r15,%rdi
mov    %rbp,%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     1340 <complete_on_files+0x150>
mov    %r12,%rdi
call   1070 <strlen@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %eax,%edx
call   1050 <strncmp@plt>
test   %rax,%rax
jne    1340 <complete_on_files+0x150>
mov    (%r14),%rcx
lea    0x20(%rsp),%rdi
lea    0xc72(%rip),%rsi
mov    0x30(%rsp),%rdx
xor    %eax,%eax
call   1110 <xasprintf@plt>
mov    0x20(%rsp),%rdi
test   %rdi,%rdi
je     1328 <complete_on_files+0x138>
lea    0x28(%rsp),%rsi
call   10e0 <stat@plt>
cmp    $0xffffffff,%eax
je     1423 <complete_on_files+0x233>
mov    0x18(%rsp),%r15
lea    0x1(%r15),%esi
mov    (%rsp),%rdi
mov    %esi,0x14(%rsp)
mov    $0x8,%edx
call   1090 <xrealloc@plt>
mov    %rax,(%rsp)
mov    0x28(%rsp),%edi
call   1080 <S_ISDIR@plt>
movslq %r15d,%r15
test   %rax,%rax
je     142d <complete_on_files+0x23d>
mov    (%rsp),%rax
lea    (%rax,%r15,8),%r15
mov    (%r14),%r14
mov    %r12,%rdi
call   1070 <strlen@plt>
movslq %eax,%rdx
add    %r14,%rdx
mov    %r15,%rdi
lea    0xbfc(%rip),%rsi
xor    %eax,%eax
call   1110 <xasprintf@plt>
jmp    144b <complete_on_files+0x25b>
mov    0x20(%rsp),%rsi
jmp    132a <complete_on_files+0x13a>
mov    (%r14),%r14
mov    %r12,%rdi
call   1070 <strlen@plt>
movslq %eax,%rdi
add    %r14,%rdi
call   10b0 <xstrdup@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx,%r15,8)
mov    0x14(%rsp),%eax
mov    %rax,0x18(%rsp)
jmp    1336 <complete_on_files+0x146>
mov    %rbx,%rdi
call   10c0 <closedir@plt>
mov    0x18(%rsp),%r14
test   %r14d,%r14d
mov    0x30(%rsp),%rbp
je     1492 <complete_on_files+0x2a2>
lea    0x1(%r14),%esi
mov    (%rsp),%rdi
mov    $0x8,%edx
call   1090 <xrealloc@plt>
mov    %rax,%rbx
movslq %r14d,%rax
movq   $0x0,(%rbx,%rax,8)
jmp    1496 <complete_on_files+0x2a6>
mov    (%rsp),%rbx
mov    0x8(%rsp),%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [5 x i8] c"HOME\00"
@.str.2 = [3 x i8] c"~/\00"
@.str.3 = [5 x i8] c"%s%s\00"
@.str.4 = [2 x i8] c"/\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [6 x i8] c"%s/%s\00"
@.str.7 = [4 x i8] c"%s/\00"
@.str.8 = [3 x i8] c"%s\00"
define i8** @complete_on_files(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast %struct.stat* %2 to i8*
%6 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%7 = bitcast i8** %4 to i8*
%8 = load i8, i8* %0
%9 = icmp eq i8 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %10, %1
%14 = tail call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %38
15: ; preds = %10
%16 = tail call i8* @getenv(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i8* %16, null
br i1 %17, label %128, label %18
18: ; preds = %15
%19 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 2)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %0, i64 1
%23 = call i32 (i8**, i8*, i8*, ...) @xasprintf(i8** %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %16, i8* %22)
%24 = load i8*, i8** %3
br label %27
25: ; preds = %18
%26 = tail call i8* @xstrdup(i8* %0)
store i8* %26, i8** %3
br label %27
27: ; preds = %25, %21
%28 = phi i8* [ %26, %25 ], [ %24, %21 ]
%29 = call i8* @strrchr(i8* dereferenceable(1) %28, i8 signext 47)
%30 = icmp eq i8* %29, %28
br i1 %30, label %35, label %31
31: ; preds = %27
%32 = getelementptr inbounds i8, i8* %29, i64 1
store i8 0, i8* %29
%33 = load i8*, i8** %3
%34 = call i8* @xstrdup(i8* %33)
br label %38
35: ; preds = %27
%36 = call i8* @xstrdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = getelementptr inbounds i8, i8* %28, i64 1
br label %38
38: ; preds = %31, %35, %13
%39 = phi i8* [ %14, %13 ], [ %34, %31 ], [ %36, %35 ]
%40 = phi i8* [ %0, %13 ], [ %32, %31 ], [ %37, %35 ]
%41 = call i32* @opendir(i8* %39)
%42 = icmp eq i32* %41, null
br i1 %42, label %123, label %43
43: ; preds = %38
%44 = call %struct.dirent* @readdir(i32* %41)
%45 = icmp eq %struct.dirent* %44, null
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 @closedir(i32* %41)
br label %123
48: ; preds = %43
%49 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %50
50: ; preds = %48, %106
%51 = phi %struct.dirent* [ %44, %48 ], [ %111, %106 ]
%52 = phi i32 [ 0, %48 ], [ %108, %106 ]
%53 = phi i8** [ null, %48 ], [ %107, %106 ]
br label %54
54: ; preds = %50, %67
%55 = phi %struct.dirent* [ %51, %50 ], [ %68, %67 ]
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i64 0, i32 0
%57 = load i8*, i8** %56
%58 = call i32 @strcmp(i8* dereferenceable(1) %57, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%59 = icmp eq i32 %58, 0
br i1 %59, label %67, label %60
60: ; preds = %54
%61 = call i32 @strcmp(i8* dereferenceable(1) %57, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%62 = icmp eq i32 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %60
%64 = call i32 @strlen(i8* %40)
%65 = call i64 @strncmp(i8* %57, i8* %40, i32 %64)
%66 = icmp eq i64 %65, 0
br i1 %66, label %70, label %67
67: ; preds = %63, %60, %54
%68 = call %struct.dirent* @readdir(i32* %41)
%69 = icmp eq %struct.dirent* %68, null
br i1 %69, label %113, label %54
70: ; preds = %63
%71 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i64 0, i32 0
%72 = load i8*, i8** %71
%73 = call i32 (i8**, i8*, i8*, ...) @xasprintf(i8** %4, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %39, i8* %72)
%74 = load i8*, i8** %4
%75 = icmp eq i8* %74, null
br i1 %75, label %103, label %76
76: ; preds = %70
%77 = call i32 @stat(i8* %74, %struct.stat* %2)
%78 = icmp eq i32 %77, -1
br i1 %78, label %79, label %81
79: ; preds = %76
%80 = load i8*, i8** %4
br label %103
81: ; preds = %76
%82 = add nsw i32 %52, 1
%83 = call i8** @xrealloc(i8** %53, i32 %82, i32 8)
%84 = load i32, i32* %49
%85 = call i64 @S_ISDIR(i32 %84)
%86 = icmp eq i64 %85, 0
br i1 %86, label %95, label %87
87: ; preds = %81
%88 = sext i32 %52 to i64
%89 = getelementptr inbounds i8*, i8** %83, i64 %88
%90 = load i8*, i8** %71
%91 = call i32 @strlen(i8* %40)
%92 = sext i32 %91 to i64
%93 = getelementptr inbounds i8, i8* %90, i64 %92
%94 = call i32 (i8**, i8*, i8*, ...) @xasprintf(i8** %89, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8* %93)
br label %106
95: ; preds = %81
%96 = load i8*, i8** %71
%97 = call i32 @strlen(i8* %40)
%98 = sext i32 %97 to i64
%99 = getelementptr inbounds i8, i8* %96, i64 %98
%100 = call i8* @xstrdup(i8* %99)
%101 = sext i32 %52 to i64
%102 = getelementptr inbounds i8*, i8** %83, i64 %101
store i8* %100, i8** %102
br label %106
103: ; preds = %79, %70
%104 = phi i8* [ %80, %79 ], [ null, %70 ]
%105 = call i32 @warnl(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* %104)
br label %106
106: ; preds = %87, %95, %103
%107 = phi i8** [ %83, %87 ], [ %83, %95 ], [ %53, %103 ]
%108 = phi i32 [ %82, %87 ], [ %82, %95 ], [ %52, %103 ]
%109 = load i8*, i8** %4
%110 = call i32 @free(i8* %109)
%111 = call %struct.dirent* @readdir(i32* %41)
%112 = icmp eq %struct.dirent* %111, null
br i1 %112, label %113, label %50
113: ; preds = %106, %67
%114 = phi i8** [ %53, %67 ], [ %107, %106 ]
%115 = phi i32 [ %52, %67 ], [ %108, %106 ]
%116 = call i32 @closedir(i32* %41)
%117 = icmp eq i32 %115, 0
br i1 %117, label %123, label %118
118: ; preds = %113
%119 = add nsw i32 %115, 1
%120 = call i8** @xrealloc(i8** %114, i32 %119, i32 8)
%121 = sext i32 %115 to i64
%122 = getelementptr inbounds i8*, i8** %120, i64 %121
store i8* null, i8** %122
br label %123
123: ; preds = %46, %38, %118, %113
%124 = phi i8** [ %120, %118 ], [ %114, %113 ], [ null, %38 ], [ null, %46 ]
%125 = load i8*, i8** %3
%126 = call i32 @free(i8* %125)
%127 = call i32 @free(i8* %39)
br label %128
128: ; preds = %15, %123
%129 = phi i8** [ %124, %123 ], [ null, %15 ]
ret i8** %129
}