#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*/ not_permitted(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strrchr(char *, char);
char *strstr(char *, char *);
int /*<<< orphan*/ unknown_tag(char *, char *, char *);
int get_filename(char *vfilename, char *filename, char *directive, char *tag,
                 char *val, char *fn, int fnsize) {
  int vl, fl;
  char *cp;
  vl = strlen(vfilename);
  fl = strlen(filename);
  if (strcmp(tag, "virtual") == 0) {
    if (strstr(val, "../") != (char *)0) {
      not_permitted(directive, tag, val);
      return -1;
    }
    if (vl > fl || strcmp(vfilename, &filename[fl - vl]) != 0)
      return -1;
    if (fl - vl + strlen(val) >= fnsize)
      return -1;
    (void)strncpy(fn, filename, fl - vl);
    (void)strcpy(&fn[fl - vl], val);
  } else if (strcmp(tag, "file") == 0) {
    if (val[0] == '/' || strstr(val, "../") != (char *)0) {
      not_permitted(directive, tag, val);
      return -1;
    }
    if (fl + 1 + strlen(val) >= fnsize)
      return -1;
    (void)strcpy(fn, filename);
    cp = strrchr(fn, '/');
    if (cp == (char *)0) {
      cp = &fn[strlen(fn)];
      *cp = '/';
    }
    (void)strcpy(++cp, val);
  } else {
    unknown_tag(filename, directive, tag);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe3a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12ae <get_filename+0x12e>
mov    -0x30(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     120c <get_filename+0x8c>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <not_permitted@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
mov    -0x3c(%rbp),%eax
cmp    -0x40(%rbp),%eax
jg     123a <get_filename+0xba>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
cltq
add    %rax,%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     1246 <get_filename+0xc6>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
cltq
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
movslq 0x10(%rbp),%rcx
cmp    %rcx,%rax
jb     127e <get_filename+0xfe>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x40(%rbp),%edx
sub    -0x3c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x38(%rbp),%rdi
mov    -0x40(%rbp),%eax
sub    -0x3c(%rbp),%eax
cltq
add    %rax,%rdi
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    13d3 <get_filename+0x253>
mov    -0x28(%rbp),%rdi
lea    0xd53(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    13b1 <get_filename+0x231>
mov    -0x30(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     12f2 <get_filename+0x172>
mov    -0x30(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
je     130f <get_filename+0x18f>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
call   1070 <not_permitted@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
mov    -0x40(%rbp),%eax
add    $0x1,%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
movslq 0x10(%rbp),%rcx
cmp    %rcx,%rax
jb     1347 <get_filename+0x1c7>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x38(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    1397 <get_filename+0x217>
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x60(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x48(%rbp)
mov    -0x30(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    13ce <get_filename+0x24e>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1090 <unknown_tag@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13da <get_filename+0x25a>
jmp    13d3 <get_filename+0x253>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_filename>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9,0x10(%rsp)
mov    %r8,%r12
mov    %rcx,%rbx
mov    %rdx,%r13
mov    %rsi,%rbp
mov    %rdi,%r14
call   1050 <strlen@plt>
mov    %rax,%r15
mov    %rbp,0x8(%rsp)
mov    %rbp,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbp
lea    0xe3f(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11f7 <get_filename+0x77>
lea    0xe37(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1260 <get_filename+0xe0>
mov    0x8(%rsp),%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1090 <unknown_tag@plt>
jmp    1289 <get_filename+0x109>
lea    0xe0a(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
jne    127b <get_filename+0xfb>
mov    $0xffffffff,%ebx
sub    %r15d,%ebp
jl     128e <get_filename+0x10e>
movslq %ebp,%rbp
mov    0x8(%rsp),%r15
lea    (%r15,%rbp,1),%rsi
mov    %r14,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    128e <get_filename+0x10e>
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %rbp,%rax
movslq 0x50(%rsp),%rcx
cmp    %rcx,%rax
jae    128e <get_filename+0x10e>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1030 <strncpy@plt>
add    %rbp,%rbx
mov    %rbx,%rdi
jmp    12fc <get_filename+0x17c>
cmpb   $0x2f,(%r12)
je     127b <get_filename+0xfb>
lea    0xd9a(%rip),%rsi
mov    %r12,%rdi
call   10a0 <strstr@plt>
test   %rax,%rax
je     129f <get_filename+0x11f>
mov    %r13,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1070 <not_permitted@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
add    $0x1,%ebp
movslq %ebp,%rbx
mov    %r12,%rdi
call   1050 <strlen@plt>
add    %rbx,%rax
movslq 0x50(%rsp),%rcx
mov    $0xffffffff,%ebx
cmp    %rcx,%rax
mov    0x8(%rsp),%rsi
jae    128e <get_filename+0x10e>
mov    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
jne    12f5 <get_filename+0x175>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
add    %rbx,%rax
movb   $0x2f,(%rbx,%rcx,1)
add    $0x1,%rax
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <strcpy@plt>
xor    %ebx,%ebx
jmp    128e <get_filename+0x10e>

LLVM IR (-O0):
@.str = [8 x i8] c"virtual\00"
@.str.1 = [4 x i8] c"../\00"
@.str.2 = [5 x i8] c"file\00"
define i32 @get_filename(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i32 %6) {
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i8*
store i8* %0, i8** %9
store i8* %1, i8** %10
store i8* %2, i8** %11
store i8* %3, i8** %12
store i8* %4, i8** %13
store i8* %5, i8** %14
store i32 %6, i32* %15
%19 = load i8*, i8** %9
%20 = call i64 @strlen(i8* %19)
%21 = trunc i64 %20 to i32
store i32 %21, i32* %16
%22 = load i8*, i8** %10
%23 = call i64 @strlen(i8* %22)
%24 = trunc i64 %23 to i32
store i32 %24, i32* %17
%25 = load i8*, i8** %12
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %79
28: ; preds = %7
%29 = load i8*, i8** %13
%30 = call i8* @strstr(i8* %29, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %37
32: ; preds = %28
%33 = load i8*, i8** %11
%34 = load i8*, i8** %12
%35 = load i8*, i8** %13
%36 = call i32 @not_permitted(i8* %33, i8* %34, i8* %35)
store i32 -1, i32* %8
br label %135
37: ; preds = %28
%38 = load i32, i32* %16
%39 = load i32, i32* %17
%40 = icmp sgt i32 %38, %39
br i1 %40, label %51, label %41
41: ; preds = %37
%42 = load i8*, i8** %9
%43 = load i8*, i8** %10
%44 = load i32, i32* %17
%45 = load i32, i32* %16
%46 = sub nsw i32 %44, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
%49 = call i64 @strcmp(i8* %42, i8* %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %52
51: ; preds = %41, %37
store i32 -1, i32* %8
br label %135
52: ; preds = %41
%53 = load i32, i32* %17
%54 = load i32, i32* %16
%55 = sub nsw i32 %53, %54
%56 = sext i32 %55 to i64
%57 = load i8*, i8** %13
%58 = call i64 @strlen(i8* %57)
%59 = add i64 %56, %58
%60 = load i32, i32* %15
%61 = sext i32 %60 to i64
%62 = icmp uge i64 %59, %61
br i1 %62, label %63, label %64
63: ; preds = %52
store i32 -1, i32* %8
br label %135
64: ; preds = %52
%65 = load i8*, i8** %14
%66 = load i8*, i8** %10
%67 = load i32, i32* %17
%68 = load i32, i32* %16
%69 = sub nsw i32 %67, %68
%70 = call i32 @strncpy(i8* %65, i8* %66, i32 %69)
%71 = load i8*, i8** %14
%72 = load i32, i32* %17
%73 = load i32, i32* %16
%74 = sub nsw i32 %72, %73
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %71, i64 %75
%77 = load i8*, i8** %13
%78 = call i32 @strcpy(i8* %76, i8* %77)
br label %134
79: ; preds = %7
%80 = load i8*, i8** %12
%81 = call i64 @strcmp(i8* %80, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%82 = icmp eq i64 %81, 0
br i1 %82, label %83, label %128
83: ; preds = %79
%84 = load i8*, i8** %13
%85 = getelementptr inbounds i8, i8* %84, i64 0
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp eq i32 %87, 47
br i1 %88, label %93, label %89
89: ; preds = %83
%90 = load i8*, i8** %13
%91 = call i8* @strstr(i8* %90, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%92 = icmp ne i8* %91, null
br i1 %92, label %93, label %98
93: ; preds = %89, %83
%94 = load i8*, i8** %11
%95 = load i8*, i8** %12
%96 = load i8*, i8** %13
%97 = call i32 @not_permitted(i8* %94, i8* %95, i8* %96)
store i32 -1, i32* %8
br label %135
98: ; preds = %89
%99 = load i32, i32* %17
%100 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = load i8*, i8** %13
%103 = call i64 @strlen(i8* %102)
%104 = add i64 %101, %103
%105 = load i32, i32* %15
%106 = sext i32 %105 to i64
%107 = icmp uge i64 %104, %106
br i1 %107, label %108, label %109
108: ; preds = %98
store i32 -1, i32* %8
br label %135
109: ; preds = %98
%110 = load i8*, i8** %14
%111 = load i8*, i8** %10
%112 = call i32 @strcpy(i8* %110, i8* %111)
%113 = load i8*, i8** %14
%114 = call i8* @strrchr(i8* %113, i8 signext 47)
store i8* %114, i8** %18
%115 = load i8*, i8** %18
%116 = icmp eq i8* %115, null
br i1 %116, label %117, label %123
117: ; preds = %109
%118 = load i8*, i8** %14
%119 = load i8*, i8** %14
%120 = call i64 @strlen(i8* %119)
%121 = getelementptr inbounds i8, i8* %118, i64 %120
store i8* %121, i8** %18
%122 = load i8*, i8** %18
store i8 47, i8* %122
br label %123
123: ; preds = %117, %109
%124 = load i8*, i8** %18
%125 = getelementptr inbounds i8, i8* %124, i32 1
store i8* %125, i8** %18
%126 = load i8*, i8** %13
%127 = call i32 @strcpy(i8* %125, i8* %126)
br label %133
128: ; preds = %79
%129 = load i8*, i8** %10
%130 = load i8*, i8** %11
%131 = load i8*, i8** %12
%132 = call i32 @unknown_tag(i8* %129, i8* %130, i8* %131)
store i32 -1, i32* %8
br label %135
133: ; preds = %123
br label %134
134: ; preds = %133, %64
store i32 0, i32* %8
br label %135
135: ; preds = %134, %128, %108, %93, %63, %51, %32
%136 = load i32, i32* %8
ret i32 %136
}

LLVM IR (-O2):
@.str = [8 x i8] c"virtual\00"
@.str.1 = [4 x i8] c"../\00"
@.str.2 = [5 x i8] c"file\00"
define i32 @get_filename(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i8* %5, i32 %6) {
%8 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%9 = trunc i64 %8 to i32
%10 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%11 = trunc i64 %10 to i32
%12 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %36
14: ; preds = %7
%15 = tail call i8* @strstr(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 @not_permitted(i8* %2, i8* %3, i8* %4)
br label %68
19: ; preds = %14
%20 = icmp slt i32 %11, %9
br i1 %20, label %68, label %21
21: ; preds = %19
%22 = sub nsw i32 %11, %9
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %1, i64 %23
%25 = tail call i64 @strcmp(i8* %0, i8* %24)
%26 = icmp eq i64 %25, 0
br i1 %26, label %27, label %68
27: ; preds = %21
%28 = tail call i64 @strlen(i8* dereferenceable(1) %4)
%29 = add i64 %28, %23
%30 = sext i32 %6 to i64
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %68
32: ; preds = %27
%33 = tail call i32 @strncpy(i8* %5, i8* %1, i32 %22)
%34 = getelementptr inbounds i8, i8* %5, i64 %23
%35 = tail call i32 @strcpy(i8* %34, i8* %4)
br label %68
36: ; preds = %7
%37 = tail call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %66
39: ; preds = %36
%40 = load i8, i8* %4
%41 = icmp eq i8 %40, 47
br i1 %41, label %45, label %42
42: ; preds = %39
%43 = tail call i8* @strstr(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%44 = icmp eq i8* %43, null
br i1 %44, label %47, label %45
45: ; preds = %42, %39
%46 = tail call i32 @not_permitted(i8* %2, i8* %3, i8* %4)
br label %68
47: ; preds = %42
%48 = shl i64 %10, 32
%49 = add i64 %48, 4294967296
%50 = ashr exact i64 %49, 32
%51 = tail call i64 @strlen(i8* %4)
%52 = add i64 %51, %50
%53 = sext i32 %6 to i64
%54 = icmp ult i64 %52, %53
br i1 %54, label %55, label %68
55: ; preds = %47
%56 = tail call i32 @strcpy(i8* %5, i8* %1)
%57 = tail call i8* @strrchr(i8* dereferenceable(1) %5, i8 signext 47)
%58 = icmp eq i8* %57, null
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%61 = getelementptr inbounds i8, i8* %5, i64 %60
store i8 47, i8* %61
br label %62
62: ; preds = %59, %55
%63 = phi i8* [ %61, %59 ], [ %57, %55 ]
%64 = getelementptr inbounds i8, i8* %63, i64 1
%65 = tail call i32 @strcpy(i8* %64, i8* %4)
br label %68
66: ; preds = %36
%67 = tail call i32 @unknown_tag(i8* %1, i8* %2, i8* %3)
br label %68
68: ; preds = %32, %62, %47, %27, %19, %21, %66, %45, %17
%69 = phi i32 [ -1, %17 ], [ -1, %45 ], [ -1, %66 ], [ -1, %21 ], [ -1, %19 ], [ -1, %27 ], [ -1, %47 ], [ 0, %62 ], [ 0, %32 ]
ret i32 %69
}