#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 */

/* Variables and functions */
char **PHYSFS_enumerateFiles(char *);
scalar_t__ PHYSFS_exists(char *);
int /*<<< orphan*/ PHYSFS_freeList(char **);
scalar_t__ caseInsensitiveStringCompare(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *strrchr(char *, char);
int locateOneElement(char *buf) {
  char *ptr;
  char **rc;
  char **i;
  if (PHYSFS_exists(buf))
    return (1);
  ptr = strrchr(buf, '/');
  if (ptr == NULL) {
    rc = PHYSFS_enumerateFiles("/");
    ptr = buf;
  } else {
    *ptr = '\0';
    rc = PHYSFS_enumerateFiles(buf);
    *ptr = '/';
    ptr++;
  }
  for (i = rc; *i != NULL; i++) {
    if (caseInsensitiveStringCompare(*i, ptr) == 0) {
      strcpy(ptr, *i);
      PHYSFS_freeList(rc);
      return (1);
    }
  }
  PHYSFS_freeList(rc);
  return (0);
}


x86 assembly (clang, -O0):
<locateOneElement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <PHYSFS_exists@plt>
cmp    $0x0,%rax
je     118b <locateOneElement+0x2b>
movl   $0x1,-0x4(%rbp)
jmp    1267 <locateOneElement+0x107>
mov    -0x10(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c5 <locateOneElement+0x65>
lea    0xe51(%rip),%rdi
call   1080 <PHYSFS_enumerateFiles@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11ec <locateOneElement+0x8c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1080 <PHYSFS_enumerateFiles@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpq   $0x0,(%rax)
je     1257 <locateOneElement+0xf7>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <caseInsensitiveStringCompare@plt>
cmp    $0x0,%rax
jne    1241 <locateOneElement+0xe1>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
call   1070 <PHYSFS_freeList@plt>
movl   $0x1,-0x4(%rbp)
jmp    1267 <locateOneElement+0x107>
jmp    1246 <locateOneElement+0xe6>
mov    -0x28(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x28(%rbp)
jmp    11f4 <locateOneElement+0x94>
mov    -0x20(%rbp),%rdi
call   1070 <PHYSFS_freeList@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<locateOneElement>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1030 <PHYSFS_exists@plt>
mov    $0x1,%r15d
test   %rax,%rax
jne    1206 <locateOneElement+0xa6>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
test   %rax,%rax
je     11ae <locateOneElement+0x4e>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1080 <PHYSFS_enumerateFiles@plt>
mov    %rax,%r14
movb   $0x2f,0x0(%rbp)
add    $0x1,%rbp
mov    %rbp,%rbx
jmp    11bd <locateOneElement+0x5d>
lea    0xe4b(%rip),%rdi
call   1080 <PHYSFS_enumerateFiles@plt>
mov    %rax,%r14
mov    (%r14),%rdi
xor    %r15d,%r15d
test   %rdi,%rdi
je     11fe <locateOneElement+0x9e>
lea    0x8(%r14),%rbp
nopl   0x0(%rax)
mov    %rbx,%rsi
call   1060 <caseInsensitiveStringCompare@plt>
test   %rax,%rax
je     11ec <locateOneElement+0x8c>
mov    0x0(%rbp),%rdi
add    $0x8,%rbp
test   %rdi,%rdi
jne    11d0 <locateOneElement+0x70>
jmp    11fe <locateOneElement+0x9e>
mov    -0x8(%rbp),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    $0x1,%r15d
mov    %r14,%rdi
call   1070 <PHYSFS_freeList@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
define i32 @locateOneElement(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i8**
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i64 @PHYSFS_exists(i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i32 1, i32* %2
br label %52
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i8* @strrchr(i8* %12, i8 signext 47)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i8** @PHYSFS_enumerateFiles(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8** %17, i8*** %5
%18 = load i8*, i8** %3
store i8* %18, i8** %4
br label %26
19: ; preds = %11
%20 = load i8*, i8** %4
store i8 0, i8* %20
%21 = load i8*, i8** %3
%22 = call i8** @PHYSFS_enumerateFiles(i8* %21)
store i8** %22, i8*** %5
%23 = load i8*, i8** %4
store i8 47, i8* %23
%24 = load i8*, i8** %4
%25 = getelementptr inbounds i8, i8* %24, i32 1
store i8* %25, i8** %4
br label %26
26: ; preds = %19, %16
%27 = load i8**, i8*** %5
store i8** %27, i8*** %6
br label %28
28: ; preds = %46, %26
%29 = load i8**, i8*** %6
%30 = load i8*, i8** %29
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %49
32: ; preds = %28
%33 = load i8**, i8*** %6
%34 = load i8*, i8** %33
%35 = load i8*, i8** %4
%36 = call i64 @caseInsensitiveStringCompare(i8* %34, i8* %35)
%37 = icmp eq i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load i8*, i8** %4
%40 = load i8**, i8*** %6
%41 = load i8*, i8** %40
%42 = call i32 @strcpy(i8* %39, i8* %41)
%43 = load i8**, i8*** %5
%44 = call i32 @PHYSFS_freeList(i8** %43)
store i32 1, i32* %2
br label %52
45: ; preds = %32
br label %46
46: ; preds = %45
%47 = load i8**, i8*** %6
%48 = getelementptr inbounds i8*, i8** %47, i32 1
store i8** %48, i8*** %6
br label %28
49: ; preds = %28
%50 = load i8**, i8*** %5
%51 = call i32 @PHYSFS_freeList(i8** %50)
store i32 0, i32* %2
br label %52
52: ; preds = %49, %38, %10
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
define i32 @locateOneElement(i8* %0) {
%2 = tail call i64 @PHYSFS_exists(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %32
4: ; preds = %1
%5 = tail call i8* @strrchr(i8* dereferenceable(1) %0, i8 signext 47)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i8** @PHYSFS_enumerateFiles(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %12
9: ; preds = %4
store i8 0, i8* %5
%10 = tail call i8** @PHYSFS_enumerateFiles(i8* %0)
store i8 47, i8* %5
%11 = getelementptr inbounds i8, i8* %5, i64 1
br label %12
12: ; preds = %9, %7
%13 = phi i8* [ %0, %7 ], [ %11, %9 ]
%14 = phi i8** [ %8, %7 ], [ %10, %9 ]
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %29, label %17
17: ; preds = %12, %25
%18 = phi i8* [ %27, %25 ], [ %15, %12 ]
%19 = phi i8** [ %26, %25 ], [ %14, %12 ]
%20 = tail call i64 @caseInsensitiveStringCompare(i8* %18, i8* %13)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i8*, i8** %19
%24 = tail call i32 @strcpy(i8* %13, i8* %23)
br label %29
25: ; preds = %17
%26 = getelementptr inbounds i8*, i8** %19, i64 1
%27 = load i8*, i8** %26
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %17
29: ; preds = %25, %12, %22
%30 = phi i32 [ 1, %22 ], [ 0, %12 ], [ 0, %25 ]
%31 = tail call i32 @PHYSFS_freeList(i8** %14)
br label %32
32: ; preds = %29, %1
%33 = phi i32 [ 1, %1 ], [ %30, %29 ]
ret i32 %33
}