#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*/ 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, 2048, "%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];
    fgets(line, 2048, example_fh);
    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    1298 <IncludeExampleFile+0xe8>
lea    -0x1020(%rbp),%rdi
mov    -0x818(%rbp),%rdx
mov    $0x800,%esi
call   1070 <fgets@plt>
lea    -0x1020(%rbp),%rdi
lea    0xdad(%rip),%rsi
call   10d0 <strstr@plt>
cmp    $0x0,%rax
je     1293 <IncludeExampleFile+0xe3>
jmp    1298 <IncludeExampleFile+0xe8>
jmp    1238 <IncludeExampleFile+0x88>
jmp    129d <IncludeExampleFile+0xed>
mov    -0x818(%rbp),%rdi
call   1090 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    12be <IncludeExampleFile+0x10e>
jmp    1385 <IncludeExampleFile+0x1d5>
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    1331 <IncludeExampleFile+0x181>
mov    -0x818(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     1331 <IncludeExampleFile+0x181>
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
lea    -0x810(%rbp),%rdx
lea    0xd15(%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    0x2c92(%rip),%rax
mov    (%rax),%ecx
mov    $0x1,%esi
call   10c0 <fwrite@plt>
cmp    -0x2028(%rbp),%rax
jae    1380 <IncludeExampleFile+0x1d0>
mov    0x2c7a(%rip),%rax
mov    (%rax),%edi
lea    0xcf3(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
jmp    129d <IncludeExampleFile+0xed>
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     130d <IncludeExampleFile+0x15d>
mov    %rax,%r12
lea    0x800(%rsp),%r14
lea    0xe27(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    123c <IncludeExampleFile+0x8c>
mov    %r14,%rdi
mov    $0x800,%esi
mov    %r12,%rdx
call   1070 <fgets@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1210 <IncludeExampleFile+0x60>
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
jne    12b1 <IncludeExampleFile+0x101>
lea    0x800(%rsp),%r14
mov    0x2d81(%rip),%r15
nopw   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     128d <IncludeExampleFile+0xdd>
mov    %r12,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
jne    12e9 <IncludeExampleFile+0x139>
mov    (%r15),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    %rbx,%rdx
call   10c0 <fwrite@plt>
cmp    %rbx,%rax
jb     12c8 <IncludeExampleFile+0x118>
mov    %r12,%rdi
call   1090 <feof@plt>
test   %eax,%eax
je     1260 <IncludeExampleFile+0xb0>
mov    %r12,%rdi
call   1050 <fclose@plt>
add    $0x1808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2d11(%rip),%rax
mov    (%rax),%edi
lea    0xd8a(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%edi
lea    0xd3c(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
jmp    12f9 <IncludeExampleFile+0x149>

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 = %37, %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 %38
29: ; preds = %24
%30 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%31 = load i32*, i32** %6
%32 = call i32 @fgets(i8* %30, i32 2048, i32* %31)
%33 = getelementptr inbounds [2048 x i8], [2048 x i8]* %7, i64 0, i64 0
%34 = call i64 @strstr(i8* %33, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
br label %38
37: ; preds = %29
br label %24
38: ; preds = %36, %24
br label %39
39: ; preds = %70, %38
%40 = load i32*, i32** %6
%41 = call i32 @feof(i32* %40)
%42 = icmp ne i32 %41, 0
%43 = xor i1 %42, true
br i1 %43, label %44, label %71
44: ; preds = %39
%45 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%46 = load i32*, i32** %6
%47 = call i64 @fread(i8* %45, i32 1, i32 4096, i32* %46)
store i64 %47, i64* %9
%48 = load i64, i64* %9
%49 = icmp ult i64 %48, 4096
br i1 %49, label %50, label %59
50: ; preds = %44
%51 = load i32*, i32** %6
%52 = call i64 @ferror(i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32, i32* @stderr
%56 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %50, %44
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %8, i64 0, i64 0
%61 = load i64, i64* %9
%62 = load i32, i32* @stdout
%63 = call i64 @fwrite(i8* %60, i32 1, i64 %61, i32 %62)
%64 = load i64, i64* %9
%65 = icmp ult i64 %63, %64
br i1 %65, label %66, label %70
66: ; preds = %59
%67 = load i32, i32* @stderr
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%69 = call i32 @exit(i32 1)
unreachable
70: ; preds = %59
br label %39
71: ; preds = %39
%72 = load i32*, i32** %6
%73 = call i32 @fclose(i32* %72)
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 %12, label %10
10: ; preds = %2
%11 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
br label %16
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %10, %19
%17 = call i32 @feof(i32* %8)
%18 = icmp eq i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = call i32 @fgets(i8* %11, i32 2048, i32* %8)
%21 = call i64 @strstr(i8* %11, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %16, label %23
23: ; preds = %19, %16
%24 = call i32 @feof(i32* %8)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %49
26: ; preds = %23
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
br label %28
28: ; preds = %26, %46
%29 = call i64 @fread(i8* %27, i32 1, i32 4096, i32* %8)
%30 = icmp ult i64 %29, 4096
br i1 %30, label %31, label %38
31: ; preds = %28
%32 = call i64 @ferror(i32* %8)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %31
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31, %28
%39 = load i32, i32* @stdout
%40 = call i64 @fwrite(i8* %27, i32 1, i64 %29, i32 %39)
%41 = icmp ult i64 %40, %29
br i1 %41, label %42, label %46
42: ; preds = %38
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %38
%47 = call i32 @feof(i32* %8)
%48 = icmp eq i32 %47, 0
br i1 %48, label %28, label %49
49: ; preds = %46, %23
%50 = call i32 @fclose(i32* %8)
ret void
}