#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 /*<<< orphan*/ __PHYSFS_setError(char *);
scalar_t__ strcmp(char *, char *);
int sanitizePlatformIndependentPath(const char *src, char *dst) {
  char *prev;
  char ch;
  while (*src == '/')
    src++;
  prev = dst;
  do {
    ch = *(src++);
    if ((ch == ':') || (ch == '\\')) {
      __PHYSFS_setError("Insecure filename");
      return 0;
    };
    if (ch == '/') {
      *dst = '\0';
      if ((strcmp(prev, ".") == 0) || (strcmp(prev, "..") == 0)) {
        __PHYSFS_setError("Insecure filename");
        return 0;
      };
      while (*src == '/')
        src++;
      if (*src == '\0')
        break;
      prev = dst + 1;
    }
    *(dst++) = ch;
  } while (ch != '\0');
  return (1);
}


x86 assembly (clang, -O0):
<sanitizePlatformIndependentPath>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1151 <sanitizePlatformIndependentPath+0x31>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1130 <sanitizePlatformIndependentPath+0x10>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x10(%rbp)
mov    (%rax),%al
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
cmp    $0x3a,%eax
je     1187 <sanitizePlatformIndependentPath+0x67>
movsbl -0x21(%rbp),%eax
cmp    $0x5c,%eax
jne    119f <sanitizePlatformIndependentPath+0x7f>
lea    0xe72(%rip),%rdi
call   1040 <__PHYSFS_setError@plt>
movl   $0x0,-0x4(%rbp)
jmp    126e <sanitizePlatformIndependentPath+0x14e>
movsbl -0x21(%rbp),%eax
cmp    $0x2f,%eax
jne    1246 <sanitizePlatformIndependentPath+0x126>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
lea    0xe55(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
je     11e7 <sanitizePlatformIndependentPath+0xc7>
mov    -0x20(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    11ff <sanitizePlatformIndependentPath+0xdf>
lea    0xe12(%rip),%rdi
call   1040 <__PHYSFS_setError@plt>
movl   $0x0,-0x4(%rbp)
jmp    126e <sanitizePlatformIndependentPath+0x14e>
jmp    1204 <sanitizePlatformIndependentPath+0xe4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1225 <sanitizePlatformIndependentPath+0x105>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    1204 <sanitizePlatformIndependentPath+0xe4>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    123a <sanitizePlatformIndependentPath+0x11a>
jmp    1267 <sanitizePlatformIndependentPath+0x147>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x21(%rbp),%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
movsbl -0x21(%rbp),%eax
cmp    $0x0,%eax
jne    1159 <sanitizePlatformIndependentPath+0x39>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sanitizePlatformIndependentPath>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
add    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
movzbl 0x1(%rbx),%ebp
add    $0x1,%rbx
cmp    $0x2f,%bpl
je     1140 <sanitizePlatformIndependentPath+0x20>
lea    0xebe(%rip),%r15
lea    0xeb6(%rip),%r12
mov    %r14,%r13
add    $0x1,%rbx
cmp    $0x2f,%bpl
je     1180 <sanitizePlatformIndependentPath+0x60>
cmp    $0x3a,%bpl
je     11e0 <sanitizePlatformIndependentPath+0xc0>
cmp    $0x5c,%bpl
jne    11c8 <sanitizePlatformIndependentPath+0xa8>
jmp    11e0 <sanitizePlatformIndependentPath+0xc0>
nopw   0x0(%rax,%rax,1)
movb   $0x0,(%r14)
mov    %r13,%rdi
mov    %r15,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <sanitizePlatformIndependentPath+0xc0>
mov    %r13,%rdi
mov    %r12,%rsi
call   1030 <strcmp@plt>
test   %rax,%rax
je     11e0 <sanitizePlatformIndependentPath+0xc0>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx),%eax
cmp    $0x2f,%al
jne    11c0 <sanitizePlatformIndependentPath+0xa0>
add    $0x1,%rbx
jmp    11b0 <sanitizePlatformIndependentPath+0x90>
nopl   (%rax)
test   %al,%al
je     11d9 <sanitizePlatformIndependentPath+0xb9>
lea    0x1(%r14),%r13
mov    %bpl,(%r14)
test   %bpl,%bpl
je     11d9 <sanitizePlatformIndependentPath+0xb9>
add    $0x1,%r14
mov    (%rbx),%bpl
jmp    115f <sanitizePlatformIndependentPath+0x3f>
mov    $0x1,%eax
jmp    11ee <sanitizePlatformIndependentPath+0xce>
lea    0xe19(%rip),%rdi
call   1040 <__PHYSFS_setError@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [18 x i8] c"Insecure filename\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @sanitizePlatformIndependentPath(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8
store i8* %0, i8** %4
store i8* %1, i8** %5
br label %8
8: ; preds = %13, %2
%9 = load i8*, i8** %4
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 47
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = load i8*, i8** %4
%15 = getelementptr inbounds i8, i8* %14, i32 1
store i8* %15, i8** %4
br label %8
16: ; preds = %8
%17 = load i8*, i8** %5
store i8* %17, i8** %6
br label %18
18: ; preds = %68, %16
%19 = load i8*, i8** %4
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %4
%21 = load i8, i8* %19
store i8 %21, i8* %7
%22 = load i8, i8* %7
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 58
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i8, i8* %7
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 92
br i1 %28, label %29, label %31
29: ; preds = %25, %18
%30 = call i32 @__PHYSFS_setError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %73
31: ; preds = %25
%32 = load i8, i8* %7
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 47
br i1 %34, label %35, label %64
35: ; preds = %31
%36 = load i8*, i8** %5
store i8 0, i8* %36
%37 = load i8*, i8** %6
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %40, %35
%45 = call i32 @__PHYSFS_setError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %73
46: ; preds = %40
br label %47
47: ; preds = %52, %46
%48 = load i8*, i8** %4
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp eq i32 %50, 47
br i1 %51, label %52, label %55
52: ; preds = %47
%53 = load i8*, i8** %4
%54 = getelementptr inbounds i8, i8* %53, i32 1
store i8* %54, i8** %4
br label %47
55: ; preds = %47
%56 = load i8*, i8** %4
%57 = load i8, i8* %56
%58 = sext i8 %57 to i32
%59 = icmp eq i32 %58, 0
br i1 %59, label %60, label %61
60: ; preds = %55
br label %72
61: ; preds = %55
%62 = load i8*, i8** %5
%63 = getelementptr inbounds i8, i8* %62, i64 1
store i8* %63, i8** %6
br label %64
64: ; preds = %61, %31
%65 = load i8, i8* %7
%66 = load i8*, i8** %5
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %5
store i8 %65, i8* %66
br label %68
68: ; preds = %64
%69 = load i8, i8* %7
%70 = sext i8 %69 to i32
%71 = icmp ne i32 %70, 0
br i1 %71, label %18, label %72
72: ; preds = %68, %60
store i32 1, i32* %3
br label %73
73: ; preds = %72, %44, %29
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str = [18 x i8] c"Insecure filename\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define i32 @sanitizePlatformIndependentPath(i8* nocapture %0, i8* %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i8* [ %0, %2 ], [ %7, %3 ]
%5 = load i8, i8* %4
%6 = icmp eq i8 %5, 47
%7 = getelementptr inbounds i8, i8* %4, i64 1
br i1 %6, label %3, label %11
8: ; preds = %30
%9 = getelementptr inbounds i8, i8* %14, i64 1
%10 = load i8, i8* %31
br label %11
11: ; preds = %3, %8
%12 = phi i8 [ %10, %8 ], [ %5, %3 ]
%13 = phi i8* [ %31, %8 ], [ %4, %3 ]
%14 = phi i8* [ %9, %8 ], [ %1, %3 ]
%15 = phi i8* [ %32, %8 ], [ %1, %3 ]
%16 = getelementptr inbounds i8, i8* %13, i64 1
switch i8 %12, label %30 [
i8 92, label %34
i8 58, label %34
i8 47, label %17
]
17: ; preds = %11
store i8 0, i8* %14
%18 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %34, label %20
20: ; preds = %17
%21 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %20, %26
%24 = phi i8* [ %27, %26 ], [ %16, %20 ]
%25 = load i8, i8* %24
switch i8 %25, label %28 [
i8 47, label %26
i8 0, label %36
]
26: ; preds = %23
%27 = getelementptr inbounds i8, i8* %24, i64 1
br label %23
28: ; preds = %23
%29 = getelementptr inbounds i8, i8* %14, i64 1
br label %30
30: ; preds = %11, %28
%31 = phi i8* [ %24, %28 ], [ %16, %11 ]
%32 = phi i8* [ %29, %28 ], [ %15, %11 ]
store i8 %12, i8* %14
%33 = icmp eq i8 %12, 0
br i1 %33, label %36, label %8
34: ; preds = %17, %20, %11, %11
%35 = tail call i32 @__PHYSFS_setError(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %36
36: ; preds = %30, %23, %34
%37 = phi i32 [ 0, %34 ], [ 1, %23 ], [ 1, %30 ]
ret i32 %37
}