#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 */
scalar_t__ pathIsAbsolute(char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
int strlen(char const *);
int /*<<< orphan*/ strncmp(char const *, char *, int);
scalar_t__ strstr(char const *, char *);
int pathIsSafe(const char *path) {
  if (pathIsAbsolute(path))
    return 0;
  if (!strcmp(path, ".."))
    return 0;
  if (!strncmp(path, "../", 3))
    return 0;
  if ((strlen(path) > 3) && !strcmp(path + strlen(path) - 3, "/.."))
    return 0;
  if (strstr(path, "/../"))
    return 0;
  return 1;
}


x86 assembly (clang, -O0):
<pathIsSafe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <pathIsAbsolute@plt>
cmp    $0x0,%rax
je     117b <pathIsSafe+0x2b>
movl   $0x0,-0x4(%rbp)
jmp    1248 <pathIsSafe+0xf8>
mov    -0x10(%rbp),%rdi
lea    0xe7b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11a0 <pathIsSafe+0x50>
movl   $0x0,-0x4(%rbp)
jmp    1248 <pathIsSafe+0xf8>
mov    -0x10(%rbp),%rdi
lea    0xe5a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11ca <pathIsSafe+0x7a>
movl   $0x0,-0x4(%rbp)
jmp    1248 <pathIsSafe+0xf8>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x3,%eax
jle    121b <pathIsSafe+0xcb>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rdi
cltq
add    %rax,%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xdff(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    121b <pathIsSafe+0xcb>
movl   $0x0,-0x4(%rbp)
jmp    1248 <pathIsSafe+0xf8>
mov    -0x10(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     1241 <pathIsSafe+0xf1>
movl   $0x0,-0x4(%rbp)
jmp    1248 <pathIsSafe+0xf8>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pathIsSafe>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1060 <pathIsAbsolute@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     116b <pathIsSafe+0x1b>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe8f(%rip),%rsi
mov    %rbx,%rdi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1162 <pathIsSafe+0x12>
lea    0xe80(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1162 <pathIsSafe+0x12>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cmp    $0x4,%eax
jl     11c5 <pathIsSafe+0x75>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdi
add    $0xfffffffffffffffd,%rdi
lea    0xe44(%rip),%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1162 <pathIsSafe+0x12>
lea    0xe38(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strstr@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
jmp    1162 <pathIsSafe+0x12>

LLVM IR (-O0):
@.str = [3 x i8] c"..\00"
@.str.1 = [4 x i8] c"../\00"
@.str.2 = [4 x i8] c"/..\00"
@.str.3 = [5 x i8] c"/../\00"
define i32 @pathIsSafe(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = call i64 @pathIsAbsolute(i8* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 0, i32* %2
br label %38
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8
store i32 0, i32* %2
br label %38
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @strncmp(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %13
store i32 0, i32* %2
br label %38
18: ; preds = %13
%19 = load i8*, i8** %3
%20 = call i32 @strlen(i8* %19)
%21 = icmp sgt i32 %20, 3
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load i8*, i8** %3
%24 = load i8*, i8** %3
%25 = call i32 @strlen(i8* %24)
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %23, i64 %26
%28 = getelementptr inbounds i8, i8* %27, i64 -3
%29 = call i32 @strcmp(i8* %28, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %22
store i32 0, i32* %2
br label %38
32: ; preds = %22, %18
%33 = load i8*, i8** %3
%34 = call i64 @strstr(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %32
store i32 0, i32* %2
br label %38
37: ; preds = %32
store i32 1, i32* %2
br label %38
38: ; preds = %37, %36, %31, %17, %12, %7
%39 = load i32, i32* %2
ret i32 %39
}

LLVM IR (-O2):
@.str = [3 x i8] c"..\00"
@.str.1 = [4 x i8] c"../\00"
@.str.2 = [4 x i8] c"/..\00"
@.str.3 = [5 x i8] c"/../\00"
define i32 @pathIsSafe(i8* %0) {
%2 = tail call i64 @pathIsAbsolute(i8* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %24
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %24, label %7
7: ; preds = %4
%8 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%9 = icmp eq i32 %8, 0
br i1 %9, label %24, label %10
10: ; preds = %7
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = tail call i32 @strlen(i8* %0)
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
%17 = getelementptr inbounds i8, i8* %16, i64 -3
%18 = tail call i32 @strcmp(i8* %17, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i32 %18, 0
br i1 %19, label %24, label %20
20: ; preds = %13, %10
%21 = tail call i64 @strstr(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
%23 = zext i1 %22 to i32
br label %24
24: ; preds = %20, %13, %7, %4, %1
%25 = phi i32 [ 0, %1 ], [ 0, %4 ], [ 0, %7 ], [ 0, %13 ], [ %23, %20 ]
ret i32 %25
}