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

/* Variables and functions */
scalar_t__ DT_DIR;
int MAXPATHLEN;
int S_IXOTH;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
void *malloc(int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ readdir_r(int /*<<< orphan*/ *, struct dirent *,
                             struct dirent **);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int find_embassy(const char *dirname, char ***aptr) {
  char **earray = NULL;
  DIR *dirp = NULL;
  struct dirent *dresult = NULL;
  char fname[MAXPATHLEN];
  char buf[sizeof(struct dirent) + MAXPATHLEN];
  struct stat sbuf;
  int count = 0;
  int i;
  dirp = opendir(dirname);
  if (!dirp) {
    fprintf(stderr, "Error: Cannot open directory [%s]\n", dirname);
    exit(-1);
  }
  count = 0;
  while (!readdir_r(dirp, (struct dirent *)buf, &dresult)) {
    if (!dresult)
      break;
    if (dresult->d_type == DT_DIR) {
      if (!strcmp(dresult->d_name, "CVS") || *dresult->d_name == '.')
        continue;
      sprintf(fname, "%s/%s", dirname, dresult->d_name);
      if (!stat(fname, &sbuf)) {
        if (sbuf.st_mode & S_IXOTH)
          ++count;
      }
    }
  }
  rewinddir(dirp);
  *aptr = malloc((sizeof(char *) * (count + 1)));
  earray = *aptr;
  for (i = 0; i < count; ++i)
    earray[i] = malloc(sizeof(char) * MAXPATHLEN);
  earray[count] = NULL;
  i = 0;
  while (!readdir_r(dirp, (struct dirent *)buf, &dresult)) {
    if (!dresult)
      break;
    if (dresult->d_type == DT_DIR) {
      if (!strcmp(dresult->d_name, "CVS") || *dresult->d_name == '.')
        continue;
      sprintf(fname, "%s/%s", dirname, dresult->d_name);
      if (!stat(fname, &sbuf)) {
        if (sbuf.st_mode & S_IXOTH)
          strcpy(earray[i++], dresult->d_name);
      }
    }
  }
  closedir(dirp);
  return count;
}


x86 assembly (clang, -O0):
<find_embassy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x30(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x60(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x38(%rbp)
movslq (%rax),%rdx
mov    %rdx,%rax
add    $0x10,%rax
add    $0x1f,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x58(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x40(%rbp)
movl   $0x0,-0x4c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1269 <find_embassy+0xb9>
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xda6(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
movl   $0x0,-0x4c(%rbp)
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rdx
call   1040 <readdir_r@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1296 <find_embassy+0xe6>
jmp    1352 <find_embassy+0x1a2>
cmpq   $0x0,-0x28(%rbp)
jne    12a6 <find_embassy+0xf6>
jmp    1352 <find_embassy+0x1a2>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2d14(%rip),%rcx
cmp    (%rcx),%rax
jne    134d <find_embassy+0x19d>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd57(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
je     12ee <find_embassy+0x13e>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12f3 <find_embassy+0x143>
jmp    1270 <find_embassy+0xc0>
mov    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xd1d(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x60(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%eax
jne    1348 <find_embassy+0x198>
mov    -0x48(%rbp),%eax
mov    0x2cb9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1343 <find_embassy+0x193>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1348 <find_embassy+0x198>
jmp    134d <find_embassy+0x19d>
jmp    1270 <find_embassy+0xc0>
mov    -0x20(%rbp),%rdi
call   1060 <rewinddir@plt>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x3,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jge    13c8 <find_embassy+0x218>
mov    0x2c43(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   10b0 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x50(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x50(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
jmp    138a <find_embassy+0x1da>
mov    -0x18(%rbp),%rax
movslq -0x4c(%rbp),%rcx
movq   $0x0,(%rax,%rcx,8)
movl   $0x0,-0x50(%rbp)
mov    -0x58(%rbp),%rsi
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rdx
call   1040 <readdir_r@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1405 <find_embassy+0x255>
jmp    14db <find_embassy+0x32b>
cmpq   $0x0,-0x28(%rbp)
jne    1415 <find_embassy+0x265>
jmp    14db <find_embassy+0x32b>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2ba5(%rip),%rcx
cmp    (%rcx),%rax
jne    14d6 <find_embassy+0x326>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xbe8(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%eax
je     145d <find_embassy+0x2ad>
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1462 <find_embassy+0x2b2>
jmp    13df <find_embassy+0x22f>
mov    -0x60(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xbae(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x60(%rbp),%rdi
lea    -0x48(%rbp),%rsi
call   10a0 <stat@plt>
cmp    $0x0,%eax
jne    14d1 <find_embassy+0x321>
mov    -0x48(%rbp),%eax
mov    0x2b4a(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     14cc <find_embassy+0x31c>
mov    -0x18(%rbp),%rax
mov    -0x50(%rbp),%ecx
mov    %ecx,%edx
add    $0x1,%edx
mov    %edx,-0x50(%rbp)
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    14d1 <find_embassy+0x321>
jmp    14d6 <find_embassy+0x326>
jmp    13df <find_embassy+0x22f>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x4c(%rbp),%eax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_embassy>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rsp,%rbx
movq   $0x0,-0x30(%rbp)
mov    0x2e0a(%rip),%rdx
mov    (%rdx),%eax
mov    %rsp,%rcx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
movslq (%rdx),%rax
mov    %rsp,%r12
add    $0x1f,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rdi,-0x58(%rbp)
call   1050 <opendir@plt>
test   %rax,%rax
je     1453 <find_embassy+0x2a3>
mov    %rax,%r13
lea    -0x30(%rbp),%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <readdir_r@plt>
xor    %ecx,%ecx
mov    %rcx,-0x38(%rbp)
test   %eax,%eax
mov    %r12,-0x48(%rbp)
mov    %rbx,-0x68(%rbp)
mov    %r14,-0x50(%rbp)
jne    12eb <find_embassy+0x13b>
mov    -0x30(%rbp),%rax
test   %rax,%rax
je     12eb <find_embassy+0x13b>
xor    %ecx,%ecx
mov    %rcx,-0x38(%rbp)
mov    0x2d6f(%rip),%r14
lea    -0x30(%rbp),%r15
nopl   (%rax)
mov    (%rax),%rcx
cmp    (%r14),%rcx
jne    1284 <find_embassy+0xd4>
mov    0x8(%rax),%rbx
mov    %rbx,%rdi
lea    0xdad(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     1284 <find_embassy+0xd4>
cmpb   $0x2e,(%rbx)
jne    12a1 <find_embassy+0xf1>
mov    %r13,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1040 <readdir_r@plt>
test   %eax,%eax
jne    12eb <find_embassy+0x13b>
mov    -0x30(%rbp),%rax
test   %rax,%rax
jne    1260 <find_embassy+0xb0>
jmp    12eb <find_embassy+0x13b>
mov    -0x60(%rbp),%r12
mov    %r12,%rdi
lea    0xd78(%rip),%rsi
mov    -0x58(%rbp),%rdx
mov    %rbx,%rcx
call   10c0 <sprintf@plt>
mov    %r12,%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <stat@plt>
test   %eax,%eax
jne    12e5 <find_embassy+0x135>
mov    0x2d16(%rip),%rax
mov    (%rax),%eax
and    -0x40(%rbp),%eax
cmp    $0x1,%eax
mov    -0x38(%rbp),%rax
sbb    $0xffffffff,%eax
mov    %rax,-0x38(%rbp)
mov    -0x48(%rbp),%r12
jmp    1284 <find_embassy+0xd4>
mov    %r13,%rdi
call   1060 <rewinddir@plt>
mov    -0x38(%rbp),%rbx
lea    0x8(,%rbx,8),%edi
call   10b0 <malloc@plt>
mov    %rax,%r14
mov    -0x50(%rbp),%rax
mov    %r14,(%rax)
test   %ebx,%ebx
jle    1345 <find_embassy+0x195>
mov    0x2cc8(%rip),%rax
mov    (%rax),%r15d
mov    -0x38(%rbp),%ebx
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   10b0 <malloc@plt>
mov    %rax,(%r14,%r12,8)
add    $0x1,%r12
cmp    %r12,%rbx
jne    1330 <find_embassy+0x180>
movslq -0x38(%rbp),%rax
movq   $0x0,(%r14,%rax,8)
lea    -0x30(%rbp),%rdx
mov    %r13,%rdi
mov    -0x48(%rbp),%rbx
mov    %rbx,%rsi
call   1040 <readdir_r@plt>
test   %eax,%eax
jne    1434 <find_embassy+0x284>
mov    -0x30(%rbp),%rax
test   %rax,%rax
je     1434 <find_embassy+0x284>
movl   $0x0,-0x50(%rbp)
lea    -0x30(%rbp),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%rax),%rcx
mov    0x2c2e(%rip),%rdx
cmp    (%rdx),%rcx
jne    13bc <find_embassy+0x20c>
mov    0x8(%rax),%r15
mov    %r15,%rdi
lea    0xc76(%rip),%rsi
call   1080 <strcmp@plt>
test   %eax,%eax
je     13bc <find_embassy+0x20c>
cmpb   $0x2e,(%r15)
jne    13d9 <find_embassy+0x229>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1040 <readdir_r@plt>
test   %eax,%eax
jne    1434 <find_embassy+0x284>
mov    -0x30(%rbp),%rax
test   %rax,%rax
jne    1390 <find_embassy+0x1e0>
jmp    1434 <find_embassy+0x284>
mov    -0x60(%rbp),%rbx
mov    %rbx,%rdi
lea    0xc40(%rip),%rsi
mov    -0x58(%rbp),%rdx
mov    %r15,%rcx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
lea    -0x40(%rbp),%rsi
call   10a0 <stat@plt>
test   %eax,%eax
jne    142e <find_embassy+0x27e>
mov    0x2bde(%rip),%rax
mov    (%rax),%eax
test   %eax,-0x40(%rbp)
je     142e <find_embassy+0x27e>
mov    -0x50(%rbp),%ecx
movslq %ecx,%rax
add    $0x1,%ecx
mov    %ecx,-0x50(%rbp)
mov    (%r14,%rax,8),%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x48(%rbp),%rbx
jmp    13bc <find_embassy+0x20c>
mov    %r13,%rdi
call   1070 <closedir@plt>
mov    -0x68(%rbp),%rsp
mov    -0x38(%rbp),%rax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
lea    0xb9d(%rip),%rsi
mov    -0x58(%rbp),%rdx
call   1090 <fprintf@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

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

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