#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;
};

/* Variables and functions */
int S_IFREG;
scalar_t__ exists(char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcattoc_esc(char *, char const *, char);
scalar_t__ strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
char *strdup(char const *);
int strlen(char const *);
char *find_in_path(const char *path, const char *filename) {
  struct stat statbuf;
  const char *home;
  char *buf;
  int buf_size;
  if (filename == NULL) {
    return NULL;
  }
  if (path == NULL || strchr(filename, '/')) {
    if (stat(filename, &statbuf) == 0)
      if (statbuf.st_mode & S_IFREG)
        if (exists(filename) == 0) {
          return strdup(filename);
        }
    do {
      if (3 >= 3) {
        fprintf(stderr, "Giving up, screw it I'll return NULL.");
      }
    } while (0);
    return NULL;
  }
  home = "/dev_hdd0/game/PS3Roar00/USRDIR/ROMS/";
  buf_size = strlen(path) + strlen(filename) + 3;
  if (home) {
    buf_size += strlen(home) - 1;
  }
  buf = malloc(buf_size);
  if (buf == NULL)
    return NULL;
  while (*path) {
    *buf = 0;
    if (home && *path == '~' && *(path + 1) == '/') {
      strcpy(buf, home);
      path += 2;
      if (buf[strlen(buf) - 1] != '/')
        strcat(buf, "/");
    }
    strcattoc_esc(buf, path, ':');
    if (*buf == 0)
      strcpy(buf, "./");
    else if (buf[strlen(buf) - 1] != '/')
      strcat(buf, "/");
    strcat(buf, filename);
    if (stat(buf, &statbuf) == 0)
      if (statbuf.st_mode & S_IFREG)
        if (exists(buf) == 0) {
          return buf;
        }
    while (*path && *path != ':') {
      if (*path == '\\' && *(path + 1) != 0)
        path++;
      path++;
    }
    if (*path == ':')
      path++;
  }
  free(buf);
  return NULL;
}


x86 assembly (clang, -O0):
<find_in_path>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <find_in_path+0x28>
movq   $0x0,-0x8(%rbp)
jmp    150b <find_in_path+0x35b>
cmpq   $0x0,-0x10(%rbp)
je     11fb <find_in_path+0x4b>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
cmp    $0x0,%rax
je     127d <find_in_path+0xcd>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jne    1256 <find_in_path+0xa6>
mov    -0x20(%rbp),%eax
mov    0x2dcc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1251 <find_in_path+0xa1>
mov    -0x18(%rbp),%rdi
call   10a0 <exists@plt>
cmp    $0x0,%rax
jne    124c <find_in_path+0x9c>
mov    -0x18(%rbp),%rdi
call   10d0 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    150b <find_in_path+0x35b>
jmp    1251 <find_in_path+0xa1>
jmp    1256 <find_in_path+0xa6>
jmp    125b <find_in_path+0xab>
mov    0x2d76(%rip),%rax
mov    (%rax),%edi
lea    0xd95(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    150b <find_in_path+0x35b>
lea    0xda2(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
add    $0x3,%eax
mov    %eax,-0x34(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     12c7 <find_in_path+0x117>
mov    -0x28(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
add    -0x34(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1090 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12eb <find_in_path+0x13b>
movq   $0x0,-0x8(%rbp)
jmp    150b <find_in_path+0x35b>
jmp    12f0 <find_in_path+0x140>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     14fa <find_in_path+0x34a>
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
je     1388 <find_in_path+0x1d8>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x7e,%eax
jne    1388 <find_in_path+0x1d8>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
jne    1388 <find_in_path+0x1d8>
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x10(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1383 <find_in_path+0x1d3>
mov    -0x30(%rbp),%rdi
lea    0xccf(%rip),%rsi
call   10c0 <strcat@plt>
jmp    1388 <find_in_path+0x1d8>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x3a,%edx
call   10b0 <strcattoc_esc@plt>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    13bf <find_in_path+0x20f>
mov    -0x30(%rbp),%rdi
lea    0xc97(%rip),%rsi
call   1040 <strcpy@plt>
jmp    13fe <find_in_path+0x24e>
mov    -0x30(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     13f9 <find_in_path+0x249>
mov    -0x30(%rbp),%rdi
lea    0xc59(%rip),%rsi
call   10c0 <strcat@plt>
jmp    13fe <find_in_path+0x24e>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10c0 <strcat@plt>
mov    -0x30(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0x0,%rax
jne    1461 <find_in_path+0x2b1>
mov    -0x20(%rbp),%eax
mov    0x2bbc(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     145c <find_in_path+0x2ac>
mov    -0x30(%rbp),%rdi
call   10a0 <exists@plt>
cmp    $0x0,%rax
jne    1457 <find_in_path+0x2a7>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    150b <find_in_path+0x35b>
jmp    145c <find_in_path+0x2ac>
jmp    1461 <find_in_path+0x2b1>
jmp    1466 <find_in_path+0x2b6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x49(%rbp)
je     148b <find_in_path+0x2db>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
setne  %al
mov    %al,-0x49(%rbp)
mov    -0x49(%rbp),%al
test   $0x1,%al
jne    149b <find_in_path+0x2eb>
jmp    14d9 <find_in_path+0x329>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    14c8 <find_in_path+0x318>
mov    -0x10(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     14c8 <find_in_path+0x318>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1466 <find_in_path+0x2b6>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x3a,%eax
jne    14f5 <find_in_path+0x345>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12f0 <find_in_path+0x140>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_in_path>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rsi,%rsi
je     1202 <find_in_path+0x52>
mov    %rsi,%r14
mov    %rdi,%rbx
test   %rdi,%rdi
je     11dd <find_in_path+0x2d>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strchr@plt>
test   %rax,%rax
je     123f <find_in_path+0x8f>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1080 <stat@plt>
test   %rax,%rax
je     1217 <find_in_path+0x67>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
call   1070 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dca(%rip),%rax
mov    (%rax),%eax
test   %eax,(%rsp)
je     11ed <find_in_path+0x3d>
mov    %r14,%rdi
call   10a0 <exists@plt>
test   %rax,%rax
jne    11ed <find_in_path+0x3d>
mov    %r14,%rdi
call   10d0 <strdup@plt>
mov    %rax,%r15
jmp    1205 <find_in_path+0x55>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %eax,%r15d
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebp
lea    0xdcb(%rip),%rdi
call   1050 <strlen@plt>
add    %r15d,%ebp
lea    (%rax,%rbp,1),%edi
add    $0x2,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1202 <find_in_path+0x52>
mov    %rax,%r15
cmpb   $0x0,(%rbx)
je     13bc <find_in_path+0x20c>
lea    0xdc7(%rip),%r13
mov    %rsp,%r12
mov    0x2d58(%rip),%rbp
jmp    12b5 <find_in_path+0x105>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %ecx,%ecx
cmp    $0x3a,%al
sete   %cl
cmpb   $0x0,(%rbx,%rcx,1)
lea    (%rbx,%rcx,1),%rbx
je     13bc <find_in_path+0x20c>
movb   $0x0,(%r15)
cmpb   $0x7e,(%rbx)
jne    1300 <find_in_path+0x150>
cmpb   $0x2f,0x1(%rbx)
jne    1300 <find_in_path+0x150>
mov    %r15,%rdi
lea    0xd58(%rip),%rsi
call   1040 <strcpy@plt>
add    $0x2,%rbx
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
je     1300 <find_in_path+0x150>
mov    %r15,%rdi
mov    %r13,%rsi
call   10c0 <strcat@plt>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x3a,%edx
call   10b0 <strcattoc_esc@plt>
cmpb   $0x0,(%r15)
je     1340 <find_in_path+0x190>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r15,1)
je     134f <find_in_path+0x19f>
mov    %r15,%rdi
mov    %r13,%rsi
call   10c0 <strcat@plt>
jmp    134f <find_in_path+0x19f>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
lea    0xd02(%rip),%rsi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   10c0 <strcat@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1080 <stat@plt>
test   %rax,%rax
jne    1394 <find_in_path+0x1e4>
mov    0x0(%rbp),%eax
test   %eax,(%rsp)
je     1394 <find_in_path+0x1e4>
mov    %r15,%rdi
call   10a0 <exists@plt>
test   %rax,%rax
jne    1394 <find_in_path+0x1e4>
jmp    1205 <find_in_path+0x55>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     13b0 <find_in_path+0x200>
test   %al,%al
je     12a0 <find_in_path+0xf0>
cmp    $0x3a,%al
jne    1390 <find_in_path+0x1e0>
jmp    12a0 <find_in_path+0xf0>
nopl   0x0(%rax)
cmpb   $0x0,0x1(%rbx)
je     1390 <find_in_path+0x1e0>
add    $0x1,%rbx
jmp    1390 <find_in_path+0x1e0>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1202 <find_in_path+0x52>

LLVM IR (-O0):
%struct.stat = type { i32 }
@S_IFREG = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Giving up, screw it I'll return NULL.\00"
@.str.1 = [38 x i8] c"/dev_hdd0/game/PS3Roar00/USRDIR/ROMS/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [3 x i8] c"./\00"
define i8* @find_in_path(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %5
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i8* null, i8** %3
br label %192
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %20, label %16
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = call i64 @strchr(i8* %17, i8 signext 47)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %44
20: ; preds = %16, %13
%21 = load i8*, i8** %5
%22 = call i64 @stat(i8* %21, %struct.stat* %6)
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %39
24: ; preds = %20
%25 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%26 = load i32, i32* %25
%27 = load i32, i32* @S_IFREG
%28 = and i32 %26, %27
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %38
30: ; preds = %24
%31 = load i8*, i8** %5
%32 = call i64 @exists(i8* %31)
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i8*, i8** %5
%36 = call i8* @strdup(i8* %35)
store i8* %36, i8** %3
br label %192
37: ; preds = %30
br label %38
38: ; preds = %37, %24
br label %39
39: ; preds = %38, %20
br label %40
40: ; preds = %39
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %43
43: ; preds = %40
store i8* null, i8** %3
br label %192
44: ; preds = %16
store i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8** %7
%45 = load i8*, i8** %4
%46 = call i32 @strlen(i8* %45)
%47 = load i8*, i8** %5
%48 = call i32 @strlen(i8* %47)
%49 = add nsw i32 %46, %48
%50 = add nsw i32 %49, 3
store i32 %50, i32* %9
%51 = load i8*, i8** %7
%52 = icmp ne i8* %51, null
br i1 %52, label %53, label %59
53: ; preds = %44
%54 = load i8*, i8** %7
%55 = call i32 @strlen(i8* %54)
%56 = sub nsw i32 %55, 1
%57 = load i32, i32* %9
%58 = add nsw i32 %57, %56
store i32 %58, i32* %9
br label %59
59: ; preds = %53, %44
%60 = load i32, i32* %9
%61 = call i8* @malloc(i32 %60)
store i8* %61, i8** %8
%62 = load i8*, i8** %8
%63 = icmp eq i8* %62, null
br i1 %63, label %64, label %65
64: ; preds = %59
store i8* null, i8** %3
br label %192
65: ; preds = %59
br label %66
66: ; preds = %188, %65
%67 = load i8*, i8** %4
%68 = load i8, i8* %67
%69 = icmp ne i8 %68, 0
br i1 %69, label %70, label %189
70: ; preds = %66
%71 = load i8*, i8** %8
store i8 0, i8* %71
%72 = load i8*, i8** %7
%73 = icmp ne i8* %72, null
br i1 %73, label %74, label %104
74: ; preds = %70
%75 = load i8*, i8** %4
%76 = load i8, i8* %75
%77 = sext i8 %76 to i32
%78 = icmp eq i32 %77, 126
br i1 %78, label %79, label %104
79: ; preds = %74
%80 = load i8*, i8** %4
%81 = getelementptr inbounds i8, i8* %80, i64 1
%82 = load i8, i8* %81
%83 = sext i8 %82 to i32
%84 = icmp eq i32 %83, 47
br i1 %84, label %85, label %104
85: ; preds = %79
%86 = load i8*, i8** %8
%87 = load i8*, i8** %7
%88 = call i32 @strcpy(i8* %86, i8* %87)
%89 = load i8*, i8** %4
%90 = getelementptr inbounds i8, i8* %89, i64 2
store i8* %90, i8** %4
%91 = load i8*, i8** %8
%92 = load i8*, i8** %8
%93 = call i32 @strlen(i8* %92)
%94 = sub nsw i32 %93, 1
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8, i8* %91, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = icmp ne i32 %98, 47
br i1 %99, label %100, label %103
100: ; preds = %85
%101 = load i8*, i8** %8
%102 = call i32 @strcat(i8* %101, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %103
103: ; preds = %100, %85
br label %104
104: ; preds = %103, %79, %74, %70
%105 = load i8*, i8** %8
%106 = load i8*, i8** %4
%107 = call i32 @strcattoc_esc(i8* %105, i8* %106, i8 signext 58)
%108 = load i8*, i8** %8
%109 = load i8, i8* %108
%110 = sext i8 %109 to i32
%111 = icmp eq i32 %110, 0
br i1 %111, label %112, label %115
112: ; preds = %104
%113 = load i8*, i8** %8
%114 = call i32 @strcpy(i8* %113, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %129
115: ; preds = %104
%116 = load i8*, i8** %8
%117 = load i8*, i8** %8
%118 = call i32 @strlen(i8* %117)
%119 = sub nsw i32 %118, 1
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds i8, i8* %116, i64 %120
%122 = load i8, i8* %121
%123 = sext i8 %122 to i32
%124 = icmp ne i32 %123, 47
br i1 %124, label %125, label %128
125: ; preds = %115
%126 = load i8*, i8** %8
%127 = call i32 @strcat(i8* %126, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %128
128: ; preds = %125, %115
br label %129
129: ; preds = %128, %112
%130 = load i8*, i8** %8
%131 = load i8*, i8** %5
%132 = call i32 @strcat(i8* %130, i8* %131)
%133 = load i8*, i8** %8
%134 = call i64 @stat(i8* %133, %struct.stat* %6)
%135 = icmp eq i64 %134, 0
br i1 %135, label %136, label %150
136: ; preds = %129
%137 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%138 = load i32, i32* %137
%139 = load i32, i32* @S_IFREG
%140 = and i32 %138, %139
%141 = icmp ne i32 %140, 0
br i1 %141, label %142, label %149
142: ; preds = %136
%143 = load i8*, i8** %8
%144 = call i64 @exists(i8* %143)
%145 = icmp eq i64 %144, 0
br i1 %145, label %146, label %148
146: ; preds = %142
%147 = load i8*, i8** %8
store i8* %147, i8** %3
br label %192
148: ; preds = %142
br label %149
149: ; preds = %148, %136
br label %150
150: ; preds = %149, %129
br label %151
151: ; preds = %177, %150
%152 = load i8*, i8** %4
%153 = load i8, i8* %152
%154 = sext i8 %153 to i32
%155 = icmp ne i32 %154, 0
br i1 %155, label %156, label %161
156: ; preds = %151
%157 = load i8*, i8** %4
%158 = load i8, i8* %157
%159 = sext i8 %158 to i32
%160 = icmp ne i32 %159, 58
br label %161
161: ; preds = %156, %151
%162 = phi i1 [ false, %151 ], [ %160, %156 ]
br i1 %162, label %163, label %180
163: ; preds = %161
%164 = load i8*, i8** %4
%165 = load i8, i8* %164
%166 = sext i8 %165 to i32
%167 = icmp eq i32 %166, 92
br i1 %167, label %168, label %177
168: ; preds = %163
%169 = load i8*, i8** %4
%170 = getelementptr inbounds i8, i8* %169, i64 1
%171 = load i8, i8* %170
%172 = sext i8 %171 to i32
%173 = icmp ne i32 %172, 0
br i1 %173, label %174, label %177
174: ; preds = %168
%175 = load i8*, i8** %4
%176 = getelementptr inbounds i8, i8* %175, i32 1
store i8* %176, i8** %4
br label %177
177: ; preds = %174, %168, %163
%178 = load i8*, i8** %4
%179 = getelementptr inbounds i8, i8* %178, i32 1
store i8* %179, i8** %4
br label %151
180: ; preds = %161
%181 = load i8*, i8** %4
%182 = load i8, i8* %181
%183 = sext i8 %182 to i32
%184 = icmp eq i32 %183, 58
br i1 %184, label %185, label %188
185: ; preds = %180
%186 = load i8*, i8** %4
%187 = getelementptr inbounds i8, i8* %186, i32 1
store i8* %187, i8** %4
br label %188
188: ; preds = %185, %180
br label %66
189: ; preds = %66
%190 = load i8*, i8** %8
%191 = call i32 @free(i8* %190)
store i8* null, i8** %3
br label %192
192: ; preds = %189, %146, %64, %43, %34, %12
%193 = load i8*, i8** %3
ret i8* %193
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@S_IFREG = global i32 0
@stderr = global i32 0
@.str = [38 x i8] c"Giving up, screw it I'll return NULL.\00"
@.str.1 = [38 x i8] c"/dev_hdd0/game/PS3Roar00/USRDIR/ROMS/\00"
@.str.2 = [2 x i8] c"/\00"
@.str.3 = [3 x i8] c"./\00"
define i8* @find_in_path(i8* %0, i8* %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i8* %1, null
br i1 %5, label %109, label %6
6: ; preds = %2
%7 = icmp eq i8* %0, null
br i1 %7, label %11, label %8
8: ; preds = %6
%9 = tail call i64 @strchr(i8* %1, i8 signext 47)
%10 = icmp eq i64 %9, 0
br i1 %10, label %28, label %11
11: ; preds = %8, %6
%12 = call i64 @stat(i8* %1, %struct.stat* %3)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %25
14: ; preds = %11
%15 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%16 = load i32, i32* %15
%17 = load i32, i32* @S_IFREG
%18 = and i32 %17, %16
%19 = icmp eq i32 %18, 0
br i1 %19, label %25, label %20
20: ; preds = %14
%21 = call i64 @exists(i8* %1)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %20
%24 = call i8* @strdup(i8* %1)
br label %109
25: ; preds = %11, %20, %14
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %109
28: ; preds = %8
%29 = tail call i32 @strlen(i8* %0)
%30 = tail call i32 @strlen(i8* %1)
%31 = tail call i32 @strlen(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%32 = add i32 %29, 2
%33 = add i32 %32, %30
%34 = add i32 %33, %31
%35 = tail call i8* @malloc(i32 %34)
%36 = icmp eq i8* %35, null
br i1 %36, label %109, label %37
37: ; preds = %28
%38 = load i8, i8* %0
%39 = icmp eq i8 %38, 0
br i1 %39, label %107, label %40
40: ; preds = %37
%41 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
br label %42
42: ; preds = %40, %101
%43 = phi i8* [ %0, %40 ], [ %104, %101 ]
store i8 0, i8* %35
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 126
br i1 %45, label %46, label %61
46: ; preds = %42
%47 = getelementptr inbounds i8, i8* %43, i64 1
%48 = load i8, i8* %47
%49 = icmp eq i8 %48, 47
br i1 %49, label %50, label %61
50: ; preds = %46
%51 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0))
%52 = getelementptr inbounds i8, i8* %43, i64 2
%53 = call i32 @strlen(i8* %35)
%54 = add nsw i32 %53, -1
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8, i8* %35, i64 %55
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 47
br i1 %58, label %61, label %59
59: ; preds = %50
%60 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %61
61: ; preds = %50, %59, %46, %42
%62 = phi i8* [ %52, %59 ], [ %52, %50 ], [ %43, %46 ], [ %43, %42 ]
%63 = call i32 @strcattoc_esc(i8* %35, i8* %62, i8 signext 58)
%64 = load i8, i8* %35
%65 = icmp eq i8 %64, 0
br i1 %65, label %66, label %68
66: ; preds = %61
%67 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %77
68: ; preds = %61
%69 = call i32 @strlen(i8* %35)
%70 = add nsw i32 %69, -1
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %35, i64 %71
%73 = load i8, i8* %72
%74 = icmp eq i8 %73, 47
br i1 %74, label %77, label %75
75: ; preds = %68
%76 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %77
77: ; preds = %68, %75, %66
%78 = call i32 @strcat(i8* %35, i8* %1)
%79 = call i64 @stat(i8* %35, %struct.stat* %3)
%80 = icmp eq i64 %79, 0
br i1 %80, label %81, label %89
81: ; preds = %77
%82 = load i32, i32* %41
%83 = load i32, i32* @S_IFREG
%84 = and i32 %83, %82
%85 = icmp eq i32 %84, 0
br i1 %85, label %89, label %86
86: ; preds = %81
%87 = call i64 @exists(i8* %35)
%88 = icmp eq i64 %87, 0
br i1 %88, label %109, label %89
89: ; preds = %81, %86, %77
br label %90
90: ; preds = %89, %98
%91 = phi i8* [ %100, %98 ], [ %62, %89 ]
%92 = load i8, i8* %91
switch i8 %92, label %98 [
i8 0, label %101
i8 58, label %101
i8 92, label %93
]
93: ; preds = %90
%94 = getelementptr inbounds i8, i8* %91, i64 1
%95 = load i8, i8* %94
%96 = icmp eq i8 %95, 0
%97 = select i1 %96, i8* %91, i8* %94
br label %98
98: ; preds = %93, %90
%99 = phi i8* [ %91, %90 ], [ %97, %93 ]
%100 = getelementptr inbounds i8, i8* %99, i64 1
br label %90
101: ; preds = %90, %90
%102 = icmp eq i8 %92, 58
%103 = zext i1 %102 to i64
%104 = getelementptr i8, i8* %91, i64 %103
%105 = load i8, i8* %104
%106 = icmp eq i8 %105, 0
br i1 %106, label %107, label %42
107: ; preds = %101, %37
%108 = call i32 @free(i8* %35)
br label %109
109: ; preds = %86, %28, %2, %107, %25, %23
%110 = phi i8* [ %24, %23 ], [ null, %25 ], [ null, %107 ], [ null, %2 ], [ null, %28 ], [ %35, %86 ]
ret i8* %110
}