int search_subdirs(char *parent, char *libdir) {
  char *ptr;
  int found;
  sprintf(libdir, "%s%cshare%ctop%cgurgle.dat", parent, '/', '/', '/');
  found = fexist(libdir);
  if (!found) {
    sprintf(libdir, "%s%cshare%cgromacs%ctop%cgurgle.dat", parent, '/', '/',
            '/', '/');
    found = fexist(libdir);
  }
  if (!found) {
    sprintf(libdir, "%s%cshare%cgromacs-%s%ctop%cgurgle.dat", parent, '/', '/',
            "specbench-3.1.2", '/', '/');
    found = fexist(libdir);
  }
  if (!found) {
    sprintf(libdir, "%s%cshare%cgromacs%cgromacs-%s%ctop%cgurgle.dat", parent,
            '/', '/', '/', "specbench-3.1.2", '/', '/');
    found = fexist(libdir);
  }
  if (found) {
    ptr = strrchr(libdir, '/');
    *ptr = '\0';
  }
  return found;
}


x86 assembly (clang, -O0):
<search_subdirs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xeb1(%rip),%rsi
mov    $0x2f,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <fexist@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b1 <search_subdirs+0x81>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe92(%rip),%rsi
mov    $0x2f,%r9d
mov    %r9d,%ecx
mov    %r9d,%r8d
movl   $0x2f,(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <fexist@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11fe <search_subdirs+0xce>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe75(%rip),%rsi
mov    $0x2f,%r8d
lea    0xe8f(%rip),%r9
mov    %r8d,%ecx
movl   $0x2f,(%rsp)
movl   $0x2f,0x8(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <fexist@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1253 <search_subdirs+0x123>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe5f(%rip),%rsi
mov    $0x2f,%r9d
lea    0xe42(%rip),%rax
mov    %r9d,%ecx
mov    %r9d,%r8d
mov    %rax,(%rsp)
movl   $0x2f,0x8(%rsp)
movl   $0x2f,0x10(%rsp)
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    $0x0,%al
call   1030 <fexist@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
je     1276 <search_subdirs+0x146>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_subdirs>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebb(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2f,%ecx
mov    $0x2f,%r8d
mov    $0x2f,%r9d
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fexist@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1241 <search_subdirs+0x111>
sub    $0x8,%rsp
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2f,%ecx
mov    $0x2f,%r8d
mov    $0x2f,%r9d
xor    %eax,%eax
push   $0x2f
call   1050 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fexist@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1241 <search_subdirs+0x111>
lea    0xe7e(%rip),%rsi
lea    0xe9e(%rip),%r15
xor    %r12d,%r12d
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2f,%ecx
mov    $0x2f,%r8d
mov    %r15,%r9
xor    %eax,%eax
push   $0x2f
push   $0x2f
call   1050 <sprintf@plt>
add    $0x10,%rsp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fexist@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    1241 <search_subdirs+0x111>
sub    $0x8,%rsp
lea    0xe6d(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    $0x2f,%ecx
mov    $0x2f,%r8d
mov    $0x2f,%r9d
xor    %eax,%eax
push   $0x2f
push   $0x2f
push   %r15
call   1050 <sprintf@plt>
add    $0x20,%rsp
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <fexist@plt>
mov    %eax,%ebp
test   %eax,%eax
je     1254 <search_subdirs+0x124>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1040 <strrchr@plt>
movb   $0x0,(%rax)
mov    %ebp,%r12d
mov    %r12d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [27 x i8] c"%s%cshare%ctop%cgurgle.dat\00"
@.str.1 = [36 x i8] c"%s%cshare%cgromacs%ctop%cgurgle.dat\00"
@.str.2 = [39 x i8] c"%s%cshare%cgromacs-%s%ctop%cgurgle.dat\00"
@.str.3 = [16 x i8] c"specbench-3.1.2\00"
@.str.4 = [48 x i8] c"%s%cshare%cgromacs%cgromacs-%s%ctop%cgurgle.dat\00"
define i32 @search_subdirs(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = load i8*, i8** %3
%9 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %8, i32 47, i32 47, i32 47)
%10 = load i8*, i8** %4
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp ne i32 %12, 0
br i1 %13, label %20, label %14
14: ; preds = %2
%15 = load i8*, i8** %4
%16 = load i8*, i8** %3
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %16, i32 47, i32 47, i32 47, i32 47)
%18 = load i8*, i8** %4
%19 = call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %18)
store i32 %19, i32* %6
br label %20
20: ; preds = %14, %2
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i8*, i8** %4
%25 = load i8*, i8** %3
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %25, i32 47, i32 47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 47, i32 47)
%27 = load i8*, i8** %4
%28 = call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %27)
store i32 %28, i32* %6
br label %29
29: ; preds = %23, %20
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %38, label %32
32: ; preds = %29
%33 = load i8*, i8** %4
%34 = load i8*, i8** %3
%35 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %34, i32 47, i32 47, i32 47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 47, i32 47)
%36 = load i8*, i8** %4
%37 = call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %36)
store i32 %37, i32* %6
br label %38
38: ; preds = %32, %29
%39 = load i32, i32* %6
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %45
41: ; preds = %38
%42 = load i8*, i8** %4
%43 = call i8* @strrchr(i8* %42, i32 47)
store i8* %43, i8** %5
%44 = load i8*, i8** %5
store i8 0, i8* %44
br label %45
45: ; preds = %41, %38
%46 = load i32, i32* %6
ret i32 %46
}

LLVM IR (-O2):
@.str = [27 x i8] c"%s%cshare%ctop%cgurgle.dat\00"
@.str.1 = [36 x i8] c"%s%cshare%cgromacs%ctop%cgurgle.dat\00"
@.str.2 = [39 x i8] c"%s%cshare%cgromacs-%s%ctop%cgurgle.dat\00"
@.str.3 = [16 x i8] c"specbench-3.1.2\00"
@.str.4 = [48 x i8] c"%s%cshare%cgromacs%cgromacs-%s%ctop%cgurgle.dat\00"
define i32 @search_subdirs(i8* %0, i8* %1) {
%3 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* %0, i32 47, i32 47, i32 47)
%4 = tail call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %18
6: ; preds = %2
%7 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 47, i32 47, i32 47, i32 47)
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %1)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %18
10: ; preds = %6
%11 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 47, i32 47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 47, i32 47)
%12 = tail call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %1)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0), i8* %0, i32 47, i32 47, i32 47, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0), i32 47, i32 47)
%16 = tail call i32 (i8*, ...) bitcast (i32 (...)* @fexist to i32 (i8*, ...)*)(i8* %1)
%17 = icmp eq i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %2, %6, %10, %14
%19 = phi i32 [ %16, %14 ], [ %12, %10 ], [ %8, %6 ], [ %4, %2 ]
%20 = tail call i8* @strrchr(i8* dereferenceable(1) %1, i32 47)
store i8 0, i8* %20
br label %21
21: ; preds = %18, %14
%22 = phi i32 [ %19, %18 ], [ 0, %14 ]
ret i32 %22
}