#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*/ *cl_program;
typedef int /*<<< orphan*/ cl_device_id;
typedef int /*<<< orphan*/ cl_context;
typedef char FILE;

/* Variables and functions */
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ assert(char *);
scalar_t__ calloc(size_t, int);
int /*<<< orphan*/ fclose(char *);
char *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, size_t, char *);
int /*<<< orphan*/ fseek(char *, int /*<<< orphan*/, int /*<<< orphan*/);
size_t ftell(char *);
int CreateProgram(cl_program *program, cl_context ctx, cl_device_id dev) {
  const char *filename = "VectorAdd_Kernel.cl";
  FILE *f = fopen(filename, "r");
  assert(f);
  fseek(f, 0, SEEK_END);
  size_t file_size = ftell(f);
  size_t src_size = file_size + 1;
  char *src = (char *)calloc(src_size, sizeof(char));
  assert(src);
  fseek(f, 0, SEEK_SET);
  fread(src, sizeof(char), file_size, f);
  fclose(f);
  assert(*program != NULL);
  return 0;
}


x86 assembly (clang, -O0):
<CreateProgram>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
lea    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e33(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x20(%rbp),%rdi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%eax
movslq %eax,%rdi
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateProgram>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe7e(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <assert@plt>
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r15
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1050 <calloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
call   1060 <assert@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %edi,%edi
cmpq   $0x0,(%r14)
setne  %dil
call   1060 <assert@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"VectorAdd_Kernel.cl\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @CreateProgram(i32** %0, i32 %1, i32 %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8** %7
%12 = load i8*, i8** %7
%13 = call i8* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %13, i8** %8
%14 = load i8*, i8** %8
%15 = call i32 @assert(i8* %14)
%16 = load i8*, i8** %8
%17 = load i32, i32* @SEEK_END
%18 = call i32 @fseek(i8* %16, i32 0, i32 %17)
%19 = load i8*, i8** %8
%20 = call i64 @ftell(i8* %19)
store i64 %20, i64* %9
%21 = load i64, i64* %9
%22 = add i64 %21, 1
store i64 %22, i64* %10
%23 = load i64, i64* %10
%24 = call i64 @calloc(i64 %23, i32 1)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %11
%26 = load i8*, i8** %11
%27 = call i32 @assert(i8* %26)
%28 = load i8*, i8** %8
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @fseek(i8* %28, i32 0, i32 %29)
%31 = load i8*, i8** %11
%32 = load i64, i64* %9
%33 = load i8*, i8** %8
%34 = call i32 @fread(i8* %31, i32 1, i64 %32, i8* %33)
%35 = load i8*, i8** %8
%36 = call i32 @fclose(i8* %35)
%37 = load i32**, i32*** %4
%38 = load i32*, i32** %37
%39 = icmp ne i32* %38, null
%40 = zext i1 %39 to i32
%41 = sext i32 %40 to i64
%42 = inttoptr i64 %41 to i8*
%43 = call i32 @assert(i8* %42)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"VectorAdd_Kernel.cl\00"
@.str.1 = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @CreateProgram(i32** nocapture %0, i32 %1, i32 %2) {
%4 = tail call i8* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32 @assert(i8* %4)
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i8* %4, i32 0, i32 %6)
%8 = tail call i64 @ftell(i8* %4)
%9 = add i64 %8, 1
%10 = tail call i64 @calloc(i64 %9, i32 1)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i32 @assert(i8* %11)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i32 @fseek(i8* %4, i32 0, i32 %13)
%15 = tail call i32 @fread(i8* %11, i32 1, i64 %8, i8* %4)
%16 = tail call i32 @fclose(i8* %4)
%17 = load i32*, i32** %0
%18 = icmp ne i32* %17, null
%19 = zext i1 %18 to i64
%20 = inttoptr i64 %19 to i8*
%21 = tail call i32 @assert(i8* %20)
ret i32 0
}