#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 */
typedef int /*<<< orphan*/ vfilename2;
typedef int /*<<< orphan*/ filename2;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ check_filename(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ get_filename(char *, char *, char *, char *, char *, char *, int);
int /*<<< orphan*/ not_found2(char *, char *, char *);
int /*<<< orphan*/ not_permitted(char *, char *, char *);
int /*<<< orphan*/ read_file(char *, char *, int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
size_t strlen(char *);
char *strrchr(char *, char);
void do_include(char *vfilename, char *filename, FILE *fp, char *directive,
                char *tag, char *val) {
  char vfilename2[1000];
  char filename2[1000];
  FILE *fp2;
  if (get_filename(vfilename, filename, directive, tag, val, filename2,
                   sizeof(filename2)) < 0)
    return;
  if (!check_filename(filename2)) {
    not_permitted(directive, tag, filename2);
    return;
  }
  fp2 = fopen(filename2, "r");
  if (fp2 == (FILE *)0) {
    not_found2(directive, tag, filename2);
    return;
  }
  if (strcmp(tag, "virtual") == 0) {
    if (strlen(val) < sizeof(vfilename2))
      (void)strcpy(vfilename2, val);
    else
      (void)strcpy(vfilename2, filename2);
  } else {
    if (strlen(vfilename) + 1 + strlen(val) < sizeof(vfilename2)) {
      char *cp;
      (void)strcpy(vfilename2, vfilename);
      cp = strrchr(vfilename2, '/');
      if (cp == (char *)0) {
        cp = &vfilename2[strlen(vfilename2)];
        *cp = '/';
      }
      (void)strcpy(++cp, val);
    } else
      (void)strcpy(vfilename2, filename2);
  }
  read_file(vfilename2, filename2, fp2);
  (void)fclose(fp2);
}


x86 assembly (clang, -O0):
<do_include>:
push   %rbp
mov    %rsp,%rbp
sub    $0x830,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
lea    -0x810(%rbp),%r9
movl   $0x3e8,(%rsp)
call   1040 <get_filename@plt>
cmp    $0x0,%rax
jge    1209 <do_include+0x59>
jmp    13c8 <do_include+0x218>
lea    -0x810(%rbp),%rdi
call   10c0 <check_filename@plt>
cmp    $0x0,%eax
jne    1237 <do_include+0x87>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x810(%rbp),%rdx
call   1080 <not_permitted@plt>
jmp    13c8 <do_include+0x218>
lea    -0x810(%rbp),%rdi
lea    0xdbb(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
jne    1278 <do_include+0xc8>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    -0x810(%rbp),%rdx
call   10d0 <not_found2@plt>
jmp    13c8 <do_include+0x218>
mov    -0x28(%rbp),%rdi
lea    0xd7f(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    12d4 <do_include+0x124>
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
cmp    $0x3e8,%rax
jae    12bc <do_include+0x10c>
lea    -0x420(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    12cf <do_include+0x11f>
lea    -0x420(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    13a2 <do_include+0x1f2>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x828(%rbp)
mov    -0x30(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x828(%rbp),%rax
add    %rcx,%rax
cmp    $0x3e8,%rax
jae    138a <do_include+0x1da>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
mov    %rax,-0x820(%rbp)
cmpq   $0x0,-0x820(%rbp)
jne    136a <do_include+0x1ba>
lea    -0x420(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
lea    -0x420(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x820(%rbp)
mov    -0x820(%rbp),%rax
movb   $0x2f,(%rax)
mov    -0x820(%rbp),%rdi
add    $0x1,%rdi
mov    %rdi,-0x820(%rbp)
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    139d <do_include+0x1ed>
lea    -0x420(%rbp),%rdi
lea    -0x810(%rbp),%rsi
call   1030 <strcpy@plt>
jmp    13a2 <do_include+0x1f2>
lea    -0x420(%rbp),%rdi
lea    -0x810(%rbp),%rsi
mov    -0x818(%rbp),%rdx
call   10a0 <read_file@plt>
mov    -0x818(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x830,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_include>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x7f0,%rsp
mov    %r9,%r15
mov    %r8,%rbx
mov    %rcx,%r13
mov    %rdi,%r12
movl   $0x3e8,(%rsp)
lea    0x10(%rsp),%r9
mov    %rcx,%rdx
mov    %r8,%rcx
mov    %r15,%r8
call   1040 <get_filename@plt>
test   %rax,%rax
js     131e <do_include+0x16e>
lea    0x10(%rsp),%rdi
call   10c0 <check_filename@plt>
test   %eax,%eax
je     12ae <do_include+0xfe>
lea    0xdf8(%rip),%rsi
lea    0x10(%rsp),%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     12c0 <do_include+0x110>
mov    %rax,%r14
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     12d2 <do_include+0x122>
mov    %r12,%rdi
call   1060 <strlen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
add    %rbx,%rax
add    $0x1,%rax
cmp    $0x3e7,%rax
ja     12ef <do_include+0x13f>
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1070 <strrchr@plt>
test   %rax,%rax
jne    12a2 <do_include+0xf2>
lea    0x400(%rsp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
add    %rsp,%rax
add    $0x400,%rax
movb   $0x2f,0x400(%rsp,%rcx,1)
2f
add    $0x1,%rax
mov    %rax,%rdi
mov    %r15,%rsi
jmp    12fc <do_include+0x14c>
lea    0x10(%rsp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   1080 <not_permitted@plt>
jmp    131e <do_include+0x16e>
lea    0x10(%rsp),%rdx
mov    %r13,%rdi
mov    %rbx,%rsi
call   10d0 <not_found2@plt>
jmp    131e <do_include+0x16e>
mov    %r15,%rdi
call   1060 <strlen@plt>
cmp    $0x3e7,%rax
ja     12ef <do_include+0x13f>
lea    0x400(%rsp),%rdi
mov    %r15,%rsi
jmp    12fc <do_include+0x14c>
lea    0x400(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <strcpy@plt>
lea    0x400(%rsp),%rdi
lea    0x10(%rsp),%rsi
mov    %r14,%rdx
call   10a0 <read_file@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
add    $0x7f0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"virtual\00"
define void @do_include(i8* %0, i8* %1, i32* %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [1000 x i8]
%14 = alloca [1000 x i8]
%15 = alloca i32*
%16 = alloca i8*
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32* %2, i32** %9
store i8* %3, i8** %10
store i8* %4, i8** %11
store i8* %5, i8** %12
%17 = load i8*, i8** %7
%18 = load i8*, i8** %8
%19 = load i8*, i8** %10
%20 = load i8*, i8** %11
%21 = load i8*, i8** %12
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%23 = call i64 @get_filename(i8* %17, i8* %18, i8* %19, i8* %20, i8* %21, i8* %22, i32 1000)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %6
br label %100
26: ; preds = %6
%27 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%28 = call i32 @check_filename(i8* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %35, label %30
30: ; preds = %26
%31 = load i8*, i8** %10
%32 = load i8*, i8** %11
%33 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%34 = call i32 @not_permitted(i8* %31, i8* %32, i8* %33)
br label %100
35: ; preds = %26
%36 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %15
%38 = load i32*, i32** %15
%39 = icmp eq i32* %38, null
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = load i8*, i8** %10
%42 = load i8*, i8** %11
%43 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%44 = call i32 @not_found2(i8* %41, i8* %42, i8* %43)
br label %100
45: ; preds = %35
%46 = load i8*, i8** %11
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %45
%50 = load i8*, i8** %12
%51 = call i64 @strlen(i8* %50)
%52 = icmp ult i64 %51, 1000
br i1 %52, label %53, label %57
53: ; preds = %49
%54 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%55 = load i8*, i8** %12
%56 = call i32 @strcpy(i8* %54, i8* %55)
br label %61
57: ; preds = %49
%58 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%59 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%60 = call i32 @strcpy(i8* %58, i8* %59)
br label %61
61: ; preds = %57, %53
br label %93
62: ; preds = %45
%63 = load i8*, i8** %7
%64 = call i64 @strlen(i8* %63)
%65 = add i64 %64, 1
%66 = load i8*, i8** %12
%67 = call i64 @strlen(i8* %66)
%68 = add i64 %65, %67
%69 = icmp ult i64 %68, 1000
br i1 %69, label %70, label %88
70: ; preds = %62
%71 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%72 = load i8*, i8** %7
%73 = call i32 @strcpy(i8* %71, i8* %72)
%74 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%75 = call i8* @strrchr(i8* %74, i8 signext 47)
store i8* %75, i8** %16
%76 = load i8*, i8** %16
%77 = icmp eq i8* %76, null
br i1 %77, label %78, label %83
78: ; preds = %70
%79 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%80 = call i64 @strlen(i8* %79)
%81 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 %80
store i8* %81, i8** %16
%82 = load i8*, i8** %16
store i8 47, i8* %82
br label %83
83: ; preds = %78, %70
%84 = load i8*, i8** %16
%85 = getelementptr inbounds i8, i8* %84, i32 1
store i8* %85, i8** %16
%86 = load i8*, i8** %12
%87 = call i32 @strcpy(i8* %85, i8* %86)
br label %92
88: ; preds = %62
%89 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%90 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%91 = call i32 @strcpy(i8* %89, i8* %90)
br label %92
92: ; preds = %88, %83
br label %93
93: ; preds = %92, %61
%94 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%95 = getelementptr inbounds [1000 x i8], [1000 x i8]* %14, i64 0, i64 0
%96 = load i32*, i32** %15
%97 = call i32 @read_file(i8* %94, i8* %95, i32* %96)
%98 = load i32*, i32** %15
%99 = call i32 @fclose(i32* %98)
br label %100
100: ; preds = %93, %40, %30, %25
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [8 x i8] c"virtual\00"
define void @do_include(i8* %0, i8* %1, i32* nocapture readnone %2, i8* %3, i8* %4, i8* %5) {
%7 = alloca [1000 x i8]
%8 = alloca [1000 x i8]
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %8, i64 0, i64 0
%11 = call i64 @get_filename(i8* %0, i8* %1, i8* %3, i8* %4, i8* %5, i8* %10, i32 1000)
%12 = icmp slt i64 %11, 0
br i1 %12, label %55, label %13
13: ; preds = %6
%14 = call i32 @check_filename(i8* %10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @not_permitted(i8* %3, i8* %4, i8* %10)
br label %55
18: ; preds = %13
%19 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @not_found2(i8* %3, i8* %4, i8* %10)
br label %55
23: ; preds = %18
%24 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %23
%27 = call i64 @strlen(i8* dereferenceable(1) %5)
%28 = icmp ult i64 %27, 1000
br i1 %28, label %29, label %31
29: ; preds = %26
%30 = call i32 @strcpy(i8* %9, i8* %5)
br label %52
31: ; preds = %26
%32 = call i32 @strcpy(i8* %9, i8* %10)
br label %52
33: ; preds = %23
%34 = call i64 @strlen(i8* dereferenceable(1) %0)
%35 = add i64 %34, 1
%36 = call i64 @strlen(i8* dereferenceable(1) %5)
%37 = add i64 %35, %36
%38 = icmp ult i64 %37, 1000
br i1 %38, label %39, label %50
39: ; preds = %33
%40 = call i32 @strcpy(i8* %9, i8* %0)
%41 = call i8* @strrchr(i8* %9, i8 signext 47)
%42 = icmp eq i8* %41, null
br i1 %42, label %43, label %46
43: ; preds = %39
%44 = call i64 @strlen(i8* %9)
%45 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 %44
store i8 47, i8* %45
br label %46
46: ; preds = %43, %39
%47 = phi i8* [ %45, %43 ], [ %41, %39 ]
%48 = getelementptr inbounds i8, i8* %47, i64 1
%49 = call i32 @strcpy(i8* %48, i8* %5)
br label %52
50: ; preds = %33
%51 = call i32 @strcpy(i8* %9, i8* %10)
br label %52
52: ; preds = %46, %50, %29, %31
%53 = call i32 @read_file(i8* %9, i8* %10, i32* %19)
%54 = call i32 @fclose(i32* %19)
br label %55
55: ; preds = %6, %52, %21, %16
ret void
}