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

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int /*<<< orphan*/, size_t, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
size_t strlen(char const *);
char *oclLoadProgSource(const char *cFilename, const char *cPreamble,
                        size_t *szFinalLength) {
  FILE *pFileStream = NULL;
  size_t szSourceLength, szPreambleLength;
  char *cSourceString;
  pFileStream = fopen(cFilename, "rb");
  if (pFileStream == 0)
    return NULL;
  szPreambleLength = strlen(cPreamble);
  fseek(pFileStream, 0, SEEK_END);
  szSourceLength = ftell(pFileStream);
  fseek(pFileStream, 0, SEEK_SET);
  cSourceString = (char *)malloc(szSourceLength + szPreambleLength + 1);
  memcpy(cSourceString, cPreamble, szPreambleLength);
  if (fread((cSourceString) + szPreambleLength, szSourceLength, 1,
            pFileStream) != 1) {
    fclose(pFileStream);
    free(cSourceString);
    return 0;
  }
  fclose(pFileStream);
  if (szFinalLength != 0)
    *szFinalLength = szSourceLength + szPreambleLength;
  cSourceString[szSourceLength + szPreambleLength] = '\0';
  return cSourceString;
}


x86 assembly (clang, -O0):
<oclLoadProgSource>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    11d8 <oclLoadProgSource+0x48>
movq   $0x0,-0x8(%rbp)
jmp    12bf <oclLoadProgSource+0x12f>
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2df8(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    -0x30(%rbp),%rdi
add    -0x38(%rbp),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1080 <memcpy@plt>
mov    -0x40(%rbp),%rax
add    -0x38(%rbp),%rax
mov    %eax,%edi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     1284 <oclLoadProgSource+0xf4>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x40(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    12bf <oclLoadProgSource+0x12f>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpq   $0x0,-0x20(%rbp)
je     12a7 <oclLoadProgSource+0x117>
mov    -0x30(%rbp),%rcx
add    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
mov    -0x30(%rbp),%rcx
add    -0x38(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<oclLoadProgSource>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
lea    0xe58(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1251 <oclLoadProgSource+0xc1>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %rax,%r15
mov    0x2e1d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
lea    (%r12,%r15,1),%rdi
add    $0x1,%rdi
call   1090 <malloc@plt>
mov    %rax,%r13
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r15,%rdx
call   1080 <memcpy@plt>
lea    (%r15,%r13,1),%edi
mov    %r12,%rsi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    $0x1,%ebp
jne    1249 <oclLoadProgSource+0xb9>
add    %r15,%r12
test   %r14,%r14
je     1241 <oclLoadProgSource+0xb1>
mov    %r12,(%r14)
movb   $0x0,0x0(%r13,%r12,1)
jmp    1254 <oclLoadProgSource+0xc4>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %r13d,%r13d
mov    %r13,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @oclLoadProgSource(i8* %0, i8* %1, i64* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i64* %2, i64** %7
store i32* null, i32** %8
%12 = load i8*, i8** %5
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %3
store i8* null, i8** %4
br label %68
17: ; preds = %3
%18 = load i8*, i8** %6
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %10
%20 = load i32*, i32** %8
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i32*, i32** %8
%24 = call i64 @ftell(i32* %23)
store i64 %24, i64* %9
%25 = load i32*, i32** %8
%26 = load i32, i32* @SEEK_SET
%27 = call i32 @fseek(i32* %25, i32 0, i32 %26)
%28 = load i64, i64* %9
%29 = load i64, i64* %10
%30 = add i64 %28, %29
%31 = add i64 %30, 1
%32 = call i64 @malloc(i64 %31)
%33 = inttoptr i64 %32 to i8*
store i8* %33, i8** %11
%34 = load i8*, i8** %11
%35 = load i8*, i8** %6
%36 = load i64, i64* %10
%37 = call i32 @memcpy(i8* %34, i8* %35, i64 %36)
%38 = load i8*, i8** %11
%39 = load i64, i64* %10
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = ptrtoint i8* %40 to i32
%42 = load i64, i64* %9
%43 = load i32*, i32** %8
%44 = call i32 @fread(i32 %41, i64 %42, i32 1, i32* %43)
%45 = icmp ne i32 %44, 1
br i1 %45, label %46, label %51
46: ; preds = %17
%47 = load i32*, i32** %8
%48 = call i32 @fclose(i32* %47)
%49 = load i8*, i8** %11
%50 = call i32 @free(i8* %49)
store i8* null, i8** %4
br label %68
51: ; preds = %17
%52 = load i32*, i32** %8
%53 = call i32 @fclose(i32* %52)
%54 = load i64*, i64** %7
%55 = icmp ne i64* %54, null
br i1 %55, label %56, label %61
56: ; preds = %51
%57 = load i64, i64* %9
%58 = load i64, i64* %10
%59 = add i64 %57, %58
%60 = load i64*, i64** %7
store i64 %59, i64* %60
br label %61
61: ; preds = %56, %51
%62 = load i8*, i8** %11
%63 = load i64, i64* %9
%64 = load i64, i64* %10
%65 = add i64 %63, %64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %11
store i8* %67, i8** %4
br label %68
68: ; preds = %61, %46, %16
%69 = load i8*, i8** %4
ret i8* %69
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @oclLoadProgSource(i8* nocapture %0, i8* %1, i64* writeonly %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %31, label %6
6: ; preds = %3
%7 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %4, i32 0, i32 %8)
%10 = tail call i64 @ftell(i32* %4)
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @fseek(i32* %4, i32 0, i32 %11)
%13 = add i64 %10, %7
%14 = add i64 %13, 1
%15 = tail call i64 @malloc(i64 %14)
%16 = inttoptr i64 %15 to i8*
%17 = tail call i32 @memcpy(i8* %16, i8* %1, i64 %7)
%18 = getelementptr inbounds i8, i8* %16, i64 %7
%19 = ptrtoint i8* %18 to i64
%20 = trunc i64 %19 to i32
%21 = tail call i32 @fread(i32 %20, i64 %10, i32 1, i32* %4)
%22 = icmp eq i32 %21, 1
%23 = tail call i32 @fclose(i32* %4)
br i1 %22, label %26, label %24
24: ; preds = %6
%25 = tail call i32 @free(i8* %16)
br label %31
26: ; preds = %6
%27 = icmp eq i64* %2, null
br i1 %27, label %29, label %28
28: ; preds = %26
store i64 %13, i64* %2
br label %29
29: ; preds = %28, %26
%30 = getelementptr inbounds i8, i8* %16, i64 %13
store i8 0, i8* %30
br label %31
31: ; preds = %3, %29, %24
%32 = phi i8* [ null, %24 ], [ %16, %29 ], [ null, %3 ]
ret i8* %32
}