#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 {
  scalar_t__ st_rdev;
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
};
typedef scalar_t__ dev_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ S_ISCHR(int /*<<< orphan*/);
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ chdir(char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
scalar_t__ lstat(char *, struct stat *);
char *malloc(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int strlen(char const *);
int findtty(char *res, const char *startdir, int rlen, dev_t dev) {
  DIR *dir;
  struct dirent *ent;
  struct stat st;
  int r = -1;
  char *olddir = getcwd(NULL, 0);
  if (chdir(startdir) < 0 || (dir = opendir(".")) == NULL) {
    int msglen = strlen(startdir) + 11;
    char *msg = malloc(msglen);
    snprintf(msg, msglen, "bootlogd: %s", startdir);
    perror(msg);
    free(msg);
    chdir(olddir);
    return -1;
  }
  while ((ent = readdir(dir)) != NULL) {
    if (lstat(ent->d_name, &st) != 0)
      continue;
    if (S_ISDIR(st.st_mode) && 0 != strcmp(".", ent->d_name) &&
        0 != strcmp("..", ent->d_name)) {
      char *path = malloc(rlen);
      snprintf(path, rlen, "%s/%s", startdir, ent->d_name);
      r = findtty(res, path, rlen, dev);
      free(path);
      if (0 == r) {
        closedir(dir);
        chdir(olddir);
        return 0;
      }
      continue;
    }
    if (!S_ISCHR(st.st_mode))
      continue;
    if (st.st_rdev == dev) {
      if ((int)(strlen(ent->d_name) + strlen(startdir) + 1) >= rlen) {
        fprintf(stderr, "bootlogd: console device name too long\n");
        closedir(dir);
        chdir(olddir);
        return -1;
      } else {
        snprintf(res, rlen, "%s/%s", startdir, ent->d_name);
        closedir(dir);
        chdir(olddir);
        return 0;
      }
    }
  }
  closedir(dir);
  chdir(olddir);
  return r;
}


x86 assembly (clang, -O0):
<findtty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0xffffffff,-0x4c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1090 <getcwd@plt>
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <chdir@plt>
cmp    $0x0,%eax
jl     125c <findtty+0x5c>
lea    0xdc5(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    12b7 <findtty+0xb7>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0xb,%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0x18(%rbp),%rcx
lea    0xd77(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x68(%rbp),%rdi
call   1110 <perror@plt>
mov    -0x68(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rdi
call   1060 <chdir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149d <findtty+0x29d>
jmp    12bc <findtty+0xbc>
mov    -0x30(%rbp),%rdi
call   10e0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1485 <findtty+0x285>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    -0x48(%rbp),%rsi
call   10b0 <lstat@plt>
cmp    $0x0,%rax
je     12f2 <findtty+0xf2>
jmp    12bc <findtty+0xbc>
mov    -0x40(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%rax
je     13c0 <findtty+0x1c0>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xcfc(%rip),%rdi
call   10c0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     13c0 <findtty+0x1c0>
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
lea    0xcda(%rip),%rdi
call   10c0 <strcmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     13c0 <findtty+0x1c0>
mov    -0x1c(%rbp),%edi
call   10f0 <malloc@plt>
mov    %rax,-0x70(%rbp)
mov    -0x70(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    (%rax),%r8
lea    0xca5(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
call   1120 <findtty@plt>
mov    %eax,-0x4c(%rbp)
mov    -0x70(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
cmp    -0x4c(%rbp),%eax
jne    13bb <findtty+0x1bb>
mov    -0x30(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x58(%rbp),%rdi
call   1060 <chdir@plt>
movl   $0x0,-0x4(%rbp)
jmp    149d <findtty+0x29d>
jmp    12bc <findtty+0xbc>
mov    -0x40(%rbp),%edi
call   1100 <S_ISCHR@plt>
cmp    $0x0,%eax
jne    13d6 <findtty+0x1d6>
jmp    12bc <findtty+0xbc>
mov    -0x48(%rbp),%rax
cmp    -0x28(%rbp),%rax
jne    1480 <findtty+0x280>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x74(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x74(%rbp),%eax
add    %ecx,%eax
add    $0x1,%eax
cmp    -0x1c(%rbp),%eax
jl     1442 <findtty+0x242>
mov    0x2bca(%rip),%rax
mov    (%rax),%edi
lea    0xbf7(%rip),%rsi
call   10d0 <fprintf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x58(%rbp),%rdi
call   1060 <chdir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    149d <findtty+0x29d>
mov    -0x10(%rbp),%rdi
mov    -0x1c(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x38(%rbp),%rax
mov    (%rax),%r8
lea    0xbb5(%rip),%rdx
mov    $0x0,%al
call   1080 <snprintf@plt>
mov    -0x30(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x58(%rbp),%rdi
call   1060 <chdir@plt>
movl   $0x0,-0x4(%rbp)
jmp    149d <findtty+0x29d>
jmp    12bc <findtty+0xbc>
mov    -0x30(%rbp),%rdi
call   10a0 <closedir@plt>
mov    -0x58(%rbp),%rdi
call   1060 <chdir@plt>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<findtty>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r12
mov    %edx,0xc(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r13
xor    %edi,%edi
xor    %esi,%esi
call   1090 <getcwd@plt>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <chdir@plt>
test   %eax,%eax
js     13d6 <findtty+0x1d6>
lea    0xdd0(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     13d6 <findtty+0x1d6>
mov    %rax,%rbp
mov    %rbx,0x20(%rsp)
mov    %r15,0x10(%rsp)
mov    $0xffffffff,%ebx
lea    0x28(%rsp),%r14
mov    %r13,0x18(%rsp)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   10e0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     138c <findtty+0x18c>
mov    0x0(%r13),%rdi
mov    %r14,%rsi
call   10b0 <lstat@plt>
test   %rax,%rax
jne    1270 <findtty+0x70>
mov    0x30(%rsp),%r15d
mov    %r15d,%edi
call   1070 <S_ISDIR@plt>
test   %rax,%rax
je     12d1 <findtty+0xd1>
mov    0x0(%r13),%rsi
lea    0xd5c(%rip),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     12d1 <findtty+0xd1>
mov    0x0(%r13),%rsi
lea    0xd46(%rip),%rdi
call   10c0 <strcmp@plt>
test   %rax,%rax
jne    12e6 <findtty+0xe6>
mov    %r15d,%edi
call   1100 <S_ISCHR@plt>
test   %eax,%eax
je     1270 <findtty+0x70>
cmp    %r12,0x28(%rsp)
jne    1270 <findtty+0x70>
jmp    1349 <findtty+0x149>
mov    0xc(%rsp),%r15d
mov    %r15d,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    0x0(%r13),%r8
mov    %rax,%rdi
mov    %r15d,%esi
lea    0xd09(%rip),%rdx
mov    0x20(%rsp),%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    0x18(%rsp),%rdi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r12,%rcx
call   1120 <findtty@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15d,%ebx
test   %r15d,%r15d
jne    1270 <findtty+0x70>
mov    %rbp,%rdi
call   10a0 <closedir@plt>
xor    %ebx,%ebx
jmp    1394 <findtty+0x194>
mov    0x0(%r13),%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    0x20(%rsp),%r14
mov    %r14,%rdi
call   1050 <strlen@plt>
add    %r15d,%eax
add    $0x1,%eax
mov    0xc(%rsp),%esi
cmp    %esi,%eax
jge    13b2 <findtty+0x1b2>
mov    0x0(%r13),%r8
lea    0xc95(%rip),%rdx
xor    %ebx,%ebx
mov    0x18(%rsp),%rdi
mov    %r14,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   10a0 <closedir@plt>
mov    0x10(%rsp),%r15
mov    %r15,%rdi
call   1060 <chdir@plt>
mov    %ebx,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
lea    0xc54(%rip),%rsi
call   10d0 <fprintf@plt>
mov    %rbp,%rdi
call   10a0 <closedir@plt>
mov    $0xffffffff,%ebx
jmp    1394 <findtty+0x194>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0xb(%rax),%r14d
mov    %r14d,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbp
lea    0xc0c(%rip),%rdx
mov    %rax,%rdi
mov    %r14d,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <snprintf@plt>
mov    %rbp,%rdi
call   1110 <perror@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    $0xffffffff,%ebx
jmp    1399 <findtty+0x199>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i64, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"bootlogd: %s\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.4 = [40 x i8] c"bootlogd: console device name too long\0A\00"
define i32 @findtty(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca %struct.stat
%13 = alloca i32
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i32 -1, i32* %13
%18 = call i8* @getcwd(i32* null, i32 0)
store i8* %18, i8** %14
%19 = load i8*, i8** %7
%20 = call i32 @chdir(i8* %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %4
%23 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %23, i32** %10
%24 = icmp eq i32* %23, null
br i1 %24, label %25, label %41
25: ; preds = %22, %4
%26 = load i8*, i8** %7
%27 = call i32 @strlen(i8* %26)
%28 = add nsw i32 %27, 11
store i32 %28, i32* %15
%29 = load i32, i32* %15
%30 = call i8* @malloc(i32 %29)
store i8* %30, i8** %16
%31 = load i8*, i8** %16
%32 = load i32, i32* %15
%33 = load i8*, i8** %7
%34 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %33)
%35 = load i8*, i8** %16
%36 = call i32 @perror(i8* %35)
%37 = load i8*, i8** %16
%38 = call i32 @free(i8* %37)
%39 = load i8*, i8** %14
%40 = call i32 @chdir(i8* %39)
store i32 -1, i32* %5
br label %143
41: ; preds = %22
br label %42
42: ; preds = %136, %100, %94, %52, %41
%43 = load i32*, i32** %10
%44 = call %struct.dirent* @readdir(i32* %43)
store %struct.dirent* %44, %struct.dirent** %11
%45 = icmp ne %struct.dirent* %44, null
br i1 %45, label %46, label %137
46: ; preds = %42
%47 = load %struct.dirent*, %struct.dirent** %11
%48 = getelementptr inbounds %struct.dirent, %struct.dirent* %47, i32 0, i32 0
%49 = load i8*, i8** %48
%50 = call i64 @lstat(i8* %49, %struct.stat* %12)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %46
br label %42
53: ; preds = %46
%54 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%55 = load i32, i32* %54
%56 = call i64 @S_ISDIR(i32 %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %95
58: ; preds = %53
%59 = load %struct.dirent*, %struct.dirent** %11
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %61)
%63 = icmp ne i64 0, %62
br i1 %63, label %64, label %95
64: ; preds = %58
%65 = load %struct.dirent*, %struct.dirent** %11
%66 = getelementptr inbounds %struct.dirent, %struct.dirent* %65, i32 0, i32 0
%67 = load i8*, i8** %66
%68 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %67)
%69 = icmp ne i64 0, %68
br i1 %69, label %70, label %95
70: ; preds = %64
%71 = load i32, i32* %8
%72 = call i8* @malloc(i32 %71)
store i8* %72, i8** %17
%73 = load i8*, i8** %17
%74 = load i32, i32* %8
%75 = load i8*, i8** %7
%76 = load %struct.dirent*, %struct.dirent** %11
%77 = getelementptr inbounds %struct.dirent, %struct.dirent* %76, i32 0, i32 0
%78 = load i8*, i8** %77
%79 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %73, i32 %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %75, i8* %78)
%80 = load i8*, i8** %6
%81 = load i8*, i8** %17
%82 = load i32, i32* %8
%83 = load i64, i64* %9
%84 = call i32 @findtty(i8* %80, i8* %81, i32 %82, i64 %83)
store i32 %84, i32* %13
%85 = load i8*, i8** %17
%86 = call i32 @free(i8* %85)
%87 = load i32, i32* %13
%88 = icmp eq i32 0, %87
br i1 %88, label %89, label %94
89: ; preds = %70
%90 = load i32*, i32** %10
%91 = call i32 @closedir(i32* %90)
%92 = load i8*, i8** %14
%93 = call i32 @chdir(i8* %92)
store i32 0, i32* %5
br label %143
94: ; preds = %70
br label %42
95: ; preds = %64, %58, %53
%96 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%97 = load i32, i32* %96
%98 = call i32 @S_ISCHR(i32 %97)
%99 = icmp ne i32 %98, 0
br i1 %99, label %101, label %100
100: ; preds = %95
br label %42
101: ; preds = %95
%102 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%103 = load i64, i64* %102
%104 = load i64, i64* %9
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %136
106: ; preds = %101
%107 = load %struct.dirent*, %struct.dirent** %11
%108 = getelementptr inbounds %struct.dirent, %struct.dirent* %107, i32 0, i32 0
%109 = load i8*, i8** %108
%110 = call i32 @strlen(i8* %109)
%111 = load i8*, i8** %7
%112 = call i32 @strlen(i8* %111)
%113 = add nsw i32 %110, %112
%114 = add nsw i32 %113, 1
%115 = load i32, i32* %8
%116 = icmp sge i32 %114, %115
br i1 %116, label %117, label %124
117: ; preds = %106
%118 = load i32, i32* @stderr
%119 = call i32 @fprintf(i32 %118, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%120 = load i32*, i32** %10
%121 = call i32 @closedir(i32* %120)
%122 = load i8*, i8** %14
%123 = call i32 @chdir(i8* %122)
store i32 -1, i32* %5
br label %143
124: ; preds = %106
%125 = load i8*, i8** %6
%126 = load i32, i32* %8
%127 = load i8*, i8** %7
%128 = load %struct.dirent*, %struct.dirent** %11
%129 = getelementptr inbounds %struct.dirent, %struct.dirent* %128, i32 0, i32 0
%130 = load i8*, i8** %129
%131 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %125, i32 %126, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %127, i8* %130)
%132 = load i32*, i32** %10
%133 = call i32 @closedir(i32* %132)
%134 = load i8*, i8** %14
%135 = call i32 @chdir(i8* %134)
store i32 0, i32* %5
br label %143
136: ; preds = %101
br label %42
137: ; preds = %42
%138 = load i32*, i32** %10
%139 = call i32 @closedir(i32* %138)
%140 = load i8*, i8** %14
%141 = call i32 @chdir(i8* %140)
%142 = load i32, i32* %13
store i32 %142, i32* %5
br label %143
143: ; preds = %137, %124, %117, %89, %25
%144 = load i32, i32* %5
ret i32 %144
}

LLVM IR (-O2):
%struct.stat = type { i64, i32 }
%struct.dirent = type { i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [13 x i8] c"bootlogd: %s\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [6 x i8] c"%s/%s\00"
@stderr = global i32 0
@.str.4 = [40 x i8] c"bootlogd: console device name too long\0A\00"
define i32 @findtty(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca %struct.stat
%6 = bitcast %struct.stat* %5 to i8*
%7 = tail call i8* @getcwd(i32* null, i32 0)
%8 = tail call i32 @chdir(i8* %1)
%9 = icmp slt i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %4
%11 = tail call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%15 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %51
16: ; preds = %10, %4
%17 = tail call i32 @strlen(i8* %1)
%18 = add nsw i32 %17, 11
%19 = tail call i8* @malloc(i32 %18)
%20 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %19, i32 %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%21 = tail call i32 @perror(i8* %19)
%22 = tail call i32 @free(i8* %19)
br label %80
23: ; preds = %51, %29
%24 = phi %struct.dirent* [ %30, %29 ], [ %53, %51 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
%27 = call i64 @lstat(i8* %26, %struct.stat* %5)
%28 = icmp eq i64 %27, 0
br i1 %28, label %32, label %29
29: ; preds = %23, %57
%30 = tail call %struct.dirent* @readdir(i32* %11)
%31 = icmp eq %struct.dirent* %30, null
br i1 %31, label %78, label %23
32: ; preds = %23
%33 = load i32, i32* %14
%34 = tail call i64 @S_ISDIR(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %57, label %36
36: ; preds = %32
%37 = load i8*, i8** %25
%38 = tail call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %57, label %40
40: ; preds = %36
%41 = load i8*, i8** %25
%42 = tail call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %41)
%43 = icmp eq i64 %42, 0
br i1 %43, label %57, label %44
44: ; preds = %40
%45 = tail call i8* @malloc(i32 %2)
%46 = load i8*, i8** %25
%47 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %45, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %46)
%48 = tail call i32 @findtty(i8* %0, i8* %45, i32 %2, i64 %3)
%49 = tail call i32 @free(i8* %45)
%50 = icmp eq i32 %48, 0
br i1 %50, label %55, label %51
51: ; preds = %13, %44
%52 = phi i32 [ -1, %13 ], [ %48, %44 ]
%53 = tail call %struct.dirent* @readdir(i32* %11)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %78, label %23
55: ; preds = %44
%56 = tail call i32 @closedir(i32* %11)
br label %80
57: ; preds = %40, %36, %32
%58 = tail call i32 @S_ISCHR(i32 %33)
%59 = icmp ne i32 %58, 0
%60 = load i64, i64* %15
%61 = icmp eq i64 %60, %3
%62 = select i1 %59, i1 %61, i1 false
br i1 %62, label %63, label %29
63: ; preds = %57
%64 = load i8*, i8** %25
%65 = tail call i32 @strlen(i8* %64)
%66 = tail call i32 @strlen(i8* %1)
%67 = add i32 %65, 1
%68 = add i32 %67, %66
%69 = icmp slt i32 %68, %2
br i1 %69, label %74, label %70
70: ; preds = %63
%71 = load i32, i32* @stderr
%72 = tail call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0))
%73 = tail call i32 @closedir(i32* %11)
br label %80
74: ; preds = %63
%75 = load i8*, i8** %25
%76 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %75)
%77 = tail call i32 @closedir(i32* %11)
br label %80
78: ; preds = %51, %29
%79 = tail call i32 @closedir(i32* %11)
br label %80
80: ; preds = %55, %78, %74, %70, %16
%81 = phi i32 [ -1, %16 ], [ 0, %55 ], [ -1, %70 ], [ 0, %74 ], [ %52, %78 ]
%82 = tail call i32 @chdir(i8* %7)
ret i32 %81
}