#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 */
int locateOneElement(char *);
char *strchr(char *, char);
int PHYSFSEXT_locateCorrectCase(char *buf) {
  int rc;
  char *ptr;
  char *prevptr;
  while (*buf == '/')
    buf++;
  ptr = prevptr = buf;
  if (*ptr == '\0')
    return (0);
  while (ptr = strchr(ptr + 1, '/')) {
    *ptr = '\0';
    rc = locateOneElement(buf);
    *ptr = '/';
    if (!rc)
      return (-2);
  }
  return (locateOneElement(buf) ? 0 : -1);
}


x86 assembly (clang, -O0):
<PHYSFSEXT_locateCorrectCase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    114d <PHYSFSEXT_locateCorrectCase+0x2d>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112c <PHYSFSEXT_locateCorrectCase+0xc>
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    1175 <PHYSFSEXT_locateCorrectCase+0x55>
movl   $0x0,-0x4(%rbp)
jmp    11ea <PHYSFSEXT_locateCorrectCase+0xca>
jmp    117a <PHYSFSEXT_locateCorrectCase+0x5a>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11cf <PHYSFSEXT_locateCorrectCase+0xaf>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1040 <locateOneElement@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x2f,(%rax)
cmpl   $0x0,-0x14(%rbp)
jne    11ca <PHYSFSEXT_locateCorrectCase+0xaa>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11ea <PHYSFSEXT_locateCorrectCase+0xca>
jmp    117a <PHYSFSEXT_locateCorrectCase+0x5a>
mov    -0x10(%rbp),%rdi
call   1040 <locateOneElement@plt>
mov    %eax,%edx
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PHYSFSEXT_locateCorrectCase>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
nopw   0x0(%rax,%rax,1)
movzbl (%r14),%eax
cmp    $0x2f,%al
jne    113e <PHYSFSEXT_locateCorrectCase+0x1e>
add    $0x1,%r14
jmp    1130 <PHYSFSEXT_locateCorrectCase+0x10>
test   %al,%al
jne    1146 <PHYSFSEXT_locateCorrectCase+0x26>
xor    %eax,%eax
jmp    118f <PHYSFSEXT_locateCorrectCase+0x6f>
mov    %r14,%rbx
nopl   0x0(%rax)
add    $0x1,%rbx
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1182 <PHYSFSEXT_locateCorrectCase+0x62>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1040 <locateOneElement@plt>
movb   $0x2f,(%rbx)
test   %eax,%eax
jne    1150 <PHYSFSEXT_locateCorrectCase+0x30>
mov    $0xfffffffe,%eax
jmp    118f <PHYSFSEXT_locateCorrectCase+0x6f>
mov    %r14,%rdi
call   1040 <locateOneElement@plt>
cmp    $0x1,%eax
sbb    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i32 @PHYSFSEXT_locateCorrectCase(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
br label %7
7: ; preds = %12, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 47
br i1 %11, label %12, label %15
12: ; preds = %7
%13 = load i8*, i8** %3
%14 = getelementptr inbounds i8, i8* %13, i32 1
store i8* %14, i8** %3
br label %7
15: ; preds = %7
%16 = load i8*, i8** %3
store i8* %16, i8** %6
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp eq i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %2
br label %43
22: ; preds = %15
br label %23
23: ; preds = %36, %22
%24 = load i8*, i8** %5
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = call i8* @strchr(i8* %25, i8 signext 47)
store i8* %26, i8** %5
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %37
28: ; preds = %23
%29 = load i8*, i8** %5
store i8 0, i8* %29
%30 = load i8*, i8** %3
%31 = call i32 @locateOneElement(i8* %30)
store i32 %31, i32* %4
%32 = load i8*, i8** %5
store i8 47, i8* %32
%33 = load i32, i32* %4
%34 = icmp ne i32 %33, 0
br i1 %34, label %36, label %35
35: ; preds = %28
store i32 -2, i32* %2
br label %43
36: ; preds = %28
br label %23
37: ; preds = %23
%38 = load i8*, i8** %3
%39 = call i32 @locateOneElement(i8* %38)
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i32 0, i32 -1
store i32 %42, i32* %2
br label %43
43: ; preds = %37, %35, %21
%44 = load i32, i32* %2
ret i32 %44
}

LLVM IR (-O2):
define i32 @PHYSFSEXT_locateCorrectCase(i8* %0) {
br label %2
2: ; preds = %5, %1
%3 = phi i8* [ %0, %1 ], [ %6, %5 ]
%4 = load i8, i8* %3
switch i8 %4, label %7 [
i8 47, label %5
i8 0, label %19
]
5: ; preds = %2
%6 = getelementptr inbounds i8, i8* %3, i64 1
br label %2
7: ; preds = %2, %12
%8 = phi i8* [ %10, %12 ], [ %3, %2 ]
%9 = getelementptr inbounds i8, i8* %8, i64 1
%10 = tail call i8* @strchr(i8* %9, i8 signext 47)
%11 = icmp eq i8* %10, null
br i1 %11, label %15, label %12
12: ; preds = %7
store i8 0, i8* %10
%13 = tail call i32 @locateOneElement(i8* %3)
store i8 47, i8* %10
%14 = icmp eq i32 %13, 0
br i1 %14, label %19, label %7
15: ; preds = %7
%16 = tail call i32 @locateOneElement(i8* %3)
%17 = icmp eq i32 %16, 0
%18 = sext i1 %17 to i32
br label %19
19: ; preds = %2, %12, %15
%20 = phi i32 [ %18, %15 ], [ -2, %12 ], [ 0, %2 ]
ret i32 %20
}