#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 */
typedef int /*<<< orphan*/ known_filenames;
typedef int /*<<< orphan*/ known_extensions;
typedef int /*<<< orphan*/ cover;

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *,
                            char const *);
char *strdup(char *);
int strlen(char const *);
char *strndup(char const *, int);
char *strrchr(char const *, char);
scalar_t__ vh_file_exists(char *);
char *grabber_local_get(const char *filename) {
  char *s, *dir = NULL, *file = NULL, *cv = NULL;
  unsigned int i, j;
  const char *known_filenames[] = {"cover", "COVER", "front", "FRONT"};
  const char *known_extensions[] = {"jpg", "JPG", "jpeg", "JPEG",
                                    "png", "PNG", "tbn",  "TBN"};
  if (!filename)
    goto get_end;
  s = strrchr(filename, '/');
  if (!s)
    goto get_end;
  dir = strndup(filename, strlen(filename) - strlen(s));
  s = strrchr(filename, '.');
  if (!s)
    goto get_end;
  file = strndup(filename + strlen(dir) + 1,
                 strlen(filename) - strlen(dir) - strlen(s) - 1);
  for (i = 0; i < (sizeof(known_extensions) / sizeof(known_extensions[0]));
       i++) {
    char cover[1024] = {0};
    snprintf(cover, sizeof(cover), "%s/%s.%s", dir, file, known_extensions[i]);
    if (vh_file_exists(cover)) {
      cv = strdup(cover);
      goto get_end;
    }
  }
  for (i = 0; i < (sizeof(known_extensions) / sizeof(known_extensions[0])); i++)
    for (j = 0; j < (sizeof(known_filenames) / sizeof(known_filenames[0]));
         j++) {
      char cover[1024] = {0};
      snprintf(cover, sizeof(cover), "%s/%s.%s", dir, known_filenames[j],
               known_extensions[i]);
      if (vh_file_exists(cover)) {
        cv = strdup(cover);
        goto get_end;
      }
    }
get_end:
  if (dir)
    free(dir);
  if (file)
    free(file);
  return cv;
}


x86 assembly (clang, -O0):
<grabber_local_get>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8c0,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    0x2c02(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2bff(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2bfc(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0x2bf9(%rip),%rax
mov    %rax,-0x38(%rbp)
lea    -0x90(%rbp),%rdi
lea    0x2bef(%rip),%rsi
mov    $0x40,%edx
call   10a0 <memcpy@plt>
cmpq   $0x0,-0x8(%rbp)
jne    120b <grabber_local_get+0x7b>
jmp    1454 <grabber_local_get+0x2c4>
mov    -0x8(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    122d <grabber_local_get+0x9d>
jmp    1454 <grabber_local_get+0x2c4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x898(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x89c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x89c(%rbp),%esi
mov    -0x898(%rbp),%rdi
sub    %eax,%esi
call   1090 <strndup@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    128a <grabber_local_get+0xfa>
jmp    1454 <grabber_local_get+0x2c4>
mov    -0x8(%rbp),%rax
mov    %rax,-0x8b8(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8b8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x8a8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x8b0(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8b0(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x8ac(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8ac(%rbp),%esi
mov    -0x8a8(%rbp),%rdi
sub    %eax,%esi
sub    $0x1,%esi
call   1090 <strndup@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    $0x8,%rax
jae    1394 <grabber_local_get+0x204>
lea    -0x490(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x490(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x2c(%rbp),%eax
mov    -0x90(%rbp,%rax,8),%r9
ff
mov    $0x400,%esi
lea    0xce9(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x490(%rbp),%rdi
call   1050 <vh_file_exists@plt>
cmp    $0x0,%rax
je     1381 <grabber_local_get+0x1f1>
lea    -0x490(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1454 <grabber_local_get+0x2c4>
jmp    1386 <grabber_local_get+0x1f6>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    130b <grabber_local_get+0x17b>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    $0x8,%rax
jae    144f <grabber_local_get+0x2bf>
movl   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    $0x4,%rax
jae    143c <grabber_local_get+0x2ac>
lea    -0x890(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
lea    -0x890(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x30(%rbp),%eax
mov    -0x50(%rbp,%rax,8),%r8
mov    -0x2c(%rbp),%eax
mov    -0x90(%rbp,%rax,8),%r9
ff
mov    $0x400,%esi
lea    0xc41(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x890(%rbp),%rdi
call   1050 <vh_file_exists@plt>
cmp    $0x0,%rax
je     1429 <grabber_local_get+0x299>
lea    -0x890(%rbp),%rdi
call   10b0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1454 <grabber_local_get+0x2c4>
jmp    142e <grabber_local_get+0x29e>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    13af <grabber_local_get+0x21f>
jmp    1441 <grabber_local_get+0x2b1>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    139b <grabber_local_get+0x20b>
jmp    1454 <grabber_local_get+0x2c4>
cmpq   $0x0,-0x18(%rbp)
je     1468 <grabber_local_get+0x2d8>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x20(%rbp)
je     147c <grabber_local_get+0x2ec>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
add    $0x8c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grabber_local_get>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
test   %rdi,%rdi
je     1458 <grabber_local_get+0x2d8>
mov    %rdi,%rbx
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     1458 <grabber_local_get+0x2d8>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %rbp,%rdi
call   1040 <strlen@plt>
sub    %eax,%r14d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1090 <strndup@plt>
mov    %rax,%r15
mov    %rbx,%rdi
mov    $0x2e,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
je     145c <grabber_local_get+0x2dc>
mov    %rax,%rbp
mov    %r15,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%r14
add    $0x1,%r14
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1040 <strlen@plt>
add    %eax,%ebx
not    %ebx
add    %r12d,%ebx
mov    %r14,%rdi
mov    %ebx,%esi
call   1090 <strndup@plt>
mov    %rax,%r14
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xdee(%rip),%rdx
lea    0xdc5(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xdaa(%rip),%rdx
lea    0xd85(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xd66(%rip),%rdx
lea    0xd45(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xd22(%rip),%rdx
lea    0xd06(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xcde(%rip),%rdx
lea    0xcc7(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xc9a(%rip),%rdx
lea    0xc87(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xc56(%rip),%rdx
lea    0xc47(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    %rsp,%rbx
mov    $0x400,%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xc16(%rip),%rdx
lea    0xc0b(%rip),%r9
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r15,%rcx
mov    %r14,%r8
call   1060 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
je     1490 <grabber_local_get+0x310>
mov    %rsp,%rdi
call   10a0 <strdup@plt>
mov    %rax,%rbx
jmp    1461 <grabber_local_get+0x2e1>
xor    %ebx,%ebx
jmp    147b <grabber_local_get+0x2fb>
xor    %r14d,%r14d
xor    %ebx,%ebx
test   %r15,%r15
je     146e <grabber_local_get+0x2ee>
mov    %r15,%rdi
call   1030 <free@plt>
test   %r14,%r14
je     147b <grabber_local_get+0x2fb>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebx,%ebx
mov    %rsp,%r12
xor    %r13d,%r13d
lea    0x2941(%rip),%rax
mov    0x0(%r13,%rax,1),%rbp
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12,%rdi
mov    $0x400,%esi
lea    0xb78(%rip),%rdx
mov    %r15,%rcx
lea    0xb34(%rip),%r8
mov    %rbp,%r9
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12,%rdi
mov    $0x400,%esi
lea    0xb37(%rip),%rdx
mov    %r15,%rcx
lea    0xaf9(%rip),%r8
mov    %rbp,%r9
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12,%rdi
mov    $0x400,%esi
lea    0xaf6(%rip),%rdx
mov    %r15,%rcx
lea    0xabe(%rip),%r8
mov    %rbp,%r9
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
mov    $0x400,%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <memset@plt>
mov    %r12,%rdi
mov    $0x400,%esi
lea    0xab5(%rip),%rdx
mov    %r15,%rcx
lea    0xa83(%rip),%r8
mov    %rbp,%r9
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1050 <vh_file_exists@plt>
test   %rax,%rax
jne    144b <grabber_local_get+0x2cb>
add    $0x8,%r13
cmp    $0x40,%r13
jne    1498 <grabber_local_get+0x318>
jmp    1461 <grabber_local_get+0x2e1>

LLVM IR (-O0):
@.str = [6 x i8] c"cover\00"
@.str.1 = [6 x i8] c"COVER\00"
@.str.2 = [6 x i8] c"front\00"
@.str.3 = [6 x i8] c"FRONT\00"
@__const.grabber_local_get.known_filenames = [4 x i8*] [i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0)]
@.str.4 = [4 x i8] c"jpg\00"
@.str.5 = [4 x i8] c"JPG\00"
@.str.6 = [5 x i8] c"jpeg\00"
@.str.7 = [5 x i8] c"JPEG\00"
@.str.8 = [4 x i8] c"png\00"
@.str.9 = [4 x i8] c"PNG\00"
@.str.10 = [4 x i8] c"tbn\00"
@.str.11 = [4 x i8] c"TBN\00"
@__const.grabber_local_get.known_extensions = [8 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [9 x i8] c"%s/%s.%s\00"
define i8* @grabber_local_get(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [4 x i8*]
%10 = alloca [8 x i8*]
%11 = alloca [1024 x i8]
%12 = alloca [1024 x i8]
store i8* %0, i8** %2
store i8* null, i8** %4
store i8* null, i8** %5
store i8* null, i8** %6
%13 = bitcast [4 x i8*]* %9 to i8*
%14 = bitcast [8 x i8*]* %10 to i8*
%15 = load i8*, i8** %2
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %1
br label %116
18: ; preds = %1
%19 = load i8*, i8** %2
%20 = call i8* @strrchr(i8* %19, i8 signext 47)
store i8* %20, i8** %3
%21 = load i8*, i8** %3
%22 = icmp ne i8* %21, null
br i1 %22, label %24, label %23
23: ; preds = %18
br label %116
24: ; preds = %18
%25 = load i8*, i8** %2
%26 = load i8*, i8** %2
%27 = call i32 @strlen(i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @strlen(i8* %28)
%30 = sub nsw i32 %27, %29
%31 = call i8* @strndup(i8* %25, i32 %30)
store i8* %31, i8** %4
%32 = load i8*, i8** %2
%33 = call i8* @strrchr(i8* %32, i8 signext 46)
store i8* %33, i8** %3
%34 = load i8*, i8** %3
%35 = icmp ne i8* %34, null
br i1 %35, label %37, label %36
36: ; preds = %24
br label %116
37: ; preds = %24
%38 = load i8*, i8** %2
%39 = load i8*, i8** %4
%40 = call i32 @strlen(i8* %39)
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %38, i64 %41
%43 = getelementptr inbounds i8, i8* %42, i64 1
%44 = load i8*, i8** %2
%45 = call i32 @strlen(i8* %44)
%46 = load i8*, i8** %4
%47 = call i32 @strlen(i8* %46)
%48 = sub nsw i32 %45, %47
%49 = load i8*, i8** %3
%50 = call i32 @strlen(i8* %49)
%51 = sub nsw i32 %48, %50
%52 = sub nsw i32 %51, 1
%53 = call i8* @strndup(i8* %43, i32 %52)
store i8* %53, i8** %5
store i32 0, i32* %7
br label %54
54: ; preds = %75, %37
%55 = load i32, i32* %7
%56 = zext i32 %55 to i64
%57 = icmp ult i64 %56, 8
br i1 %57, label %58, label %78
58: ; preds = %54
%59 = bitcast [1024 x i8]* %11 to i8*
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%61 = load i8*, i8** %4
%62 = load i8*, i8** %5
%63 = load i32, i32* %7
%64 = zext i32 %63 to i64
%65 = getelementptr inbounds [8 x i8*], [8 x i8*]* %10, i64 0, i64 %64
%66 = load i8*, i8** %65
%67 = call i32 @snprintf(i8* %60, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %61, i8* %62, i8* %66)
%68 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%69 = call i64 @vh_file_exists(i8* %68)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %58
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %11, i64 0, i64 0
%73 = call i8* @strdup(i8* %72)
store i8* %73, i8** %6
br label %116
74: ; preds = %58
br label %75
75: ; preds = %74
%76 = load i32, i32* %7
%77 = add i32 %76, 1
store i32 %77, i32* %7
br label %54
78: ; preds = %54
store i32 0, i32* %7
br label %79
79: ; preds = %112, %78
%80 = load i32, i32* %7
%81 = zext i32 %80 to i64
%82 = icmp ult i64 %81, 8
br i1 %82, label %83, label %115
83: ; preds = %79
store i32 0, i32* %8
br label %84
84: ; preds = %108, %83
%85 = load i32, i32* %8
%86 = zext i32 %85 to i64
%87 = icmp ult i64 %86, 4
br i1 %87, label %88, label %111
88: ; preds = %84
%89 = bitcast [1024 x i8]* %12 to i8*
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%91 = load i8*, i8** %4
%92 = load i32, i32* %8
%93 = zext i32 %92 to i64
%94 = getelementptr inbounds [4 x i8*], [4 x i8*]* %9, i64 0, i64 %93
%95 = load i8*, i8** %94
%96 = load i32, i32* %7
%97 = zext i32 %96 to i64
%98 = getelementptr inbounds [8 x i8*], [8 x i8*]* %10, i64 0, i64 %97
%99 = load i8*, i8** %98
%100 = call i32 @snprintf(i8* %90, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %91, i8* %95, i8* %99)
%101 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%102 = call i64 @vh_file_exists(i8* %101)
%103 = icmp ne i64 %102, 0
br i1 %103, label %104, label %107
104: ; preds = %88
%105 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%106 = call i8* @strdup(i8* %105)
store i8* %106, i8** %6
br label %116
107: ; preds = %88
br label %108
108: ; preds = %107
%109 = load i32, i32* %8
%110 = add i32 %109, 1
store i32 %110, i32* %8
br label %84
111: ; preds = %84
br label %112
112: ; preds = %111
%113 = load i32, i32* %7
%114 = add i32 %113, 1
store i32 %114, i32* %7
br label %79
115: ; preds = %79
br label %116
116: ; preds = %115, %104, %71, %36, %23, %17
%117 = load i8*, i8** %4
%118 = icmp ne i8* %117, null
br i1 %118, label %119, label %122
119: ; preds = %116
%120 = load i8*, i8** %4
%121 = call i32 @free(i8* %120)
br label %122
122: ; preds = %119, %116
%123 = load i8*, i8** %5
%124 = icmp ne i8* %123, null
br i1 %124, label %125, label %128
125: ; preds = %122
%126 = load i8*, i8** %5
%127 = call i32 @free(i8* %126)
br label %128
128: ; preds = %125, %122
%129 = load i8*, i8** %6
ret i8* %129
}

LLVM IR (-O2):
@.str = [6 x i8] c"cover\00"
@.str.1 = [6 x i8] c"COVER\00"
@.str.2 = [6 x i8] c"front\00"
@.str.3 = [6 x i8] c"FRONT\00"
@.str.4 = [4 x i8] c"jpg\00"
@.str.5 = [4 x i8] c"JPG\00"
@.str.6 = [5 x i8] c"jpeg\00"
@.str.7 = [5 x i8] c"JPEG\00"
@.str.8 = [4 x i8] c"png\00"
@.str.9 = [4 x i8] c"PNG\00"
@.str.10 = [4 x i8] c"tbn\00"
@.str.11 = [4 x i8] c"TBN\00"
@__const.grabber_local_get.known_extensions = [8 x i8*] [i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [9 x i8] c"%s/%s.%s\00"
define noalias i8* @grabber_local_get(i8* %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = icmp eq i8* %0, null
br i1 %4, label %97, label %5
5: ; preds = %1
%6 = tail call i8* @strrchr(i8* %0, i8 signext 47)
%7 = icmp eq i8* %6, null
br i1 %7, label %97, label %8
8: ; preds = %5
%9 = tail call i32 @strlen(i8* %0)
%10 = tail call i32 @strlen(i8* %6)
%11 = sub nsw i32 %9, %10
%12 = tail call i8* @strndup(i8* %0, i32 %11)
%13 = tail call i8* @strrchr(i8* %0, i8 signext 46)
%14 = icmp eq i8* %13, null
br i1 %14, label %87, label %15
15: ; preds = %8
%16 = tail call i32 @strlen(i8* %12)
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = tail call i32 @strlen(i8* %0)
%21 = tail call i32 @strlen(i8* %12)
%22 = tail call i32 @strlen(i8* %13)
%23 = add i32 %22, %21
%24 = xor i32 %23, -1
%25 = add i32 %20, %24
%26 = tail call i8* @strndup(i8* %19, i32 %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%28 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%29 = call i64 @vh_file_exists(i8* %27)
%30 = icmp eq i64 %29, 0
br i1 %30, label %33, label %31
31: ; preds = %57, %53, %49, %45, %41, %37, %33, %15
%32 = call i8* @strdup(i8* %27)
br label %87
33: ; preds = %15
%34 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0))
%35 = call i64 @vh_file_exists(i8* %27)
%36 = icmp eq i64 %35, 0
br i1 %36, label %37, label %31
37: ; preds = %33
%38 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.6, i64 0, i64 0))
%39 = call i64 @vh_file_exists(i8* %27)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %31
41: ; preds = %37
%42 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%43 = call i64 @vh_file_exists(i8* %27)
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %31
45: ; preds = %41
%46 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0))
%47 = call i64 @vh_file_exists(i8* %27)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %31
49: ; preds = %45
%50 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%51 = call i64 @vh_file_exists(i8* %27)
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %31
53: ; preds = %49
%54 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.10, i64 0, i64 0))
%55 = call i64 @vh_file_exists(i8* %27)
%56 = icmp eq i64 %55, 0
br i1 %56, label %57, label %31
57: ; preds = %53
%58 = call i32 @snprintf(i8* %27, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%59 = call i64 @vh_file_exists(i8* %27)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %31
61: ; preds = %57
%62 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %63
63: ; preds = %61, %84
%64 = phi i64 [ 0, %61 ], [ %85, %84 ]
%65 = getelementptr inbounds [8 x i8*], [8 x i8*]* @__const.grabber_local_get.known_extensions, i64 0, i64 %64
%66 = load i8*, i8** %65
%67 = call i32 @snprintf(i8* %62, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %66)
%68 = call i64 @vh_file_exists(i8* %62)
%69 = icmp eq i64 %68, 0
br i1 %69, label %72, label %70
70: ; preds = %80, %76, %72, %63
%71 = call i8* @strdup(i8* %62)
br label %87
72: ; preds = %63
%73 = call i32 @snprintf(i8* %62, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %66)
%74 = call i64 @vh_file_exists(i8* %62)
%75 = icmp eq i64 %74, 0
br i1 %75, label %76, label %70
76: ; preds = %72
%77 = call i32 @snprintf(i8* %62, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %66)
%78 = call i64 @vh_file_exists(i8* %62)
%79 = icmp eq i64 %78, 0
br i1 %79, label %80, label %70
80: ; preds = %76
%81 = call i32 @snprintf(i8* %62, i32 1024, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.12, i64 0, i64 0), i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %66)
%82 = call i64 @vh_file_exists(i8* %62)
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %70
84: ; preds = %80
%85 = add nuw nsw i64 %64, 1
%86 = icmp eq i64 %85, 8
br i1 %86, label %87, label %63
87: ; preds = %84, %70, %31, %8
%88 = phi i8* [ %26, %31 ], [ %26, %70 ], [ null, %8 ], [ %26, %84 ]
%89 = phi i8* [ %32, %31 ], [ %71, %70 ], [ null, %8 ], [ null, %84 ]
%90 = icmp eq i8* %12, null
br i1 %90, label %93, label %91
91: ; preds = %87
%92 = call i32 @free(i8* %12)
br label %93
93: ; preds = %91, %87
%94 = icmp eq i8* %88, null
br i1 %94, label %97, label %95
95: ; preds = %93
%96 = call i32 @free(i8* %88)
br label %97
97: ; preds = %5, %1, %93, %95
%98 = phi i8* [ %89, %93 ], [ %89, %95 ], [ null, %1 ], [ null, %5 ]
ret i8* %98
}