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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(char *, int, size_t, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
scalar_t__ strstr(char *, char *);
void IncludeExampleFile(const char *examples_dir, const char *filename) {
  char path[2048];
  snprintf(path, sizeof(path), "%s/%s", examples_dir, filename);
  FILE *example_fh = fopen(path, "r");
  if (example_fh == NULL) {
    fprintf(stderr, "Unable to find file %s to include.\n", path);
    exit(1);
  }
  while (!feof(example_fh)) {
    char line[2048];
    line[0] = '\0';
    if (fgets(line, sizeof(line), example_fh) != NULL) {
      if (strstr(line, "COSL.txt")) {
        break;
      }
    }
  }
  while (!feof(example_fh)) {
    char buf[4096];
    size_t read_ = fread(buf, 1, 4096, example_fh);
    if (read_ < 4096 && ferror(example_fh)) {
      fprintf(stderr, "Error reading example file %s. Bailing out.\n", path);
      exit(1);
    }
    if (fwrite(buf, 1, read_, stdout) < read_) {
      fprintf(stderr, "Error writing to stdout. Bailing out.\n");
      exit(1);
    }
  }
  fclose(example_fh);
}


x86 assembly (clang, -O0):
<IncludeExampleFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    $0x800,%esi
lea    0xe22(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x810(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x818(%rbp)
cmpq   $0x0,-0x818(%rbp)
jne    1233 <IncludeExampleFile+0x83>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    1238 <IncludeExampleFile+0x88>
mov    -0x818(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1259 <IncludeExampleFile+0xa9>
jmp    12ae <IncludeExampleFile+0xfe>
movb   $0x0,-0x1020(%rbp)
lea    -0x1020(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
cmp    $0x0,%rax
je     12a9 <IncludeExampleFile+0xf9>
lea    -0x1020(%rbp),%rdi
lea    0xd9c(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     12a4 <IncludeExampleFile+0xf4>
jmp    12ae <IncludeExampleFile+0xfe>
jmp    12a9 <IncludeExampleFile+0xf9>
jmp    1238 <IncludeExampleFile+0x88>
jmp    12b3 <IncludeExampleFile+0x103>
mov    -0x818(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12d4 <IncludeExampleFile+0x124>
jmp    139b <IncludeExampleFile+0x1eb>
lea    -0x2020(%rbp),%rdi
mov    -0x818(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1000,%edx
call   1040 <fread@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x1000,-0x2028(%rbp)
jae    1347 <IncludeExampleFile+0x197>
mov    -0x818(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1347 <IncludeExampleFile+0x197>
mov    0x2cba(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xcff(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0x2020(%rbp),%rdi
mov    -0x2028(%rbp),%rdx
mov    0x2c7c(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
cmp    -0x2028(%rbp),%rax
jae    1396 <IncludeExampleFile+0x1e6>
mov    0x2c64(%rip),%rax
mov    (%rax),%edi
lea    0xcdd(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    12b3 <IncludeExampleFile+0x103>
mov    -0x818(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<IncludeExampleFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1808,%rsp
mov    %rsi,%r8
mov    %rdi,%rcx
lea    0xe35(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1060 <snprintf@plt>
lea    0xe24(%rip),%rsi
mov    %rbx,%rdi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1337 <IncludeExampleFile+0x187>
mov    %rax,%r12
mov    %rax,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     129c <IncludeExampleFile+0xec>
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1285 <IncludeExampleFile+0xd5>
lea    0x800(%rsp),%r14
mov    0x2db7(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1000,%edx
mov    %r12,%rcx
call   1040 <fread@plt>
mov    %rax,%rbx
cmp    $0xfff,%rax
ja     1261 <IncludeExampleFile+0xb1>
mov    %r12,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    1313 <IncludeExampleFile+0x163>
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   10c0 <fwrite@plt>
cmp    %rbx,%rax
jb     12f2 <IncludeExampleFile+0x142>
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1230 <IncludeExampleFile+0x80>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x1808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0x800(%rsp),%r14
lea    0xd81(%rip),%r15
jmp    12c0 <IncludeExampleFile+0x110>
nopl   (%rax)
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    1206 <IncludeExampleFile+0x56>
movb   $0x0,0x800(%rsp)
mov    %r14,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
test   %rax,%rax
je     12b0 <IncludeExampleFile+0x100>
mov    %r14,%rdi
mov    %r15,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     12b0 <IncludeExampleFile+0x100>
jmp    1206 <IncludeExampleFile+0x56>
mov    0x2ce7(%rip),%rax
mov    (%rax),%edi
lea    0xd60(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cc6(%rip),%rax
mov    (%rax),%edi
lea    0xd12(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2ca2(%rip),%rax
mov    (%rax),%edi
lea    0xcc1(%rip),%rsi
jmp    1323 <IncludeExampleFile+0x173>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to find file %s to include.\0A\00"
@.str.3 = [9 x i8] c"COSL.txt\00"
@.str.4 = [45 x i8] c"Error reading example file %s. Bailing out.\0A\00"
@stdout = global i32 0
@.str.5 = [39 x i8] c"Error writing to stdout. Bailing out.\0A\00"
define void @IncludeExampleFile(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [2048 x i8]
%6 = alloca i32*
%7 = alloca [2048 x i8]
%8 = alloca [4096 x i8]
%9 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = load i8*, i8** %4
%13 = call i32 @snprintf(i8* %10, i32 2048, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32*, i32** %6
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %23
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
br label %24
24: ; preds = %41, %23
%25 = load i32*, i32** %6
%26 = call i32 @feof(i32* %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
br i1 %28, label %29, label %42
29: ; preds = %24
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
store i8 0, i8* %30
%31 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%32 = load i32*, i32** %6
%33 = call i32* @fgets(i8* %31, i32 2048, i32* %32)
%34 = icmp ne i32* %33, null
br i1 %34, label %35, label %41
35: ; preds = %29
%36 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%37 = call i64 @strstr(i8* %36, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %40
39: ; preds = %35
br label %42
40: ; preds = %35
br label %41
41: ; preds = %40, %29
br label %24
42: ; preds = %39, %24
br label %43
43: ; preds = %74, %42
%44 = load i32*, i32** %6
%45 = call i32 @feof(i32* %44)
%46 = icmp ne i32 %45, 0
%47 = xor i1 %46, true
br i1 %47, label %48, label %75
48: ; preds = %43
%49 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%50 = load i32*, i32** %6
%51 = call i64 @fread(i8* %49, i32 1, i32 4096, i32* %50)
store i64 %51, i64* %9
%52 = load i64, i64* %9
%53 = icmp ult i64 %52, 4096
br i1 %53, label %54, label %63
54: ; preds = %48
%55 = load i32*, i32** %6
%56 = call i64 @ferror(i32* %55)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %63
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %60)
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %54, %48
%64 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%65 = load i64, i64* %9
%66 = load i32, i32* @stdout
%67 = call i64 @fwrite(i8* %64, i32 1, i64 %65, i32 %66)
%68 = load i64, i64* %9
%69 = icmp ult i64 %67, %68
br i1 %69, label %70, label %74
70: ; preds = %63
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %63
br label %43
75: ; preds = %43
%76 = load i32*, i32** %6
%77 = call i32 @fclose(i32* %76)
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Unable to find file %s to include.\0A\00"
@.str.3 = [9 x i8] c"COSL.txt\00"
@.str.4 = [45 x i8] c"Error reading example file %s. Bailing out.\0A\00"
@stdout = global i32 0
@.str.5 = [39 x i8] c"Error writing to stdout. Bailing out.\0A\00"
define void @IncludeExampleFile(i8* %0, i8* %1) {
%3 = alloca [2048 x i8]
%4 = alloca [2048 x i8]
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%8 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = call i32 @feof(i32* %8)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %29
13: ; preds = %10
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
br label %19
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13, %26
store i8 0, i8* %14
%20 = call i32* @fgets(i8* %14, i32 2048, i32* %8)
%21 = icmp eq i32* %20, null
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = call i64 @strstr(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %22
br label %29
26: ; preds = %19, %22
%27 = call i32 @feof(i32* %8)
%28 = icmp eq i32 %27, 0
br i1 %28, label %19, label %29
29: ; preds = %26, %10, %25
%30 = call i32 @feof(i32* %8)
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %55
32: ; preds = %29
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
br label %34
34: ; preds = %32, %52
%35 = call i64 @fread(i8* %33, i32 1, i32 4096, i32* %8)
%36 = icmp ult i64 %35, 4096
br i1 %36, label %37, label %44
37: ; preds = %34
%38 = call i64 @ferror(i32* %8)
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37, %34
%45 = load i32, i32* @stdout
%46 = call i64 @fwrite(i8* %33, i32 1, i64 %35, i32 %45)
%47 = icmp ult i64 %46, %35
br i1 %47, label %48, label %52
48: ; preds = %44
%49 = load i32, i32* @stderr
%50 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 1)
unreachable
52: ; preds = %44
%53 = call i32 @feof(i32* %8)
%54 = icmp eq i32 %53, 0
br i1 %54, label %34, label %55
55: ; preds = %52, %29
%56 = call i32 @fclose(i32* %8)
ret void
}